-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.go
More file actions
108 lines (96 loc) · 2.65 KB
/
Copy pathremove.go
File metadata and controls
108 lines (96 loc) · 2.65 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
// MODIFIED VERSION OF INSTALL SCRIPT
// if someone would like to clean up and rewrite, that would be greatly appreciated
package main
import (
//main.go
"fmt"
"os"
"strings"
"github.com/pelletier/go-toml"
)
func remove(pkg string) error {
fmt.Println("Enter package name: ")
fmt.Scanln(&pkg)
// TOML loading
pkglist, err := toml.LoadFile("/bin/arfpkg/temp/packages.toml")
if err != nil {
panic(err)
}
b, err := os.ReadFile("/bin/arfpkg/temp/packages.toml")
if err != nil {
os.Exit(1)
}
s := string(b)
// TOML refs
url := pkglist.Get("packages." + pkg + ".url").(string)
xzname := pkglist.Get("packages." + pkg + ".xzname").(string)
foldername := pkglist.Get("packages." + pkg + ".foldername").(string)
version := pkglist.Get("packages." + pkg + ".version").(string)
// easier just to point and not make the code unbearbly long
move := os.Rename
mkpkgdir := os.MkdirAll
extpkg := tarxz
del := os.Remove
archive := move
cleartmp := os.Remove
if strings.Contains(s, pkg) {
// if it contains a recognized package, ask with Y/N dialog to remove
fmt.Printf("Remove %s %s? [y/[N]]: ", pkg, version)
var yn string
fmt.Scanln(&yn)
yn = strings.ToLower(strings.TrimSpace(yn))
if yn != "y" {
fmt.Println("Aborted.")
return nil
}
// if yes, begin removing
fmt.Printf("Downloading Package Metadata...\n")
// download files with download function
err := download(xzname, url)
if err != nil {
return nil
}
fmt.Printf("Extracting...")
// extract tarball with tar
// make package directory
err = mkpkgdir("/bin/arfpkg/temp/"+foldername+version, 0755)
if err != nil {
fmt.Println("Error (cannot continue): ", err)
}
extpkg(xzname, foldername, version)
fmt.Printf("\nRemoving...\n")
// load package TOML
pkgconf, err := toml.LoadFile("/bin/arfpkg/temp/" + pkg + "-" + version + "/" + pkg + "-latest/" + pkg + ".toml")
if err != nil {
panic(err)
}
instdir := pkgconf.Get(pkg + "." + "install-location").(string)
// bins := pkgconf.Get(pkg + ".binaries" + ".mainexec").(string)
err = del(instdir + "/" + pkg)
if err != nil {
return nil
}
fmt.Printf("\nCleaning Up...\n")
err = del("/bin/arfpkg/temp/" + foldername + version)
if err != nil {
return nil
}
err = archive("/bin/arfpkg/temp/"+xzname, "/bin/arfpkg/package_archive/"+pkg+".tar.xz")
if err != nil {
return nil
}
err = del("/bin/arfpkg/packages/" + pkg + ".toml") // delete package TOML; Unused for now
if err != nil {
panic(err)
}
err = cleartmp("/bin/arfpkg/temp/packages.toml")
if err != nil {
return nil
}
fmt.Printf("\nAll Done! 🦴\n")
} else {
// if no, abort
fmt.Printf("Aborted.\n")
}
return nil
}