mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-25 06:24:26 +00:00
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:
parent
d6d27980de
commit
28533b9f38
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
. ../common-script.sh
|
||||
|
||||
themeinstall(){
|
||||
|
|
|
@ -157,8 +157,8 @@ configure_firewall() {
|
|||
}
|
||||
|
||||
setup_ssh_samba(){
|
||||
printf "Samba and SSH Setup Script\n"
|
||||
printf "----------------------------\n"
|
||||
printf "%b\n" "Samba and SSH Setup Script"
|
||||
printf "%b\n" "--------------------------"
|
||||
clear
|
||||
|
||||
# Display menu
|
||||
|
|
|
@ -4,18 +4,18 @@
|
|||
|
||||
# Function to list common session options
|
||||
list_sessions() {
|
||||
printf "Select the session:\n"
|
||||
printf "1) GNOME (gnome.desktop)\n"
|
||||
printf "2) KDE Plasma (plasma.desktop)\n"
|
||||
printf "3) XFCE (xfce.desktop)\n"
|
||||
printf "4) LXDE (LXDE.desktop)\n"
|
||||
printf "5) LXQt (lxqt.desktop)\n"
|
||||
printf "6) Cinnamon (cinnamon.desktop)\n"
|
||||
printf "7) MATE (mate.desktop)\n"
|
||||
printf "8) Openbox (openbox.desktop)\n"
|
||||
printf "9) i3 (i3.desktop)\n"
|
||||
printf "10) Custom session\n"
|
||||
printf "Enter your choice [1-10]: "
|
||||
printf "%b\n" "Select the session:"
|
||||
printf "%b\n" "1) GNOME (gnome.desktop)"
|
||||
printf "%b\n" "2) KDE Plasma (plasma.desktop)"
|
||||
printf "%b\n" "3) XFCE (xfce.desktop)"
|
||||
printf "%b\n" "4) LXDE (LXDE.desktop)"
|
||||
printf "%b\n" "5) LXQt (lxqt.desktop)"
|
||||
printf "%b\n" "6) Cinnamon (cinnamon.desktop)"
|
||||
printf "%b\n" "7) MATE (mate.desktop)"
|
||||
printf "%b\n" "8) Openbox (openbox.desktop)"
|
||||
printf "%b\n" "9) i3 (i3.desktop)"
|
||||
printf "%b\n" "10) Custom session"
|
||||
printf "%b\n" "Enter your choice [1-10]: "
|
||||
read -r session_choice
|
||||
|
||||
case "$session_choice" in
|
||||
|
@ -29,62 +29,59 @@ list_sessions() {
|
|||
8) session="openbox.desktop" ;;
|
||||
9) session="i3.desktop" ;;
|
||||
10)
|
||||
printf "Enter custom session name (e.g., mysession.desktop): "
|
||||
printf "%b\n" "Enter custom session name (e.g., mysession.desktop): "
|
||||
read -r session ;;
|
||||
*)
|
||||
printf "Invalid option selected.\n"
|
||||
printf "%b\n" "Invalid option selected."
|
||||
exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to configure LightDM
|
||||
configure_lightdm() {
|
||||
printf "Configuring LightDM for autologin...\n"
|
||||
|
||||
printf "Enter username for LightDM autologin: "
|
||||
printf "%b\n" "Configuring LightDM for autologin..."
|
||||
printf "%b\n" "Enter username for LightDM autologin: "
|
||||
read -r user
|
||||
|
||||
"$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-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
|
||||
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
|
||||
printf "LightDM autologin configuration has been removed.\n"
|
||||
printf "%b\n" "LightDM autologin configuration has been removed."
|
||||
}
|
||||
|
||||
# Function to configure GDM
|
||||
configure_gdm() {
|
||||
printf "Configuring GDM for autologin...\n"
|
||||
|
||||
printf "Enter username for GDM autologin: "
|
||||
printf "%b\n" "Configuring GDM for autologin..."
|
||||
printf "%b\n" "Enter username for GDM autologin: "
|
||||
read -r user
|
||||
|
||||
"$ESCALATION_TOOL" "printf '[daemon]' > /etc/gdm/custom.conf"
|
||||
"$ESCALATION_TOOL" "printf 'AutomaticLoginEnable = true' >> /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
|
||||
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 '/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
|
||||
configure_sddm() {
|
||||
printf "Configuring SDDM for autologin...\n"
|
||||
|
||||
printf "Enter username for SDDM autologin: "
|
||||
printf "%b\n" "Configuring SDDM for autologin..."
|
||||
printf "%b\n" "Enter username for SDDM autologin: "
|
||||
read -r user
|
||||
list_sessions # Show session options
|
||||
|
||||
|
@ -92,53 +89,52 @@ configure_sddm() {
|
|||
"$ESCALATION_TOOL" "printf 'User=$user' >> /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
|
||||
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
|
||||
printf "SDDM autologin configuration has been removed.\n"
|
||||
printf "%b\n" "SDDM autologin configuration has been removed."
|
||||
}
|
||||
|
||||
# Function to configure LXDM
|
||||
configure_lxdm() {
|
||||
printf "Configuring LXDM for autologin...\n"
|
||||
|
||||
printf "Enter username for LXDM autologin: "
|
||||
printf "%b\n" "Configuring LXDM for autologin..."
|
||||
printf "%b\n" "Enter username for LXDM autologin: "
|
||||
read -r user
|
||||
list_sessions # Show session options
|
||||
|
||||
"$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
|
||||
|
||||
printf "LXDM has been configured for autologin.\n"
|
||||
printf "%b\n" "LXDM has been configured for autologin."
|
||||
}
|
||||
|
||||
# Function to 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/^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
|
||||
configure_or_remove_autologin() {
|
||||
printf "Do you want to add or remove autologin?\n"
|
||||
printf "1) Add autologin\n"
|
||||
printf "2) Remove autologin\n"
|
||||
printf "Enter your choice [1-2]: "
|
||||
printf "%b\n" "Do you want to add or remove autologin?"
|
||||
printf "%b\n" "1) Add autologin"
|
||||
printf "%b\n" "2) Remove autologin"
|
||||
printf "%b\n" "Enter your choice [1-2]: "
|
||||
read -r action_choice
|
||||
|
||||
if [ "$action_choice" = "1" ]; then
|
||||
printf "Choose the display manager to configure:\n"
|
||||
printf "1) LightDM\n"
|
||||
printf "2) GDM\n"
|
||||
printf "3) SDDM\n"
|
||||
printf "4) LXDM\n"
|
||||
printf "Enter your choice [1-4]: "
|
||||
printf "%b\n" "Choose the display manager to configure:"
|
||||
printf "%b\n" "1) LightDM"
|
||||
printf "%b\n" "2) GDM"
|
||||
printf "%b\n" "3) SDDM"
|
||||
printf "%b\n" "4) LXDM"
|
||||
printf "%b\n" "Enter your choice [1-4]: "
|
||||
read -r choice
|
||||
|
||||
case "$choice" in
|
||||
|
@ -146,15 +142,15 @@ configure_or_remove_autologin() {
|
|||
2) configure_gdm ;;
|
||||
3) configure_sddm ;;
|
||||
4) configure_lxdm ;;
|
||||
*) printf "Invalid option selected.\n" ;;
|
||||
*) printf "%b\n" "Invalid option selected." ;;
|
||||
esac
|
||||
elif [ "$action_choice" = "2" ]; then
|
||||
printf "Choose the display manager to remove autologin:\n"
|
||||
printf "1) LightDM\n"
|
||||
printf "2) GDM\n"
|
||||
printf "3) SDDM\n"
|
||||
printf "4) LXDM\n"
|
||||
printf "Enter your choice [1-4]: "
|
||||
printf "%b\n" "Choose the display manager to remove autologin:"
|
||||
printf "%b\n" "1) LightDM"
|
||||
printf "%b\n" "2) GDM"
|
||||
printf "%b\n" "3) SDDM"
|
||||
printf "%b\n" "4) LXDM"
|
||||
printf "%b\n" "Enter your choice [1-4]: "
|
||||
read -r choice
|
||||
|
||||
case "$choice" in
|
||||
|
@ -162,14 +158,14 @@ configure_or_remove_autologin() {
|
|||
2) remove_gdm_autologin ;;
|
||||
3) remove_sddm_autologin ;;
|
||||
4) remove_lxdm_autologin ;;
|
||||
*) printf "Invalid option selected.\n" ;;
|
||||
*) printf "%b\n" "Invalid option selected." ;;
|
||||
esac
|
||||
else
|
||||
printf "Invalid choice. Exiting...\n"
|
||||
printf "%b\n" "Invalid choice. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "Action completed. Exiting...\n"
|
||||
printf "%b\n" "Action completed. Exiting..."
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# Function to display usage instructions
|
||||
usage() {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,9 @@ choose_iso_source() {
|
|||
fetch_iso_urls() {
|
||||
clear
|
||||
printf "%b\n" "${YELLOW}Available ISOs for download:${RC}"
|
||||
printf "1) Arch Linux (latest)\n"
|
||||
printf "2) Arch Linux (older versions)\n"
|
||||
printf "3) Debian Linux (latest)\n"
|
||||
printf "%b\n" "1) Arch Linux (latest)"
|
||||
printf "%b\n" "2) Arch Linux (older versions)"
|
||||
printf "%b\n" "3) Debian Linux (latest)"
|
||||
printf "\n"
|
||||
printf "Select the ISO you want to download (1-3): "
|
||||
read -r ISO_OPTION
|
||||
|
|
|
@ -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" "${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
|
||||
fi
|
||||
|
||||
show_menu() {
|
||||
echo "========================================================"
|
||||
echo " File/Directory Encryption/Decryption"
|
||||
echo "========================================================"
|
||||
echo "How to use:-"
|
||||
echo "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"
|
||||
echo "========================================================"
|
||||
echo "1. Encrypt a file or directory"
|
||||
echo "2. Decrypt a file or directory"
|
||||
echo "3. Exit"
|
||||
echo "========================================================"
|
||||
printf "%b\n" "========================================================"
|
||||
printf "%b\n" " File/Directory Encryption/Decryption"
|
||||
printf "%b\n" "========================================================"
|
||||
printf "%b\n" "How to use:-"
|
||||
printf "%b\n" "if you encrypt or decrypt a file include new file name for successful operation"
|
||||
printf "%b\n" "if you encrypt or decrypt a folder include new directory name for successful operation"
|
||||
printf "%b\n" "========================================================"
|
||||
printf "%b\n" "1. Encrypt a file or directory"
|
||||
printf "%b\n" "2. Decrypt a file or directory"
|
||||
printf "%b\n" "3. Exit"
|
||||
printf "%b\n" "========================================================"
|
||||
}
|
||||
|
||||
# Function to encrypt a 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
|
||||
|
||||
if [ ! -e "$INPUT_PATH" ]; then
|
||||
echo "Path does not exist!"
|
||||
printf "%b\n" "Path does not exist!"
|
||||
return
|
||||
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
|
||||
|
||||
printf "Enter the encryption password: "
|
||||
printf "%b\n" "Enter the encryption password: "
|
||||
read -r PASSWORD
|
||||
|
||||
if [ -d "$INPUT_PATH" ]; then
|
||||
|
@ -65,41 +65,41 @@ encrypt_file() {
|
|||
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
||||
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Encrypted: $OUTPUT_FILE"
|
||||
printf "%b\n" "Encrypted: $OUTPUT_FILE"
|
||||
else
|
||||
echo "Failed to encrypt: $FILE"
|
||||
printf "%b\n" "Failed to encrypt: $FILE"
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Encrypt a single file
|
||||
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
|
||||
fi
|
||||
mkdir -p "$(dirname "$OUTPUT_PATH")"
|
||||
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Encrypted: $OUTPUT_PATH"
|
||||
printf "%b\n" "Encrypted: $OUTPUT_PATH"
|
||||
else
|
||||
echo "Failed to encrypt: $INPUT_PATH"
|
||||
printf "%b\n" "Failed to encrypt: $INPUT_PATH"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to decrypt a 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
|
||||
|
||||
if [ ! -e "$INPUT_PATH" ]; then
|
||||
echo "Path does not exist!"
|
||||
printf "%b\n" "Path does not exist!"
|
||||
return
|
||||
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
|
||||
|
||||
printf "Enter the decryption password: "
|
||||
printf "%b\n" "Enter the decryption password: "
|
||||
read -r PASSWORD
|
||||
|
||||
if [ -d "$INPUT_PATH" ]; then
|
||||
|
@ -110,23 +110,23 @@ decrypt_file() {
|
|||
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
||||
openssl enc -aes-256-cbc -d -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Decrypted: $OUTPUT_FILE"
|
||||
printf "%b\n" "Decrypted: $OUTPUT_FILE"
|
||||
else
|
||||
echo "Failed to decrypt: $FILE"
|
||||
printf "%b\n" "Failed to decrypt: $FILE"
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Decrypt a single file
|
||||
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
|
||||
fi
|
||||
mkdir -p "$(dirname "$OUTPUT_PATH")"
|
||||
openssl enc -aes-256-cbc -d -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Decrypted: $OUTPUT_PATH"
|
||||
printf "%b\n" "Decrypted: $OUTPUT_PATH"
|
||||
else
|
||||
echo "Failed to decrypt: $INPUT_PATH"
|
||||
printf "%b\n" "Failed to decrypt: $INPUT_PATH"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -135,17 +135,17 @@ main(){
|
|||
clear
|
||||
while true; do
|
||||
show_menu
|
||||
echo "Enter your choice:"
|
||||
printf "%b\n" "Enter your choice:"
|
||||
read -r CHOICE
|
||||
|
||||
case $CHOICE in
|
||||
1) encrypt_file ;;
|
||||
2) decrypt_file ;;
|
||||
3) echo "Exiting..."; exit 0 ;;
|
||||
*) echo "Invalid choice. Please try again." ;;
|
||||
3) printf "%b\n" "Exiting..."; exit 0 ;;
|
||||
*) printf "%b\n" "Invalid choice. Please try again." ;;
|
||||
esac
|
||||
|
||||
printf "Press [Enter] to continue..."
|
||||
printf "%b\n" "Press [Enter] to continue..."
|
||||
read -r dummy
|
||||
done
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# Create a script to toggle numlock
|
||||
|
||||
create_file() {
|
||||
printf "Creating script...\n"
|
||||
printf "%b\n" "Creating script..."
|
||||
"$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
|
@ -23,7 +23,7 @@ EOF
|
|||
|
||||
# Create a systemd service to run the script on boot
|
||||
create_service() {
|
||||
printf "Creating service...\n"
|
||||
printf "%b\n" "Creating service..."
|
||||
"$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF'
|
||||
[Unit]
|
||||
Description=numlock
|
||||
|
@ -48,14 +48,14 @@ numlockSetup() {
|
|||
create_service
|
||||
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
|
||||
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
|
||||
"$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
|
||||
"$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
|
||||
}
|
||||
|
||||
|
|
|
@ -28,25 +28,25 @@ show_menu() {
|
|||
|
||||
# Function to 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
|
||||
}
|
||||
|
||||
# Function to 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
|
||||
}
|
||||
|
||||
# Function to 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
|
||||
}
|
||||
|
||||
# Function to 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
|
||||
}
|
||||
|
||||
|
@ -86,9 +86,9 @@ add_service() {
|
|||
printf "\n"
|
||||
printf "[Service]\n"
|
||||
printf "ExecStart=$EXEC_START\n"
|
||||
[ -n "$SERVICE_USER" ] && printf "User=$SERVICE_USER\n"
|
||||
[ -n "$WORKING_DIRECTORY" ] && printf "WorkingDirectory=$WORKING_DIRECTORY\n"
|
||||
[ -n "$RESTART_POLICY" ] && printf "Restart=$RESTART_POLICY\n"
|
||||
[ -n "$SERVICE_USER" ] && printf "%b\n" "User=$SERVICE_USER"
|
||||
[ -n "$WORKING_DIRECTORY" ] && printf "%b\n" "WorkingDirectory=$WORKING_DIRECTORY"
|
||||
[ -n "$RESTART_POLICY" ] && printf "%b\n" "Restart=$RESTART_POLICY"
|
||||
printf "\n"
|
||||
printf "[Install]\n"
|
||||
printf "WantedBy=multi-user.target\n"
|
||||
|
@ -97,7 +97,7 @@ add_service() {
|
|||
# Set permissions and reload systemd
|
||||
"$ESCALATION_TOOL" chmod 644 "$SERVICE_FILE"
|
||||
"$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
|
||||
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
|
||||
"$ESCALATION_TOOL" systemctl start "$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
|
||||
printf "Service $SERVICE_NAME has been created but not started.\n"
|
||||
printf "%b\n" "Service $SERVICE_NAME has been created but not started."
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -120,29 +120,29 @@ remove_service() {
|
|||
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
|
||||
|
||||
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 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" systemctl daemon-reload
|
||||
printf "Service $SERVICE_NAME has been removed.\n"
|
||||
printf "%b\n" "Service $SERVICE_NAME has been removed."
|
||||
else
|
||||
printf "Service $SERVICE_NAME does not exist.\n"
|
||||
printf "%b\n" "Service $SERVICE_NAME does not exist."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start a service
|
||||
start_service() {
|
||||
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
|
||||
|
||||
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
|
||||
printf "Failed to start service: $SERVICE_NAME.\n"
|
||||
printf "%b\n" "Failed to start service: $SERVICE_NAME."
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -153,9 +153,9 @@ stop_service() {
|
|||
read -r SERVICE_NAME
|
||||
|
||||
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
|
||||
printf "Failed to stop service: $SERVICE_NAME.\n"
|
||||
printf "%b\n" "Failed to stop service: $SERVICE_NAME."
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -166,9 +166,9 @@ enable_service() {
|
|||
read -r SERVICE_NAME
|
||||
|
||||
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
|
||||
printf "Failed to enable service: $SERVICE_NAME.\n"
|
||||
printf "%b\n" "Failed to enable service: $SERVICE_NAME."
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -179,9 +179,9 @@ disable_service() {
|
|||
read -r SERVICE_NAME
|
||||
|
||||
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
|
||||
printf "Failed to enable service: $SERVICE_NAME.\n"
|
||||
printf "%b\n" "Failed to enable service: $SERVICE_NAME."
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ create_service_from_external() {
|
|||
SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service"
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
|
@ -230,7 +230,7 @@ create_service_from_external() {
|
|||
# Set permissions and reload systemd
|
||||
"$ESCALATION_TOOL" chmod 644 "$SYSTEMD_SERVICE_FILE"
|
||||
"$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
|
||||
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
|
||||
"$ESCALATION_TOOL" systemctl start "$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
|
||||
printf "Service $SERVICE_NAME has been created but not started.\n"
|
||||
printf "%b\n" "Service $SERVICE_NAME has been created but not started."
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,14 @@ ask_for_host_details() {
|
|||
read -r host
|
||||
printf "%b\n" "Enter Remote User: "
|
||||
read -r user
|
||||
printf "%b\n" "Host $host_alias" >> ~/.ssh/config
|
||||
printf "%b\n" " HostName $host" >> ~/.ssh/config
|
||||
printf "%b\n" " User $user" >> ~/.ssh/config
|
||||
printf "%b\n" " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
|
||||
printf "%b\n" " StrictHostKeyChecking no" >> ~/.ssh/config
|
||||
printf "%b\n" " UserKnownHostsFile=/dev/null" >> ~/.ssh/config
|
||||
{
|
||||
printf "%b\n" "Host $host_alias"
|
||||
printf "%b\n" " HostName $host"
|
||||
printf "%b\n" " User $user"
|
||||
printf "%b\n" " IdentityFile ~/.ssh/id_rsa"
|
||||
printf "%b\n" " StrictHostKeyChecking no"
|
||||
printf "%b\n" " UserKnownHostsFile=/dev/null"
|
||||
} >> ~/.ssh/config
|
||||
printf "%b\n" "Host $host_alias added successfully."
|
||||
}
|
||||
|
||||
|
@ -187,7 +189,7 @@ sync_directories() {
|
|||
|
||||
# Function to check SSH key authentication status
|
||||
check_ssh_key_authentication() {
|
||||
printf "%b\n""Enter the alias of the host: "
|
||||
printf "%b\n" "Enter the alias of the host: "
|
||||
read -r host_alias
|
||||
ssh $host_alias "grep '^PubkeyAuthentication' /etc/ssh/sshd_config"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user