Skip to content

Commit a6b64c9

Browse files
committed
fix: skip copying if executable already exists
1 parent 6f1a634 commit a6b64c9

5 files changed

Lines changed: 36 additions & 27 deletions

File tree

install.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,14 @@ func gitUserCheck(ctx routes.RouterContext) bool {
262262
fmt.Printf("Failed to copy Aegis executable: %s\n", err.Error())
263263
gitUserSetupCheckPrompt(); return false
264264
}
265+
aegisPath := path.Join(homeDir, "git-shell-commands", "aegis")
266+
if aegisPath == s { return true }
265267
f, err := os.Open(s)
266268
if err != nil {
267269
fmt.Printf("Failed to copy Aegis executable: %s\n", err.Error())
268270
gitUserSetupCheckPrompt(); return false
269271
}
270272
defer f.Close()
271-
aegisPath := path.Join(homeDir, "git-shell-commands", "aegis")
272273
fout, err := os.OpenFile(aegisPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0754)
273274
if err != nil {
274275
fmt.Printf("Failed to copy Aegis executable: %s\n", err.Error())

routes/controller/index.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func bindIndexController(ctx *RouterContext) {
1717
http.HandleFunc("GET /", UseMiddleware(
1818
[]Middleware{Logged, UseLoginInfo, GlobalVisibility, ErrorGuard}, ctx,
1919
func(rc *RouterContext, w http.ResponseWriter, r *http.Request) {
20+
fmt.Println(r.Header.Get("Host"))
21+
fmt.Println(r.URL.Path)
22+
2023
if strings.HasPrefix(rc.Config.FrontPageType, "static/") {
2124
frontPageContentType := rc.Config.FrontPageType[len("static/"):]
2225
f := rc.Config.FrontPageContent

static/style.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
:root {
2+
--foreground-color: white;
3+
--background-color: #1f1f1f;;
4+
}
5+
16
* {
27
box-sizing: border-box;
38
scrollbar-color: var(--foreground-color) var(--background-color);
49
scrollbar-width: thin;
510
}
611

712
:root {
8-
--foreground-color: white;
9-
--background-color: #1f1f1f;;
1013
--white-shade-degree-0: #ffffff1f;
1114
--white-shade-degree-1: #ffffff3f;
1215
--white-shade-degree-2: #ffffff7f;

templates/_footer.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{{define "_footer"}}
33
<div class="footer-message">
4-
Powered by <a href="https://github.com/bctnry/aegis">Aegis</a>, version v0.1.4-alpha (v0.1.4-alpha,1)
4+
Powered by <a href="https://github.com/bctnry/aegis">Aegis</a>, version v0.1.4-alpha (v0.1.4-alpha,13)
55
</div>
66
{{end}}

webinstaller.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -443,28 +443,32 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
443443
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s</p>", err.Error())
444444
return false
445445
}
446-
f, err := os.Open(s)
447-
if err != nil {
448-
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s</p>", err.Error())
449-
return false
450-
}
451-
defer f.Close()
452446
aegisPath := path.Join(homePath, "git-shell-commands", "aegis")
453-
fout, err := os.OpenFile(aegisPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0754)
454-
if err != nil {
455-
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s\n</p>", err.Error())
456-
return false
457-
}
458-
defer fout.Close()
459-
_, err = io.Copy(fout, f)
460-
if err != nil {
461-
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s\n</p>", err.Error())
462-
return false
463-
}
464-
err = os.Chown(aegisPath, uid, gid)
465-
if err != nil {
466-
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s\n</p>", err.Error())
467-
return false
447+
if aegisPath == s {
448+
fmt.Fprint(w, "<p>Seems like executable already exists. Not copying...</p>\n")
449+
} else {
450+
f, err := os.Open(s)
451+
if err != nil {
452+
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s</p>", err.Error())
453+
return false
454+
}
455+
defer f.Close()
456+
fout, err := os.OpenFile(aegisPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0754)
457+
if err != nil {
458+
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s\n</p>", err.Error())
459+
return false
460+
}
461+
defer fout.Close()
462+
_, err = io.Copy(fout, f)
463+
if err != nil {
464+
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s\n</p>", err.Error())
465+
return false
466+
}
467+
err = os.Chown(aegisPath, uid, gid)
468+
if err != nil {
469+
fmt.Fprintf(w, "<p>Failed to copy Aegis executable: %s\n</p>", err.Error())
470+
return false
471+
}
468472
}
469473
err = os.MkdirAll(ctx.Config.GitRoot, os.ModeDir|0755)
470474
if errors.Is(err, os.ErrExist) {
@@ -610,13 +614,11 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
610614
uid, _ = strconv.Atoi(gitUser.Uid)
611615
gid, _ = strconv.Atoi(gitUser.Gid)
612616
}
613-
fmt.Println("fp", ctx.Config.FilePath)
614617
if ctx.Config.Database.Type == "sqlite" {
615618
if gitUser == nil {
616619
fmt.Fprint(w, "<p class=\"warning\">Failed to fild Git user's uid & gid when chowning sqlite database. You need to perform this action on your own after this installation process...")
617620
} else {
618621
err := os.Chown(ctx.Config.ProperDatabasePath(), uid, gid)
619-
fmt.Println("prop", ctx.Config.ProperDatabasePath())
620622
if err != nil {
621623
fmt.Fprintf(w, "<p class=\"warning\">Failed to chown sqlite database: %s. You need to perform this action on your own after this installation process...", err.Error())
622624
}

0 commit comments

Comments
 (0)