forked from environmentalinformatics-marburg/rsdb-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_update.sh
171 lines (147 loc) · 3.74 KB
/
github_update.sh
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
update_folders=(
lib
webcontent
)
update_files=(
rsdb.jar
)
GREEN='\033[0;32m'
RED='\033[0;31m'
WHITE='\033[0;97m'
NC='\033[0m' # No Color
echo -e ""
echo -e "${WHITE}--------------------------------------------------------------------------------------------------${NC}"
echo -e "${RED}!! only proceed if you stopped a running RSDB instance !!${NC}"
echo -e "${GREEN}Do you want to download the latest RSDB release package, backup changed files and performe update?${NC}"
echo -e "${WHITE}--------------------------------------------------------------------------------------------------${NC}"
select yn in "Yes" "No" "Cancel"; do
case $yn in
Yes ) break;;
No ) exit;;
Cancel ) exit;;
esac
done
timestamp=$(date +%Y_%m_%d__%H_%M_%S)
echo $timestamp
echo -e "${GREEN}delete folder 'update'${NC}"
rm -rf ./update
if [ -d ./update ]
then
echo -e "${RED}folder 'update' still exists, abort. (no changes performed)${NC}"
exit 1
fi
echo -e "${GREEN}download latest 'package.zip'${NC}"
wget --directory-prefix=./update https://github.com/environmentalinformatics-marburg/rsdb/releases/latest/download/package.zip
if [ ! -f ./update/package.zip ]
then
echo -e "${RED}could not find 'update/package.zip', abort. (no changes performed)${NC}"
exit 2
fi
echo -e "extract 'package.zip'"
unzip ./update/package.zip -d ./update
echo -e "${GREEN}download update done.${NC}"
for i in "${update_folders[@]}"; do
#echo "$i"
if [ ! -d ./update/$i ]
then
echo -e "${RED}folder '$i' is missing in update, abort. (no changes performed)${NC}"
exit 3
fi
done
for i in "${update_files[@]}"; do
#echo "$i"
if [ ! -f ./update/$i ]
then
echo -e "${RED}file '$i' is missing in update, abort. (no changes performed)${NC}"
exit 4
fi
done
if [ ! -d ./backup ]
then
mkdir ./backup
fi
if [ ! -d ./backup ]
then
echo -e "${RED}could not create 'backup' folder, abort. (no changes performed)${NC}"
exit 5
fi
backup=./backup/$timestamp
if [ -d $backup ]
then
echo -e "${RED}backup folder '$backup' already exists, abort. (no changes performed)${NC}"
exit 6
fi
mkdir $backup
if [ ! -d $backup ]
then
echo -e "${RED}could not create backup folder '$backup', abort. (no changes performed)${NC}"
exit 7
fi
for i in "${update_folders[@]}"; do
#echo "$i"
if [ -d ./$i ]
then
mv ./$i $backup
else
echo -e "missing folder for backup '$i'. continue."
fi
done
for i in "${update_files[@]}"; do
#echo "$i"
if [ -f ./$i ]
then
mv ./$i $backup
else
echo -e "missing file for backup '$i'. continue."
fi
done
for i in "${update_folders[@]}"; do
#echo "$i"
if [ -d ./$i ]
then
echo -e "${RED}folder '$i' still exists after backup, abort. (some folders/files may be moved to backup already)${NC}"
exit 8
fi
done
for i in "${update_files[@]}"; do
#echo "$i"
if [ -f ./$i ]
then
echo -e "${RED}file '$i' still exists after backup, abort. (some folders/files may be moved to backup already)${NC}"
exit 9
fi
done
echo -e "${GREEN}backup done. ('$backup')${NC}"
for i in "${update_folders[@]}"; do
#echo "$i"
mv ./update/$i ./
done
for i in "${update_files[@]}"; do
#echo "$i"
mv ./update/$i ./
done
for i in "${update_folders[@]}"; do
#echo "$i"
if [ -d ./$i ]
then
echo -e "updated folder: ${WHITE}$i${NC}"
else
echo -e "${RED}folder '$i' has not beend updated (missing), abort. (some updates may have been performed, your should revert to a backup))${NC}"
exit 10
fi
done
for i in "${update_files[@]}"; do
#echo "$i"
if [ -f ./$i ]
then
echo -e "updated file: ${WHITE}$i${NC}"
else
echo -e "${RED}file '$i' has not beend updated (missing), abort. (some updates may have been performed, your should revert to a backup))${NC}"
exit 11
fi
done
echo -e ""
echo -e "${GREEN}update done. backup in '$backup'${NC}"
echo -e ""
exit 0