Skip to content

Commit

Permalink
Merge pull request #282 from nnyyxxxx/testing-6
Browse files Browse the repository at this point in the history
Remove every bashism
  • Loading branch information
ChrisTitusTech authored Sep 15, 2024
2 parents f2e322f + 38d1732 commit 43740a4
Show file tree
Hide file tree
Showing 24 changed files with 378 additions and 422 deletions.
121 changes: 46 additions & 75 deletions tabs/applications-setup/dwmtitus-setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh -e

. ../common-script.sh

makeDWM() {
Expand Down Expand Up @@ -114,7 +115,7 @@ picom_animations() {
fi

# Install the built binary
if ! sudo ninja -C build install; then
if ! $ESCALATION_TOOL ninja -C build install; then
echo "Failed to install the built binary"
return 1
fi
Expand Down Expand Up @@ -192,8 +193,8 @@ setupDisplayManager() {
echo "Setting up Display Manager"
currentdm="none"
for dm in gdm sddm lightdm; do
if systemctl is-active --quiet $dm.service; then
currentdm=$dm
if systemctl is-active --quiet "$dm.service"; then
currentdm="$dm"
break
fi
done
Expand All @@ -203,92 +204,62 @@ setupDisplayManager() {
echo "No display manager found, installing $DM"
case "$PACKAGER" in
pacman)
$ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm $DM
$ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm "$DM"
;;
apt)
$ESCALATION_TOOL "$PACKAGER" install -y $DM
$ESCALATION_TOOL "$PACKAGER" install -y "$DM"
;;
dnf)
$ESCALATION_TOOL "$PACKAGER" install -y $DM
$ESCALATION_TOOL "$PACKAGER" install -y "$DM"
;;
*)
echo "Unsupported package manager: $PACKAGER"
exit 1
;;
esac
echo "$DM installed successfully"
systemctl enable $DM

# Clear the screen
clear
systemctl enable "$DM"

# Prompt user for auto-login
echo "Do you want to enable auto-login?"
echo "Use arrow keys or j/k to navigate, Enter to select"
options=("Yes" "No")
selected=0

# Function to print menu
print_menu() {
for i in "${!options[@]}"; do
if [ $i -eq $selected ]; then
echo "> ${options[$i]}"
# Using printf instead of echo -n as It's more posix-compliant.
printf "Do you want to enable auto-login? (Y/n) "
read -r answer
case "$answer" in
[Yy]*)
echo "Configuring SDDM for autologin"
SDDM_CONF="/etc/sddm.conf"
if [ ! -f "$SDDM_CONF" ]; then
echo "[Autologin]" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "User=$USER" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "Session=dwm" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
else
echo " ${options[$i]}"
$ESCALATION_TOOL sed -i '/^\[Autologin\]/d' "$SDDM_CONF"
$ESCALATION_TOOL sed -i '/^User=/d' "$SDDM_CONF"
$ESCALATION_TOOL sed -i '/^Session=/d' "$SDDM_CONF"
echo "[Autologin]" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "User=$USER" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
echo "Session=dwm" | $ESCALATION_TOOL tee -a "$SDDM_CONF"
fi
done
}

# Handle user input
while true; do
print_menu
read -rsn1 key
case "$key" in
$'\x1B') # ESC sequence for arrow keys
read -rsn2 key
case "$key" in
'[A' | 'k') ((selected > 0)) && ((selected--));; # Up arrow or k
'[B' | 'j') ((selected < ${#options[@]}-1)) && ((selected++));; # Down arrow or j
esac
;;
'') break;; # Enter key
esac
clear
done

if [ "${options[$selected]}" = "Yes" ]; then
echo "Configuring SDDM for autologin"
SDDM_CONF="/etc/sddm.conf"
if [ ! -f "$SDDM_CONF" ]; then
echo "[Autologin]" | sudo tee -a "$SDDM_CONF"
echo "User=$USER" | sudo tee -a "$SDDM_CONF"
echo "Session=dwm" | sudo tee -a "$SDDM_CONF"
else
sudo sed -i '/^\[Autologin\]/d' "$SDDM_CONF"
sudo sed -i '/^User=/d' "$SDDM_CONF"
sudo sed -i '/^Session=/d' "$SDDM_CONF"
echo "[Autologin]" | sudo tee -a "$SDDM_CONF"
echo "User=$USER" | sudo tee -a "$SDDM_CONF"
echo "Session=dwm" | sudo tee -a "$SDDM_CONF"
fi
echo "Checking if autologin group exists"
if ! getent group autologin > /dev/null; then
echo "Creating autologin group"
sudo groupadd autologin
else
echo "Autologin group already exists"
fi
echo "Adding user with UID 1000 to autologin group"
USER_UID_1000=$(getent passwd 1000 | cut -d: -f1)
if [ -n "$USER_UID_1000" ]; then
sudo usermod -aG autologin "$USER_UID_1000"
echo "User $USER_UID_1000 added to autologin group"
else
echo "No user with UID 1000 found - Auto login not possible"
fi
else
echo "Auto-login configuration skipped"
fi
echo "Checking if autologin group exists"
if ! getent group autologin > /dev/null; then
echo "Creating autologin group"
$ESCALATION_TOOL groupadd autologin
else
echo "Autologin group already exists"
fi
echo "Adding user with UID 1000 to autologin group"
USER_UID_1000=$(getent passwd 1000 | cut -d: -f1)
if [ -n "$USER_UID_1000" ]; then
$ESCALATION_TOOL usermod -aG autologin "$USER_UID_1000"
echo "User $USER_UID_1000 added to autologin group"
else
echo "No user with UID 1000 found - Auto login not possible"
fi
;;
*)
echo "Auto-login configuration skipped"
;;
esac
fi


Expand All @@ -302,4 +273,4 @@ setupDWM
makeDWM
install_nerd_font
clone_config_folders
configure_backgrounds
configure_backgrounds
4 changes: 2 additions & 2 deletions tabs/common-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ checkEscalationTool() {
fi
done

echo -e "${RED}Can't find a supported escalation tool${RC}"
printf "%b\n" "${RED}Can't find a supported escalation tool${RC}"
exit 1
fi
}
Expand Down Expand Up @@ -82,7 +82,7 @@ checkPackageManager() {
done

if [ -z "${PACKAGER}" ]; then
echo -e "${RED}Can't find a supported package manager${RC}"
printf "%b\n" "${RED}Can't find a supported package manager${RC}"
exit 1
fi
}
Expand Down
4 changes: 2 additions & 2 deletions tabs/security/firewall-baselines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ installPkg() {
}

configureUFW() {
echo -e "${GREEN}Using Chris Titus Recommended Firewall Rules${RC}"
printf "%b\n" "${GREEN}Using Chris Titus Recommended Firewall Rules${RC}"

echo "Disabling UFW"
$ESCALATION_TOOL ufw disable
Expand All @@ -40,7 +40,7 @@ configureUFW() {
$ESCALATION_TOOL ufw default allow outgoing

$ESCALATION_TOOL ufw enable
echo -e "${GREEN}Enabled Firewall with Baselines!${RC}"
printf "%b\n" "${GREEN}Enabled Firewall with Baselines!${RC}"
}

checkEnv
Expand Down
2 changes: 1 addition & 1 deletion tabs/system-setup/1-compile-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
installDepend() {
## Check for dependencies.
DEPENDENCIES='tar tree multitail tldr trash-cli unzip cmake make jq'
echo -e "${YELLOW}Installing dependencies...${RC}"
printf "%b\n" "${YELLOW}Installing dependencies...${RC}"
case $PACKAGER in
pacman)
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
Expand Down
2 changes: 1 addition & 1 deletion tabs/system-setup/2-gaming-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

installDepend() {
## Check for dependencies.
echo -e "${YELLOW}Installing dependencies...${RC}"
printf "%b\n" "${YELLOW}Installing dependencies...${RC}"
if [ "$PACKAGER" = "pacman" ]; then
if ! grep -q "^\s*\[multilib\]" /etc/pacman.conf; then
echo "[multilib]" | $ESCALATION_TOOL tee -a /etc/pacman.conf
Expand Down
18 changes: 9 additions & 9 deletions tabs/system-setup/3-global-theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. ../common-script.sh

install_theme_tools() {
printf "${YELLOW}Installing theme tools (qt6ct and kvantum)...${RC}\n"
printf "%b\n" "${YELLOW}Installing theme tools (qt6ct and kvantum)...${RC}\n"
case $PACKAGER in
apt-get)
$ESCALATION_TOOL apt-get update
Expand All @@ -21,41 +21,41 @@ install_theme_tools() {
$ESCALATION_TOOL pacman -S --needed --noconfirm qt6ct kvantum
;;
*)
printf "${RED}Unsupported package manager. Please install qt6ct and kvantum manually.${RC}\n"
printf "%b\n" "${RED}Unsupported package manager. Please install qt6ct and kvantum manually.${RC}\n"
exit 1
;;
esac
}

configure_qt6ct() {
printf "${YELLOW}Configuring qt6ct...${RC}\n"
printf "%b\n" "${YELLOW}Configuring qt6ct...${RC}\n"
mkdir -p "$HOME/.config/qt6ct"
cat <<EOF > "$HOME/.config/qt6ct/qt6ct.conf"
[Appearance]
style=kvantum
color_scheme=default
icon_theme=breeze
EOF
printf "${GREEN}qt6ct configured successfully.${RC}\n"
printf "%b\n" "${GREEN}qt6ct configured successfully.${RC}\n"

# Add QT_QPA_PLATFORMTHEME to /etc/environment
if ! grep -q "QT_QPA_PLATFORMTHEME=qt6ct" /etc/environment; then
printf "${YELLOW}Adding QT_QPA_PLATFORMTHEME to /etc/environment...${RC}\n"
printf "%b\n" "${YELLOW}Adding QT_QPA_PLATFORMTHEME to /etc/environment...${RC}\n"
echo "QT_QPA_PLATFORMTHEME=qt6ct" | $ESCALATION_TOOL tee -a /etc/environment > /dev/null
printf "${GREEN}QT_QPA_PLATFORMTHEME added to /etc/environment.${RC}\n"
printf "%b\n" "${GREEN}QT_QPA_PLATFORMTHEME added to /etc/environment.${RC}\n"
else
printf "${GREEN}QT_QPA_PLATFORMTHEME already set in /etc/environment.${RC}\n"
printf "%b\n" "${GREEN}QT_QPA_PLATFORMTHEME already set in /etc/environment.${RC}\n"
fi
}

configure_kvantum() {
printf "${YELLOW}Configuring Kvantum...${RC}\n"
printf "%b\n" "${YELLOW}Configuring Kvantum...${RC}\n"
mkdir -p "$HOME/.config/Kvantum"
cat <<EOF > "$HOME/.config/Kvantum/kvantum.kvconfig"
[General]
theme=Breeze
EOF
printf "${GREEN}Kvantum configured successfully.${RC}\n"
printf "%b\n" "${GREEN}Kvantum configured successfully.${RC}\n"
}

checkEnv
Expand Down
2 changes: 1 addition & 1 deletion tabs/system-setup/arch/paru-setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e

. "$(dirname "$0")/../../common-script.sh"
. ../../common-script.sh

installDepend() {
case $PACKAGER in
Expand Down
2 changes: 1 addition & 1 deletion tabs/system-setup/arch/yay-setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e

. "$(dirname "$0")/../../common-script.sh"
. ../../common-script.sh

installDepend() {
case $PACKAGER in
Expand Down
4 changes: 2 additions & 2 deletions tabs/system-setup/fedora/rpm-fusion-setup.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh -e

. "$(dirname "$0")/../../common-script.sh"
. ../../common-script.sh

# https://rpmfusion.org/Configuration

installRPMFusion() {
case $PACKAGER in
dnf)
if [[ ! -e /etc/yum.repos.d/rpmfusion-free.repo || ! -e /etc/yum.repos.d/rpmfusion-nonfree.repo ]]; then
if [ ! -e /etc/yum.repos.d/rpmfusion-free.repo ] || [ ! -e /etc/yum.repos.d/rpmfusion-nonfree.repo ]; then
echo "Installing RPM Fusion..."
$ESCALATION_TOOL "$PACKAGER" install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
$ESCALATION_TOOL "$PACKAGER" config-manager --enable fedora-cisco-openh264
Expand Down
10 changes: 5 additions & 5 deletions tabs/system-setup/system-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ fastUpdate() {

$ESCALATION_TOOL rate-mirrors --top-mirrors-number-to-retest=5 --disable-comments --save /etc/pacman.d/mirrorlist --allow-root ${dtype_local}
if [ $? -ne 0 ] || [ ! -s /etc/pacman.d/mirrorlist ]; then
echo -e "${RED}Rate-mirrors failed, restoring backup.${RC}"
printf "%b\n" "${RED}Rate-mirrors failed, restoring backup.${RC}"
$ESCALATION_TOOL cp /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
fi
;;

apt-get|nala)
$ESCALATION_TOOL apt-get update
if ! command_exists nala; then
$ESCALATION_TOOL apt-get install -y nala || { echo -e "${YELLOW}Falling back to apt-get${RC}"; PACKAGER="apt-get"; }
$ESCALATION_TOOL apt-get install -y nala || { printf "%b\n" "${YELLOW}Falling back to apt-get${RC}"; PACKAGER="apt-get"; }
fi

if [ "${PACKAGER}" = "nala" ]; then
Expand All @@ -54,14 +54,14 @@ fastUpdate() {
$ESCALATION_TOOL ${PACKAGER} -Syu
;;
*)
echo -e "${RED}Unsupported package manager: $PACKAGER${RC}"
printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}"
exit 1
;;
esac
}

updateSystem() {
echo -e "${GREEN}Updating system${RC}"
printf "%b\n" "${GREEN}Updating system${RC}"
case ${PACKAGER} in
nala|apt-get)
$ESCALATION_TOOL "${PACKAGER}" update -y
Expand All @@ -83,7 +83,7 @@ updateSystem() {
$ESCALATION_TOOL ${PACKAGER} -Syu
;;
*)
echo -e "${RED}Unsupported package manager: ${PACKAGER}${RC}"
printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}${RC}"
exit 1
;;
esac
Expand Down
Loading

0 comments on commit 43740a4

Please sign in to comment.