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

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.

  • 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. – PSkocik Jul 28 '18 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? – slm Jul 28 '18 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.