@@ -27,35 +27,50 @@ function update_script() {
2727 msg_error " No ${APP} Installation Found!"
2828 exit
2929 fi
30- msg_info " Stopping ${APP} "
31- systemctl stop wikijs
32- msg_ok " Stopped ${APP} "
30+ RELEASE=$( curl -s https://api.github.com/repos/Requarks/wiki/releases/latest | grep " tag_name" | awk ' {print substr($2, 3, length($2)-4) }' )
31+ if [[ " ${RELEASE} " != " $( cat /opt/${APP} _version.txt) " ]] || [[ ! -f /opt/${APP} _version.txt ]]; then
32+ msg_info " Verifying whether ${APP} ' new release is v3.x+ and current install uses SQLite."
33+ SQLITE_INSTALL=$( [ -f /opt/wikijs/db.sqlite ] && echo " true" || echo " false" )
34+ if [[ " ${SQLITE_INSTALL} " == " true" && " ${RELEASE} " =~ ^3.* ]]; then
35+ echo " SQLite is not supported in v3.x+, currently there is no update path availble."
36+ exit
37+ fi
38+ msg_ok " There is an update path available for ${APP} to v${RELEASE} "
3339
34- msg_info " Backing up Data"
35- rm -rf ~ /data-backup
36- mkdir -p ~ /data-backup
37- [ -f /opt/wikijs/db.sqlite ] && cp /opt/wikijs/db.sqlite ~ /data-backup
38- [ -f /opt/wikijs/config.yml ] && cp /opt/wikijs/config.yml ~ /data-backup
39- [ -d /opt/wikijs/data ] && cp -R /opt/wikijs/data ~ /data-backup
40- msg_ok " Backed up Data"
40+ msg_info " Stopping ${APP} "
41+ systemctl stop wikijs
42+ msg_ok " Stopped ${APP} "
4143
42- msg_info " Updating ${APP} "
43- rm -rf /opt/wikijs/*
44- cd /opt/wikijs
45- wget -q https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz
46- tar xzf wiki-js.tar.gz
47- msg_ok " Updated ${APP} "
44+ msg_info " Backing up Data"
45+ mkdir /opt/wikijs-backup
46+ $SQLITE_INSTALL && cp /opt/wikijs/db.sqlite /opt/wikijs-backup
47+ cp -R /opt/wikijs/{config.yml,/data} /opt/wikijs-backup
48+ msg_ok " Backed up Data"
4849
49- msg_info " Restoring Data"
50- cp -R ~ /data-backup/* /opt/wikijs
51- rm -rf ~ /data-backup
52- $STD npm rebuild sqlite3
53- msg_ok " Restored Data"
50+ msg_info " Updating ${APP} "
51+ rm -rf /opt/wikijs/*
52+ cd /opt/wikijs
53+ wget -q " https://github.com/requarks/wiki/releases/download/v${RELEASE} /wiki-js.tar.gz"
54+ tar -xzf wiki-js.tar.gz
55+ msg_ok " Updated ${APP} "
5456
55- msg_info " Starting ${APP} "
56- systemctl start wikijs
57- msg_ok " Started ${APP} "
58- msg_ok " Updated Successfully"
57+ msg_info " Restoring Data"
58+ cp -R /opt/wikijs-backup/* /opt/wikijs
59+ $SQLITE_INSTALL && $STD npm rebuild sqlite3
60+ msg_ok " Restored Data"
61+
62+ msg_info " Starting ${APP} "
63+ systemctl start wikijs
64+ msg_ok " Started ${APP} "
65+
66+ msg_info " Cleaning Up"
67+ rm -rf /opt/wikijs/wiki-js.tar.gz
68+ rm -rf /opt/wikijs-backup
69+ msg_ok " Cleanup Completed"
70+ msg_ok " Updated Successfully"
71+ else
72+ msg_ok " No update required. ${APP} is already at v${RELEASE} "
73+ fi
5974 exit
6075}
6176
@@ -66,4 +81,4 @@ description
6681msg_ok " Completed Successfully!\n"
6782echo -e " ${CREATING}${GN}${APP} setup has been successfully initialized!${CL} "
6883echo -e " ${INFO}${YW} Access it using the following URL:${CL} "
69- echo -e " ${TAB}${GATEWAY}${BGN} http://${IP} :3000${CL} "
84+ echo -e " ${TAB}${GATEWAY}${BGN} http://${IP} :3000${CL} "
0 commit comments