linutil/core/tabs/utils/numlock.sh
Adam Perkowski 216f1a4836
Restructure the crates (#549)
* BIG CHANGES

* core metadata

* Added readme.md to the package

* Moved the crate back to tui

Co-authored-by: Liam <lj3954@users.noreply.github.com>

---------

Co-authored-by: Liam <lj3954@users.noreply.github.com>
2024-09-19 19:09:53 -05:00

65 lines
1.4 KiB
Bash
Executable File

#!/bin/sh -e
. ../common-script.sh
# setleds can be used in all distros
# This method works by calling a script using systemd service
# Create a script to toggle numlock
create_file() {
printf "Creating script...\n"
"$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF'
#!/bin/bash
for tty in /dev/tty{1..6}
do
/usr/bin/setleds -D +num < "$tty";
done
EOF
"$ESCALATION_TOOL" chmod +x /usr/local/bin/numlock
}
# Create a systemd service to run the script on boot
create_service() {
printf "Creating service...\n"
"$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF'
[Unit]
Description=numlock
[Service]
ExecStart=/usr/local/bin/numlock
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
}
numlockSetup() {
# Check if the script and service files exists
if [ ! -f "/usr/local/bin/numlock" ]; then
create_file
fi
if [ ! -f "/etc/systemd/system/numlock.service" ]; then
create_service
fi
printf "Do you want to enable Numlock on boot? (y/n): "
read -r confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
"$ESCALATION_TOOL" systemctl enable numlock.service --quiet
printf "Numlock will be enabled on boot\n"
else
"$ESCALATION_TOOL" systemctl disable numlock.service --quiet
printf "Numlock will not be enabled on boot\n"
fi
}
checkEnv
checkEscalationTool
numlockSetup