-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-create
More file actions
executable file
·186 lines (158 loc) · 4.59 KB
/
Copy pathgit-create
File metadata and controls
executable file
·186 lines (158 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
# Determine Repo Name
REPO_NAME=${1:-$(basename "$PWD")}
# --- CONFIG ---
# Replace these with your actual values or export them in your .bashrc
FORGEJO_URL="http://192.168.50.44:3000"
FORGEJO_USER="${FORGEJO_USER}"
GITHUB_USER="${GITHUB_USER}"
FORGEJO_TOKEN="${FORGEJO_TOKEN}"
GITHUB_TOKEN="${GITHUB_TOKEN}"
# Define colors
red=$(tput setaf 1)
green=$(tput setaf 2)
cyan=$(tput setaf 6)
reset=$(tput sgr0)
echo "${cyan}Targeting repository: '$REPO_NAME'${reset}"
# Local Initialization
if [ "$(basename "$PWD")" != "$REPO_NAME" ]; then
mkdir -p "$REPO_NAME" && cd "$REPO_NAME" || exit
fi
git init >/dev/null
if [ ! -f README.md ]; then
echo "# $REPO_NAME" >README.md
fi
# Edit as needed
if [ ! -f LICENSE ]; then
cat >LICENSE <<EOF
MIT License
Copyright(c)2026 Spreadneck
EOF
fi
# Edit as needed
if [ ! -f .gitignore ]; then
cat >.gitignore <<'EOF'
# Go
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
vendor/
# Python
__pycache__/
*.py[cod]
*.pyo
*.pyd
.venv/
venv/
dist/
build/
*.egg-info/
.env
# GoLand / JetBrains
.idea/
*.iml
# Rust
/target/
EOF
echo "${cyan}Created .gitignore${reset}"
fi
# --- Language Selection ---
echo ""
echo "${cyan}Select project type:${reset}"
select PROJECT_TYPE in "C" "Go" "Odin" "Python" "Rust" "Bash" "Exit"; do
case $PROJECT_TYPE in
"C")
printf '#include <stdio.h>\n\nint main() {\n\n}' >>main.c
break
;;
"Go")
go mod init "$REPO_NAME"
# echo 'package main; import "fmt"; func main() { fmt.Println("Hello") }' > main.go
printf 'package main\n\nfunc main() {\n\n}\n' >main.go
break
;;
"Odin")
printf 'package %s\n\n' "$REPO_NAME" >"$REPO_NAME".odin
break
;;
"Python")
if command -v uv &>/dev/null; then
uv init
mv hello.py main.py 2>/dev/null
else touch main.py; fi
break
;;
"Rust")
if command -v cargo &>/dev/null; then
if ! cargo init --name "${REPO_NAME//-/_}" --vcs none; then
echo "${red}cargo init failed (likely an existing Cargo.toml) — leaving Rust files untouched.${reset}"
fi
else
printf 'fn main() {\n\n}\n' >main.rs
fi
break
;;
"Bash")
echo "#!/bin/bash" >main.sh
chmod +x main.sh
break
;;
"Exit") exit 0 ;;
esac
done
# --- Optional Remote Setup ---
git branch -M main 2>/dev/null || true
echo ""
echo "${cyan}Set up remote repos on Forgejo + GitHub now? (y/N)${reset}"
read -r -n 1 REMOTE_CHOICE
echo ""
if [[ "$REMOTE_CHOICE" != "y" && "$REMOTE_CHOICE" != "Y" ]]; then
echo "${green}SUCCESS: Local repository '$REPO_NAME' ready. Skipping remote setup.${reset}"
exit 0
fi
if [[ -z "$FORGEJO_TOKEN" || -z "$GITHUB_TOKEN" ]]; then
echo "${red}Error: FORGEJO_TOKEN or GITHUB_TOKEN not found in environment.${reset}"
exit 1
fi
# --- Visibility Selection ---
echo "${cyan}Should this repository be Private or Public? (p/P for Private, any other key for Public)${reset}"
read -r -n 1 VISIBILITY_CHOICE
echo ""
if [[ "$VISIBILITY_CHOICE" == "p" || "$VISIBILITY_CHOICE" == "P" ]]; then
IS_PRIVATE="true"
echo "${cyan}Setting repository to PRIVATE...${reset}"
else
IS_PRIVATE="false"
echo "${cyan}Setting repository to PUBLIC...${reset}"
fi
# Creating repositories on GitHub and Forgejo
echo "${cyan}1. Creating repository on GitHub...${reset}"
curl -s -X POST "https://api.github.com/user/repos" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\":\"$REPO_NAME\", \"private\": $IS_PRIVATE}"
echo "${cyan}2. Creating repository on Forgejo...${reset}"
curl -s -X POST "$FORGEJO_URL/api/v1/user/repos" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\":\"$REPO_NAME\", \"private\": $IS_PRIVATE, \"default_branch\": \"main\"}"
# Setup remote
git remote remove origin 2>/dev/null
git remote add origin "forgejo:$FORGEJO_USER/$REPO_NAME.git"
# Setup GitHub push mirror
echo "${cyan}3. Setting up GitHub Push Mirror...${reset}"
curl -s -o /dev/null -X POST "$FORGEJO_URL/api/v1/repos/$FORGEJO_USER/$REPO_NAME/push_mirrors" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"remote_address\": \"git@github.com:$GITHUB_USER/$REPO_NAME.git\",
\"remote_username\": \"$GITHUB_USER\",
\"remote_password\": \"$GITHUB_TOKEN\",
\"interval\": \"8h0m0s\",
\"sync_on_commit\": true
}"
echo "${green}SUCCESS: $REPO_NAME created and mirror configured.${reset}"