From 96af3c9b6e4d713e1c21a861ceeb73bdaeaf250d Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Tue, 24 Sep 2024 13:38:07 +0200 Subject: [PATCH 1/3] Changed every `~` to `$HOME` --- .../tabs/applications-setup/dwmtitus-setup.sh | 6 ++--- core/tabs/applications-setup/mybash-setup.sh | 4 ++-- core/tabs/utils/ssh.sh | 24 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/core/tabs/applications-setup/dwmtitus-setup.sh b/core/tabs/applications-setup/dwmtitus-setup.sh index 01ec0ef1..2ef4f379 100755 --- a/core/tabs/applications-setup/dwmtitus-setup.sh +++ b/core/tabs/applications-setup/dwmtitus-setup.sh @@ -129,7 +129,7 @@ picom_animations() { clone_config_folders() { # Ensure the target directory exists - [ ! -d ~/.config ] && mkdir -p ~/.config + [ ! -d "$HOME/.config" ] && mkdir -p "$HOME/.config" # Iterate over all directories in config/* for dir in config/*/; do @@ -138,7 +138,7 @@ clone_config_folders() { # Clone the directory to ~/.config/ if [ -d "$dir" ]; then - cp -r "$dir" ~/.config/ + cp -r "$dir" "$HOME/.config/" printf "%b\n" "${GREEN}Cloned $dir_name to ~/.config/${RC}" else printf "%b\n" "${RED}Directory $dir_name does not exist, skipping${RC}" @@ -157,7 +157,7 @@ configure_backgrounds() { if [ ! -d "$PIC_DIR" ]; then # If it doesn't exist, print an error message and return with a status of 1 (indicating failure) printf "%b\n" "${RED}Pictures directory does not exist${RC}" - mkdir ~/Pictures + mkdir "$HOME/Pictures" printf "%b\n" "${GREEN}Directory was created in Home folder${RC}" fi diff --git a/core/tabs/applications-setup/mybash-setup.sh b/core/tabs/applications-setup/mybash-setup.sh index 7cda9942..76160e93 100644 --- a/core/tabs/applications-setup/mybash-setup.sh +++ b/core/tabs/applications-setup/mybash-setup.sh @@ -61,8 +61,8 @@ installStarshipAndFzf() { if command_exists fzf; then printf "%b\n" "${GREEN}Fzf already installed${RC}" else - git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf - "$ESCALATION_TOOL" ~/.fzf/install + git clone --depth 1 https://github.com/junegunn/fzf.git "$HOME/.fzf" + "$ESCALATION_TOOL" "$HOME/.fzf/install" fi } diff --git a/core/tabs/utils/ssh.sh b/core/tabs/utils/ssh.sh index 1e402546..5d0ba3de 100644 --- a/core/tabs/utils/ssh.sh +++ b/core/tabs/utils/ssh.sh @@ -3,15 +3,15 @@ . ../common-script.sh # Check if ~/.ssh/config exists, if not, create it -if [ ! -f ~/.ssh/config ]; then - touch ~/.ssh/config - chmod 600 ~/.ssh/config +if [ ! -f "$HOME/.ssh/config" ]; then + touch "$HOME/.ssh/config" + chmod 600 "$HOME/.ssh/config" fi # Function to show available hosts from ~/.ssh/config show_available_hosts() { printf "%b\n" "Available Systems:" - grep -E "^Host " ~/.ssh/config | awk '{print $2}' + grep -E "^Host " "$HOME/.ssh/config" | awk '{print $2}' printf "%b\n" "-------------------" } @@ -27,18 +27,18 @@ ask_for_host_details() { 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" " IdentityFile $HOME/.ssh/id_rsa" printf "%b\n" " StrictHostKeyChecking no" printf "%b\n" " UserKnownHostsFile=/dev/null" - } >> ~/.ssh/config + } >> "$HOME/.ssh/config" printf "%b\n" "Host $host_alias added successfully." } # Function to generate SSH key if not exists generate_ssh_key() { - if [ ! -f ~/.ssh/id_rsa ]; then + if [ ! -f "$HOME/.ssh/id_rsa" ]; then printf "%b\n" "SSH key not found, generating one..." - ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N "" -C "$(whoami)@$(hostname)" + ssh-keygen -t rsa -b 4096 -f "$HOME/.ssh/id_rsa -N" "" -C "$(whoami)@$(hostname)" else printf "%b\n" "SSH key already exists." fi @@ -150,7 +150,7 @@ move_directory_to_remote() { remove_system() { printf "%b\n" "Enter the alias of the host to remove: " read -r host_alias - sed -i "/^Host $host_alias/,+3d" ~/.ssh/config + sed -i "/^Host $host_alias/,+3d" "$HOME/.ssh/config" printf "%b\n" "Removed $host_alias from SSH configuration." } @@ -159,9 +159,9 @@ view_ssh_config() { printf "%b\n" "Enter the alias of the host to view (or press Enter to view all): " read -r host_alias if [ -z "$host_alias" ]; then - cat ~/.ssh/config + cat "$HOME/.ssh/config" else - grep -A 3 "^Host $host_alias" ~/.ssh/config + grep -A 3 "^Host $host_alias" "$HOME/.ssh/config" fi } @@ -249,4 +249,4 @@ done checkEnv checkEscalationTool -main \ No newline at end of file +main From 9618128ff8fb8e960e6788395ad7b9c8e891043c Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Sat, 28 Sep 2024 21:04:14 +0200 Subject: [PATCH 2/3] more tildas --- core/tabs/applications-setup/dwmtitus-setup.sh | 6 +++--- core/tabs/utils/ssh.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/tabs/applications-setup/dwmtitus-setup.sh b/core/tabs/applications-setup/dwmtitus-setup.sh index 2ef4f379..b17c3545 100755 --- a/core/tabs/applications-setup/dwmtitus-setup.sh +++ b/core/tabs/applications-setup/dwmtitus-setup.sh @@ -136,10 +136,10 @@ clone_config_folders() { # Extract the directory name dir_name=$(basename "$dir") - # Clone the directory to ~/.config/ + # Clone the directory to $HOME/.config/ if [ -d "$dir" ]; then cp -r "$dir" "$HOME/.config/" - printf "%b\n" "${GREEN}Cloned $dir_name to ~/.config/${RC}" + printf "%b\n" "${GREEN}Cloned $dir_name to $HOME/.config/${RC}" else printf "%b\n" "${RED}Directory $dir_name does not exist, skipping${RC}" fi @@ -153,7 +153,7 @@ configure_backgrounds() { # Set the variable BG_DIR to the path where backgrounds will be stored BG_DIR="$PIC_DIR/backgrounds" - # Check if the ~/Pictures directory exists + # Check if the $HOME/Pictures directory exists if [ ! -d "$PIC_DIR" ]; then # If it doesn't exist, print an error message and return with a status of 1 (indicating failure) printf "%b\n" "${RED}Pictures directory does not exist${RC}" diff --git a/core/tabs/utils/ssh.sh b/core/tabs/utils/ssh.sh index 5d0ba3de..40bf63dd 100644 --- a/core/tabs/utils/ssh.sh +++ b/core/tabs/utils/ssh.sh @@ -2,13 +2,13 @@ . ../common-script.sh -# Check if ~/.ssh/config exists, if not, create it +# Check if $HOME/.ssh/config exists, if not, create it if [ ! -f "$HOME/.ssh/config" ]; then touch "$HOME/.ssh/config" chmod 600 "$HOME/.ssh/config" fi -# Function to show available hosts from ~/.ssh/config +# Function to show available hosts from $HOME/.ssh/config show_available_hosts() { printf "%b\n" "Available Systems:" grep -E "^Host " "$HOME/.ssh/config" | awk '{print $2}' From f688f0c9dde9cb944f2b276230cdb3328bcb9ed8 Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Mon, 30 Sep 2024 00:17:46 +0200 Subject: [PATCH 3/3] even more + `,,` --- core/tabs/system-setup/arch/server-setup.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/tabs/system-setup/arch/server-setup.sh b/core/tabs/system-setup/arch/server-setup.sh index 4ae0afd6..0650db38 100755 --- a/core/tabs/system-setup/arch/server-setup.sh +++ b/core/tabs/system-setup/arch/server-setup.sh @@ -242,7 +242,7 @@ userinfo () { while true do read -r -p "Please enter username: " username - if [[ "${username,,}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]] + if echo "$username" | grep -qE '^[a-z_][a-z0-9_-]{0,31}(\$)?$' then break fi @@ -267,20 +267,23 @@ userinfo () { # Loop through user input until the user gives a valid hostname, but allow the user to force save while true do - read -r -p "Please name your machine: " name_of_machine - # hostname regex (!!couldn't find spec for computer name!!) - if [[ "${name_of_machine,,}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]] + printf "%b" "Please name your machine: " + read -r machine_name + + lower_machine_name=$(echo "$machine_name" | tr '[:upper:]' '[:lower:]') + if echo "$lower_machine_name" | grep -q '^[a-z][a-z0-9_.-]\{0,62\}[a-z0-9]$' then break fi # if validation fails allow the user to force saving of the hostname - read -r -p "Hostname doesn't seem correct. Do you still want to save it? (y/n)" force - if [[ "${force,,}" = "y" ]] + printf "%b" "Hostname doesn't seem correct. Do you still want to save it? (y/N) " + read -r force + if [[ "$force" == "y" || "$force" == "Y" ]] then break fi done - export NAME_OF_MACHINE=$name_of_machine + export NAME_OF_MACHINE=$lower_machine_name } # Starting functions @@ -376,7 +379,7 @@ subvolumesetup () { mountallsubvol } -if [[ "${DISK}" =~ "nvme" ]]; then +if echo "$DISK" | grep -q "nvme"; then partition2=${DISK}p2 partition3=${DISK}p3 else @@ -670,4 +673,4 @@ sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL/# %wheel ALL=(ALL:ALL) NOPASSWD: A # Add sudo rights sed -i 's/^# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers -EOF \ No newline at end of file +EOF