0

I'm trying to run a script at startup as root.

(Just sets up a root-owned directory in /tmp).

Currently, I'm using this script to set up the boot hook and it appears to get the job done:

#!/bin/sh -eu
if [ 0 -eq $((${1:-0})) ]; then
    #install
    [ -x /etc/init.d/tmpsetup ] ||  {
        cat > /etc/init.d/tmpsetup <<'EOF'
#!/bin/sh -eu
[ $(id -u) -eq 0 ]
umask 0222
mkdir -p /tmp/u/
EOF
        chmod a+rx /etc/init.d/tmpsetup
        update-rc.d tmpsetup defaults 99
        }
else
    #uninstall
        rm -f /etc/init.d/tmpsetup
        update-rc.d tmpsetup remove
fi

Is there a more portable/better way to do it?

(It's to implement a /tmp per user feature. Should be part of an install script that adapts an existing system.)

1 Answer 1

1

I would've just put this into /etc/rc.local instead:

umask 0222 && mkdir -p /tmp/u/

Making a service around this seems like it's over complicating things.

2
  • Thanks. I want to be able to graft this onto an existing system without causing clashes, though (In actuality, all the filenames are namespaced but I removed the namespace before posting). This looks like a file only local admins should be writing into. Commented Jul 28, 2018 at 21:04
  • @PSkocik - this file is meant for modifications that are system specific. The introduction of this /tmp/u directory for the root user would qualify under that, IMO. Unless I'm missing something. Perhaps expand your Q? Commented Jul 28, 2018 at 21:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.