|
| 1 | +#!/bin/bash |
| 2 | +# Script to set up and push the Proxmox-AI repository to GitHub |
| 3 | + |
| 4 | +# Colors for output |
| 5 | +RED='\033[0;31m' |
| 6 | +GREEN='\033[0;32m' |
| 7 | +YELLOW='\033[0;33m' |
| 8 | +NC='\033[0m' # No Color |
| 9 | + |
| 10 | +echo -e "${GREEN}=== Proxmox-AI GitHub Setup ===${NC}" |
| 11 | +echo "This script will help you set up and push your Proxmox-AI codebase to GitHub" |
| 12 | + |
| 13 | +# 1. Check if git is installed |
| 14 | +if ! command -v git &> /dev/null; then |
| 15 | + echo -e "${RED}Git is not installed. Please install git first.${NC}" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# 2. Navigate to the repository |
| 20 | +cd "$(dirname "$0")" |
| 21 | +REPO_DIR=$(pwd) |
| 22 | +echo -e "${GREEN}Working directory:${NC} $REPO_DIR" |
| 23 | + |
| 24 | +# 3. Check if this is already a git repository |
| 25 | +if [ ! -d ".git" ]; then |
| 26 | + echo -e "${RED}Not a git repository. Please initialize git first with 'git init'.${NC}" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +# 4. Ask for GitHub username and repository name |
| 31 | +read -p "Enter your GitHub username: " GITHUB_USERNAME |
| 32 | +read -p "Enter the repository name (default: proxmox-ai): " REPO_NAME |
| 33 | +REPO_NAME=${REPO_NAME:-proxmox-ai} |
| 34 | + |
| 35 | +# 5. Check if the remote already exists |
| 36 | +REMOTE_URL=$(git remote get-url origin 2>/dev/null || echo "") |
| 37 | +if [ -z "$REMOTE_URL" ]; then |
| 38 | + echo -e "${YELLOW}Setting up new remote origin...${NC}" |
| 39 | + git remote add origin "git@github.com:$GITHUB_USERNAME/$REPO_NAME.git" |
| 40 | +else |
| 41 | + echo -e "${YELLOW}Remote origin already exists. Updating it...${NC}" |
| 42 | + git remote set-url origin "git@github.com:$GITHUB_USERNAME/$REPO_NAME.git" |
| 43 | +fi |
| 44 | + |
| 45 | +# 6. Handle submodules |
| 46 | +echo -e "${YELLOW}Checking submodules...${NC}" |
| 47 | +if [ -f ".gitmodules" ]; then |
| 48 | + echo -e "${YELLOW}Submodules found. Initializing...${NC}" |
| 49 | + git submodule update --init --recursive || echo -e "${RED}Failed to update submodules, but continuing...${NC}" |
| 50 | +fi |
| 51 | + |
| 52 | +# 7. Check if there are uncommitted changes |
| 53 | +if ! git diff-index --quiet HEAD --; then |
| 54 | + echo -e "${YELLOW}You have uncommitted changes.${NC}" |
| 55 | + read -p "Do you want to commit all changes? (y/n): " COMMIT_CHANGES |
| 56 | + if [[ $COMMIT_CHANGES =~ ^[Yy]$ ]]; then |
| 57 | + git add . |
| 58 | + read -p "Enter commit message (default: Update Proxmox-AI codebase): " COMMIT_MSG |
| 59 | + COMMIT_MSG=${COMMIT_MSG:-"Update Proxmox-AI codebase"} |
| 60 | + git commit -m "$COMMIT_MSG" |
| 61 | + else |
| 62 | + echo -e "${RED}Please commit your changes before pushing.${NC}" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +fi |
| 66 | + |
| 67 | +# 8. Ensure we're on a branch (main or master) |
| 68 | +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 69 | +if [ "$CURRENT_BRANCH" = "HEAD" ]; then |
| 70 | + echo -e "${YELLOW}Not on a branch. Creating 'main' branch...${NC}" |
| 71 | + git checkout -b main |
| 72 | + CURRENT_BRANCH="main" |
| 73 | +fi |
| 74 | + |
| 75 | +# 9. Push to GitHub with SSH URL |
| 76 | +echo -e "${GREEN}Pushing to GitHub using SSH...${NC}" |
| 77 | +echo -e "${YELLOW}Make sure you have SSH keys set up with GitHub${NC}" |
| 78 | +echo -e "If you don't have SSH keys set up, please follow these instructions:" |
| 79 | +echo -e "https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent" |
| 80 | +echo -e "and then add the key to your GitHub account." |
| 81 | +echo -e "" |
| 82 | +read -p "Ready to push? (y/n): " READY_TO_PUSH |
| 83 | + |
| 84 | +if [[ $READY_TO_PUSH =~ ^[Yy]$ ]]; then |
| 85 | + git push -u origin $CURRENT_BRANCH |
| 86 | + |
| 87 | + if [ $? -eq 0 ]; then |
| 88 | + echo -e "${GREEN}Successfully pushed to GitHub!${NC}" |
| 89 | + echo -e "Your repository is now available at: https://github.com/$GITHUB_USERNAME/$REPO_NAME" |
| 90 | + else |
| 91 | + echo -e "${RED}Failed to push to GitHub.${NC}" |
| 92 | + echo -e "Try pushing manually with: git push -u origin $CURRENT_BRANCH" |
| 93 | + fi |
| 94 | +else |
| 95 | + echo -e "${YELLOW}Push cancelled. You can push manually later with:${NC}" |
| 96 | + echo -e "git push -u origin $CURRENT_BRANCH" |
| 97 | +fi |
| 98 | + |
| 99 | +echo -e "${GREEN}Setup complete!${NC}" |
0 commit comments