@@ -29,38 +29,55 @@ function update_script() {
2929 fi
3030 if [[ ! -f /opt/${APP} _version.txt ]]; then touch /opt/${APP} _version.txt; fi
3131 RELEASE=$( curl -fsSL https://api.github.com/repos/TriliumNext/Notes/releases/latest | grep " tag_name" | awk ' {print substr($2, 3, length($2)-4) }' )
32- if [[ " v${RELEASE} " != " $( cat /opt/${APP} _version.txt) " ]] || [[ ! -f /opt/${APP} _version.txt ]]; then
33- msg_info " Stopping ${APP} "
34- systemctl stop trilium
35- sleep 1
36- msg_ok " Stopped ${APP} "
32+ if [[ " v${RELEASE} " != " $( cat /opt/${APP} _version.txt 2> /dev/null) " ]] || [[ ! -f /opt/${APP} _version.txt ]]; then
33+
34+ if [[ -d /opt/trilium/db ]]; then
35+ DB_PATH=" /opt/trilium/db"
36+ DB_RESTORE_PATH=" /opt/trilium/db"
37+ elif [[ -d /opt/trilium/assets/db ]]; then
38+ DB_PATH=" /opt/trilium/assets/db"
39+ DB_RESTORE_PATH=" /opt/trilium/assets/db"
40+ else
41+ msg_error " Database not found in either /opt/trilium/db or /opt/trilium/assets/db"
42+ exit 1
43+ fi
3744
38- msg_info " Updating to ${RELEASE} "
39- mkdir -p /opt/trilium_backup
40- mv /opt/trilium/db /opt/trilium_backup/
41- rm -rf /opt/trilium
42- cd /tmp
43- curl -fsSL " https://github.com/TriliumNext/Notes/releases/download/v${RELEASE} /TriliumNextNotes-Server-v${RELEASE} -linux-x64.tar.xz" -o $( basename " https://github.com/TriliumNext/Notes/releases/download/v${RELEASE} /TriliumNextNotes-Server-v${RELEASE} -linux-x64.tar.xz" )
44- tar -xf TriliumNextNotes-Server-v${RELEASE} -linux-x64.tar.xz
45- mv TriliumNextNotes-Server-$RELEASE -linux-x64 /opt/trilium
46- cp -r /opt/trilium_backup/db /opt/trilium/
47- echo " v${RELEASE} " > /opt/${APP} _version.txt
48- msg_ok " Updated to ${RELEASE} "
45+ msg_info " Stopping ${APP} "
46+ systemctl stop trilium
47+ sleep 1
48+ msg_ok " Stopped ${APP} "
4949
50- msg_info " Cleaning up"
51- rm -rf /tmp/TriliumNextNotes-Server-${RELEASE} -linux-x64.tar.xz
52- rm -rf /opt/trilium_backup
53- msg_ok " Cleaned"
50+ msg_info " Updating to ${RELEASE} "
51+ mkdir -p /opt/trilium_backup
52+ cp -r " ${DB_PATH} " /opt/trilium_backup/
53+ rm -rf /opt/trilium
54+ cd /tmp
55+ curl -fsSL " https://github.com/TriliumNext/Notes/releases/download/v${RELEASE} /TriliumNextNotes-Server-v${RELEASE} -linux-x64.tar.xz" -o " TriliumNextNotes-Server-v${RELEASE} -linux-x64.tar.xz"
56+ tar -xf " TriliumNextNotes-Server-v${RELEASE} -linux-x64.tar.xz"
57+ mv " TriliumNextNotes-Server-${RELEASE} -linux-x64" /opt/trilium
5458
55- msg_info " Starting ${APP} "
56- systemctl start trilium
57- sleep 1
58- msg_ok " Started ${APP} "
59- msg_ok " Updated Successfully"
60- else
61- msg_ok " No update required. ${APP} is already at ${RELEASE} "
62- fi
63- exit
59+ # Restore database
60+ mkdir -p " $( dirname " ${DB_RESTORE_PATH} " ) "
61+ cp -r /opt/trilium_backup/$( basename " ${DB_PATH} " ) " ${DB_RESTORE_PATH} "
62+
63+ echo " v${RELEASE} " > /opt/${APP} _version.txt
64+ msg_ok " Updated to ${RELEASE} "
65+
66+ msg_info " Cleaning up"
67+ rm -rf " /tmp/TriliumNextNotes-Server-${RELEASE} -linux-x64.tar.xz"
68+ rm -rf /opt/trilium_backup
69+ msg_ok " Cleaned"
70+
71+ msg_info " Starting ${APP} "
72+ systemctl start trilium
73+ sleep 1
74+ msg_ok " Started ${APP} "
75+ msg_ok " Updated Successfully"
76+ else
77+ msg_ok " No update required. ${APP} is already at ${RELEASE} "
78+ fi
79+
80+ exit
6481}
6582
6683start
0 commit comments