You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

4 years ago
#!/usr/bin/env bash
11 months ago
script_cmdline() {
4 years ago
local param
11 months ago
for param in $(</proc/cmdline); do
4 years ago
case "${param}" in
11 months ago
script=*)
echo "${param#*=}"
return 0
;;
4 years ago
esac
done
}
11 months ago
automated_script() {
4 years ago
local script rt
script="$(script_cmdline)"
if [[ -n "${script}" && ! -x /tmp/startup_script ]]; then
11 months ago
if [[ "${script}" =~ ^((http|https|ftp|tftp)://) ]]; then
2 years ago
# there's no synchronization for network availability before executing this script
printf '%s: waiting for network-online.target\n' "$0"
until systemctl --quiet is-active network-online.target; do
sleep 1
done
printf '%s: downloading %s\n' "$0" "${script}"
curl "${script}" --location --retry-connrefused --retry 10 -s -o /tmp/startup_script
4 years ago
rt=$?
else
cp "${script}" /tmp/startup_script
rt=$?
fi
if [[ ${rt} -eq 0 ]]; then
chmod +x /tmp/startup_script
2 years ago
printf '%s: executing automated script\n' "$0"
# note that script is executed when other services (like pacman-init) may be still in progress, please
# synchronize to "systemctl is-system-running --wait" when your script depends on other services
4 years ago
/tmp/startup_script
fi
fi
}
if [[ $(tty) == "/dev/tty1" ]]; then
automated_script
fi