Skip to content

Commit

Permalink
Replace echos with printf (utils) (#479)
Browse files Browse the repository at this point in the history
Co-authored-by: nnyyxxxx <[email protected]>
Co-authored-by: Chris Titus <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent cca4fd1 commit 969c83d
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 254 deletions.
127 changes: 63 additions & 64 deletions tabs/utils/auto-login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

# Function to list common session options
list_sessions() {
echo "Select the session:"
echo "1) GNOME (gnome.desktop)"
echo "2) KDE Plasma (plasma.desktop)"
echo "3) XFCE (xfce.desktop)"
echo "4) LXDE (LXDE.desktop)"
echo "5) LXQt (lxqt.desktop)"
echo "6) Cinnamon (cinnamon.desktop)"
echo "7) MATE (mate.desktop)"
echo "8) Openbox (openbox.desktop)"
echo "9) i3 (i3.desktop)"
echo "10) Custom session"
echo "Enter your choice [1-10]: "
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]: "
read session_choice

case "$session_choice" in
Expand All @@ -29,151 +29,150 @@ list_sessions() {
8) session="openbox.desktop" ;;
9) session="i3.desktop" ;;
10)
echo "Enter custom session name (e.g., mysession.desktop): "
printf "Enter custom session name (e.g., mysession.desktop): "
read -r session ;;
*)
echo "Invalid option selected."
printf "Invalid option selected.\n"
exit 1 ;;
esac
}

# Function to 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

$ESCALATION_TOOL "echo '[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 "echo 'autologin-user-timeout=0' >> /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-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
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
echo "LightDM autologin configuration has been removed."
printf "LightDM autologin configuration has been removed.\n"
}

# Function to 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

$ESCALATION_TOOL "echo '[daemon]' > /etc/gdm/custom.conf"
$ESCALATION_TOOL "echo 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
$ESCALATION_TOOL "echo 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
$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"

echo "GDM has been configured for autologin."
printf "GDM has been configured for autologin.\n"
}

# Function to 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 '/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
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
list_sessions # Show session options

$ESCALATION_TOOL "echo '[Autologin]' > /etc/sddm.conf"
$ESCALATION_TOOL "echo 'User=$user' >> /etc/sddm.conf"
$ESCALATION_TOOL "echo 'Session=$session' >> /etc/sddm.conf"
$ESCALATION_TOOL "printf '[Autologin]' > /etc/sddm.conf"
$ESCALATION_TOOL "printf 'User=$user' >> /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
remove_sddm_autologin() {
echo "Removing SDDM autologin configuration..."
printf "Removing SDDM autologin configuration...\n"
$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
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
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

echo "LXDM has been configured for autologin."
printf "LXDM has been configured for autologin.\n"
}

# Function to 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/^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
configure_or_remove_autologin() {
echo "Do you want to add or remove autologin?"
echo "1) Add autologin"
echo "2) Remove autologin"
echo "Enter your choice [1-2]: "
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]: "
read action_choice

if [ "$action_choice" = "1" ]; then
echo "Choose the display manager to configure:"
echo "1) LightDM"
echo "2) GDM"
echo "3) SDDM"
echo "4) LXDM"
echo "Enter your choice [1-4]: "
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]: "
read choice

case "$choice" in
1) configure_lightdm ;;
2) configure_gdm ;;
3) configure_sddm ;;
4) configure_lxdm ;;
*) echo "Invalid option selected." ;;
*) printf "Invalid option selected.\n" ;;
esac
elif [ "$action_choice" = "2" ]; then
echo "Choose the display manager to remove autologin:"
echo "1) LightDM"
echo "2) GDM"
echo "3) SDDM"
echo "4) LXDM"
echo "Enter your choice [1-4]: "
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]: "
read choice

case "$choice" in
1) remove_lightdm_autologin ;;
2) remove_gdm_autologin ;;
3) remove_sddm_autologin ;;
4) remove_lxdm_autologin ;;
*) echo "Invalid option selected." ;;
*) printf "Invalid option selected.\n" ;;
esac
else
echo "Invalid choice. Exiting..."
printf "Invalid choice. Exiting...\n"
exit 1
fi

echo "Action completed. Exiting..."
printf "Action completed. Exiting...\n"
exit 0
}


checkEnv
checkEscalationTool
configure_or_remove_autologin
22 changes: 11 additions & 11 deletions tabs/utils/bluetooth-control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ main_menu() {
clear
printf "%b\n" "${YELLOW}Bluetooth Manager${RC}"
printf "%b\n" "${YELLOW}=================${RC}"
echo "1. Scan for devices"
echo "2. Pair with a device"
echo "3. Connect to a device"
echo "4. Disconnect from a device"
echo "5. Remove a device"
echo "0. Exit"
echo -n "Choose an option: "
printf "1. Scan for devices\n"
printf "2. Pair with a device\n"
printf "3. Connect to a device\n"
printf "4. Disconnect from a device\n"
printf "5. Remove a device\n"
printf "0. Exit\n"
printf -n "Choose an option: "
read choice

case $choice in
Expand All @@ -66,7 +66,7 @@ scan_devices() {
printf "%b\n" "${RED}No devices found.${RC}"
else
printf "%b\n" "${GREEN}Devices found:${RC}"
echo "$devices"
printf "%s\n" "$devices"
fi
printf "Press any key to return to the main menu..."
read -r dummy
Expand Down Expand Up @@ -94,11 +94,11 @@ prompt_for_mac() {
device_list=$(echo "$devices" | tr '\n' '\n')
i=1
echo "$device_list" | while IFS= read -r device; do
echo "$i. $device"
printf "%d. %s\n" "$i" "$device"
i=$((i + 1))
done
echo "0. Exit to main menu"
echo -n "$prompt_msg"
printf "0. Exit to main menu\n"
printf "%s\n" "$prompt_msg"
read choice

# Validate the choice
Expand Down
17 changes: 8 additions & 9 deletions tabs/utils/create-bootable-usb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# Function to display usage instructions
usage() {
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
}

# Function to display all available block devices
list_devices() {
printf "%b\n" "${YELLOW} Available devices and partitions: ${RC}"
echo ""
printf "\n"
$ESCALATION_TOOL lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
echo ""
printf "\n"
}

# Function to fetch the latest Arch Linux ISO
Expand Down Expand Up @@ -47,7 +47,7 @@ fetch_arch_older_isos() {
printf "%-5s${YELLOW}%-15s ${RC}" "$COUNTER)" "$VERSION"

if [ $(( COUNTER % ROW_ITEMS )) -eq 0 ]; then
echo "" # New line after every 6 versions
printf "\n" # New line after every 6 versions
fi

COUNTER=$((COUNTER + 1))
Expand All @@ -60,7 +60,6 @@ fetch_arch_older_isos() {
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
}


# Function to fetch the latest Debian Linux 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)
Expand Down Expand Up @@ -99,10 +98,10 @@ choose_iso_source() {
fetch_iso_urls() {
clear
printf "%b\n" "${YELLOW}Available ISOs for download:${RC}"
echo "1) Arch Linux (latest)"
echo "2) Arch Linux (older versions)"
echo "3) Debian Linux (latest)"
echo ""
printf "1) Arch Linux (latest)\n"
printf "2) Arch Linux (older versions)\n"
printf "3) Debian Linux (latest)\n"
printf "\n"
printf "Select the ISO you want to download (1-3): "
read -r ISO_OPTION

Expand Down
9 changes: 4 additions & 5 deletions tabs/utils/numlock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Create a script to toggle numlock

create_file() {
echo "Creating script..."
printf "Creating script...\n"
"$ESCALATION_TOOL" tee "/usr/local/bin/numlock" >/dev/null <<'EOF'
#!/bin/bash
Expand All @@ -23,7 +23,7 @@ EOF

# Create a systemd service to run the script on boot
create_service() {
echo "Creating service..."
printf "Creating service...\n"
"$ESCALATION_TOOL" tee "/etc/systemd/system/numlock.service" >/dev/null <<'EOF'
[Unit]
Description=numlock
Expand Down Expand Up @@ -52,11 +52,10 @@ numlockSetup() {
read -r confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
"$ESCALATION_TOOL" systemctl enable numlock.service --quiet
echo "Numlock will be enabled on boot"
printf "Numlock will be enabled on boot\n"
else
"$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
}

Expand Down
Loading

0 comments on commit 969c83d

Please sign in to comment.