norg --update works on linux
This commit is contained in:
parent
bc815f46fd
commit
c8ddbf3243
5 changed files with 103 additions and 40 deletions
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "0.1.14"
|
||||
version = "0.1.13"
|
||||
author = "Paul Wilde"
|
||||
description = "A Borg Backup Orchestration Tool"
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
|
|
@ -21,7 +21,7 @@ proc start() =
|
|||
if norg_args.show_version:
|
||||
showVersion()
|
||||
elif norg_args.update:
|
||||
updateNorg(VERSION)
|
||||
checkUpdates(VERSION)
|
||||
elif norg_args.command == GEN_CONF:
|
||||
var config_file = "norg_backup.toml"
|
||||
if norg_args.config_file != "":
|
||||
|
|
|
@ -2,11 +2,67 @@
|
|||
##
|
||||
import httpclient
|
||||
import json
|
||||
import strformat
|
||||
import strutils
|
||||
import terminal
|
||||
import osproc
|
||||
import os
|
||||
|
||||
import ../model/log_type
|
||||
import version
|
||||
|
||||
proc updateNorg*(cur_vers: string)=
|
||||
const sh = """
|
||||
#!/usr/bin/env sh
|
||||
mv {new} {old}
|
||||
{old} --version
|
||||
rm -r tmp
|
||||
"""
|
||||
proc extractUpdate(name, file: string) =
|
||||
var client = newHttpClient()
|
||||
try:
|
||||
createDir("tmp")
|
||||
client.downloadFile(file,fmt"tmp/{name}")
|
||||
let cwd = getAppDir()
|
||||
let cwf = getAppFilename()
|
||||
case hostOS
|
||||
of "linux":
|
||||
let ok = osproc.execCmd(fmt"tar xf tmp/{name} -C tmp/")
|
||||
if ok == 0:
|
||||
copyFile(cwf,fmt"{cwd}/norg_backup")
|
||||
let content = sh.replace("{new}", "tmp/norg").replace("{old}", cwf)
|
||||
writeFile("tmp/norg_update", content)
|
||||
discard osproc.execCmd("sh tmp/norg_update")
|
||||
quit(0)
|
||||
of "windows":
|
||||
let ok = osproc.execCmd(fmt"decompress tmp/{name} -C tmp/")
|
||||
if ok == 0:
|
||||
copyFile(cwf,fmt"{cwd}/norg_backup")
|
||||
let content = sh.replace("{new}", "tmp/norg").replace("{old}", cwf)
|
||||
writeFile("tmp/norg_update", content)
|
||||
discard osproc.execCmd("sh tmp/norg_update")
|
||||
quit(0)
|
||||
except:
|
||||
error getCurrentExceptionMsg()
|
||||
finally:
|
||||
removeDir("tmp")
|
||||
|
||||
proc updateNorg(version: string, j: JsonNode) =
|
||||
let newvers = version[1..^1].replace(".","_")
|
||||
#let check_file = fmt"norg_{hostOS}_{hostCPU}-{newvers}.tar.gz"
|
||||
let check_file = fmt"norg_{hostOS}_{newvers}.tar.gz"
|
||||
var update_found = false
|
||||
for asset in j["assets"].getElems():
|
||||
let name = asset["name"].getStr()
|
||||
if checkfile == name:
|
||||
let file = asset["browser_download_url"].getStr()
|
||||
update_found = true
|
||||
extractUpdate(name,file)
|
||||
if not update_found:
|
||||
info "Unable to find update file for your OS and architecture."
|
||||
info "Please check https://codeberg.org/pswilde/norgbackup/releases/latest for more information"
|
||||
|
||||
|
||||
proc checkUpdates*(cur_vers: string)=
|
||||
initLogger(strfmt = "[$levelname] ")
|
||||
let latest_url = "https://codeberg.org/api/v1/repos/pswilde/norgbackup/releases/latest"
|
||||
var client = newHttpClient()
|
||||
|
@ -16,7 +72,13 @@ proc updateNorg*(cur_vers: string)=
|
|||
let j = res.body.parseJson()
|
||||
let new_vers = j["tag_name"].getStr()
|
||||
if new_vers.newerThan(cur_vers):
|
||||
info "Update available"
|
||||
info "An update is available, would you like to update? (y/N)"
|
||||
let resp = getch()
|
||||
case resp
|
||||
of 'y', 'Y':
|
||||
new_vers.updateNorg(j)
|
||||
else:
|
||||
info "Not updating"
|
||||
else:
|
||||
info "No new Update available."
|
||||
else:
|
||||
|
|
|
@ -15,7 +15,6 @@ proc newerThan*(a,b: string): bool =
|
|||
let cur = b[1..^1].split(".").map(proc(s: string): int = s.parseInt())
|
||||
echo "Latest Version: " & a
|
||||
echo "Current Version: " & b
|
||||
if new[0] > cur[0]: return true
|
||||
elif new[1] > cur[1]: return true
|
||||
elif new[2] > cur[2]: return true
|
||||
for i in countup(0, len(cur) - 1):
|
||||
if new[i] > cur[i]: return true
|
||||
return false
|
||||
|
|
|
@ -3,36 +3,38 @@
|
|||
version=$(grep -i version norg.nimble | awk '{print $3}' | sed "s/\"//g" | sed "s/\./_/g")
|
||||
dir=$(pwd)
|
||||
echo Building for Linux
|
||||
nimble build -d:linux
|
||||
if [ $? != 1 ]; then
|
||||
echo "Compressing..."
|
||||
cd bin || exit
|
||||
tar cvzf "norg_linux_$version.tar.gz" norg
|
||||
rm norg
|
||||
cd "$dir" || exit
|
||||
echo Done.
|
||||
fi
|
||||
for cpu in amd64; do
|
||||
nimble build -d:linux --cpu:$cpu
|
||||
if [ $? != 1 ]; then
|
||||
echo "Compressing..."
|
||||
cd bin || exit
|
||||
tar cvzf "norg_linux_$cpu-$version.tar.gz" norg
|
||||
rm norg
|
||||
cd "$dir" || exit
|
||||
echo Done.
|
||||
fi
|
||||
|
||||
echo Building for FreeBSD
|
||||
nimble build -d:freebsd
|
||||
if [ $? != 1 ]; then
|
||||
echo "Compressing..."
|
||||
cd bin || exit
|
||||
tar cvzf "norg_freebsd_$version.tar.gz" norg
|
||||
rm norg
|
||||
cd "$dir" || exit
|
||||
echo Done.
|
||||
fi
|
||||
echo Building for FreeBSD
|
||||
nimble build -d:freebsd --cpu:$cpu
|
||||
if [ $? != 1 ]; then
|
||||
echo "Compressing..."
|
||||
cd bin || exit
|
||||
tar cvzf "norg_freebsd_$cpu-$version.tar.gz" norg
|
||||
rm norg
|
||||
cd "$dir" || exit
|
||||
echo Done.
|
||||
fi
|
||||
|
||||
echo Building for Windows
|
||||
nimble build -d:mingw
|
||||
if [ $? != 1 ]; then
|
||||
echo "Zipping..."
|
||||
cd bin || exit
|
||||
cp ../resources/windows/lib* ./
|
||||
zip "norg_windows_$version.zip" norg.exe lib*
|
||||
rm ./lib*
|
||||
cd "$dir" || exit
|
||||
rm bin/norg.exe
|
||||
echo Done.
|
||||
fi
|
||||
echo Building for Windows
|
||||
nimble build -d:mingw --cpu:$cpu
|
||||
if [ $? != 1 ]; then
|
||||
echo "Zipping..."
|
||||
cd bin || exit
|
||||
cp ../resources/windows/lib* ./
|
||||
zip "norg_windows_$cpu-$version.zip" norg.exe lib*
|
||||
rm ./lib*
|
||||
cd "$dir" || exit
|
||||
rm bin/norg.exe
|
||||
echo Done.
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue