diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index 6743da3c7..c7c81726d 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -51,3 +51,4 @@ script = "3-global-theme.sh" [[data]] name = "Remove Snaps" script = "4-remove-snaps.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..127c56d6c --- /dev/null +++ b/tabs/utils/git-auto-conf-cli.sh @@ -0,0 +1,89 @@ +#!/bin/sh -e + +# Import common utilities +. ../common-script.sh + +# Install Git if it's not already present +installGit() { + if ! command -v git >/dev/null 2>&1; 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 "%sGit installation not supported for this package manager%s\n" "$RED" "$RC" + exit 1 + ;; + esac + + printf "%sGit installed successfully.%s\n" "$GREEN" "$RC" + 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 + + # 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 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.\n" + 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 + if ! ssh-add -l >/dev/null 2>&1; then + eval "$(ssh-agent -s)" + fi + ssh-add "$ssh_key_path" + else + printf "Skipping passphrase setup.\n" + fi + + 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 +installGit +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"