This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupgrading.go
130 lines (90 loc) · 3.16 KB
/
upgrading.go
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
package main
import (
"strings"
)
// Function to upgrade a package.
func upgradePkgFunc(pkgName string, chapPrefix string) {
chapLog(chapPrefix+"=>", "", "Upgrading %s", pkgName)
pkgDisplayName := bolden(pkgName)
chapLog(chapPrefix+"==>", "", "Running checks")
log(1, "Checking if %s exists...", pkgDisplayName)
if !pkgExists(pkgName) {
if force {
log(3, "%s is not installed, but force is on, so continuing.", pkgDisplayName)
} else {
log(3, "%s is not installed, so it can't be upgraded.", pkgDisplayName)
return
}
}
chapLog(chapPrefix+"==>", "", "Pulling source code")
log(1, "Updating source code for %s...", pkgDisplayName)
isUpToDate, directDownload := pullPkgRepo(pkgName)
log(1, "Checking if up to date...")
if isUpToDate {
if force {
log(3, "%s already up to date, but force is on, so continuing.", pkgDisplayName)
} else {
log(0, "%s already up to date.", pkgDisplayName)
return
}
}
chapLog(chapPrefix+"==>", "", "Reading package info")
pkg := readLoad(pkgName)
if directDownload {
chapLog(chapPrefix+"==>", "", "Updating info")
log(1, "Getting & writing new info for %s...", pkgDisplayName)
log(1, "Checking for info URL...")
rawGetInfo(pkgName, pkg)
chapLog(chapPrefix+"==>", "", "Getting version numbers")
log(1, "Reading new version number...")
newVer := readLoad(pkgName).Version
log(1, "Saving old version number...")
oldVer := pkg.Version
debugLog("Old version: %s. New version: %s", oldVer, newVer)
chapLog(chapPrefix+"==>", "", "Checking if already up to date")
log(1, "Checking if %s is already up to date...", bolden(pkgName))
if oldVer == newVer {
if !force {
chapLog(chapPrefix+"==>", textCol.Green, "Success")
log(0, "%s already up to date.", pkgDisplayName)
return
}
log(3, "%s already up to date, but force is on, so continuing.", pkgDisplayName)
} else {
log(1, "Not up to date. Upgrading from %s to %s", bolden(oldVer), bolden(newVer))
}
chapLog(chapPrefix+"==>", "", "Downloading file")
doDirectDownload(pkg, srcPath)
}
chapLog(chapPrefix+"==>", "", "Getting upgrade commands")
if cmds := getUpdCmd(pkg); len(cmds) > 0 { // Check if there are upgrade commands to run
chapLog(chapPrefix+"==>", "", "Compiling")
runCmds(cmds, pkg, srcPath+pkg.Name, "upgrade")
}
chapLog(chapPrefix+"==>", "", "Upgrading")
copyBins(pkg, srcPath)
copyManpages(pkg, srcPath)
chapLog(chapPrefix+"==>", textCol.Green, "Success")
log(0, "Successfully upgraded %s!", pkgDisplayName)
}
func upgradePackage(pkgNames []string) {
fullInit()
for _, pkgName := range pkgNames {
upgradePkgFunc(pkgName, "")
}
}
func upgradeAllPackages() {
fullInit()
chapLog("==>", "", "Getting installed packages")
installedPackages := make([]string, 0)
files := dirContents(infoPath, "An error occurred while getting list of installed packages")
for _, file := range files {
installedPackages = append(installedPackages, strings.ReplaceAll(file.Name(), ".json", ""))
}
chapLog("=>", "", "Starting upgrades")
for _, installedPackage := range installedPackages {
upgradePkgFunc(installedPackage, "=")
}
chapLog("=>", textCol.Green, "Success")
log(0, "Upgraded all packages.")
}