Skip to content
Snippets Groups Projects
Unverified Commit 01966cd2 authored by Massimiliano Adamo's avatar Massimiliano Adamo
Browse files

fixing self update feature

parent a92c021c
No related branches found
No related tags found
No related merge requests found
Pipeline #29564 passed
......@@ -38,7 +38,7 @@ usage() {
exit
}
OPTS=$(getopt -o "h" --longoptions "help,os:,arch:,upx,no-upx:,version:" -- "$@")
OPTS=$(getopt -o "h" --longoptions "help,os:,arch:,upx,no-upx,version:" -- "$@")
eval set -- "$OPTS"
while true; do
......@@ -106,10 +106,9 @@ run_upx() {
upx --brute "$EXECUTABLE_PATH"
}
if [ -n $UPX ]; then
if [[ "$UPX" == 'UPX' ]]; then
run_upx
cp $EXECUTABLE_PATH .
elif [ -n $NOUPX ]; then
elif [[ "$NOUPX" == 'NOUPX' ]]; then
true
else
while true; do
......@@ -130,4 +129,6 @@ else
done
fi
cp $EXECUTABLE_PATH .
echo -e "\nthe binary was compiled and it is avilable as:\n - \"$EXECUTABLE_PATH\"\n"
......@@ -320,6 +320,12 @@ func downloadFile(filepath string, url string) (err error) {
return err
}
// change filemode
err = os.Chmod(filepath, 0755)
if err != nil {
return err
}
return nil
}
......@@ -359,6 +365,7 @@ Usage:
acme-downloader -h | --help
acme-downloader -v | --version
acme-downloader -b | --build
acme-downloader --update
Options:
-h --help Show this screen
......@@ -385,7 +392,7 @@ Options:
appExit(0)
}
if arguments["--wildcard"] == true {
if arguments["--update"] == true {
ArtifactoryBase := "https://artifactory.software.geant.org/artifactory/acme-downloader"
ArtifactName := fmt.Sprintf("acme-downloader_%v_%v", runtime.GOOS, runtime.GOARCH)
ToolName := os.Args[0]
......@@ -393,8 +400,18 @@ Options:
if runtime.GOOS == "windows" {
ArtifactURL = fmt.Sprintf("%v/%v.exe", ArtifactoryBase, ArtifactName)
}
downloadFile(ToolName, ArtifactURL)
deleteErr := os.Remove(ToolName)
if deleteErr != nil {
fmt.Printf("Error deleting %v: %v!\n", ToolName, deleteErr)
appExit(2)
}
downloadErr := downloadFile(ToolName, ArtifactURL)
if downloadErr != nil {
fmt.Printf("Error downloading %v: %v!\n", ToolName, downloadErr)
appExit(2)
}
fmt.Printf("%v updated successfully!\n", ToolName)
appExit(0)
}
if runtime.GOOS == "windows" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment