From d430358091d419021c0f67dcca73648e84b01289 Mon Sep 17 00:00:00 2001 From: fam007e Date: Tue, 17 Sep 2024 20:41:03 +0600 Subject: [PATCH 01/10] auto git config's script added and consequential change is made to tab_data toml file. --- tabs/system-setup/git-auto-conf-cli.sh | 86 ++++++++++++++++++++++++++ tabs/system-setup/tab_data.toml | 4 ++ 2 files changed, 90 insertions(+) create mode 100755 tabs/system-setup/git-auto-conf-cli.sh diff --git a/tabs/system-setup/git-auto-conf-cli.sh b/tabs/system-setup/git-auto-conf-cli.sh new file mode 100755 index 000000000..dda7d0195 --- /dev/null +++ b/tabs/system-setup/git-auto-conf-cli.sh @@ -0,0 +1,86 @@ +#!/bin/sh -e + +# Import common utilities +. ../common-script.sh + +# Function to prompt for GitHub configuration +setup_git_config() { + # Prompt for GitHub email + printf "Enter your GitHub email address: " + read email + + # Prompt for SSH key type + echo "Choose your SSH key type:" + echo "1. Ed25519 (recommended)" + echo "2. RSA (legacy)" + printf "Enter your choice (1 or 2): " + read key_type + + # Set key algorithm based on user choice + case "$key_type" in + 1) key_algo="ed25519" ;; + 2) key_algo="rsa" ;; + *) + echo "Invalid choice. Exiting." + exit 1 + ;; + esac + + # Prompt for custom key name + printf "Enter a custom SSH key name (leave blank for default): " + read key_name + + # Set the SSH key path based on user input + ssh_key_path="${HOME}/.ssh/${key_name:-id_$key_algo}" + + # Generate SSH key with specified type and email + ssh-keygen -t "$key_algo" -C "$email" -f "$ssh_key_path" + + # Prompt for passphrase usage + printf "Do you want to use a passphrase? (y/n): " + read use_passphrase + + # If user opts for a passphrase, add key to SSH agent + if [ "$use_passphrase" = "y" ]; then + ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" + ssh-add "$ssh_key_path" + else + echo "Skipping passphrase setup." + fi + + echo "SSH key generation and setup completed." +} + +# Function to copy the SSH key to the clipboard and prompt user to add it to GitHub +copy_and_confirm_ssh_key() { + # Check if xclip is installed + checkCommandRequirements "xclip" + + # Copy the generated public key to the clipboard using xclip + if command -v xclip >/dev/null 2>&1; then + cat "${ssh_key_path}.pub" | xclip -selection clipboard + echo "Your SSH public key has been copied to the clipboard." + else + echo "xclip not found. Please manually copy the SSH key." + cat "${ssh_key_path}.pub" + fi + + # Prompt user to confirm they've added the key to GitHub + while true; do + printf "Have you pasted your SSH public key into your GitHub account? (y/n): " + read yn + case "$yn" in + [Yy]* ) echo "Proceeding..."; break ;; + [Nn]* ) echo "Please paste your SSH public key into GitHub and try again."; exit ;; + * ) echo "Please answer yes (y) or no (n)." ;; + esac + done + + # Test the SSH connection with GitHub + ssh -T git@github.com +} + +# Main execution +checkEnv +setup_git_config +copy_and_confirm_ssh_key diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index 6743da3c7..b0ca66781 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -51,3 +51,7 @@ script = "3-global-theme.sh" [[data]] name = "Remove Snaps" script = "4-remove-snaps.sh" + +[[data]] +name = "Git Auto-conf CLI" +script = "git-auto-conf-cli.sh" From 78cad31875bd025ff488b0b6de0fb553d4e41ceb Mon Sep 17 00:00:00 2001 From: Dark Knightz Date: Tue, 17 Sep 2024 22:55:55 +0600 Subject: [PATCH 02/10] Update tabs/system-setup/tab_data.toml Co-authored-by: Adam Perkowski --- tabs/system-setup/tab_data.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index b0ca66781..1c086dcda 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -53,5 +53,5 @@ name = "Remove Snaps" script = "4-remove-snaps.sh" [[data]] -name = "Git Auto-conf CLI" +name = "Git Configuration" script = "git-auto-conf-cli.sh" From 5040b27fd0b6d22cf0eaed182e5eb51d6d2c738b Mon Sep 17 00:00:00 2001 From: Dark Knightz Date: Tue, 17 Sep 2024 22:56:11 +0600 Subject: [PATCH 03/10] Update tabs/system-setup/git-auto-conf-cli.sh Co-authored-by: Adam Perkowski --- tabs/system-setup/git-auto-conf-cli.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tabs/system-setup/git-auto-conf-cli.sh b/tabs/system-setup/git-auto-conf-cli.sh index dda7d0195..d640980d0 100755 --- a/tabs/system-setup/git-auto-conf-cli.sh +++ b/tabs/system-setup/git-auto-conf-cli.sh @@ -5,8 +5,7 @@ # Function to prompt for GitHub configuration setup_git_config() { - # Prompt for GitHub email - printf "Enter your GitHub email address: " + printf "Enter your email address: " read email # Prompt for SSH key type From 5947b3393a54df834e60ae723a35f224eaf4b992 Mon Sep 17 00:00:00 2001 From: Dark Knightz Date: Tue, 17 Sep 2024 22:56:25 +0600 Subject: [PATCH 04/10] Update tabs/system-setup/git-auto-conf-cli.sh Co-authored-by: Adam Perkowski --- tabs/system-setup/git-auto-conf-cli.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tabs/system-setup/git-auto-conf-cli.sh b/tabs/system-setup/git-auto-conf-cli.sh index d640980d0..74351b854 100755 --- a/tabs/system-setup/git-auto-conf-cli.sh +++ b/tabs/system-setup/git-auto-conf-cli.sh @@ -36,16 +36,18 @@ setup_git_config() { ssh-keygen -t "$key_algo" -C "$email" -f "$ssh_key_path" # Prompt for passphrase usage - printf "Do you want to use a passphrase? (y/n): " + printf "Do you want to use a passphrase? (Y/n): " read use_passphrase - - # If user opts for a passphrase, add key to SSH agent - if [ "$use_passphrase" = "y" ]; then - ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" - ssh-add "$ssh_key_path" - else - echo "Skipping passphrase setup." - fi + + case "$use_passphrase" in + n|N) + echo "Skipping passphrase setup." + ;; + *) + ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" + ssh-add "$ssh_key_path" + ;; + esac echo "SSH key generation and setup completed." } From bb095b0425db6bccf531d339f46a3ff0c9caf104 Mon Sep 17 00:00:00 2001 From: fam007e Date: Tue, 17 Sep 2024 23:54:27 +0600 Subject: [PATCH 05/10] check cmd req for git cmd is added and the script for git config is moved to utils dir as a concsequence affected tabs TOML is edited --- tabs/system-setup/git-auto-conf-cli.sh | 87 -------------------------- tabs/system-setup/tab_data.toml | 3 - tabs/utils/git-auto-conf-cli.sh | 57 +++++++++++++++++ tabs/utils/tab_data.toml | 4 ++ 4 files changed, 61 insertions(+), 90 deletions(-) delete mode 100755 tabs/system-setup/git-auto-conf-cli.sh create mode 100755 tabs/utils/git-auto-conf-cli.sh diff --git a/tabs/system-setup/git-auto-conf-cli.sh b/tabs/system-setup/git-auto-conf-cli.sh deleted file mode 100755 index 74351b854..000000000 --- a/tabs/system-setup/git-auto-conf-cli.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/sh -e - -# Import common utilities -. ../common-script.sh - -# Function to prompt for GitHub configuration -setup_git_config() { - printf "Enter your email address: " - read email - - # Prompt for SSH key type - echo "Choose your SSH key type:" - echo "1. Ed25519 (recommended)" - echo "2. RSA (legacy)" - printf "Enter your choice (1 or 2): " - read key_type - - # Set key algorithm based on user choice - case "$key_type" in - 1) key_algo="ed25519" ;; - 2) key_algo="rsa" ;; - *) - echo "Invalid choice. Exiting." - exit 1 - ;; - esac - - # Prompt for custom key name - printf "Enter a custom SSH key name (leave blank for default): " - read key_name - - # Set the SSH key path based on user input - ssh_key_path="${HOME}/.ssh/${key_name:-id_$key_algo}" - - # Generate SSH key with specified type and email - ssh-keygen -t "$key_algo" -C "$email" -f "$ssh_key_path" - - # Prompt for passphrase usage - printf "Do you want to use a passphrase? (Y/n): " - read use_passphrase - - case "$use_passphrase" in - n|N) - echo "Skipping passphrase setup." - ;; - *) - ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" - ssh-add "$ssh_key_path" - ;; - esac - - echo "SSH key generation and setup completed." -} - -# Function to copy the SSH key to the clipboard and prompt user to add it to GitHub -copy_and_confirm_ssh_key() { - # Check if xclip is installed - checkCommandRequirements "xclip" - - # Copy the generated public key to the clipboard using xclip - if command -v xclip >/dev/null 2>&1; then - cat "${ssh_key_path}.pub" | xclip -selection clipboard - echo "Your SSH public key has been copied to the clipboard." - else - echo "xclip not found. Please manually copy the SSH key." - cat "${ssh_key_path}.pub" - fi - - # Prompt user to confirm they've added the key to GitHub - while true; do - printf "Have you pasted your SSH public key into your GitHub account? (y/n): " - read yn - case "$yn" in - [Yy]* ) echo "Proceeding..."; break ;; - [Nn]* ) echo "Please paste your SSH public key into GitHub and try again."; exit ;; - * ) echo "Please answer yes (y) or no (n)." ;; - esac - done - - # Test the SSH connection with GitHub - ssh -T git@github.com -} - -# Main execution -checkEnv -setup_git_config -copy_and_confirm_ssh_key diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index 1c086dcda..c7c81726d 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -52,6 +52,3 @@ script = "3-global-theme.sh" name = "Remove Snaps" script = "4-remove-snaps.sh" -[[data]] -name = "Git Configuration" -script = "git-auto-conf-cli.sh" diff --git a/tabs/utils/git-auto-conf-cli.sh b/tabs/utils/git-auto-conf-cli.sh new file mode 100755 index 000000000..004bc3d8c --- /dev/null +++ b/tabs/utils/git-auto-conf-cli.sh @@ -0,0 +1,57 @@ +#!/bin/sh -e + +# Import common utilities +. ../common-script.sh + +# Function to prompt for GitHub configuration +setup_git_config() { + checkCommandRequirements "git" + # Prompt for GitHub email + printf "Enter your GitHub email address: " + read email + + # Prompt for SSH key type + echo "Choose your SSH key type:" + echo "1. Ed25519 (recommended)" + echo "2. RSA (legacy)" + printf "Enter your choice (1 or 2): " + read key_type + + # Set key algorithm based on user choice + case "$key_type" in + 1) key_algo="ed25519" ;; + 2) key_algo="rsa" ;; + *) + echo "Invalid choice. Exiting." + exit 1 + ;; + esac + + # Prompt for custom key name + printf "Enter a custom SSH key name (leave blank for default): " + read key_name + + # Set the SSH key path based on user input + ssh_key_path="${HOME}/.ssh/${key_name:-id_$key_algo}" + + # Generate SSH key with specified type and email + ssh-keygen -t "$key_algo" -C "$email" -f "$ssh_key_path" + + # Prompt for passphrase usage + printf "Do you want to use a passphrase? (y/n): " + read use_passphrase + + # If user opts for a passphrase, add key to SSH agent + if [ "$use_passphrase" = "y" ]; then + ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" + ssh-add "$ssh_key_path" + else + echo "Skipping passphrase setup." + fi + echo "SSH key generation and setup completed.\nPlease copy the key from your ssh dir and paste it to your corresponding account ssh key add section of your github settings page.\nThen run this command to verify ssh connection:\nssh -T git@github.com" +} + + +# Main execution +checkEnv +setup_git_config diff --git a/tabs/utils/tab_data.toml b/tabs/utils/tab_data.toml index 67ba893fd..36e1a75ed 100644 --- a/tabs/utils/tab_data.toml +++ b/tabs/utils/tab_data.toml @@ -12,6 +12,10 @@ script = "bluetooth-control.sh" name = "Numlock on Startup" script = "numlock.sh" +[[data]] +name = "Git Configuration" +script = "git-auto-conf-cli.sh" + [[data]] name = "Monitor Control" From 8c7557b4644eed7fb534fda46bd28670be982384 Mon Sep 17 00:00:00 2001 From: fam007e Date: Wed, 18 Sep 2024 00:02:56 +0600 Subject: [PATCH 06/10] check cmd req for git cmd is added at the main exec part --- tabs/utils/git-auto-conf-cli.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tabs/utils/git-auto-conf-cli.sh b/tabs/utils/git-auto-conf-cli.sh index 004bc3d8c..a0d3e809e 100755 --- a/tabs/utils/git-auto-conf-cli.sh +++ b/tabs/utils/git-auto-conf-cli.sh @@ -5,7 +5,7 @@ # Function to prompt for GitHub configuration setup_git_config() { - checkCommandRequirements "git" + # Prompt for GitHub email printf "Enter your GitHub email address: " read email @@ -54,4 +54,5 @@ setup_git_config() { # Main execution checkEnv +checkCommandRequirements "git" setup_git_config From 8a14b107c063b26cdc25522f6bb66983e93f849b Mon Sep 17 00:00:00 2001 From: fam007e Date: Wed, 18 Sep 2024 00:05:06 +0600 Subject: [PATCH 07/10] removed extra line from the script --- tabs/utils/git-auto-conf-cli.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tabs/utils/git-auto-conf-cli.sh b/tabs/utils/git-auto-conf-cli.sh index a0d3e809e..12078017f 100755 --- a/tabs/utils/git-auto-conf-cli.sh +++ b/tabs/utils/git-auto-conf-cli.sh @@ -5,7 +5,6 @@ # Function to prompt for GitHub configuration setup_git_config() { - # Prompt for GitHub email printf "Enter your GitHub email address: " read email @@ -51,7 +50,6 @@ setup_git_config() { echo "SSH key generation and setup completed.\nPlease copy the key from your ssh dir and paste it to your corresponding account ssh key add section of your github settings page.\nThen run this command to verify ssh connection:\nssh -T git@github.com" } - # Main execution checkEnv checkCommandRequirements "git" From b7134ce83c32a6fa47339f08997de0a7da13b6aa Mon Sep 17 00:00:00 2001 From: fam007e Date: Wed, 18 Sep 2024 00:07:26 +0600 Subject: [PATCH 08/10] removed echo cmd --- tabs/utils/git-auto-conf-cli.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tabs/utils/git-auto-conf-cli.sh b/tabs/utils/git-auto-conf-cli.sh index 12078017f..f51536ef0 100755 --- a/tabs/utils/git-auto-conf-cli.sh +++ b/tabs/utils/git-auto-conf-cli.sh @@ -10,9 +10,9 @@ setup_git_config() { read email # Prompt for SSH key type - echo "Choose your SSH key type:" - echo "1. Ed25519 (recommended)" - echo "2. RSA (legacy)" + printf "Choose your SSH key type:" + printf "1. Ed25519 (recommended)" + printf "2. RSA (legacy)" printf "Enter your choice (1 or 2): " read key_type @@ -21,7 +21,7 @@ setup_git_config() { 1) key_algo="ed25519" ;; 2) key_algo="rsa" ;; *) - echo "Invalid choice. Exiting." + printf "Invalid choice. Exiting." exit 1 ;; esac @@ -45,9 +45,9 @@ setup_git_config() { ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" ssh-add "$ssh_key_path" else - echo "Skipping passphrase setup." + printf "Skipping passphrase setup." fi - echo "SSH key generation and setup completed.\nPlease copy the key from your ssh dir and paste it to your corresponding account ssh key add section of your github settings page.\nThen run this command to verify ssh connection:\nssh -T git@github.com" + printf "SSH key generation and setup completed.\nPlease copy the key from your ssh dir and paste it to your corresponding account ssh key add section of your github settings page.\nThen run this command to verify ssh connection:\nssh -T git@github.com" } # Main execution From 521c8e5ecf7c89c0b6391934e24e4836512209d9 Mon Sep 17 00:00:00 2001 From: fam007e Date: Wed, 18 Sep 2024 00:24:05 +0600 Subject: [PATCH 09/10] new fresh approach --- tabs/utils/git-auto-conf-cli.sh | 57 ++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/tabs/utils/git-auto-conf-cli.sh b/tabs/utils/git-auto-conf-cli.sh index f51536ef0..08b024397 100755 --- a/tabs/utils/git-auto-conf-cli.sh +++ b/tabs/utils/git-auto-conf-cli.sh @@ -3,32 +3,59 @@ # Import common utilities . ../common-script.sh +# Install Git if it's not already present +installGit() { + if ! command_exists git; then + printf "Git is not installed. Installing it now...\n" + + case $PACKAGER in + pacman|xbps-install) + $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm git + ;; + apt-get|nala|dnf|zypper) + $ESCALATION_TOOL "$PACKAGER" install -y git + ;; + nix-env) + nix-env -iA nixpkgs.git + ;; + *) + printf "${RED}Git installation not supported for this package manager${RC}\n" + exit 1 + ;; + esac + + printf "${GREEN}Git installed successfully.${RC}\n" + else + printf "Git is already installed.\n" + fi +} + # Function to prompt for GitHub configuration setup_git_config() { # Prompt for GitHub email printf "Enter your GitHub email address: " - read email + read -r email # Prompt for SSH key type - printf "Choose your SSH key type:" - printf "1. Ed25519 (recommended)" - printf "2. RSA (legacy)" + printf "Choose your SSH key type:\n" + printf "1. Ed25519 (recommended)\n" + printf "2. RSA (legacy)\n" printf "Enter your choice (1 or 2): " - read key_type + read -r key_type # Set key algorithm based on user choice case "$key_type" in 1) key_algo="ed25519" ;; 2) key_algo="rsa" ;; *) - printf "Invalid choice. Exiting." + printf "Invalid choice. Exiting.\n" exit 1 ;; esac # Prompt for custom key name printf "Enter a custom SSH key name (leave blank for default): " - read key_name + read -r key_name # Set the SSH key path based on user input ssh_key_path="${HOME}/.ssh/${key_name:-id_$key_algo}" @@ -38,19 +65,25 @@ setup_git_config() { # Prompt for passphrase usage printf "Do you want to use a passphrase? (y/n): " - read use_passphrase + read -r use_passphrase # If user opts for a passphrase, add key to SSH agent if [ "$use_passphrase" = "y" ]; then - ssh-add -l >/dev/null 2>&1 || eval "$(ssh-agent -s)" + if ! ssh-add -l >/dev/null 2>&1; then + eval "$(ssh-agent -s)" + fi ssh-add "$ssh_key_path" else - printf "Skipping passphrase setup." + printf "Skipping passphrase setup.\n" fi - printf "SSH key generation and setup completed.\nPlease copy the key from your ssh dir and paste it to your corresponding account ssh key add section of your github settings page.\nThen run this command to verify ssh connection:\nssh -T git@github.com" + + printf "SSH key generation and setup completed.\n" + printf "Please copy the SSH key and add it to your GitHub account.\n" + printf "Then run this command to verify the SSH connection:\n" + printf "ssh -T git@github.com\n" } # Main execution checkEnv -checkCommandRequirements "git" +installGit setup_git_config From ff7049452db7b1e09df2e25f80f3516f375b0c48 Mon Sep 17 00:00:00 2001 From: fam007e Date: Wed, 18 Sep 2024 00:34:52 +0600 Subject: [PATCH 10/10] ok if this is not to your liking close and trash the PR, I am done --- tabs/utils/git-auto-conf-cli.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tabs/utils/git-auto-conf-cli.sh b/tabs/utils/git-auto-conf-cli.sh index 08b024397..127c56d6c 100755 --- a/tabs/utils/git-auto-conf-cli.sh +++ b/tabs/utils/git-auto-conf-cli.sh @@ -5,26 +5,26 @@ # Install Git if it's not already present installGit() { - if ! command_exists git; then + if ! command -v git >/dev/null 2>&1; then printf "Git is not installed. Installing it now...\n" - case $PACKAGER in + case "$PACKAGER" in pacman|xbps-install) - $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm git + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm git ;; apt-get|nala|dnf|zypper) - $ESCALATION_TOOL "$PACKAGER" install -y git + "$ESCALATION_TOOL" "$PACKAGER" install -y git ;; nix-env) nix-env -iA nixpkgs.git ;; *) - printf "${RED}Git installation not supported for this package manager${RC}\n" + printf "%sGit installation not supported for this package manager%s\n" "$RED" "$RC" exit 1 ;; esac - printf "${GREEN}Git installed successfully.${RC}\n" + printf "%sGit installed successfully.%s\n" "$GREEN" "$RC" else printf "Git is already installed.\n" fi @@ -34,14 +34,14 @@ installGit() { setup_git_config() { # Prompt for GitHub email printf "Enter your GitHub email address: " - read -r email + read email # Prompt for SSH key type printf "Choose your SSH key type:\n" printf "1. Ed25519 (recommended)\n" printf "2. RSA (legacy)\n" printf "Enter your choice (1 or 2): " - read -r key_type + read key_type # Set key algorithm based on user choice case "$key_type" in @@ -55,7 +55,7 @@ setup_git_config() { # Prompt for custom key name printf "Enter a custom SSH key name (leave blank for default): " - read -r key_name + read key_name # Set the SSH key path based on user input ssh_key_path="${HOME}/.ssh/${key_name:-id_$key_algo}" @@ -65,7 +65,7 @@ setup_git_config() { # Prompt for passphrase usage printf "Do you want to use a passphrase? (y/n): " - read -r use_passphrase + read use_passphrase # If user opts for a passphrase, add key to SSH agent if [ "$use_passphrase" = "y" ]; then