mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
Replace echos with printf (utils) (#479)
Co-authored-by: nnyyxxxx <nnyyxxxx@users.noreply.github.com> Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
parent
cca4fd1ced
commit
969c83dda6
|
@ -4,18 +4,18 @@
|
||||||
|
|
||||||
# Function to list common session options
|
# Function to list common session options
|
||||||
list_sessions() {
|
list_sessions() {
|
||||||
echo "Select the session:"
|
printf "Select the session:\n"
|
||||||
echo "1) GNOME (gnome.desktop)"
|
printf "1) GNOME (gnome.desktop)\n"
|
||||||
echo "2) KDE Plasma (plasma.desktop)"
|
printf "2) KDE Plasma (plasma.desktop)\n"
|
||||||
echo "3) XFCE (xfce.desktop)"
|
printf "3) XFCE (xfce.desktop)\n"
|
||||||
echo "4) LXDE (LXDE.desktop)"
|
printf "4) LXDE (LXDE.desktop)\n"
|
||||||
echo "5) LXQt (lxqt.desktop)"
|
printf "5) LXQt (lxqt.desktop)\n"
|
||||||
echo "6) Cinnamon (cinnamon.desktop)"
|
printf "6) Cinnamon (cinnamon.desktop)\n"
|
||||||
echo "7) MATE (mate.desktop)"
|
printf "7) MATE (mate.desktop)\n"
|
||||||
echo "8) Openbox (openbox.desktop)"
|
printf "8) Openbox (openbox.desktop)\n"
|
||||||
echo "9) i3 (i3.desktop)"
|
printf "9) i3 (i3.desktop)\n"
|
||||||
echo "10) Custom session"
|
printf "10) Custom session\n"
|
||||||
echo "Enter your choice [1-10]: "
|
printf "Enter your choice [1-10]: "
|
||||||
read session_choice
|
read session_choice
|
||||||
|
|
||||||
case "$session_choice" in
|
case "$session_choice" in
|
||||||
|
@ -29,116 +29,116 @@ list_sessions() {
|
||||||
8) session="openbox.desktop" ;;
|
8) session="openbox.desktop" ;;
|
||||||
9) session="i3.desktop" ;;
|
9) session="i3.desktop" ;;
|
||||||
10)
|
10)
|
||||||
echo "Enter custom session name (e.g., mysession.desktop): "
|
printf "Enter custom session name (e.g., mysession.desktop): "
|
||||||
read -r session ;;
|
read -r session ;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid option selected."
|
printf "Invalid option selected.\n"
|
||||||
exit 1 ;;
|
exit 1 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to configure LightDM
|
# Function to configure LightDM
|
||||||
configure_lightdm() {
|
configure_lightdm() {
|
||||||
echo "Configuring LightDM for autologin..."
|
printf "Configuring LightDM for autologin...\n"
|
||||||
|
|
||||||
echo "Enter username for LightDM autologin: "
|
printf "Enter username for LightDM autologin: "
|
||||||
read -r user
|
read -r user
|
||||||
|
|
||||||
$ESCALATION_TOOL "echo '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
$ESCALATION_TOOL "printf '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
|
||||||
$ESCALATION_TOOL "echo '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 "echo '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"
|
||||||
|
|
||||||
echo "LightDM has been configured for autologin."
|
printf "LightDM has been configured for autologin.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove LightDM autologin
|
# Function to remove LightDM autologin
|
||||||
remove_lightdm_autologin() {
|
remove_lightdm_autologin() {
|
||||||
echo "Removing LightDM autologin configuration..."
|
printf "Removing LightDM autologin configuration...\n"
|
||||||
$ESCALATION_TOOL rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf
|
$ESCALATION_TOOL rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf
|
||||||
echo "LightDM autologin configuration has been removed."
|
printf "LightDM autologin configuration has been removed.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to configure GDM
|
# Function to configure GDM
|
||||||
configure_gdm() {
|
configure_gdm() {
|
||||||
echo "Configuring GDM for autologin..."
|
printf "Configuring GDM for autologin...\n"
|
||||||
|
|
||||||
echo "Enter username for GDM autologin: "
|
printf "Enter username for GDM autologin: "
|
||||||
read -r user
|
read -r user
|
||||||
|
|
||||||
$ESCALATION_TOOL "echo '[daemon]' > /etc/gdm/custom.conf"
|
$ESCALATION_TOOL "printf '[daemon]' > /etc/gdm/custom.conf"
|
||||||
$ESCALATION_TOOL "echo 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
|
$ESCALATION_TOOL "printf 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
|
||||||
$ESCALATION_TOOL "echo 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
|
$ESCALATION_TOOL "printf 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
|
||||||
|
|
||||||
echo "GDM has been configured for autologin."
|
printf "GDM has been configured for autologin.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove GDM autologin
|
# Function to remove GDM autologin
|
||||||
remove_gdm_autologin() {
|
remove_gdm_autologin() {
|
||||||
echo "Removing GDM autologin configuration..."
|
printf "Removing GDM autologin configuration...\n"
|
||||||
$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
|
||||||
echo "GDM autologin configuration has been removed."
|
printf "GDM autologin configuration has been removed.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to configure SDDM
|
# Function to configure SDDM
|
||||||
configure_sddm() {
|
configure_sddm() {
|
||||||
echo "Configuring SDDM for autologin..."
|
printf "Configuring SDDM for autologin...\n"
|
||||||
|
|
||||||
echo "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
|
||||||
|
|
||||||
$ESCALATION_TOOL "echo '[Autologin]' > /etc/sddm.conf"
|
$ESCALATION_TOOL "printf '[Autologin]' > /etc/sddm.conf"
|
||||||
$ESCALATION_TOOL "echo 'User=$user' >> /etc/sddm.conf"
|
$ESCALATION_TOOL "printf 'User=$user' >> /etc/sddm.conf"
|
||||||
$ESCALATION_TOOL "echo 'Session=$session' >> /etc/sddm.conf"
|
$ESCALATION_TOOL "printf 'Session=$session' >> /etc/sddm.conf"
|
||||||
|
|
||||||
echo "SDDM has been configured for autologin."
|
printf "SDDM has been configured for autologin.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove SDDM autologin
|
# Function to remove SDDM autologin
|
||||||
remove_sddm_autologin() {
|
remove_sddm_autologin() {
|
||||||
echo "Removing SDDM autologin configuration..."
|
printf "Removing SDDM autologin configuration...\n"
|
||||||
$ESCALATION_TOOL sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf
|
$ESCALATION_TOOL sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf
|
||||||
echo "SDDM autologin configuration has been removed."
|
printf "SDDM autologin configuration has been removed.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to configure LXDM
|
# Function to configure LXDM
|
||||||
configure_lxdm() {
|
configure_lxdm() {
|
||||||
echo "Configuring LXDM for autologin..."
|
printf "Configuring LXDM for autologin...\n"
|
||||||
|
|
||||||
echo "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
|
||||||
|
|
||||||
echo "LXDM has been configured for autologin."
|
printf "LXDM has been configured for autologin.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove LXDM autologin
|
# Function to remove LXDM autologin
|
||||||
remove_lxdm_autologin() {
|
remove_lxdm_autologin() {
|
||||||
echo "Removing LXDM autologin configuration..."
|
printf "Removing LXDM autologin configuration...\n"
|
||||||
$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
|
||||||
echo "LXDM autologin configuration has been removed."
|
printf "LXDM autologin configuration has been removed.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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() {
|
||||||
echo "Do you want to add or remove autologin?"
|
printf "Do you want to add or remove autologin?\n"
|
||||||
echo "1) Add autologin"
|
printf "1) Add autologin\n"
|
||||||
echo "2) Remove autologin"
|
printf "2) Remove autologin\n"
|
||||||
echo "Enter your choice [1-2]: "
|
printf "Enter your choice [1-2]: "
|
||||||
read action_choice
|
read action_choice
|
||||||
|
|
||||||
if [ "$action_choice" = "1" ]; then
|
if [ "$action_choice" = "1" ]; then
|
||||||
echo "Choose the display manager to configure:"
|
printf "Choose the display manager to configure:\n"
|
||||||
echo "1) LightDM"
|
printf "1) LightDM\n"
|
||||||
echo "2) GDM"
|
printf "2) GDM\n"
|
||||||
echo "3) SDDM"
|
printf "3) SDDM\n"
|
||||||
echo "4) LXDM"
|
printf "4) LXDM\n"
|
||||||
echo "Enter your choice [1-4]: "
|
printf "Enter your choice [1-4]: "
|
||||||
read choice
|
read choice
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
|
@ -146,15 +146,15 @@ configure_or_remove_autologin() {
|
||||||
2) configure_gdm ;;
|
2) configure_gdm ;;
|
||||||
3) configure_sddm ;;
|
3) configure_sddm ;;
|
||||||
4) configure_lxdm ;;
|
4) configure_lxdm ;;
|
||||||
*) echo "Invalid option selected." ;;
|
*) printf "Invalid option selected.\n" ;;
|
||||||
esac
|
esac
|
||||||
elif [ "$action_choice" = "2" ]; then
|
elif [ "$action_choice" = "2" ]; then
|
||||||
echo "Choose the display manager to remove autologin:"
|
printf "Choose the display manager to remove autologin:\n"
|
||||||
echo "1) LightDM"
|
printf "1) LightDM\n"
|
||||||
echo "2) GDM"
|
printf "2) GDM\n"
|
||||||
echo "3) SDDM"
|
printf "3) SDDM\n"
|
||||||
echo "4) LXDM"
|
printf "4) LXDM\n"
|
||||||
echo "Enter your choice [1-4]: "
|
printf "Enter your choice [1-4]: "
|
||||||
read choice
|
read choice
|
||||||
|
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
|
@ -162,18 +162,17 @@ 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 ;;
|
||||||
*) echo "Invalid option selected." ;;
|
*) printf "Invalid option selected.\n" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
echo "Invalid choice. Exiting..."
|
printf "Invalid choice. Exiting...\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Action completed. Exiting..."
|
printf "Action completed. Exiting...\n"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
checkEnv
|
checkEnv
|
||||||
checkEscalationTool
|
checkEscalationTool
|
||||||
configure_or_remove_autologin
|
configure_or_remove_autologin
|
||||||
|
|
|
@ -35,13 +35,13 @@ main_menu() {
|
||||||
clear
|
clear
|
||||||
printf "%b\n" "${YELLOW}Bluetooth Manager${RC}"
|
printf "%b\n" "${YELLOW}Bluetooth Manager${RC}"
|
||||||
printf "%b\n" "${YELLOW}=================${RC}"
|
printf "%b\n" "${YELLOW}=================${RC}"
|
||||||
echo "1. Scan for devices"
|
printf "1. Scan for devices\n"
|
||||||
echo "2. Pair with a device"
|
printf "2. Pair with a device\n"
|
||||||
echo "3. Connect to a device"
|
printf "3. Connect to a device\n"
|
||||||
echo "4. Disconnect from a device"
|
printf "4. Disconnect from a device\n"
|
||||||
echo "5. Remove a device"
|
printf "5. Remove a device\n"
|
||||||
echo "0. Exit"
|
printf "0. Exit\n"
|
||||||
echo -n "Choose an option: "
|
printf -n "Choose an option: "
|
||||||
read choice
|
read choice
|
||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
|
@ -66,7 +66,7 @@ scan_devices() {
|
||||||
printf "%b\n" "${RED}No devices found.${RC}"
|
printf "%b\n" "${RED}No devices found.${RC}"
|
||||||
else
|
else
|
||||||
printf "%b\n" "${GREEN}Devices found:${RC}"
|
printf "%b\n" "${GREEN}Devices found:${RC}"
|
||||||
echo "$devices"
|
printf "%s\n" "$devices"
|
||||||
fi
|
fi
|
||||||
printf "Press any key to return to the main menu..."
|
printf "Press any key to return to the main menu..."
|
||||||
read -r dummy
|
read -r dummy
|
||||||
|
@ -94,11 +94,11 @@ prompt_for_mac() {
|
||||||
device_list=$(echo "$devices" | tr '\n' '\n')
|
device_list=$(echo "$devices" | tr '\n' '\n')
|
||||||
i=1
|
i=1
|
||||||
echo "$device_list" | while IFS= read -r device; do
|
echo "$device_list" | while IFS= read -r device; do
|
||||||
echo "$i. $device"
|
printf "%d. %s\n" "$i" "$device"
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
echo "0. Exit to main menu"
|
printf "0. Exit to main menu\n"
|
||||||
echo -n "$prompt_msg"
|
printf "%s\n" "$prompt_msg"
|
||||||
read choice
|
read choice
|
||||||
|
|
||||||
# Validate the choice
|
# Validate the choice
|
||||||
|
|
|
@ -5,16 +5,16 @@
|
||||||
# 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}"
|
||||||
echo "No arguments needed. The script will prompt for ISO path and USB device."
|
printf "No arguments needed. The script will prompt for ISO path and USB device.\n"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to display all available block devices
|
# Function to display all available block devices
|
||||||
list_devices() {
|
list_devices() {
|
||||||
printf "%b\n" "${YELLOW} Available devices and partitions: ${RC}"
|
printf "%b\n" "${YELLOW} Available devices and partitions: ${RC}"
|
||||||
echo ""
|
printf "\n"
|
||||||
$ESCALATION_TOOL lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
|
$ESCALATION_TOOL lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
|
||||||
echo ""
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to fetch the latest Arch Linux ISO
|
# Function to fetch the latest Arch Linux ISO
|
||||||
|
@ -47,7 +47,7 @@ fetch_arch_older_isos() {
|
||||||
printf "%-5s${YELLOW}%-15s ${RC}" "$COUNTER)" "$VERSION"
|
printf "%-5s${YELLOW}%-15s ${RC}" "$COUNTER)" "$VERSION"
|
||||||
|
|
||||||
if [ $(( COUNTER % ROW_ITEMS )) -eq 0 ]; then
|
if [ $(( COUNTER % ROW_ITEMS )) -eq 0 ]; then
|
||||||
echo "" # New line after every 6 versions
|
printf "\n" # New line after every 6 versions
|
||||||
fi
|
fi
|
||||||
|
|
||||||
COUNTER=$((COUNTER + 1))
|
COUNTER=$((COUNTER + 1))
|
||||||
|
@ -60,7 +60,6 @@ fetch_arch_older_isos() {
|
||||||
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
|
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Function to fetch the latest Debian Linux ISO
|
# Function to fetch the latest Debian Linux ISO
|
||||||
fetch_debian_latest_iso() {
|
fetch_debian_latest_iso() {
|
||||||
DEBIAN_URL=$(curl -s https://www.debian.org/distrib/netinst | grep -oP '(?<=href=")[^"]+debian-[0-9.]+-amd64-netinst.iso(?=")' | head -1)
|
DEBIAN_URL=$(curl -s https://www.debian.org/distrib/netinst | grep -oP '(?<=href=")[^"]+debian-[0-9.]+-amd64-netinst.iso(?=")' | head -1)
|
||||||
|
@ -99,10 +98,10 @@ 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}"
|
||||||
echo "1) Arch Linux (latest)"
|
printf "1) Arch Linux (latest)\n"
|
||||||
echo "2) Arch Linux (older versions)"
|
printf "2) Arch Linux (older versions)\n"
|
||||||
echo "3) Debian Linux (latest)"
|
printf "3) Debian Linux (latest)\n"
|
||||||
echo ""
|
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
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# Create a script to toggle numlock
|
# Create a script to toggle numlock
|
||||||
|
|
||||||
create_file() {
|
create_file() {
|
||||||
echo "Creating script..."
|
printf "Creating script...\n"
|
||||||
"$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() {
|
||||||
echo "Creating service..."
|
printf "Creating service...\n"
|
||||||
"$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
|
||||||
|
@ -52,11 +52,10 @@ numlockSetup() {
|
||||||
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
|
||||||
echo "Numlock will be enabled on boot"
|
printf "Numlock will be enabled on boot\n"
|
||||||
else
|
else
|
||||||
"$ESCALATION_TOOL" systemctl disable numlock.service --quiet
|
"$ESCALATION_TOOL" systemctl disable numlock.service --quiet
|
||||||
echo "Numlock will not be enabled on boot"
|
printf "Numlock will not be enabled on boot\n"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ installollama() {
|
||||||
clear
|
clear
|
||||||
printf "%b\n" "${YELLOW}Checking if ollama is already installed...${RC}"
|
printf "%b\n" "${YELLOW}Checking if ollama is already installed...${RC}"
|
||||||
|
|
||||||
# Check if ollama is already installed
|
|
||||||
if command_exists ollama; then
|
if command_exists ollama; then
|
||||||
printf "%b\n" "${GREEN}ollama is already installed.${RC}"
|
printf "%b\n" "${GREEN}ollama is already installed.${RC}"
|
||||||
else
|
else
|
||||||
|
@ -32,7 +31,6 @@ show_model_info() {
|
||||||
ollama show "$model_name"
|
ollama show "$model_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to display available models
|
|
||||||
display_models() {
|
display_models() {
|
||||||
clear
|
clear
|
||||||
printf "%b\n" "${RED}Available Models${RC}"
|
printf "%b\n" "${RED}Available Models${RC}"
|
||||||
|
@ -58,23 +56,23 @@ display_models() {
|
||||||
select_model() {
|
select_model() {
|
||||||
local choice="$1"
|
local choice="$1"
|
||||||
case $choice in
|
case $choice in
|
||||||
1) echo "llama3.1";;
|
1) printf "%b\n" "llama3.1";;
|
||||||
2) echo "llama3.1:70b";;
|
2) printf "%b\n" "llama3.1:70b";;
|
||||||
3) echo "llama3.1:405b";;
|
3) printf "%b\n" "llama3.1:405b";;
|
||||||
4) echo "phi3";;
|
4) printf "%b\n" "phi3";;
|
||||||
5) echo "phi3:medium";;
|
5) printf "%b\n" "phi3:medium";;
|
||||||
6) echo "gemma2:2b";;
|
6) printf "%b\n" "gemma2:2b";;
|
||||||
7) echo "gemma2";;
|
7) printf "%b\n" "gemma2";;
|
||||||
8) echo "gemma2:27b";;
|
8) printf "%b\n" "gemma2:27b";;
|
||||||
9) echo "mistral";;
|
9) printf "%b\n" "mistral";;
|
||||||
10) echo "moondream";;
|
10) printf "%b\n" "moondream";;
|
||||||
11) echo "neural-chat";;
|
11) printf "%b\n" "neural-chat";;
|
||||||
12) echo "starling-lm";;
|
12) printf "%b\n" "starling-lm";;
|
||||||
13) echo "codellama";;
|
13) printf "%b\n" "codellama";;
|
||||||
14) echo "llama2-uncensored";;
|
14) printf "%b\n" "llama2-uncensored";;
|
||||||
15) echo "llava";;
|
15) printf "%b\n" "llava";;
|
||||||
16) echo "solar";;
|
16) printf "%b\n" "solar";;
|
||||||
*) echo "$choice";; # Treat any other input as a custom model name
|
*) printf "%b\n" "$choice";;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +96,6 @@ run_model() {
|
||||||
|
|
||||||
printf "%b\n" "${YELLOW}Running the model: $model...${RC}"
|
printf "%b\n" "${YELLOW}Running the model: $model...${RC}"
|
||||||
ollama run "$model"
|
ollama run "$model"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_model() {
|
create_model() {
|
||||||
|
@ -184,7 +181,7 @@ menu() {
|
||||||
printf "5) Remove a model\n"
|
printf "5) Remove a model\n"
|
||||||
printf "6) Exit\n"
|
printf "6) Exit\n"
|
||||||
|
|
||||||
printf "%b" "${YELLOW}Enter your choice (1-5): ${RC}"
|
printf "%b\n" "${YELLOW}Enter your choice (1-5): ${RC}"
|
||||||
read -r choice
|
read -r choice
|
||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
|
|
|
@ -9,72 +9,71 @@ SCRIPT_DIR="./services"
|
||||||
# Function to show the main menu
|
# Function to show the main menu
|
||||||
show_menu() {
|
show_menu() {
|
||||||
clear
|
clear
|
||||||
echo "============================"
|
printf "============================\n"
|
||||||
echo " Service Management Menu"
|
printf " Service Management Menu\n"
|
||||||
echo "============================"
|
printf "============================\n"
|
||||||
echo "1. View all services"
|
printf "1. View all services\n"
|
||||||
echo "2. View enabled services"
|
printf "2. View enabled services\n"
|
||||||
echo "3. View disabled services"
|
printf "3. View disabled services\n"
|
||||||
echo "4. Add a new service"
|
printf "4. Add a new service\n"
|
||||||
echo "5. Remove a service"
|
printf "5. Remove a service\n"
|
||||||
echo "6. Start a service"
|
printf "6. Start a service\n"
|
||||||
echo "7. Stop a service"
|
printf "7. Stop a service\n"
|
||||||
echo "8. Enable a service"
|
printf "8. Enable a service\n"
|
||||||
echo "9. Disable a service"
|
printf "9. Disable a service\n"
|
||||||
echo "10. Create a service from external scripts"
|
printf "10. Create a service from external scripts\n"
|
||||||
echo "11. Exit"
|
printf "11. Exit\n"
|
||||||
echo "============================"
|
printf "============================\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to view all services
|
# Function to view all services
|
||||||
view_all_services() {
|
view_all_services() {
|
||||||
echo "Listing all services..."
|
printf "Listing all services...\n"
|
||||||
"$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() {
|
||||||
echo "Listing enabled services..."
|
printf "Listing enabled services...\n"
|
||||||
"$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() {
|
||||||
echo "Listing disabled services..."
|
printf "Listing disabled services...\n"
|
||||||
"$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() {
|
||||||
echo "Listing started services:"
|
printf "Listing started services:\n"
|
||||||
"$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
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to add a new service
|
# Function to add a new service
|
||||||
add_service() {
|
add_service() {
|
||||||
while [ -z "$SERVICE_NAME" ]; do
|
while [ -z "$SERVICE_NAME" ]; do
|
||||||
echo "Enter the name of the new service (e.g., my_service):"
|
printf "Enter the name of the new service (e.g., my_service):\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
if "$ESCALATION_TOOL" systemctl list-units --type=service --all --no-legend | grep -q "$SERVICE_NAME.service"; then
|
if "$ESCALATION_TOOL" systemctl list-units --type=service --all --no-legend | grep -q "$SERVICE_NAME.service"; then
|
||||||
echo "Service already exists!"
|
printf "Service already exists!\n"
|
||||||
SERVICE_NAME=""
|
SERVICE_NAME=""
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Enter the description of the service:"
|
printf "Enter the description of the service:\n"
|
||||||
read -r SERVICE_DESCRIPTION
|
read -r SERVICE_DESCRIPTION
|
||||||
|
|
||||||
echo "Enter the command to execute the service (e.g., /usr/local/bin/my_service.sh):"
|
printf "Enter the command to execute the service (e.g., /usr/local/bin/my_service.sh):\n"
|
||||||
read -r EXEC_START
|
read -r EXEC_START
|
||||||
|
|
||||||
echo "Enter the user to run the service as (leave empty for default):"
|
printf "Enter the user to run the service as (leave empty for default):\n"
|
||||||
read -r SERVICE_USER
|
read -r SERVICE_USER
|
||||||
|
|
||||||
echo "Enter the working directory for the service (leave empty for default):"
|
printf "Enter the working directory for the service (leave empty for default):\n"
|
||||||
read -r WORKING_DIRECTORY
|
read -r WORKING_DIRECTORY
|
||||||
|
|
||||||
echo "Enter the restart policy (e.g., always, on-failure; leave empty for no restart):"
|
printf "Enter the restart policy (e.g., always, on-failure; leave empty for no restart):\n"
|
||||||
read -r RESTART_POLICY
|
read -r RESTART_POLICY
|
||||||
|
|
||||||
# Create the service unit file
|
# Create the service unit file
|
||||||
|
@ -82,108 +81,107 @@ add_service() {
|
||||||
|
|
||||||
# Create the service file with conditionals for optional fields
|
# Create the service file with conditionals for optional fields
|
||||||
{
|
{
|
||||||
echo "[Unit]"
|
printf "[Unit]\n"
|
||||||
echo "Description=$SERVICE_DESCRIPTION"
|
printf "Description=$SERVICE_DESCRIPTION\n"
|
||||||
echo ""
|
printf "\n"
|
||||||
echo "[Service]"
|
printf "[Service]\n"
|
||||||
echo "ExecStart=$EXEC_START"
|
printf "ExecStart=$EXEC_START\n"
|
||||||
[ -n "$SERVICE_USER" ] && echo "User=$SERVICE_USER"
|
[ -n "$SERVICE_USER" ] && printf "User=$SERVICE_USER\n"
|
||||||
[ -n "$WORKING_DIRECTORY" ] && echo "WorkingDirectory=$WORKING_DIRECTORY"
|
[ -n "$WORKING_DIRECTORY" ] && printf "WorkingDirectory=$WORKING_DIRECTORY\n"
|
||||||
[ -n "$RESTART_POLICY" ] && echo "Restart=$RESTART_POLICY"
|
[ -n "$RESTART_POLICY" ] && printf "Restart=$RESTART_POLICY\n"
|
||||||
echo ""
|
printf "\n"
|
||||||
echo "[Install]"
|
printf "[Install]\n"
|
||||||
echo "WantedBy=multi-user.target"
|
printf "WantedBy=multi-user.target\n"
|
||||||
} | "$ESCALATION_TOOL" tee "$SERVICE_FILE" > /dev/null
|
} | $ESCALATION_TOOL tee "$SERVICE_FILE" > /dev/null
|
||||||
|
|
||||||
# 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
|
||||||
echo "Service $SERVICE_NAME has been created and is ready to be started."
|
printf "Service $SERVICE_NAME has been created and is ready to be started.\n"
|
||||||
|
|
||||||
# Optionally, enable and start the service
|
# Optionally, enable and start the service
|
||||||
echo "Do you want to start and enable the service now? (y/n)"
|
printf "Do you want to start and enable the service now? (y/n)\n"
|
||||||
read -r START_ENABLE
|
read -r START_ENABLE
|
||||||
|
|
||||||
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"
|
||||||
echo "Service $SERVICE_NAME has been started and enabled."
|
printf "Service $SERVICE_NAME has been started and enabled.\n"
|
||||||
else
|
else
|
||||||
echo "Service $SERVICE_NAME has been created but not started."
|
printf "Service $SERVICE_NAME has been created but not started.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to remove a service
|
# Function to remove a service
|
||||||
remove_service() {
|
remove_service() {
|
||||||
echo "Enter the name of the service to remove (e.g., my_service):"
|
printf "Enter the name of the service to remove (e.g., my_service):\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
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
|
||||||
echo "Stopping and disabling the service..."
|
printf "Stopping and disabling the service...\n"
|
||||||
"$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"
|
$ESCALATION_TOOL systemctl stop "$SERVICE_NAME"
|
||||||
"$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"
|
$ESCALATION_TOOL systemctl disable "$SERVICE_NAME"
|
||||||
|
|
||||||
echo "Removing the service file..."
|
printf "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"
|
||||||
echo "Service $SERVICE_NAME has been removed."
|
|
||||||
else
|
else
|
||||||
echo "Service $SERVICE_NAME does not exist."
|
printf "Service $SERVICE_NAME does not exist.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to start a service
|
# Function to start a service
|
||||||
start_service() {
|
start_service() {
|
||||||
view_disabled_services
|
view_disabled_services
|
||||||
echo "Enter the name of the service to start (e.g., my_service):"
|
printf "Enter the name of the service to start (e.g., my_service):\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
if "$ESCALATION_TOOL" systemctl start "$SERVICE_NAME"; then
|
if $ESCALATION_TOOL systemctl start "$SERVICE_NAME"; then
|
||||||
echo "Service $SERVICE_NAME has been started."
|
printf "Service $SERVICE_NAME has been started.\n"
|
||||||
else
|
else
|
||||||
echo "Failed to start service: $SERVICE_NAME."
|
printf "Failed to start service: $SERVICE_NAME.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to stop a service
|
# Function to stop a service
|
||||||
stop_service() {
|
stop_service() {
|
||||||
view_started_services
|
view_started_services
|
||||||
echo "Enter the name of the service to stop (e.g., my_service):"
|
printf "Enter the name of the service to stop (e.g., my_service):\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
if "$ESCALATION_TOOL" systemctl stop "$SERVICE_NAME"; then
|
if $ESCALATION_TOOL systemctl stop "$SERVICE_NAME"; then
|
||||||
echo "Service $SERVICE_NAME has been stopped."
|
printf "Service $SERVICE_NAME has been stopped.\n"
|
||||||
else
|
else
|
||||||
echo "Failed to stop service: $SERVICE_NAME."
|
printf "Failed to stop service: $SERVICE_NAME.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to enable a service
|
# Function to enable a service
|
||||||
enable_service() {
|
enable_service() {
|
||||||
view_disabled_services
|
view_disabled_services
|
||||||
echo "Enter the name of the service to enable (e.g., my_service):"
|
printf "Enter the name of the service to enable (e.g., my_service):\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
if "$ESCALATION_TOOL" systemctl enable "$SERVICE_NAME"; then
|
if $ESCALATION_TOOL systemctl enable "$SERVICE_NAME"; then
|
||||||
echo "Service $SERVICE_NAME has been enabled."
|
printf "Service $SERVICE_NAME has been enabled.\n"
|
||||||
else
|
else
|
||||||
echo "Failed to enable service: $SERVICE_NAME."
|
printf "Failed to enable service: $SERVICE_NAME.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to enable a service
|
# Function to enable a service
|
||||||
disable_service() {
|
disable_service() {
|
||||||
view_enabled_services
|
view_enabled_services
|
||||||
echo "Enter the name of the service to disable (e.g., my_service):"
|
printf "Enter the name of the service to disable (e.g., my_service):\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
if "$ESCALATION_TOOL" systemctl disable "$SERVICE_NAME"; then
|
if $ESCALATION_TOOL systemctl disable "$SERVICE_NAME"; then
|
||||||
echo "Service $SERVICE_NAME has been enabled."
|
printf "Service $SERVICE_NAME has been enabled.\n"
|
||||||
else
|
else
|
||||||
echo "Failed to enable service: $SERVICE_NAME."
|
printf "Failed to enable service: $SERVICE_NAME.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,24 +189,24 @@ disable_service() {
|
||||||
create_service_from_external() {
|
create_service_from_external() {
|
||||||
|
|
||||||
# List all .service files in the SCRIPT_DIR
|
# List all .service files in the SCRIPT_DIR
|
||||||
echo "============================"
|
printf "============================\n"
|
||||||
echo "Listing available service files"
|
printf "Listing available service files\n"
|
||||||
echo "============================"
|
printf "============================\n"
|
||||||
for FILE in "$SCRIPT_DIR"/*.service; do
|
for FILE in "$SCRIPT_DIR"/*.service; do
|
||||||
echo "$(basename "$FILE")"
|
printf "%s\n" "$(basename "$FILE")"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Enter the filename (without the .service extension) of the service to create:"
|
printf "Enter the filename (without the .service extension) of the service to create:\n"
|
||||||
read -r SERVICE_NAME
|
read -r SERVICE_NAME
|
||||||
|
|
||||||
SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service"
|
SERVICE_FILE="$SCRIPT_DIR/$SERVICE_NAME.service"
|
||||||
|
|
||||||
if [ ! -f "$SERVICE_FILE" ]; then
|
if [ ! -f "$SERVICE_FILE" ]; then
|
||||||
echo "Service file $SERVICE_FILE does not exist."
|
printf "Service file $SERVICE_FILE does not exist.\n"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Enter the username to run the service as (leave empty for no specific user):"
|
printf "Enter the username to run the service as (leave empty for no specific user):\n"
|
||||||
read -r SERVICE_USER
|
read -r SERVICE_USER
|
||||||
|
|
||||||
# Create the systemd service file path
|
# Create the systemd service file path
|
||||||
|
@ -230,27 +228,27 @@ create_service_from_external() {
|
||||||
"$ESCALATION_TOOL" cp "$SERVICE_FILE" "$SYSTEMD_SERVICE_FILE"
|
"$ESCALATION_TOOL" cp "$SERVICE_FILE" "$SYSTEMD_SERVICE_FILE"
|
||||||
|
|
||||||
# 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
|
||||||
echo "Service $SERVICE_NAME has been created and is ready to be started."
|
printf "Service $SERVICE_NAME has been created and is ready to be started.\n"
|
||||||
|
|
||||||
# Optionally, enable and start the service
|
# Optionally, enable and start the service
|
||||||
echo "Do you want to start and enable the service now? (y/n)"
|
printf "Do you want to start and enable the service now? (y/n)\n"
|
||||||
read -r START_ENABLE
|
read -r START_ENABLE
|
||||||
|
|
||||||
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"
|
||||||
echo "Service $SERVICE_NAME has been started and enabled."
|
printf "Service $SERVICE_NAME has been started and enabled.\n"
|
||||||
else
|
else
|
||||||
echo "Service $SERVICE_NAME has been created but not started."
|
printf "Service $SERVICE_NAME has been created but not started.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
while true; do
|
while true; do
|
||||||
show_menu
|
show_menu
|
||||||
echo "Enter your choice:"
|
printf "Enter your choice:\n"
|
||||||
read -r CHOICE
|
read -r CHOICE
|
||||||
|
|
||||||
case $CHOICE in
|
case $CHOICE in
|
||||||
|
@ -264,11 +262,11 @@ main() {
|
||||||
8) enable_service ;;
|
8) enable_service ;;
|
||||||
9) disable_service ;;
|
9) disable_service ;;
|
||||||
10) create_service_from_external ;;
|
10) create_service_from_external ;;
|
||||||
11) echo "Exiting..."; exit 0 ;;
|
11) printf "Exiting...\n"; exit 0 ;;
|
||||||
*) echo "Invalid choice. Please try again." ;;
|
*) printf "Invalid choice. Please try again.\n" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo "Press [Enter] to continue..."
|
printf "Press [Enter] to continue...\n"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ install_timeshift() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
echo "Timeshift is already installed."
|
printf "%b\n" "${GREEN}Timeshift is already installed.${RC}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ install_timeshift() {
|
||||||
display_menu() {
|
display_menu() {
|
||||||
clear
|
clear
|
||||||
printf "%b\n" "${CYAN}Timeshift CLI Automation${RC}"
|
printf "%b\n" "${CYAN}Timeshift CLI Automation${RC}"
|
||||||
printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
|
|
||||||
printf "%b\n" "${CYAN}1) List Snapshots${RC}"
|
printf "%b\n" "${CYAN}1) List Snapshots${RC}"
|
||||||
printf "%b\n" "${CYAN}2) List Devices${RC}"
|
printf "%b\n" "${CYAN}2) List Devices${RC}"
|
||||||
printf "%b\n" "${CYAN}3) Create Snapshot${RC}"
|
printf "%b\n" "${CYAN}3) Create Snapshot${RC}"
|
||||||
|
@ -33,7 +32,6 @@ display_menu() {
|
||||||
printf "%b\n" "${CYAN}5) Delete Snapshot${RC}"
|
printf "%b\n" "${CYAN}5) Delete Snapshot${RC}"
|
||||||
printf "%b\n" "${CYAN}6) Delete All Snapshots${RC}"
|
printf "%b\n" "${CYAN}6) Delete All Snapshots${RC}"
|
||||||
printf "%b\n" "${CYAN}7) Exit${RC}"
|
printf "%b\n" "${CYAN}7) Exit${RC}"
|
||||||
printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to list snapshots
|
# Function to list snapshots
|
||||||
|
@ -50,26 +48,26 @@ list_devices() {
|
||||||
|
|
||||||
# Function to create a new snapshot
|
# Function to create a new snapshot
|
||||||
create_snapshot() {
|
create_snapshot() {
|
||||||
printf "%b" "${CYAN}Enter a comment for the snapshot (optional): ${RC}"
|
printf "%b\n" "${CYAN}Enter a comment for the snapshot (optional): ${RC}"
|
||||||
read -r COMMENT
|
read -r COMMENT
|
||||||
printf "%b" "${CYAN}Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): ${RC}"
|
printf "%b\n" "${CYAN}Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): ${RC}"
|
||||||
read -r TAG
|
read -r TAG
|
||||||
|
|
||||||
if [ -z "$COMMENT" ] && [ -z "$TAG" ]; then
|
if [ -z "$COMMENT" ] && [ -z "$TAG" ]; then
|
||||||
echo "Creating snapshot with no comment or tag..."
|
printf "%b\n" "${CYAN}Creating snapshot with no comment or tag...${RC}"
|
||||||
$ESCALATION_TOOL timeshift --create
|
$ESCALATION_TOOL timeshift --create
|
||||||
elif [ -z "$TAG" ]; then
|
elif [ -z "$TAG" ]; then
|
||||||
echo "Creating snapshot with no tag..."
|
printf "%b\n" "${CYAN}Creating snapshot with no tag...${RC}"
|
||||||
$ESCALATION_TOOL timeshift --create --comments "$COMMENT"
|
$ESCALATION_TOOL timeshift --create --comments "$COMMENT"
|
||||||
else
|
else
|
||||||
echo "Creating snapshot with tag: $TAG..."
|
printf "%b\n" "${CYAN}Creating snapshot with tag: $TAG...${RC}"
|
||||||
$ESCALATION_TOOL timeshift --create --comments "$COMMENT" --tags "$TAG"
|
$ESCALATION_TOOL timeshift --create --comments "$COMMENT" --tags "$TAG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Snapshot created successfully."
|
printf "%b\n" "${GREEN}Snapshot created successfully.${RC}"
|
||||||
else
|
else
|
||||||
echo "Snapshot creation failed."
|
printf "%b\n" "${RED}Snapshot creation failed.${RC}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,17 +75,17 @@ create_snapshot() {
|
||||||
restore_snapshot() {
|
restore_snapshot() {
|
||||||
list_snapshots
|
list_snapshots
|
||||||
|
|
||||||
printf "%b" "${CYAN}Enter the snapshot name you want to restore: ${RC}"
|
printf "%b\n" "${CYAN}Enter the snapshot name you want to restore: ${RC}"
|
||||||
read -r SNAPSHOT
|
read -r SNAPSHOT
|
||||||
printf "%b" "${CYAN}Enter the target device (e.g., /dev/sda1): ${RC}"
|
printf "%b\n" "${CYAN}Enter the target device (e.g., /dev/sda1): ${RC}"
|
||||||
read -r TARGET_DEVICE
|
read -r TARGET_DEVICE
|
||||||
printf "%b" "${CYAN}Do you want to skip GRUB reinstall? (yes/no): ${RC}"
|
printf "%b\n" "${CYAN}Do you want to skip GRUB reinstall? (yes/no): ${RC}"
|
||||||
read -r SKIP_GRUB
|
read -r SKIP_GRUB
|
||||||
|
|
||||||
if [ "$SKIP_GRUB" = "yes" ]; then
|
if [ "$SKIP_GRUB" = "yes" ]; then
|
||||||
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --skip-grub --yes
|
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --skip-grub --yes
|
||||||
else
|
else
|
||||||
printf "%b" "${CYAN}Enter GRUB device (e.g., /dev/sda): ${RC}"
|
printf "%b\n" "${CYAN}Enter GRUB device (e.g., /dev/sda): ${RC}"
|
||||||
read -r GRUB_DEVICE
|
read -r GRUB_DEVICE
|
||||||
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --grub-device "$GRUB_DEVICE" --yes
|
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --grub-device "$GRUB_DEVICE" --yes
|
||||||
fi
|
fi
|
||||||
|
@ -103,7 +101,7 @@ restore_snapshot() {
|
||||||
delete_snapshot() {
|
delete_snapshot() {
|
||||||
list_snapshots
|
list_snapshots
|
||||||
|
|
||||||
printf "%b" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
|
printf "%b\n" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
|
||||||
read -r SNAPSHOT
|
read -r SNAPSHOT
|
||||||
|
|
||||||
printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
|
printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
|
||||||
|
@ -119,11 +117,11 @@ delete_snapshot() {
|
||||||
# Function to delete all snapshots
|
# Function to delete all snapshots
|
||||||
delete_all_snapshots() {
|
delete_all_snapshots() {
|
||||||
printf "%b\n" "${RED}WARNING: This will delete all snapshots!${RC}"
|
printf "%b\n" "${RED}WARNING: This will delete all snapshots!${RC}"
|
||||||
printf "%b" "${CYAN}Are you sure? (yes/no): ${RC}"
|
printf "%b\n" "${CYAN}Are you sure? (yes/no): ${RC}"
|
||||||
read -r CONFIRMATION
|
read -r CONFIRMATION
|
||||||
|
|
||||||
if [ "$CONFIRMATION" = "yes" ]; then
|
if [ "$CONFIRMATION" = "yes" ]; then
|
||||||
echo "Deleting all snapshots..."
|
printf "%b\n" "${CYAN}Deleting all snapshots...${RC}"
|
||||||
$ESCALATION_TOOL timeshift --delete-all --yes
|
$ESCALATION_TOOL timeshift --delete-all --yes
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
printf "%b\n" "${GREEN}All snapshots deleted successfully.${RC}"
|
printf "%b\n" "${GREEN}All snapshots deleted successfully.${RC}"
|
||||||
|
@ -138,7 +136,7 @@ delete_all_snapshots() {
|
||||||
main_menu() {
|
main_menu() {
|
||||||
while true; do
|
while true; do
|
||||||
display_menu
|
display_menu
|
||||||
printf "%b" "${CYAN}Select an option (1-7): ${RC}"
|
printf "%b\n" "${CYAN}Select an option (1-7): ${RC}"
|
||||||
read -r OPTION
|
read -r OPTION
|
||||||
|
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
|
@ -151,7 +149,7 @@ while true; do
|
||||||
7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
|
7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
|
||||||
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
||||||
esac
|
esac
|
||||||
printf "%b" "${CYAN}Press Enter to continue...${RC}"
|
printf "%b\n" "${CYAN}Press Enter to continue...${RC}"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
34
tabs/utils/wifi-control.sh
Normal file → Executable file
34
tabs/utils/wifi-control.sh
Normal file → Executable file
|
@ -38,14 +38,14 @@ main_menu() {
|
||||||
clear
|
clear
|
||||||
printf "%b\n" "${YELLOW}WiFi Manager${RC}"
|
printf "%b\n" "${YELLOW}WiFi Manager${RC}"
|
||||||
printf "%b\n" "${YELLOW}============${RC}"
|
printf "%b\n" "${YELLOW}============${RC}"
|
||||||
echo "1. Turn WiFi On"
|
printf "1. Turn WiFi On\n"
|
||||||
echo "2. Turn WiFi Off"
|
printf "2. Turn WiFi Off\n"
|
||||||
echo "3. Scan for WiFi networks"
|
printf "3. Scan for WiFi networks\n"
|
||||||
echo "4. Connect to a WiFi network"
|
printf "4. Connect to a WiFi network\n"
|
||||||
echo "5. Disconnect from a WiFi network"
|
printf "5. Disconnect from a WiFi network\n"
|
||||||
echo "6. Remove a WiFi connection"
|
printf "6. Remove a WiFi connection\n"
|
||||||
echo "0. Exit"
|
printf "0. Exit\n"
|
||||||
echo -n "Choose an option: "
|
printf "Choose an option: "
|
||||||
read choice
|
read choice
|
||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
|
@ -72,7 +72,7 @@ scan_networks() {
|
||||||
printf "%b\n" "${GREEN}Top 10 Networks found:${RC}"
|
printf "%b\n" "${GREEN}Top 10 Networks found:${RC}"
|
||||||
echo "$networks" | awk -F: '{printf("%d. SSID: %-25s \n", NR, $1)}'
|
echo "$networks" | awk -F: '{printf("%d. SSID: %-25s \n", NR, $1)}'
|
||||||
fi
|
fi
|
||||||
echo "Press any key to return to the main menu..."
|
printf "Press any key to return to the main menu...\n"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ wifi_on() {
|
||||||
} || {
|
} || {
|
||||||
printf "%b\n" "${RED}Failed to turn on WiFi.${RC}"
|
printf "%b\n" "${RED}Failed to turn on WiFi.${RC}"
|
||||||
}
|
}
|
||||||
echo "Press any key to return to the main menu..."
|
printf "Press any key to return to the main menu...\n"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ wifi_off() {
|
||||||
} || {
|
} || {
|
||||||
printf "%b\n" "${RED}Failed to turn off WiFi.${RC}"
|
printf "%b\n" "${RED}Failed to turn off WiFi.${RC}"
|
||||||
}
|
}
|
||||||
echo "Press any key to return to the main menu..."
|
printf "Press any key to return to the main menu...\n"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ prompt_for_network() {
|
||||||
networks=$(nmcli -t -f SSID dev wifi list | awk -F: '!seen[$1]++' | grep -v '^$')
|
networks=$(nmcli -t -f SSID dev wifi list | awk -F: '!seen[$1]++' | grep -v '^$')
|
||||||
if [ -z "$networks" ]; then
|
if [ -z "$networks" ]; then
|
||||||
printf "%b\n" "${RED}No networks available. Please scan for networks first.${RC}"
|
printf "%b\n" "${RED}No networks available. Please scan for networks first.${RC}"
|
||||||
echo "Press any key to return to the main menu..."
|
printf "Press any key to return to the main menu...\n"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
return
|
return
|
||||||
|
@ -130,16 +130,16 @@ prompt_for_network() {
|
||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
done < "$temp_file"
|
done < "$temp_file"
|
||||||
|
|
||||||
echo "0. Exit to main menu"
|
printf "0. Exit to main menu\n"
|
||||||
echo -n "$prompt_msg"
|
printf "%s" "$prompt_msg"
|
||||||
read choice
|
read choice
|
||||||
|
|
||||||
if [ "$choice" -ge 1 ] && [ "$choice" -lt "$i" ]; then
|
if [ "$choice" -ge 1 ] && [ "$choice" -lt "$i" ]; then
|
||||||
ssid=$(sed -n "${choice}p" "$temp_file" | awk -F: '{print $1}')
|
ssid=$(sed -n "${choice}p" "$temp_file" | awk -F: '{print $1}')
|
||||||
if [ "$action" = "connect" ]; then
|
if [ "$action" = "connect" ]; then
|
||||||
echo -n "Enter password for SSID $ssid: "
|
printf "Enter password for SSID %s: " "$ssid"
|
||||||
read password
|
read password
|
||||||
echo
|
printf "\n"
|
||||||
nmcli dev wifi connect "$ssid" password "$password" && {
|
nmcli dev wifi connect "$ssid" password "$password" && {
|
||||||
printf "%b\n" "${GREEN}$success_msg${RC}"
|
printf "%b\n" "${GREEN}$success_msg${RC}"
|
||||||
} || {
|
} || {
|
||||||
|
@ -150,7 +150,7 @@ prompt_for_network() {
|
||||||
printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
|
printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Press any key to return to the selection menu..."
|
printf "Press any key to return to the selection menu...\n"
|
||||||
read -r dummy
|
read -r dummy
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user