#How to run an interactive .sh script as root at boot?

11 messages · Page 1 of 1 (latest)

hard ibex
#

/usr/local/bin/auto_update.sh :

`!/bin/bash

Check if user presses a key within 5 seconds

echo "Press any key within 5 seconds to stop system update..."
read -t 5 -n 1 key

if [[ $? -eq 0 ]]; then
echo "Update script skipped by user."
exit 0
fi

echo "Running update script..."

rate-mirrors --allow-root --per-mirror-timeout 500 arch | sudo tee /etc/pacman.d/mirrorlist
sudo pacman -Syu`

I want this to be run at boot. And I want to see the output before the GUI loads.

wraith flint
#

put the script in ~/.config/autostart and make sure it is executable

ashen ferry
#

But I'm not really sure how exactly systemd does that

stable pike
#

@hard ibex root or sudo?

rugged thunder
#

@hard ibex I figured this out!

#

the one thing I need to know is whether you use the default getty login or a display manager

#

in the case of a getty, it’s super simple: add the following to /etc/systemd/system/[email protected]/[config name].conf

[Service]
ExecStartPre=/usr/local/bin/auto_update.sh
#

this executes your script before running the getty command, and it just works because the getty service already initialised the terminal for you

#

if you use a display manager, you’ll have to do more work and add a new service: /etc/systemd/system/[your service name].service

#
[Unit]
Description=Add description here
Before=display-manager.service

# if using Plymouth, make it exit first; if not using Plymouth, no need to add this
After=plymouth-quit.service
Requires=plymouth-quit.service

[Service]
Type=oneshot # only start display manager after script finishes
ExecStart=/usr/local/bin/auto_update.sh

# set up tty
StandardInput=tty
StandardOutput=tty

[Install]
WantedBy=display-manager.service