2024-08-17 10:31:05 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2024-08-30 00:55:25 +01:00
|
|
|
. ../common-script.sh
|
2024-10-13 08:39:18 +01:00
|
|
|
. ../common-service-script.sh
|
2024-08-30 00:55:25 +01:00
|
|
|
|
2024-08-17 10:31:05 +01:00
|
|
|
# setleds can be used in all distros
|
|
|
|
# This method works by calling a script using systemd service
|
|
|
|
|
|
|
|
# Create a script to toggle numlock
|
2024-08-30 00:55:25 +01:00
|
|
|
|
2024-08-17 10:31:05 +01:00
|
|
|
create_file() {
|
2024-09-20 02:13:04 +01:00
|
|
|
printf "%b\n" "Creating script..."
|
2024-09-19 01:03:32 +01:00
|
|
|
"$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF'
|
2024-08-17 10:31:05 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
for tty in /dev/tty{1..6}
|
|
|
|
do
|
|
|
|
/usr/bin/setleds -D +num < "$tty";
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
|
2024-09-19 01:03:32 +01:00
|
|
|
"$ESCALATION_TOOL" chmod +x /usr/local/bin/numlock
|
2024-08-17 10:31:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create a systemd service to run the script on boot
|
|
|
|
create_service() {
|
2024-09-20 02:13:04 +01:00
|
|
|
printf "%b\n" "Creating service..."
|
2024-09-19 01:03:32 +01:00
|
|
|
"$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF'
|
2024-08-17 10:31:05 +01:00
|
|
|
[Unit]
|
|
|
|
Description=numlock
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=/usr/local/bin/numlock
|
|
|
|
StandardInput=tty
|
|
|
|
RemainAfterExit=yes
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2024-08-30 00:55:25 +01:00
|
|
|
numlockSetup() {
|
2024-08-17 10:31:05 +01:00
|
|
|
# Check if the script and service files exists
|
2024-10-13 08:39:18 +01:00
|
|
|
if [ "$PACKAGER" = "apk" ]; then
|
|
|
|
printf "%b\n" "${RED}Unsupported package manager.${RC}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-17 10:31:05 +01:00
|
|
|
if [ ! -f "/usr/local/bin/numlock" ]; then
|
|
|
|
create_file
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "/etc/systemd/system/numlock.service" ]; then
|
|
|
|
create_service
|
|
|
|
fi
|
|
|
|
|
2024-09-22 17:01:10 +01:00
|
|
|
printf "%b" "Do you want to enable Numlock on boot? (y/N): "
|
2024-08-17 10:31:05 +01:00
|
|
|
read -r confirm
|
|
|
|
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
|
2024-10-13 08:39:18 +01:00
|
|
|
enableService numlock
|
2024-09-20 02:13:04 +01:00
|
|
|
printf "%b\n" "Numlock will be enabled on boot"
|
2024-08-17 10:31:05 +01:00
|
|
|
else
|
2024-10-13 08:39:18 +01:00
|
|
|
disableService numlock
|
2024-09-20 02:13:04 +01:00
|
|
|
printf "%b\n" "Numlock will not be enabled on boot"
|
2024-08-17 10:31:05 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-09-17 13:23:23 +01:00
|
|
|
checkEnv
|
2024-08-30 00:55:25 +01:00
|
|
|
checkEscalationTool
|
|
|
|
numlockSetup
|