-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.ab
80 lines (70 loc) · 1.75 KB
/
update.ab
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
import { download } from "std/http"
import { dir_exist, make_executable, create_symbolic_link,create_dir,file_exist } from "std/fs"
import { exit } from "std/env"
let bool_true = 1
let bool_false = 0
fun download_latest_package(target:Text){
echo "run download_latest_package"
let is_download_succ = download(target, "./SgridCloudServer.tar.gz")
if is_download_succ == bool_false {
echo "download failed"
exit(1)
}
}
fun linux_service_stop(){
echo "stop linux service"
$ systemctl stop sgrid $ failed {
echo "stop linux service failed"
exit(1)
}
}
fun linux_service_start(){
echo "start linux service"
$ systemctl start sgrid $ failed {
echo "start linux service failed"
exit(1)
}
}
fun remove_old(){
echo "Removing old"
$ rm -r ./app $ failed {
echo "app is not exist, ignore"
}
$ rm -rf ./dist $ failed {
echo "dist is not exist, ignore"
}
}
fun if_not_exist_then_create(path: Text): Num {
echo "Checking if {path} exists, if not, creating it..."
if not dir_exist(path) {
create_dir(path)
return bool_true
}
return bool_false
}
fun tar(){
$ tar -xvf ./SgridCloudServer.tar.gz $ failed {
echo "dist is not exist, ignore"
}
$ chmod +x ./app $ failed {
echo "add permission failed"
}
}
// how to run this script ?
// ./update.sh http://124.220.19.199:17853/fm//sgrid/sgridcloud.tar.gz
main(args){
let download_path = args[1]
if download_path == "" {
echo "error: miss download_path"
exit(1)
}
// DOWN
download_latest_package(download_path)
linux_service_stop()
// REMOVE
remove_old()
// TAR
tar()
// START
linux_service_start()
}