Always use printf with %b\n unless a different var is needed (#547)

* Always use printf with %b\n unless a different var is needed

* fix some conflicts

* fix conflicts

* Update ssh.sh

---------

Co-authored-by: nnyyxxxx <nnyyxxxx@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
Nyx 2024-09-19 21:13:04 -04:00 committed by GitHub
parent d6d27980de
commit 28533b9f38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 138 additions and 139 deletions

View File

@ -1,4 +1,5 @@
#!/bin/sh -e #!/bin/sh -e
. ../common-script.sh . ../common-script.sh
themeinstall(){ themeinstall(){

View File

@ -157,8 +157,8 @@ configure_firewall() {
} }
setup_ssh_samba(){ setup_ssh_samba(){
printf "Samba and SSH Setup Script\n" printf "%b\n" "Samba and SSH Setup Script"
printf "----------------------------\n" printf "%b\n" "--------------------------"
clear clear
# Display menu # Display menu

View File

@ -4,18 +4,18 @@
# Function to list common session options # Function to list common session options
list_sessions() { list_sessions() {
printf "Select the session:\n" printf "%b\n" "Select the session:"
printf "1) GNOME (gnome.desktop)\n" printf "%b\n" "1) GNOME (gnome.desktop)"
printf "2) KDE Plasma (plasma.desktop)\n" printf "%b\n" "2) KDE Plasma (plasma.desktop)"
printf "3) XFCE (xfce.desktop)\n" printf "%b\n" "3) XFCE (xfce.desktop)"
printf "4) LXDE (LXDE.desktop)\n" printf "%b\n" "4) LXDE (LXDE.desktop)"
printf "5) LXQt (lxqt.desktop)\n" printf "%b\n" "5) LXQt (lxqt.desktop)"
printf "6) Cinnamon (cinnamon.desktop)\n" printf "%b\n" "6) Cinnamon (cinnamon.desktop)"
printf "7) MATE (mate.desktop)\n" printf "%b\n" "7) MATE (mate.desktop)"
printf "8) Openbox (openbox.desktop)\n" printf "%b\n" "8) Openbox (openbox.desktop)"
printf "9) i3 (i3.desktop)\n" printf "%b\n" "9) i3 (i3.desktop)"
printf "10) Custom session\n" printf "%b\n" "10) Custom session"
printf "Enter your choice [1-10]: " printf "%b\n" "Enter your choice [1-10]: "
read -r session_choice read -r session_choice
case "$session_choice" in case "$session_choice" in
@ -29,62 +29,59 @@ list_sessions() {
8) session="openbox.desktop" ;; 8) session="openbox.desktop" ;;
9) session="i3.desktop" ;; 9) session="i3.desktop" ;;
10) 10)
printf "Enter custom session name (e.g., mysession.desktop): " printf "%b\n" "Enter custom session name (e.g., mysession.desktop): "
read -r session ;; read -r session ;;
*) *)
printf "Invalid option selected.\n" printf "%b\n" "Invalid option selected."
exit 1 ;; exit 1 ;;
esac esac
} }
# Function to configure LightDM # Function to configure LightDM
configure_lightdm() { configure_lightdm() {
printf "Configuring LightDM for autologin...\n" printf "%b\n" "Configuring LightDM for autologin..."
printf "%b\n" "Enter username for LightDM autologin: "
printf "Enter username for LightDM autologin: "
read -r user read -r user
"$ESCALATION_TOOL" "printf '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf" "$ESCALATION_TOOL" "printf '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
"$ESCALATION_TOOL" "printf 'autologin-user=$user' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf" "$ESCALATION_TOOL" "printf 'autologin-user=$user' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
"$ESCALATION_TOOL" "printf 'autologin-user-timeout=0' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf" "$ESCALATION_TOOL" "printf 'autologin-user-timeout=0' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
printf "LightDM has been configured for autologin.\n" printf "%b\n" "LightDM has been configured for autologin."
} }
# Function to remove LightDM autologin # Function to remove LightDM autologin
remove_lightdm_autologin() { remove_lightdm_autologin() {
printf "Removing LightDM autologin configuration...\n" printf "%b\n" "Removing LightDM autologin configuration..."
"$ESCALATION_TOOL" rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf "$ESCALATION_TOOL" rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf
printf "LightDM autologin configuration has been removed.\n" printf "%b\n" "LightDM autologin configuration has been removed."
} }
# Function to configure GDM # Function to configure GDM
configure_gdm() { configure_gdm() {
printf "Configuring GDM for autologin...\n" printf "%b\n" "Configuring GDM for autologin..."
printf "%b\n" "Enter username for GDM autologin: "
printf "Enter username for GDM autologin: "
read -r user read -r user
"$ESCALATION_TOOL" "printf '[daemon]' > /etc/gdm/custom.conf" "$ESCALATION_TOOL" "printf '[daemon]' > /etc/gdm/custom.conf"
"$ESCALATION_TOOL" "printf 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf" "$ESCALATION_TOOL" "printf 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
"$ESCALATION_TOOL" "printf 'AutomaticLogin = $user' >> /etc/gdm/custom.conf" "$ESCALATION_TOOL" "printf 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
printf "GDM has been configured for autologin.\n" printf "%b\n" "GDM has been configured for autologin."
} }
# Function to remove GDM autologin # Function to remove GDM autologin
remove_gdm_autologin() { remove_gdm_autologin() {
printf "Removing GDM autologin configuration...\n" printf "%b\n" "Removing GDM autologin configuration..."
"$ESCALATION_TOOL" sed -i '/AutomaticLoginEnable/d' /etc/gdm/custom.conf "$ESCALATION_TOOL" sed -i '/AutomaticLoginEnable/d' /etc/gdm/custom.conf
"$ESCALATION_TOOL" sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf "$ESCALATION_TOOL" sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
printf "GDM autologin configuration has been removed.\n" printf "%b\n" "GDM autologin configuration has been removed."
} }
# Function to configure SDDM # Function to configure SDDM
configure_sddm() { configure_sddm() {
printf "Configuring SDDM for autologin...\n" printf "%b\n" "Configuring SDDM for autologin..."
printf "%b\n" "Enter username for SDDM autologin: "
printf "Enter username for SDDM autologin: "
read -r user read -r user
list_sessions # Show session options list_sessions # Show session options
@ -92,53 +89,52 @@ configure_sddm() {
"$ESCALATION_TOOL" "printf 'User=$user' >> /etc/sddm.conf" "$ESCALATION_TOOL" "printf 'User=$user' >> /etc/sddm.conf"
"$ESCALATION_TOOL" "printf 'Session=$session' >> /etc/sddm.conf" "$ESCALATION_TOOL" "printf 'Session=$session' >> /etc/sddm.conf"
printf "SDDM has been configured for autologin.\n" printf "%b\n" "SDDM has been configured for autologin."
} }
# Function to remove SDDM autologin # Function to remove SDDM autologin
remove_sddm_autologin() { remove_sddm_autologin() {
printf "Removing SDDM autologin configuration...\n" printf "%b\n" "Removing SDDM autologin configuration..."
"$ESCALATION_TOOL" sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf "$ESCALATION_TOOL" sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf
printf "SDDM autologin configuration has been removed.\n" printf "%b\n" "SDDM autologin configuration has been removed."
} }
# Function to configure LXDM # Function to configure LXDM
configure_lxdm() { configure_lxdm() {
printf "Configuring LXDM for autologin...\n" printf "%b\n" "Configuring LXDM for autologin..."
printf "%b\n" "Enter username for LXDM autologin: "
printf "Enter username for LXDM autologin: "
read -r user read -r user
list_sessions # Show session options list_sessions # Show session options
"$ESCALATION_TOOL" sed -i "s/^#.*autologin=.*$/autologin=${user}/" /etc/lxdm/lxdm.conf "$ESCALATION_TOOL" sed -i "s/^#.*autologin=.*$/autologin=${user}/" /etc/lxdm/lxdm.conf
"$ESCALATION_TOOL" sed -i "s|^#.*session=.*$|session=/usr/bin/${session}|; s|^session=.*$|session=/usr/bin/${session}|" /etc/lxdm/lxdm.conf "$ESCALATION_TOOL" sed -i "s|^#.*session=.*$|session=/usr/bin/${session}|; s|^session=.*$|session=/usr/bin/${session}|" /etc/lxdm/lxdm.conf
printf "LXDM has been configured for autologin.\n" printf "%b\n" "LXDM has been configured for autologin."
} }
# Function to remove LXDM autologin # Function to remove LXDM autologin
remove_lxdm_autologin() { remove_lxdm_autologin() {
printf "Removing LXDM autologin configuration...\n" printf "%b\n" "Removing LXDM autologin configuration..."
"$ESCALATION_TOOL" sed -i "s/^autologin=.*$/#autologin=/" /etc/lxdm/lxdm.conf "$ESCALATION_TOOL" sed -i "s/^autologin=.*$/#autologin=/" /etc/lxdm/lxdm.conf
"$ESCALATION_TOOL" sed -i "s/^session=.*$/#session=/" /etc/lxdm/lxdm.conf "$ESCALATION_TOOL" sed -i "s/^session=.*$/#session=/" /etc/lxdm/lxdm.conf
printf "LXDM autologin configuration has been removed.\n" printf "%b\n" "LXDM autologin configuration has been removed."
} }
# Function to configure or remove autologin based on user choice # Function to configure or remove autologin based on user choice
configure_or_remove_autologin() { configure_or_remove_autologin() {
printf "Do you want to add or remove autologin?\n" printf "%b\n" "Do you want to add or remove autologin?"
printf "1) Add autologin\n" printf "%b\n" "1) Add autologin"
printf "2) Remove autologin\n" printf "%b\n" "2) Remove autologin"
printf "Enter your choice [1-2]: " printf "%b\n" "Enter your choice [1-2]: "
read -r action_choice read -r action_choice
if [ "$action_choice" = "1" ]; then if [ "$action_choice" = "1" ]; then
printf "Choose the display manager to configure:\n" printf "%b\n" "Choose the display manager to configure:"
printf "1) LightDM\n" printf "%b\n" "1) LightDM"
printf "2) GDM\n" printf "%b\n" "2) GDM"
printf "3) SDDM\n" printf "%b\n" "3) SDDM"
printf "4) LXDM\n" printf "%b\n" "4) LXDM"
printf "Enter your choice [1-4]: " printf "%b\n" "Enter your choice [1-4]: "
read -r choice read -r choice
case "$choice" in case "$choice" in
@ -146,15 +142,15 @@ configure_or_remove_autologin() {
2) configure_gdm ;; 2) configure_gdm ;;
3) configure_sddm ;; 3) configure_sddm ;;
4) configure_lxdm ;; 4) configure_lxdm ;;
*) printf "Invalid option selected.\n" ;; *) printf "%b\n" "Invalid option selected." ;;
esac esac
elif [ "$action_choice" = "2" ]; then elif [ "$action_choice" = "2" ]; then
printf "Choose the display manager to remove autologin:\n" printf "%b\n" "Choose the display manager to remove autologin:"
printf "1) LightDM\n" printf "%b\n" "1) LightDM"
printf "2) GDM\n" printf "%b\n" "2) GDM"
printf "3) SDDM\n" printf "%b\n" "3) SDDM"
printf "4) LXDM\n" printf "%b\n" "4) LXDM"
printf "Enter your choice [1-4]: " printf "%b\n" "Enter your choice [1-4]: "
read -r choice read -r choice
case "$choice" in case "$choice" in
@ -162,14 +158,14 @@ configure_or_remove_autologin() {
2) remove_gdm_autologin ;; 2) remove_gdm_autologin ;;
3) remove_sddm_autologin ;; 3) remove_sddm_autologin ;;
4) remove_lxdm_autologin ;; 4) remove_lxdm_autologin ;;
*) printf "Invalid option selected.\n" ;; *) printf "%b\n" "Invalid option selected." ;;
esac esac
else else
printf "Invalid choice. Exiting...\n" printf "%b\n" "Invalid choice. Exiting..."
exit 1 exit 1
fi fi
printf "Action completed. Exiting...\n" printf "%b\n" "Action completed. Exiting..."
exit 0 exit 0
} }

View File

@ -5,7 +5,7 @@
# Function to display usage instructions # Function to display usage instructions
usage() { usage() {
printf "%b\n" "${RED} Usage: $0 ${RC}" printf "%b\n" "${RED} Usage: $0 ${RC}"
printf "No arguments needed. The script will prompt for ISO path and USB device.\n" printf "%b\n" "No arguments needed. The script will prompt for ISO path and USB device."
exit 1 exit 1
} }
@ -98,9 +98,9 @@ choose_iso_source() {
fetch_iso_urls() { fetch_iso_urls() {
clear clear
printf "%b\n" "${YELLOW}Available ISOs for download:${RC}" printf "%b\n" "${YELLOW}Available ISOs for download:${RC}"
printf "1) Arch Linux (latest)\n" printf "%b\n" "1) Arch Linux (latest)"
printf "2) Arch Linux (older versions)\n" printf "%b\n" "2) Arch Linux (older versions)"
printf "3) Debian Linux (latest)\n" printf "%b\n" "3) Debian Linux (latest)"
printf "\n" printf "\n"
printf "Select the ISO you want to download (1-3): " printf "Select the ISO you want to download (1-3): "
read -r ISO_OPTION read -r ISO_OPTION

View File

@ -22,39 +22,39 @@ if ! command_exists openssl; then
*) *)
printf "%b\n" "${RED}Your Linux distribution is not supported by this script.${RC}" printf "%b\n" "${RED}Your Linux distribution is not supported by this script.${RC}"
printf "%b\n" "${YELLOW}You can try installing OpenSSL manually:${RC}" printf "%b\n" "${YELLOW}You can try installing OpenSSL manually:${RC}"
echo "1. Refer to your distribution's documentation." printf "%b\n" "1. Refer to your distribution's documentation."
;; ;;
esac esac
fi fi
show_menu() { show_menu() {
echo "========================================================" printf "%b\n" "========================================================"
echo " File/Directory Encryption/Decryption" printf "%b\n" " File/Directory Encryption/Decryption"
echo "========================================================" printf "%b\n" "========================================================"
echo "How to use:-" printf "%b\n" "How to use:-"
echo "if you encrypt or decrypt a file include new file name for successful operation" printf "%b\n" "if you encrypt or decrypt a file include new file name for successful operation"
echo "if you encrypt or decrypt a folder include new directory name for successful operation" printf "%b\n" "if you encrypt or decrypt a folder include new directory name for successful operation"
echo "========================================================" printf "%b\n" "========================================================"
echo "1. Encrypt a file or directory" printf "%b\n" "1. Encrypt a file or directory"
echo "2. Decrypt a file or directory" printf "%b\n" "2. Decrypt a file or directory"
echo "3. Exit" printf "%b\n" "3. Exit"
echo "========================================================" printf "%b\n" "========================================================"
} }
# Function to encrypt a file # Function to encrypt a file
encrypt_file() { encrypt_file() {
echo "Enter the path to the file or directory to encrypt:" printf "%b\n" "Enter the path to the file or directory to encrypt:"
read -r INPUT_PATH read -r INPUT_PATH
if [ ! -e "$INPUT_PATH" ]; then if [ ! -e "$INPUT_PATH" ]; then
echo "Path does not exist!" printf "%b\n" "Path does not exist!"
return return
fi fi
echo "Enter the path for the encrypted file or directory:" printf "%b\n" "Enter the path for the encrypted file or directory:"
read -r OUTPUT_PATH read -r OUTPUT_PATH
printf "Enter the encryption password: " printf "%b\n" "Enter the encryption password: "
read -r PASSWORD read -r PASSWORD
if [ -d "$INPUT_PATH" ]; then if [ -d "$INPUT_PATH" ]; then
@ -65,41 +65,41 @@ encrypt_file() {
mkdir -p "$(dirname "$OUTPUT_FILE")" mkdir -p "$(dirname "$OUTPUT_FILE")"
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD" openssl enc -aes-256-cbc -salt -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Encrypted: $OUTPUT_FILE" printf "%b\n" "Encrypted: $OUTPUT_FILE"
else else
echo "Failed to encrypt: $FILE" printf "%b\n" "Failed to encrypt: $FILE"
fi fi
done done
else else
# Encrypt a single file # Encrypt a single file
if [ -d "$OUTPUT_PATH" ]; then if [ -d "$OUTPUT_PATH" ]; then
echo "Output path must be a file for single file encryption." printf "%b\n" "Output path must be a file for single file encryption."
return return
fi fi
mkdir -p "$(dirname "$OUTPUT_PATH")" mkdir -p "$(dirname "$OUTPUT_PATH")"
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD" openssl enc -aes-256-cbc -salt -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Encrypted: $OUTPUT_PATH" printf "%b\n" "Encrypted: $OUTPUT_PATH"
else else
echo "Failed to encrypt: $INPUT_PATH" printf "%b\n" "Failed to encrypt: $INPUT_PATH"
fi fi
fi fi
} }
# Function to decrypt a file # Function to decrypt a file
decrypt_file() { decrypt_file() {
echo "Enter the path to the file or directory to decrypt:" printf "%b\n" "Enter the path to the file or directory to decrypt:"
read -r INPUT_PATH read -r INPUT_PATH
if [ ! -e "$INPUT_PATH" ]; then if [ ! -e "$INPUT_PATH" ]; then
echo "Path does not exist!" printf "%b\n" "Path does not exist!"
return return
fi fi
echo "Enter the path for the decrypted file or directory:" printf "%b\n" "Enter the path for the decrypted file or directory:"
read -r OUTPUT_PATH read -r OUTPUT_PATH
printf "Enter the decryption password: " printf "%b\n" "Enter the decryption password: "
read -r PASSWORD read -r PASSWORD
if [ -d "$INPUT_PATH" ]; then if [ -d "$INPUT_PATH" ]; then
@ -110,23 +110,23 @@ decrypt_file() {
mkdir -p "$(dirname "$OUTPUT_FILE")" mkdir -p "$(dirname "$OUTPUT_FILE")"
openssl enc -aes-256-cbc -d -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD" openssl enc -aes-256-cbc -d -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Decrypted: $OUTPUT_FILE" printf "%b\n" "Decrypted: $OUTPUT_FILE"
else else
echo "Failed to decrypt: $FILE" printf "%b\n" "Failed to decrypt: $FILE"
fi fi
done done
else else
# Decrypt a single file # Decrypt a single file
if [ -d "$OUTPUT_PATH" ]; then if [ -d "$OUTPUT_PATH" ]; then
echo "Output path must be a file for single file decryption." printf "%b\n" "Output path must be a file for single file decryption."
return return
fi fi
mkdir -p "$(dirname "$OUTPUT_PATH")" mkdir -p "$(dirname "$OUTPUT_PATH")"
openssl enc -aes-256-cbc -d -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD" openssl enc -aes-256-cbc -d -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Decrypted: $OUTPUT_PATH" printf "%b\n" "Decrypted: $OUTPUT_PATH"
else else
echo "Failed to decrypt: $INPUT_PATH" printf "%b\n" "Failed to decrypt: $INPUT_PATH"
fi fi
fi fi
} }
@ -135,17 +135,17 @@ main(){
clear clear
while true; do while true; do
show_menu show_menu
echo "Enter your choice:" printf "%b\n" "Enter your choice:"
read -r CHOICE read -r CHOICE
case $CHOICE in case $CHOICE in
1) encrypt_file ;; 1) encrypt_file ;;
2) decrypt_file ;; 2) decrypt_file ;;
3) echo "Exiting..."; exit 0 ;; 3) printf "%b\n" "Exiting..."; exit 0 ;;
*) echo "Invalid choice. Please try again." ;; *) printf "%b\n" "Invalid choice. Please try again." ;;
esac esac
printf "Press [Enter] to continue..." printf "%b\n" "Press [Enter] to continue..."
read -r dummy read -r dummy
done done
} }

View File

@ -8,7 +8,7 @@
# Create a script to toggle numlock # Create a script to toggle numlock
create_file() { create_file() {
printf "Creating script...\n" printf "%b\n" "Creating script..."
"$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF' "$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF'
#!/bin/bash #!/bin/bash
@ -23,7 +23,7 @@ EOF
# Create a systemd service to run the script on boot # Create a systemd service to run the script on boot
create_service() { create_service() {
printf "Creating service...\n" printf "%b\n" "Creating service..."
"$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF' "$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF'
[Unit] [Unit]
Description=numlock Description=numlock
@ -48,14 +48,14 @@ numlockSetup() {
create_service create_service
fi fi
printf "Do you want to enable Numlock on boot? (y/n): " printf "%b\n" "Do you want to enable Numlock on boot? (y/n): "
read -r confirm read -r confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
"$ESCALATION_TOOL" systemctl enable numlock.service --quiet "$ESCALATION_TOOL" systemctl enable numlock.service --quiet
printf "Numlock will be enabled on boot\n" printf "%b\n" "Numlock will be enabled on boot"
else else
"$ESCALATION_TOOL" systemctl disable numlock.service --quiet "$ESCALATION_TOOL" systemctl disable numlock.service --quiet
printf "Numlock will not be enabled on boot\n" printf "%b\n" "Numlock will not be enabled on boot"
fi fi
} }

View File

@ -28,25 +28,25 @@ show_menu() {
# Function to view all services # Function to view all services
view_all_services() { view_all_services() {
printf "Listing all services...\n" printf "%b\n" "Listing all services..."
"$ESCALATION_TOOL" systemctl list-units --type=service --all --no-legend | awk '{print $1}' | sed 's/\.service//' | more "$ESCALATION_TOOL" systemctl list-units --type=service --all --no-legend | awk '{print $1}' | sed 's/\.service//' | more
} }
# Function to view enabled services # Function to view enabled services
view_enabled_services() { view_enabled_services() {
printf "Listing enabled services...\n" printf "%b\n" "Listing enabled services..."
"$ESCALATION_TOOL" systemctl list-unit-files --type=service --state=enabled --no-legend | awk '{print $1}' | sed 's/\.service//' | more "$ESCALATION_TOOL" systemctl list-unit-files --type=service --state=enabled --no-legend | awk '{print $1}' | sed 's/\.service//' | more
} }
# Function to view disabled services # Function to view disabled services
view_disabled_services() { view_disabled_services() {
printf "Listing disabled services...\n" printf "%b\n" "Listing disabled services..."
"$ESCALATION_TOOL" systemctl list-unit-files --type=service --state=disabled --no-legend | awk '{print $1}' | sed 's/\.service//' | more "$ESCALATION_TOOL" systemctl list-unit-files --type=service --state=disabled --no-legend | awk '{print $1}' | sed 's/\.service//' | more
} }
# Function to view started services # Function to view started services
view_started_services() { view_started_services() {
printf "Listing started services:\n" printf "%b\n" "Listing started services: "
"$ESCALATION_TOOL" systemctl list-units --type=service --state=running --no-pager | head -n -6 | awk 'NR>1 {print $1}' | more "$ESCALATION_TOOL" systemctl list-units --type=service --state=running --no-pager | head -n -6 | awk 'NR>1 {print $1}' | more
} }
@ -86,9 +86,9 @@ add_service() {
printf "\n" printf "\n"
printf "[Service]\n" printf "[Service]\n"
printf "ExecStart=$EXEC_START\n" printf "ExecStart=$EXEC_START\n"
[ -n "$SERVICE_USER" ] && printf "User=$SERVICE_USER\n" [ -n "$SERVICE_USER" ] && printf "%b\n" "User=$SERVICE_USER"
[ -n "$WORKING_DIRECTORY" ] && printf "WorkingDirectory=$WORKING_DIRECTORY\n" [ -n "$WORKING_DIRECTORY" ] && printf "%b\n" "WorkingDirectory=$WORKING_DIRECTORY"
[ -n "$RESTART_POLICY" ] && printf "Restart=$RESTART_POLICY\n" [ -n "$RESTART_POLICY" ] && printf "%b\n" "Restart=$RESTART_POLICY"
printf "\n" printf "\n"
printf "[Install]\n" printf "[Install]\n"
printf "WantedBy=multi-user.target\n" printf "WantedBy=multi-user.target\n"
@ -97,7 +97,7 @@ add_service() {
# Set permissions and reload systemd # Set permissions and reload systemd
"$ESCALATION_TOOL" chmod 644 "$SERVICE_FILE" "$ESCALATION_TOOL" chmod 644 "$SERVICE_FILE"
"$ESCALATION_TOOL" systemctl daemon-reload "$ESCALATION_TOOL" systemctl daemon-reload
printf "Service $SERVICE_NAME has been created and is ready to be started.\n" printf "%b\n" "Service $SERVICE_NAME has been created and is ready to be started."
# Optionally, enable and start the service # Optionally, enable and start the service
printf "Do you want to start and enable the service now? (y/n)\n" printf "Do you want to start and enable the service now? (y/n)\n"
@ -106,9 +106,9 @@ add_service() {
if [ "$START_ENABLE" = "y" ]; then if [ "$START_ENABLE" = "y" ]; then
"$ESCALATION_TOOL" systemctl start "$SERVICE_NAME" "$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"
"$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME" "$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"
printf "Service $SERVICE_NAME has been started and enabled.\n" printf "%b\n" "Service $SERVICE_NAME has been started and enabled."
else else
printf "Service $SERVICE_NAME has been created but not started.\n" printf "%b\n" "Service $SERVICE_NAME has been created but not started."
fi fi
} }
@ -120,29 +120,29 @@ remove_service() {
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service" SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
if [ -f "$SERVICE_FILE" ]; then if [ -f "$SERVICE_FILE" ]; then
printf "Stopping and disabling the service...\n" printf "%b\n" "Stopping and disabling the service..."
"$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME" "$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"
"$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME" "$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"
printf "Removing the service file...\n" printf "%b\n" "Removing the service file...\n"
"$ESCALATION_TOOL" rm -f "$SERVICE_FILE" "$ESCALATION_TOOL" rm -f "$SERVICE_FILE"
"$ESCALATION_TOOL" systemctl daemon-reload "$ESCALATION_TOOL" systemctl daemon-reload
printf "Service $SERVICE_NAME has been removed.\n" printf "%b\n" "Service $SERVICE_NAME has been removed."
else else
printf "Service $SERVICE_NAME does not exist.\n" printf "%b\n" "Service $SERVICE_NAME does not exist."
fi fi
} }
# Function to start a service # Function to start a service
start_service() { start_service() {
view_disabled_services view_disabled_services
printf "Enter the name of the service to start (e.g., my_service):\n" printf "%b\n" "Enter the name of the service to start (e.g., my_service): "
read -r SERVICE_NAME read -r SERVICE_NAME
if "$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"; then if "$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"; then
printf "Service $SERVICE_NAME has been started.\n" printf "%b\n" "Service $SERVICE_NAME has been started."
else else
printf "Failed to start service: $SERVICE_NAME.\n" printf "%b\n" "Failed to start service: $SERVICE_NAME."
fi fi
} }
@ -153,9 +153,9 @@ stop_service() {
read -r SERVICE_NAME read -r SERVICE_NAME
if "$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"; then if "$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"; then
printf "Service $SERVICE_NAME has been stopped.\n" printf "%b\n" "Service $SERVICE_NAME has been stopped."
else else
printf "Failed to stop service: $SERVICE_NAME.\n" printf "%b\n" "Failed to stop service: $SERVICE_NAME."
fi fi
} }
@ -166,9 +166,9 @@ enable_service() {
read -r SERVICE_NAME read -r SERVICE_NAME
if "$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"; then if "$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"; then
printf "Service $SERVICE_NAME has been enabled.\n" printf "%b\n" "Service $SERVICE_NAME has been enabled."
else else
printf "Failed to enable service: $SERVICE_NAME.\n" printf "%b\n" "Failed to enable service: $SERVICE_NAME."
fi fi
} }
@ -179,9 +179,9 @@ disable_service() {
read -r SERVICE_NAME read -r SERVICE_NAME
if "$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"; then if "$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"; then
printf "Service $SERVICE_NAME has been enabled.\n" printf "%b\n" "Service $SERVICE_NAME has been enabled."
else else
printf "Failed to enable service: $SERVICE_NAME.\n" printf "%b\n" "Failed to enable service: $SERVICE_NAME."
fi fi
} }
@ -202,7 +202,7 @@ create_service_from_external() {
SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service" SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service"
if [ ! -f "$SERVICE_FILE" ]; then if [ ! -f "$SERVICE_FILE" ]; then
printf "Service file $SERVICE_FILE does not exist.\n" printf "%b\n" "Service file $SERVICE_FILE does not exist."
return return
fi fi
@ -230,7 +230,7 @@ create_service_from_external() {
# Set permissions and reload systemd # Set permissions and reload systemd
"$ESCALATION_TOOL" chmod 644 "$SYSTEMD_SERVICE_FILE" "$ESCALATION_TOOL" chmod 644 "$SYSTEMD_SERVICE_FILE"
"$ESCALATION_TOOL" systemctl daemon-reload "$ESCALATION_TOOL" systemctl daemon-reload
printf "Service $SERVICE_NAME has been created and is ready to be started.\n" printf "%b\n" "Service $SERVICE_NAME has been created and is ready to be started."
# Optionally, enable and start the service # Optionally, enable and start the service
printf "Do you want to start and enable the service now? (y/n)\n" printf "Do you want to start and enable the service now? (y/n)\n"
@ -239,9 +239,9 @@ create_service_from_external() {
if [ "$START_ENABLE" = "y" ]; then if [ "$START_ENABLE" = "y" ]; then
"$ESCALATION_TOOL" systemctl start "$SERVICE_NAME" "$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"
"$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME" "$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"
printf "Service $SERVICE_NAME has been started and enabled.\n" printf "%b\n" "Service $SERVICE_NAME has been started and enabled."
else else
printf "Service $SERVICE_NAME has been created but not started.\n" printf "%b\n" "Service $SERVICE_NAME has been created but not started."
fi fi
} }

View File

@ -23,12 +23,14 @@ ask_for_host_details() {
read -r host read -r host
printf "%b\n" "Enter Remote User: " printf "%b\n" "Enter Remote User: "
read -r user read -r user
printf "%b\n" "Host $host_alias" >> ~/.ssh/config {
printf "%b\n" " HostName $host" >> ~/.ssh/config printf "%b\n" "Host $host_alias"
printf "%b\n" " User $user" >> ~/.ssh/config printf "%b\n" " HostName $host"
printf "%b\n" " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config printf "%b\n" " User $user"
printf "%b\n" " StrictHostKeyChecking no" >> ~/.ssh/config printf "%b\n" " IdentityFile ~/.ssh/id_rsa"
printf "%b\n" " UserKnownHostsFile=/dev/null" >> ~/.ssh/config printf "%b\n" " StrictHostKeyChecking no"
printf "%b\n" " UserKnownHostsFile=/dev/null"
} >> ~/.ssh/config
printf "%b\n" "Host $host_alias added successfully." printf "%b\n" "Host $host_alias added successfully."
} }