-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
233 lines (203 loc) Β· 8.4 KB
/
install.ps1
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# GitHub Garden PowerShell Installer
$ErrorActionPreference = 'Stop'
# Function to handle errors
function Handle-Error {
param(
[string]$ErrorMessage
)
Write-Host "`nβ Error: $ErrorMessage" -ForegroundColor Red
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
exit 1
}
# Function to pause execution
function Pause-Script {
Write-Host "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
}
try {
# ASCII Art
Write-Host @"
_______ _____ _______ _ _ _ _ ____ ______ _____ _____ ______ _ _
|__ __|_ _|__ __| | | | | | | _ \ / ___\ \ / / _ \| __ \| ____| \ | |
| | | | | | | |__| | | | | |_) | | | _ \ \ /\ / /| |_) | | | | |__ | \| |
| | | | | | | __ | | | | _ < | | |_) | \/ \/ / | _ <| | | | __| | . ` |
| | _| |_ | | | | | | |__| | |_) | | |____/ \ /\ / | |_) | |__| | |____| |\ |
|_| |_____| |_| |_| |_|\____/|____/ \_____ \ \/ \/ |____/|_____/|______|_| \_|
"@ -ForegroundColor Cyan
Write-Host "`nGitHub Garden Installer`n" -ForegroundColor Green
Write-Host "Created by TELVIN TEUM`n" -ForegroundColor Yellow
function Verify-Input {
param (
[string]$input,
[string]$type
)
switch ($type) {
"token" {
return $input -match "^gh[ps]_[a-zA-Z0-9]{36}$"
}
"username" {
return $input -match "^[a-zA-Z0-9-]+$"
}
"email" {
return $input -match "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
}
}
return $false
}
# Check for required tools
$requiredTools = @{
"git" = "Git is required. Download from: https://git-scm.com/download/win"
"node" = "Node.js is required. Download from: https://nodejs.org/"
"npm" = "npm is required (comes with Node.js): https://nodejs.org/"
"gh" = "GitHub CLI is required. Download from: https://cli.github.com/"
}
foreach ($tool in $requiredTools.Keys) {
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
Handle-Error "$($requiredTools[$tool])"
}
}
# GitHub Authentication
Write-Host "`nπ Checking GitHub Authentication..." -ForegroundColor Cyan
try {
gh auth status
} catch {
Write-Host "Please login to GitHub CLI first:" -ForegroundColor Yellow
gh auth login
if ($LASTEXITCODE -ne 0) {
Handle-Error "GitHub authentication failed. Please try again."
}
}
# Fork the repository
Write-Host "`nπ΄ Forking the repository..." -ForegroundColor Cyan
$repoUrl = "https://github.com/BotCoder254/github-garden"
try {
gh repo fork $repoUrl --clone=true
Set-Location "github-garden"
} catch {
Handle-Error "Failed to fork repository: $_"
}
# Step-by-step environment setup
Write-Host "`nπ Let's set up your environment step by step" -ForegroundColor Cyan
Write-Host "Follow these instructions carefully:" -ForegroundColor Yellow
Write-Host "1. Go to: https://github.com/settings/tokens/new" -ForegroundColor White
Write-Host "2. Set token name: 'GitHub Garden'" -ForegroundColor White
Write-Host "3. Set expiration: Custom > 1 year" -ForegroundColor White
Write-Host "4. Select scopes:" -ForegroundColor White
Write-Host " βοΈ repo (Full control of private repositories)" -ForegroundColor White
Write-Host " βοΈ workflow (Update GitHub Action workflows)" -ForegroundColor White
Write-Host " βοΈ user (Update all user data)" -ForegroundColor White
Write-Host "5. Click 'Generate token'" -ForegroundColor White
Write-Host "6. Copy your token (it starts with 'ghp_' or 'ghs_')" -ForegroundColor White
# Get and verify GitHub token
do {
$token = Read-Host "`nPaste your GitHub token"
if (-not (Verify-Input -input $token -type "token")) {
Write-Host "β Invalid token format. Token should start with 'ghp_' or 'ghs_' and be 40 characters long." -ForegroundColor Red
continue
}
try {
$env:GITHUB_TOKEN = $token
gh auth status
$tokenValid = $true
} catch {
Write-Host "β Token verification failed. Please check if the token is valid." -ForegroundColor Red
$tokenValid = $false
}
} while (-not $tokenValid)
Write-Host "β
Token verified successfully!" -ForegroundColor Green
# Get and verify GitHub username
do {
$username = Read-Host "`nEnter your GitHub username"
if (-not (Verify-Input -input $username -type "username")) {
Write-Host "β Invalid username format. Username should only contain letters, numbers, and hyphens." -ForegroundColor Red
continue
}
try {
$userCheck = gh api user -q .login
if ($userCheck -eq $username) {
$usernameValid = $true
} else {
Write-Host "β Username doesn't match your GitHub account." -ForegroundColor Red
$usernameValid = $false
}
} catch {
Write-Host "β Failed to verify username. Please try again." -ForegroundColor Red
$usernameValid = $false
}
} while (-not $usernameValid)
Write-Host "β
Username verified successfully!" -ForegroundColor Green
# Get and verify GitHub email
do {
$email = Read-Host "`nEnter your GitHub email"
if (-not (Verify-Input -input $email -type "email")) {
Write-Host "β Invalid email format." -ForegroundColor Red
continue
}
try {
$emailCheck = gh api user/emails -q ".[].email | contains([$email])"
if ($emailCheck) {
$emailValid = $true
} else {
Write-Host "β Email not found in your GitHub account." -ForegroundColor Red
$emailValid = $false
}
} catch {
Write-Host "β Failed to verify email. Please try again." -ForegroundColor Red
$emailValid = $false
}
} while (-not $emailValid)
Write-Host "β
Email verified successfully!" -ForegroundColor Green
# Create .env file
Write-Host "`nπ Creating .env file..." -ForegroundColor Cyan
@"
GITHUB_TOKEN=$token
GITHUB_USERNAME=$username
GITHUB_EMAIL=$email
"@ | Out-File -FilePath ".env" -Encoding UTF8
# Set environment variables for current session
$env:GITHUB_TOKEN = $token
$env:GITHUB_USERNAME = $username
$env:GITHUB_EMAIL = $email
# Configure git
git config --global user.name $username
git config --global user.email $email
# Verify all settings
Write-Host "`nπ Verifying all settings..." -ForegroundColor Cyan
$verified = $true
# Verify Git config
$gitName = git config --global user.name
$gitEmail = git config --global user.email
if ($gitName -ne $username -or $gitEmail -ne $email) {
Write-Host "β Git configuration verification failed" -ForegroundColor Red
$verified = $false
}
# Verify .env file
if (-not (Test-Path ".env")) {
Write-Host "β .env file verification failed" -ForegroundColor Red
$verified = $false
}
if (-not $verified) {
Write-Host "β Setup verification failed. Please try again." -ForegroundColor Red
exit 1
}
Write-Host "β
All settings verified successfully!" -ForegroundColor Green
# Install dependencies
Write-Host "`nπ¦ Installing dependencies..." -ForegroundColor Cyan
try {
npm install
Write-Host "`nβ
Installation complete!" -ForegroundColor Green
Write-Host "π Starting GitHub Garden..." -ForegroundColor Cyan
# Run the contribution generator
node generate-contributions.js
} catch {
Handle-Error "Installation failed: $_"
}
Write-Host "`nπ‘ Next steps:" -ForegroundColor Yellow
Write-Host "1. Your forked repository is ready at: https://github.com/$username/github-garden" -ForegroundColor White
Write-Host "2. The script will now start generating contributions" -ForegroundColor White
Write-Host "3. Check your GitHub profile to see the changes!" -ForegroundColor White
Pause-Script
} catch {
Handle-Error $_.Exception.Message
}