nerd stuff
1#/bin/zsh
2
3# Git 'Mirror' Setup Script
4# This script sets up a git repository to push to both origin and mirror repos
5
6echo "=== Git 'Mirror' Setup ==="
7if [ $# -eq 2 ]; then
8 origin_repo="$1"
9 mirror_repo="$2"
10 echo "- Origin: $origin_repo"
11 echo "- Mirror: $mirror_repo"
12elif [ $# -eq 1 ]; then
13 echo "Error: Please provide both origin and mirror URLs, or run without arguments for interactive mode."
14 echo "Usage: $0 <origin_repo_url> <mirror_repo_url>"
15 exit 1
16elif [ $# -gt 2 ]; then
17 echo "Error: Too many arguments provided."
18 echo "Usage: $0 <origin_repo_url> <mirror_repo_url>"
19 exit 1
20else
21 read -p "Enter the origin repository URL: " origin_repo
22 if [ -z "$origin_repo" ]; then
23 echo "Error: origin repository URL cannot be empty."
24 exit 1
25 fi
26 read -p "Enter the mirror repository URL: " mirror_repo
27 if [ -z "$mirror_repo" ]; then
28 echo "Error: mirror repository URL cannot be empty."
29 exit 1
30 fi
31fi
32
33if ! git rev-parse --git-dir > /dev/null 2>&1; then
34 echo "Error: Not in a git repository. Please run this script from within a git repository."
35 exit 1
36fi
37
38echo
39echo "Setting up git remotes..."
40
41if git remote get-url origin > /dev/null 2>&1; then
42 echo "removed existing origin remote..."
43 git remote remove origin
44fi
45
46echo "adding remotes: $origin_repo"
47git remote add origin "$origin_repo"
48git remote set-url --add --push origin "$origin_repo"
49git remote set-url --add --push origin "$mirror_repo"
50echo "=== Setup Complete ==="
51git remote -v