Skip to content

Commit 2508869

Browse files
committed
update
1 parent 5c63df9 commit 2508869

File tree

12 files changed

+325
-14
lines changed

12 files changed

+325
-14
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ installer.exe
88

99
# Temporary files
1010
tmp
11+
12+
# Test run scripts
13+
test.ps1
14+
test.sh

main.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package main
22

33
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
"runtime"
8+
"time"
9+
410
"github.com/gofiber/contrib/fiberzap"
511
"github.com/gofiber/fiber/v2"
612
"github.com/gofiber/fiber/v2/middleware/recover"
13+
"github.com/installer/installer/internal/pkg/config"
14+
"github.com/installer/installer/internal/pkg/platforms"
15+
"github.com/installer/installer/scripts"
716
"github.com/pterm/pterm"
817
"github.com/pterm/pterm/putils"
918
"go.uber.org/zap"
@@ -12,6 +21,23 @@ import (
1221
)
1322

1423
func main() {
24+
test := flag.Bool("test", false, "test")
25+
flag.Parse()
26+
// Check if test flag is set
27+
if *test {
28+
platform, err := platforms.Parse(runtime.GOOS)
29+
pterm.Fatal.PrintOnError(err)
30+
script, err := scripts.ParseTemplateForPlatform(platform, config.Config{
31+
Owner: "installer",
32+
Repo: "test-repo",
33+
Version: "latest",
34+
CreatedAt: time.Now(),
35+
})
36+
pterm.Fatal.PrintOnError(err)
37+
fmt.Println(script)
38+
os.Exit(0)
39+
}
40+
1541
pterm.DefaultBigText.WithLetters(putils.LettersFromString(" INSTL")).Render()
1642

1743
logger, _ := zap.NewProduction(zap.WithCaller(false))

scripts/assets/linux/lib/colors.sh

-4
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ bWhite () {
107107

108108
# Special Colors
109109

110-
bold () {
111-
printf "\e[1m%s\e[0m" "$1"
112-
}
113-
114110
resetColor () {
115111
printf "\e[0m"
116112
}

scripts/assets/linux/lib/intro.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
secondaryColor ' ██ ███ ██ ███████ ████████ ██
2-
██ ████ ██ ██ ██ ██
3-
██ ██ ██ ██ ███████ ██ ██
4-
██ ██ ██ ██ ██ ██ ██
5-
██ ██ ████ ███████ ██ ███████'
1+
secondaryColor ' _____ _ _ _____ _______ _
2+
|_ _| \ | |/ ____|__ __| |
3+
| | | \| | (___ | | | |
4+
| | | . ` |\___ \ | | | |
5+
_| |_| |\ |____) | | | | |____
6+
|_____|_| \_|_____/ |_| |______|'
67
echo
78
echo
89
fBlueLight ' Instl is an installer for GitHub Projects' && echo

scripts/assets/linux/script.template.sh scripts/assets/linux/script.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
source ../header.txt
22

3+
# Setup variables
34
owner="{{ .Owner }}"
45
repo="{{ .Repo }}"
56
github_url="https://github.com/$owner/$repo"

scripts/assets/windows/lib/colors.ps1

+244
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Foreground Colors
2+
3+
function fRed
4+
{
5+
param (
6+
$Msg
7+
)
8+
Write-Host $Msg -NoNewline -ForegroundColor DarkRed
9+
}
10+
11+
function fRedLight
12+
{
13+
param (
14+
$Msg
15+
)
16+
Write-Host $Msg -NoNewline -ForegroundColor Red
17+
}
18+
19+
function fGreen
20+
{
21+
param (
22+
$Msg
23+
)
24+
Write-Host $Msg -NoNewline -ForegroundColor DarkGreen
25+
}
26+
27+
function fGreenLight
28+
{
29+
param (
30+
$Msg
31+
)
32+
Write-Host $Msg -NoNewline -ForegroundColor Green
33+
}
34+
35+
function fYellow
36+
{
37+
param (
38+
$Msg
39+
)
40+
Write-Host $Msg -NoNewline -ForegroundColor DarkYellow
41+
}
42+
43+
function fYellowLight
44+
{
45+
param (
46+
$Msg
47+
)
48+
Write-Host $Msg -NoNewline -ForegroundColor Yellow
49+
}
50+
51+
function fBlue
52+
{
53+
param (
54+
$Msg
55+
)
56+
Write-Host $Msg -NoNewline -ForegroundColor DarkBlue
57+
}
58+
59+
function fBlueLight
60+
{
61+
param (
62+
$Msg
63+
)
64+
Write-Host $Msg -NoNewline -ForegroundColor Blue
65+
}
66+
67+
function fMagenta
68+
{
69+
param (
70+
$Msg
71+
)
72+
Write-Host $Msg -NoNewline -ForegroundColor DarkMagenta
73+
}
74+
75+
function fMagentaLight
76+
{
77+
param (
78+
$Msg
79+
)
80+
Write-Host $Msg -NoNewline -ForegroundColor Magenta
81+
}
82+
83+
function fCyan
84+
{
85+
param (
86+
$Msg
87+
)
88+
Write-Host $Msg -NoNewline -ForegroundColor DarkCyan
89+
}
90+
91+
function fCyanLight
92+
{
93+
param (
94+
$Msg
95+
)
96+
Write-Host $Msg -NoNewline -ForegroundColor Cyan
97+
}
98+
99+
function fWhite
100+
{
101+
param (
102+
$Msg
103+
)
104+
Write-Host $Msg -NoNewline -ForegroundColor White
105+
}
106+
107+
# Background Colors
108+
109+
function bRed
110+
{
111+
param (
112+
$Msg
113+
)
114+
Write-Host $Msg -NoNewline -BackgroundColor DarkRed
115+
}
116+
117+
function bRedLight
118+
{
119+
param (
120+
$Msg
121+
)
122+
Write-Host $Msg -NoNewline -BackgroundColor Red
123+
}
124+
125+
function bGreen
126+
{
127+
param (
128+
$Msg
129+
)
130+
Write-Host $Msg -NoNewline -BackgroundColor DarkGreen
131+
}
132+
133+
function bGreenLight
134+
{
135+
param (
136+
$Msg
137+
)
138+
Write-Host $Msg -NoNewline -BackgroundColor Green
139+
}
140+
141+
function bYellow
142+
{
143+
param (
144+
$Msg
145+
)
146+
Write-Host $Msg -NoNewline -BackgroundColor DarkYellow
147+
}
148+
149+
function bYellowLight
150+
{
151+
param (
152+
$Msg
153+
)
154+
Write-Host $Msg -NoNewline -BackgroundColor Yellow
155+
}
156+
157+
function bBlue
158+
{
159+
param (
160+
$Msg
161+
)
162+
Write-Host $Msg -NoNewline -BackgroundColor DarkBlue
163+
}
164+
165+
function bBlueLight
166+
{
167+
param (
168+
$Msg
169+
)
170+
Write-Host $Msg -NoNewline -BackgroundColor Blue
171+
}
172+
173+
function bMagenta
174+
{
175+
param (
176+
$Msg
177+
)
178+
Write-Host $Msg -NoNewline -BackgroundColor DarkMagenta
179+
}
180+
181+
function bMagentaLight
182+
{
183+
param (
184+
$Msg
185+
)
186+
Write-Host $Msg -NoNewline -BackgroundColor Magenta
187+
}
188+
189+
function bCyan
190+
{
191+
param (
192+
$Msg
193+
)
194+
Write-Host $Msg -NoNewline -BackgroundColor DarkCyan
195+
}
196+
197+
function bCyanLight
198+
{
199+
param (
200+
$Msg
201+
)
202+
Write-Host $Msg -NoNewline -BackgroundColor Cyan
203+
}
204+
205+
function bWhite
206+
{
207+
param (
208+
$Msg
209+
)
210+
Write-Host $Msg -NoNewline -BackgroundColor White
211+
}
212+
213+
# Special Colors
214+
215+
function resetColor
216+
{
217+
Write-Host -NoNewline -Reset
218+
}
219+
220+
# Theme
221+
222+
function primaryColor {
223+
param (
224+
$Msg
225+
)
226+
fCyan $Msg
227+
}
228+
229+
function secondaryColor {
230+
param (
231+
$Msg
232+
)
233+
fMagentaLight $Msg
234+
}
235+
236+
function info {
237+
param (
238+
$Msg
239+
)
240+
fBlueLight " i "
241+
fBlue $Msg
242+
echo ""
243+
}
244+

scripts/assets/windows/lib/intro.ps1

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
secondaryColor ' _____ _ _ _____ _______ _
2+
|_ _| \ | |/ ____|__ __| |
3+
| | | \| | (___ | | | |
4+
| | | . ` |\___ \ | | | |
5+
_| |_| |\ |____) | | | | |____
6+
|_____|_| \_|_____/ |_| |______|'
7+
echo ""
8+
echo ""
9+
fBlueLight ' Instl is an installer for GitHub Projects'
10+
echo ""
11+
fBlue ' > https://instl.sh'
12+
echo ""
13+
echo ""

scripts/assets/windows/script.ps1

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
. "../header.txt"
2+
3+
# Setup variables
4+
$owner="{{ .Owner }}"
5+
$repo="{{ .Repo }}"
6+
$github_url="https://github.com/$owner/$repo"
7+
$install_location=""
8+
9+
# Import libraries
10+
. "./lib/colors.ps1"
11+
12+
# Print "INSTL" header
13+
. "./lib/intro.ps1"
14+
15+
# Installation
16+
17+
# GitHub public API
18+
$latestReleaseURL = "https://api.github.com/repos/$owner/$repo/releases/latest"
19+
$latestRelease = Invoke-WebRequest $latestReleaseURL | ConvertFrom-Json
20+
$tagName = $latestRelease.tag_name
21+
info "Found latest release of $repo (version: $tagName)"
22+
23+
. "../footer.txt"

scripts/assets/windows/script.template.ps1

-3
This file was deleted.

scripts/combine.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88

99
// CombineLinuxScripts combines all Linux scripts into one.
1010
func CombineLinuxScripts() (string, error) {
11-
return CombineBash("assets/linux/script.template.sh")
11+
return CombineBash("assets/linux/script.sh")
1212
}
1313

1414
// CombineWindowsScripts combines all Windows scripts into one.
1515
func CombineWindowsScripts() (string, error) {
16-
return CombinePowerShell("assets/windows/script.template.ps1")
16+
return CombinePowerShell("assets/windows/script.ps1")
1717
}
1818

1919
// CombineBash combines multiple Bash files into one.

test.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go run . -test > ./run.ps1
2+
"./run.ps1" | iex
3+
rm .\run.ps1

test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
go run . -test | bash

0 commit comments

Comments
 (0)