#!/bin/bash set -e ### === SETTINGS === ### GIT_SERVER="git.del-c.net" USERNAME="" SELECTED_REPO="" SELECTED_DIR="" ### === GET USERNAME === ### get_username() { echo "[?] Enter your git username:" read -p "Username: " USERNAME if [ -z "$USERNAME" ]; then echo "[!] Username cannot be empty. Please try again." get_username fi echo "[*] Using username: $USERNAME" echo } ### === CHECK FOR SSH KEY === ### generate_ssh_key() { if [ ! -f "$HOME/.ssh/id_ed25519.pub" ]; then echo "[+] No SSH key found. Need to generate a new SSH key..." echo "[+] Are you using the correct system user?" echo "[+] If not, please switch to the correct user and run this script again." echo "[+] If you are using the correct user, please enter your email for the SSH key." read -p "Enter your email for the SSH key: " user_email ssh-keygen -t ed25519 -C "$user_email" -f "$HOME/.ssh/id_ed25519" -N "" else echo "[~] SSH key already exists." fi } show_ssh_key() { echo "[*] Add the following public key to your GitHub account:" echo "----------------------------------------" cat "$HOME/.ssh/id_ed25519.pub" echo "----------------------------------------" echo "[*] Go to your git site and add the key to your account." echo read -p "Press Enter after you've added the key..." } ### === LIST AVAILABLE GIT PROJECTS === ### list_git_projects() { echo "[+] Fetching available git projects for user: $USERNAME..." # Get list of repositories using git ls-remote echo "[*] Available repositories:" local repo_count=1 local found_repos=() # Check for common repository patterns for repo in "dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace"; do local full_repo="$USERNAME/$repo" if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then echo "$repo_count. $full_repo" found_repos+=("$full_repo") ((repo_count++)) fi done if [ ${#found_repos[@]} -eq 0 ]; then echo "[!] No repositories found for user: $USERNAME" echo "[*] You can still enter a custom repository path." fi echo } ### === SELECT PROJECT TO DOWNLOAD === ### select_project() { list_git_projects echo "[?] Which project would you like to download?" echo "Enter the number of the repository from the list above, or:" echo "- Press Enter to use $USERNAME/dotfiles (if available)" echo "- Type 'custom' to enter a custom repository path" echo read -p "Enter your choice: " choice if [ -z "$choice" ]; then # Default to dotfiles if it exists if git ls-remote "git@$GIT_SERVER:$USERNAME/dotfiles.git" &>/dev/null; then SELECTED_REPO="git@$GIT_SERVER:$USERNAME/dotfiles.git" SELECTED_DIR="$HOME/.dotfiles" else echo "[!] $USERNAME/dotfiles not found. Please select a repository." select_project return fi elif [ "$choice" = "custom" ]; then read -p "Enter repository path (e.g., $USERNAME/myproject): " custom_repo SELECTED_REPO="git@$GIT_SERVER:$custom_repo.git" SELECTED_DIR="$HOME/$(basename $custom_repo)" elif [[ "$choice" =~ ^[0-9]+$ ]]; then # User selected a number from the list local repo_count=1 local selected_repo="" for repo in "dotfiles" "scripts" "configs" "tools" "projects" "notes" "backup" "workspace"; do local full_repo="$USERNAME/$repo" if git ls-remote "git@$GIT_SERVER:$full_repo.git" &>/dev/null; then if [ "$repo_count" -eq "$choice" ]; then selected_repo="$full_repo" break fi ((repo_count++)) fi done if [ -n "$selected_repo" ]; then SELECTED_REPO="git@$GIT_SERVER:$selected_repo.git" if [ "$(basename $selected_repo)" = "dotfiles" ]; then SELECTED_DIR="$HOME/.dotfiles" else SELECTED_DIR="$HOME/$(basename $selected_repo)" fi else echo "[!] Invalid choice. Please try again." select_project return fi else echo "[!] Invalid choice. Please try again." select_project return fi echo "[*] Selected repository: $SELECTED_REPO" echo "[*] Download directory: $SELECTED_DIR" echo } ### === CLONE SELECTED REPO === ### clone_selected_repo() { if [ ! -d "$SELECTED_DIR" ]; then echo "[+] Cloning selected repository..." git clone "$SELECTED_REPO" "$SELECTED_DIR" else echo "[~] Repository already cloned. Force pulling from remote (overwriting local changes)..." cd "$SELECTED_DIR" git fetch origin git reset --hard origin/$(git symbolic-ref --short HEAD) git clean -fd fi # Only run setup if it's the dotfiles repository if [[ "$SELECTED_REPO" == *"dotfiles.git" && -f "$SELECTED_DIR/setup.sh" ]]; then echo "[+] Launching dotfiles setup using Bash..." bash "$SELECTED_DIR/setup.sh" else echo "[*] Repository cloned successfully to: $SELECTED_DIR" fi } ### === MAIN === ### main() { get_username generate_ssh_key show_ssh_key select_project clone_selected_repo } main