refact: fix (almost) all shellcheck errors

the only files i didn't fix:
- core/tabs/utils/ssh.sh (ref #996)
- core/tabs/system-setup/arch/server-setup.sh
This commit is contained in:
Adam Perkowski 2025-01-11 16:14:38 +01:00
parent d91a44efab
commit 414c75792c
No known key found for this signature in database
GPG Key ID: 7CBDB58ECF1D3478
23 changed files with 77 additions and 72 deletions

View File

@ -19,7 +19,7 @@ install_adb() {
"$ESCALATION_TOOL" "$PACKAGER" add android-tools
;;
*)
printf "%b\n" "${RED}Unsupported package manager: "$PACKAGER"${RC}"
printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
exit 1
;;
esac

View File

@ -8,7 +8,7 @@ installLibreWolf() {
case "$PACKAGER" in
apt-get|nala)
"$ESCALATION_TOOL" "$PACKAGER" install -y gnupg lsb-release apt-transport-https ca-certificates
distro=`if echo " una bookworm vanessa focal jammy bullseye vera uma " | grep -q " $(lsb_release -sc) "; then lsb_release -sc; else echo focal; fi`
distro=$(if echo " una bookworm vanessa focal jammy bullseye vera uma " | grep -q "$(lsb_release -sc)"; then "$(lsb_release -sc)"; else echo 'focal'; fi)
curl -fsSL https://deb.librewolf.net/keyring.gpg | "$ESCALATION_TOOL" gpg --dearmor -o /usr/share/keyrings/librewolf.gpg
echo "Types: deb
URIs: https://deb.librewolf.net
@ -49,4 +49,4 @@ Signed-By: /usr/share/keyrings/librewolf.gpg" | "$ESCALATION_TOOL" tee /etc/apt/
checkEnv
checkEscalationTool
checkAURHelper
installLibreWolf
installLibreWolf

View File

@ -17,7 +17,7 @@ installDiscord() {
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm discord
;;
dnf)
"$ESCALATION_TOOL" "$PACKAGER" install -y https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
"$ESCALATION_TOOL" "$PACKAGER" install -y "https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm"
"$ESCALATION_TOOL" "$PACKAGER" install -y discord
;;
apk)
@ -36,4 +36,4 @@ installDiscord() {
checkEnv
checkEscalationTool
installDiscord
installDiscord

View File

@ -8,7 +8,7 @@ installSignal() {
case "$PACKAGER" in
apt-get|nala)
curl -fsSL https://updates.signal.org/desktop/apt/keys.asc | gpg --dearmor > signal-desktop-keyring.gpg
cat signal-desktop-keyring.gpg | "$ESCALATION_TOOL" tee /usr/share/keyrings/signal-desktop-keyring.gpg > /dev/null
"$ESCALATION_TOOL" tee /usr/share/keyrings/signal-desktop-keyring.gpg < signal-desktop-keyring.gpg > /dev/null
printf "%b\n" 'deb [arch=amd64 signed-by=/usr/share/keyrings/signal-desktop-keyring.gpg] https://updates.signal.org/desktop/apt xenial main' | "$ESCALATION_TOOL" tee /etc/apt/sources.list.d/signal-xenial.list
"$ESCALATION_TOOL" "$PACKAGER" update
"$ESCALATION_TOOL" "$PACKAGER" -y install signal-desktop
@ -39,4 +39,4 @@ installSignal() {
checkEnv
checkEscalationTool
installSignal
installSignal

View File

@ -192,7 +192,7 @@ setupDisplayManager() {
"$ESCALATION_TOOL" "$PACKAGER" install -y xorg-x11-xinit xorg-x11-server-Xorg
;;
*)
printf "%b\n" "${RED}Unsupported package manager: "$PACKAGER"${RC}"
printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
exit 1
;;
esac
@ -244,7 +244,7 @@ setupDisplayManager() {
"$ESCALATION_TOOL" "$PACKAGER" install -y "$DM"
;;
*)
printf "%b\n" "${RED}Unsupported package manager: "$PACKAGER"${RC}"
printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
exit 1
;;
esac

View File

@ -53,7 +53,7 @@ installLinutil() {
;;
*)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. $HOME/.cargo/env
. "$HOME/.cargo/env"
;;
esac
fi

View File

@ -17,7 +17,7 @@ updateLinutil() {
zypper)
"$ESCALATION_TOOL" "$PACKAGER" install -n curl gcc make
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. $HOME/.cargo/env
. "$HOME/.cargo/env"
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add build-base

View File

@ -15,33 +15,33 @@ installDepend() {
else
printf "%b\n" "${GREEN}Multilib is already enabled.${RC}"
fi
"$AUR_HELPER" -S --needed --noconfirm $DEPENDENCIES
"$AUR_HELPER" -S --needed --noconfirm "$DEPENDENCIES"
;;
apt-get|nala)
COMPILEDEPS='build-essential'
"$ESCALATION_TOOL" "$PACKAGER" update
"$ESCALATION_TOOL" dpkg --add-architecture i386
"$ESCALATION_TOOL" "$PACKAGER" update
"$ESCALATION_TOOL" "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
"$ESCALATION_TOOL" "$PACKAGER" install -y "$DEPENDENCIES" "$COMPILEDEPS"
;;
dnf)
COMPILEDEPS='@development-tools'
"$ESCALATION_TOOL" "$PACKAGER" update
"$ESCALATION_TOOL" "$PACKAGER" config-manager --set-enabled powertools
"$ESCALATION_TOOL" "$PACKAGER" install -y $DEPENDENCIES $COMPILEDEPS
"$ESCALATION_TOOL" "$PACKAGER" install -y "$DEPENDENCIES" "$COMPILEDEPS"
"$ESCALATION_TOOL" "$PACKAGER" install -y glibc-devel.i686 libgcc.i686
;;
zypper)
COMPILEDEPS='patterns-devel-base-devel_basis'
"$ESCALATION_TOOL" "$PACKAGER" refresh
"$ESCALATION_TOOL" "$PACKAGER" --non-interactive install $DEPENDENCIES $COMPILEDEPS
"$ESCALATION_TOOL" "$PACKAGER" --non-interactive install "$DEPENDENCIES" "$COMPILEDEPS"
"$ESCALATION_TOOL" "$PACKAGER" --non-interactive install libgcc_s1-gcc7-32bit glibc-devel-32bit
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add build-base multitail tar tree trash-cli unzip cmake jq
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y $DEPENDENCIES
"$ESCALATION_TOOL" "$PACKAGER" install -y "$DEPENDENCIES"
;;
esac
}
@ -49,4 +49,4 @@ installDepend() {
checkEnv
checkAURHelper
checkEscalationTool
installDepend
installDepend

View File

@ -22,7 +22,7 @@ cleanup_system() {
;;
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -Sc --noconfirm
"$ESCALATION_TOOL" "$PACKAGER" -Rns $(pacman -Qtdq) --noconfirm > /dev/null || true
"$ESCALATION_TOOL" "$PACKAGER" -Rns "$(pacman -Qtdq)" --noconfirm > /dev/null || true
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" cache clean

View File

@ -65,12 +65,11 @@ scan_devices() {
printf "%b\n" "$devices"
fi
printf "%b" "Press any key to return to the main menu..."
read -r dummy
read -r _
}
# Function to prompt for MAC address using numbers
prompt_for_mac() {
action=$1
command=$2
prompt_msg=$3
success_msg=$4
@ -82,14 +81,14 @@ prompt_for_mac() {
if [ -z "$devices" ]; then
printf "%b\n" "${RED}No devices available. Please scan for devices first.${RC}"
printf "%b" "Press any key to return to the main menu..."
read -r dummy
read -r _
return
fi
# Display devices with numbers
device_list=$(echo "$devices" | tr '\n' '\n')
i=1
echo "$device_list" | while IFS= read -r device; do
for device in $device_list; do
printf "%d. %s\n" "$i" "$device"
i=$((i + 1))
done
@ -102,12 +101,12 @@ prompt_for_mac() {
device=$(echo "$device_list" | sed -n "${choice}p")
mac=$(echo "$device" | awk '{print $2}')
if bluetoothctl info "$mac" > /dev/null 2>&1; then
bluetoothctl "$command" "$mac" && {
if bluetoothctl "$command" "$mac"; then
printf "%b\n" "${GREEN}$success_msg${RC}"
break
} || {
else
printf "%b\n" "${RED}$failure_msg${RC}"
}
fi
else
printf "%b\n" "${RED}Invalid MAC address. Please try again.${RC}"
fi
@ -118,7 +117,7 @@ prompt_for_mac() {
fi
done
printf "%b" "Press any key to return to the main menu..."
read -r dummy
read -r _
}
# Function to pair with a device

View File

@ -62,11 +62,11 @@ encrypt_file() {
if [ -d "$INPUT_PATH" ]; then
# Encrypt each file in the directory
find "$INPUT_PATH" -type f | while read -r FILE; do
REL_PATH="${FILE#$INPUT_PATH/}"
REL_PATH="${FILE#"$INPUT_PATH"/}"
OUTPUT_FILE="$OUTPUT_PATH/$REL_PATH.enc"
mkdir -p "$(dirname "$OUTPUT_FILE")"
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
if [ $? -eq 0 ]; then
if [ "$(openssl enc -aes-256-cbc -salt -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD")" -eq 0 ]; then
printf "%b\n" "Encrypted: $OUTPUT_FILE"
else
printf "%b\n" "Failed to encrypt: $FILE"
@ -79,8 +79,8 @@ encrypt_file() {
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
if [ "$(openssl enc -aes-256-cbc -salt -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD")" -eq 0 ]; then
printf "%b\n" "Encrypted: $OUTPUT_PATH"
else
printf "%b\n" "Failed to encrypt: $INPUT_PATH"
@ -107,11 +107,11 @@ decrypt_file() {
if [ -d "$INPUT_PATH" ]; then
# Decrypt each file in the directory
find "$INPUT_PATH" -type f -name '*.enc' | while read -r FILE; do
REL_PATH="${FILE#$INPUT_PATH/}"
REL_PATH="${FILE#"$INPUT_PATH"/}"
OUTPUT_FILE="$OUTPUT_PATH/${REL_PATH%.enc}"
mkdir -p "$(dirname "$OUTPUT_FILE")"
openssl enc -aes-256-cbc -d -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
if [ $? -eq 0 ]; then
if [ "$(openssl enc -aes-256-cbc -d -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD")" -eq 0 ]; then
printf "%b\n" "Decrypted: $OUTPUT_FILE"
else
printf "%b\n" "Failed to decrypt: $FILE"
@ -124,8 +124,8 @@ decrypt_file() {
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
if [ "$(openssl enc -aes-256-cbc -d -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD")" -eq 0 ]; then
printf "%b\n" "Decrypted: $OUTPUT_PATH"
else
printf "%b\n" "Failed to decrypt: $INPUT_PATH"
@ -148,10 +148,10 @@ main(){
esac
printf "%b\n" "Press [Enter] to continue..."
read -r dummy
read -r _
done
}
checkEnv
checkEscalationTool
main
main

View File

@ -29,7 +29,7 @@ adjust_monitor_brightness() {
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$'; then
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
printf "Press [Enter] to continue..."
read -r dummy
read -r _
continue
fi
@ -37,7 +37,7 @@ adjust_monitor_brightness() {
if [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$monitor_count" ]; then
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
printf "Press [Enter] to continue..."
read -r dummy
read -r _
continue
fi

View File

@ -33,7 +33,7 @@ set_resolutions() {
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
printf "%b\n" "Press [Enter] to continue..."
read -r dummy
read -r _
continue
fi

View File

@ -85,7 +85,8 @@ run_model() {
printf "%b\n" "${installed_models}"
printf "%b\n" "${YELLOW}Custom Models${RC}"
custom_models=$(ollama list | grep 'custom-model-prefix')
custom_models=$(ollama list | grep 'custom-model-prefix')
printf "%b\n" "${custom_models}"
printf "%b" "Select a model to run: "
printf "%b" "Enter the number corresponding to the model or enter the name of a custom model: "
@ -195,7 +196,7 @@ menu() {
esac
printf "%b\n" "${YELLOW}Press Enter to continue...${RC}"
read -r dummy
read -r _
done
}

View File

@ -173,7 +173,7 @@ setup_ssh_samba(){
printf "%b\n" "5. Exit"
printf "%b" "Enter your choice (1-5): "
read CHOICE
read -r CHOICE
case "$CHOICE" in
1)
@ -205,4 +205,4 @@ setup_ssh_samba(){
checkEnv
checkEscalationTool
setup_ssh_samba
setup_ssh_samba

View File

@ -267,10 +267,10 @@ main() {
esac
printf "%b\n" "Press [Enter] to continue..."
read -r dummy
read -r _
done
}
checkEnv
checkEscalationTool
main
main

View File

@ -67,6 +67,7 @@ create_snapshot() {
"$ESCALATION_TOOL" timeshift --create --comments "$COMMENT" --tags "$TAG"
fi
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
printf "%b\n" "${GREEN}Snapshot created successfully.${RC}"
else
@ -93,6 +94,7 @@ restore_snapshot() {
"$ESCALATION_TOOL" timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --grub-device "$GRUB_DEVICE" --yes
fi
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
printf "%b\n" "${GREEN}Snapshot restored successfully.${RC}"
else
@ -110,6 +112,7 @@ delete_snapshot() {
printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
"$ESCALATION_TOOL" timeshift --delete --snapshot "$SNAPSHOT" --yes
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
printf "%b\n" "${GREEN}Snapshot deleted successfully.${RC}"
else
@ -126,6 +129,7 @@ delete_all_snapshots() {
if [ "$CONFIRMATION" = "y" ] || [ "$CONFIRMATION" = "Y" ]; then
printf "%b\n" "${CYAN}Deleting all snapshots...${RC}"
"$ESCALATION_TOOL" timeshift --delete-all --yes
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
printf "%b\n" "${GREEN}All snapshots deleted successfully.${RC}"
else
@ -153,7 +157,7 @@ main_menu() {
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
esac
printf "%b\n" "${CYAN}Press Enter to continue...${RC}"
read -r dummy
read -r _
done
}

View File

@ -33,7 +33,7 @@ addToGroup() {
groups_to_add=$(echo "$groups" | tr ' ' ',')
printf "%b" "${YELLOW}Are you sure you want to add user $username to $groups_to_add? [Y/n]: ${RC}"
read -r confirm
read -r _
confirmAction || exit 1
"$ESCALATION_TOOL" usermod -aG "$groups_to_add" "$username"
@ -44,4 +44,4 @@ addToGroup() {
checkEnv
checkEscalationTool
checkGroups
addToGroup
addToGroup

View File

@ -17,7 +17,7 @@ changePassword() {
read -r password
printf "%b" "${YELLOW}Are you sure you want to change password for ""$username""? [Y/n]: ${RC}"
read -r confirm
read -r _
confirmAction || exit 1
echo "$username:$password" | "$ESCALATION_TOOL" chpasswd
@ -30,4 +30,4 @@ changePassword() {
checkEnv
checkEscalationTool
changePassword
changePassword

View File

@ -14,7 +14,7 @@ deleteUser() {
if id "$username" > /dev/null 2>&1; then
printf "%b" "${YELLOW}Are you sure you want to delete user ""$username""? [Y/n]: ${RC}"
read -r confirm
read -r _
confirmAction || exit 1
$ESCALATION_TOOL userdel --remove "$username" 2>/dev/null
@ -27,4 +27,4 @@ deleteUser() {
checkEnv
checkEscalationTool
deleteUser
deleteUser

View File

@ -34,14 +34,14 @@ removeFromGroup() {
groups_to_remove=$(echo "$groups" | tr ' ' ',')
printf "%b" "${YELLOW}Are you sure you want to remove user $username from $groups_to_remove? [Y/n]: ${RC}"
read -r confirm
read -r _
confirmAction || exit 1
$ESCALATION_TOOL usermod -rG $groups_to_remove "$username"
$ESCALATION_TOOL usermod -rG "$groups_to_remove" "$username"
printf "%b\n" "${GREEN}User successfully removed from $groups_to_remove${RC}"
}
checkEnv
checkEscalationTool
removeFromGroup
removeFromGroup

View File

@ -30,6 +30,7 @@ execute_command() {
command="$1"
printf "Executing: %s\n" "$command"
eval "$command" 2>&1 | tee /tmp/xrandr.log | tail -n 20
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
printf "%b\n" "${RED}An error occurred while executing the command. Check /tmp/xrandr.log for details.${RC}"
fi

View File

@ -75,33 +75,33 @@ scan_networks() {
echo "$networks" | awk -F: '{printf("%d. SSID: %-25s \n", NR, $1)}'
fi
printf "%b\n" "Press any key to return to the main menu..."
read -r dummy
read -r _
}
# Function to turn WiFi on
wifi_on() {
clear
printf "%b\n" "${YELLOW}Turning WiFi on...${RC}"
nmcli radio wifi on && {
if "$(nmcli radio wifi on)"; then
printf "%b\n" "${GREEN}WiFi is now turned on.${RC}"
} || {
else
printf "%b\n" "${RED}Failed to turn on WiFi.${RC}"
}
fi
printf "%b\n" "Press any key to return to the main menu..."
read -r dummy
read -r _
}
# Function to turn WiFi off
wifi_off() {
clear
printf "%b\n" "${YELLOW}Turning WiFi off...${RC}"
nmcli radio wifi off && {
if "$(nmcli radio wifi off)"; then
printf "%b\n" "${GREEN}WiFi is now turned off.${RC}"
} || {
else
printf "%b\n" "${RED}Failed to turn off WiFi.${RC}"
}
fi
printf "%b\n" "Press any key to return to the main menu..."
read -r dummy
read -r _
}
# Function to prompt for WiFi network selection
@ -118,7 +118,7 @@ prompt_for_network() {
if [ -z "$networks" ]; then
printf "%b\n" "${RED}No networks available. Please scan for networks first.${RC}"
printf "%b\n" "Press any key to return to the main menu..."
read -r dummy
read -r _
rm -f "$temp_file"
return
fi
@ -142,18 +142,18 @@ prompt_for_network() {
printf "%b" "Enter password for SSID: " "$ssid"
read -r password
printf "\n"
nmcli dev wifi connect "$ssid" password "$password" && {
if "$(nmcli dev wifi connect "$ssid" password "$password")"; then
printf "%b\n" "${GREEN}$success_msg${RC}"
} || {
else
printf "%b\n" "${RED}$failure_msg${RC}"
}
fi
fi
else
printf "%b\n" "${RED}Invalid choice. Please try again.${RC}"
fi
printf "%b\n" "Press any key to return to the selection menu..."
read -r dummy
read -r _
done
rm -f "$temp_file"
@ -178,4 +178,4 @@ remove_network() {
checkEnv
checkEscalationTool
setupNetworkManager
main_menu
main_menu