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.)