-
Notifications
You must be signed in to change notification settings - Fork 0
/
g-remote.sh
executable file
·110 lines (93 loc) · 2.6 KB
/
g-remote.sh
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
#!/bin/bash
# Function to download license template
Download() {
echo "Downloading license template..."
Template=$(curl -s https://raw.githubusercontent.com/Akshay-Vs/license-templates/master/templates/$1)
Template=${Template/@Year/$Year}
Template=${Template/@User/$User}
Template=${Template/@Repo/$Repo}
echo "$Template"
}
clear
# Reading Credentials
read -p "Enter your GitHub username: " User
read -sp "Enter Auth key: " Auth
echo ""
if [[ -z "$Auth" ]]
then
python3 -m webbrowser https://github.com/settings/tokens
read -sp "Enter Auth key: " Auth
echo ""
fi
read -p "Enter repository name: " Repo
Repo=${Repo// /-}
read -p "Enter description: " Description
if [[ -z "$Description" ]]
then
Description="$Repo Generated By G-Remote"
fi
read -p "Private repository? (y/n): " Private
if [[ "$Private" == "y" ]]
then
Private="true"
else
Private="false"
fi
echo ""
echo "0) Unlicense"
echo "1) MIT"
echo "2) Apache"
echo "3) GPL3"
echo "4) BSD3"
read -p "Choose a license template: " License
Year=$(date +%Y)
# Generating Readme.md
Readme=$(curl -s https://raw.githubusercontent.com/Akshay-Vs/templates/master/README/Black-Night.md)
# Writing files
mkdir -p "$Repo"
cd "$Repo" || exit
if ! echo "$Readme" > Readme.md
then
echo "Skipping: Cannot create Readme.md"
fi
# Generating License
if [[ "$License" -eq 1 ]]
then
License=$(Download "mit.txt")
elif [[ "$License" -eq 2 ]]
then
License=$(Download "apache.txt")
elif [[ "$License" -eq 3 ]]
then
License=$(Download "gpl3.txt")
elif [[ "$License" -eq 4 ]]
then
License=$(Download "bsd3.txt")
else
License=$(Download "unlicense.txt")
fi
# Writing License
if ! echo "$License" > LICENSE
then
echo "Skipping: Cannot create License"
fi
# Generating .gitignore
Temp=$(curl -s https://raw.githubusercontent.com/Akshay-Vs/templates/master/gitignore-template.txt)
# Writing files
if ! echo "$Temp" > .gitignore
then
echo "Skipping: Cannot create .gitignore"
fi
# Initializing Git repository
echo "Initializing new repo..."
if python3 "G-remote/src/create_repo.py" "$Auth" "$Repo" "$Description" "$Private" && \
python3 "G-remote/src/put_request.py" "LICENSE" "$Auth" "$User" "$Repo" "LICENSE" && \
python3 "G-remote/src/put_request.py" ".gitignore" "$Auth" "$User" "$Repo" ".gitignore" && \
python3 "G-remote/src/generate_readme.py" "$Auth" "$User" "$Repo" "Readme.md" && \
python3 "G-remote/src/put_request.py" "Readme.md" "$Auth" "$User" "$Repo" "Readme.md"
then
xdg-open "https://github.com/$User/$Repo"
rm -rf "../$Repo"
else
echo "Failed to initialize Git repository. Check your credentials."
fi