@@ -16,75 +16,139 @@ ensure_downloader() {
1616run_update_process () {
1717 local INITIAL_SETUP=0
1818
19- # Check if credentials file exists, if not run the updater
19+ # Check if credentials file exists, if not run the initial setup
2020 if [ ! -f " $DOWNLOAD_CRED_FILE " ]; then
2121 INITIAL_SETUP=1
22- logger warn " Credentials file not found, running initial setup..."
23- logger info " Downloading server files..."
24-
25- $DOWNLOADER -check-update
26-
27- echo " "
28- printc " {MAGENTA}╔══════════════════════════════════════════════════════════════════════════════════════╗"
29- printc " {MAGENTA}║ {BLUE}NOTE: You must have purchased Hytale on the account you are using to authenticate. {MAGENTA}║"
30- printc " {MAGENTA}╚══════════════════════════════════════════════════════════════════════════════════════╝"
31- echo " "
32-
33- if ! $DOWNLOADER -patchline $PATCHLINE -download-path server.zip; then
34- echo " "
35- logger error " Failed to download Hytale server files."
36- logger warn " Removing invalid credential file..."
37- rm -f $DOWNLOAD_CRED_FILE
38- exit 1
39- fi
22+ run_initial_setup
23+ fi
24+
25+ # Check if automatic update is enabled
26+ if [ " $AUTOMATIC_UPDATE " = " 1" ] && [ " $INITIAL_SETUP " = " 0" ]; then
27+ run_auto_update
28+ fi
4029
41- # Save version info after initial setup
42- local DOWNLOADER_VERSION=$( $DOWNLOADER -print-version -skip-update-check 2>&1 )
43- if [ $? -eq 0 ] && [ -n " $DOWNLOADER_VERSION " ]; then
44- echo " $DOWNLOADER_VERSION " > $VERSION_FILE
45- logger success " Saved version info!"
30+ # Check if patchline has changed if so update the server
31+ if [ -f " $PATCHLINE_CACHE_FILE " ]; then
32+ local CACHED_PATCHLINE=$( cat $PATCHLINE_CACHE_FILE )
33+
34+ if [ " $PATCHLINE " != " $CACHED_PATCHLINE " ]; then
35+ logger warn " Patchline mismatch, running update..."
36+ $DOWNLOADER -check-update
37+ $DOWNLOADER -patchline $PATCHLINE -download-path server.zip
38+
39+ save_patchline_version
40+ extract_server_files
41+
42+ logger success " Server has been successfully updated to patchline: $PATCHLINE "
43+ else
44+ logger info " Patchline match, skipping change"
4645 fi
46+ else
47+ logger warn " Patchline file not found, Saving patchline!"
48+ save_patchline_version
49+ fi
50+ }
51+
52+ run_patchline_change () {
53+ logger info " Updating server to patchline: $PATCHLINE "
54+
55+ $DOWNLOADER -check-update
56+ if ! $DOWNLOADER -patchline $PATCHLINE -download-path server.zip; then
57+ echo " "
58+ logger error " Failed to download Hytale server files."
59+ logger warn " Removing invalid credential file..."
60+ rm -f $DOWNLOAD_CRED_FILE
61+ exit 1
62+ fi
63+
64+ echo " $PATCHLINE " > " $PATCHLINE_CACHE_FILE "
65+ logger success " Selected patchline saved!"
66+
67+ save_downloader_version
68+
69+ extract_server_files
70+ logger success " Server has been successfully updated to patchline: $PATCHLINE "
71+ }
4772
48- extract_server_files
73+ run_initial_setup () {
74+ logger warn " Credentials file not found, running initial setup..."
75+ logger info " Downloading server files..."
76+
77+ $DOWNLOADER -check-update
78+
79+ echo " "
80+ printc " {MAGENTA}╔══════════════════════════════════════════════════════════════════════════════════════╗"
81+ printc " {MAGENTA}║ {BLUE}NOTE: You must have purchased Hytale on the account you are using to authenticate. {MAGENTA}║"
82+ printc " {MAGENTA}╚══════════════════════════════════════════════════════════════════════════════════════╝"
83+ echo " "
84+
85+ if ! $DOWNLOADER -patchline $PATCHLINE -download-path server.zip; then
86+ echo " "
87+ logger error " Failed to download Hytale server files."
88+ logger warn " Removing invalid credential file..."
89+ rm -f $DOWNLOAD_CRED_FILE
90+ exit 1
4991 fi
5092
93+ save_patchline_version
94+ save_downloader_version
95+ extract_server_files
96+ }
97+
98+ run_auto_update () {
5199 # Run automatic update if enabled
52- if [ " $AUTOMATIC_UPDATE " = " 1" ] && [ " $INITIAL_SETUP " = " 0" ]; then
53- logger info " Checking for updates..."
100+ logger info " Checking for updates..."
54101
55- local LOCAL_VERSION=" "
56- if [ -f " $VERSION_FILE " ]; then
57- LOCAL_VERSION=$( cat $VERSION_FILE )
58- else
59- logger warn " Version file not found, forcing update"
102+ local LOCAL_VERSION=" "
103+ if [ -f " $VERSION_FILE " ]; then
104+ LOCAL_VERSION=$( cat $VERSION_FILE )
105+ else
106+ logger warn " Version file not found, forcing update"
107+ fi
108+
109+ local DOWNLOADER_VERSION=$( $DOWNLOADER -print-version -skip-update-check 2>&1 )
110+
111+ if [ $? -ne 0 ] || [ -z " $DOWNLOADER_VERSION " ]; then
112+ logger error " Failed to get downloader version."
113+ exit 1
114+ else
115+ if [ -n " $LOCAL_VERSION " ]; then
116+ logger info " Local version: $LOCAL_VERSION "
60117 fi
118+ logger info " Downloader version: $DOWNLOADER_VERSION "
119+
120+ if [ " $LOCAL_VERSION " != " $DOWNLOADER_VERSION " ]; then
121+ logger warn " Version mismatch, running update..."
122+ $DOWNLOADER -check-update
123+ $DOWNLOADER -patchline $PATCHLINE -download-path server.zip
61124
62- local DOWNLOADER_VERSION=$( $DOWNLOADER -print-version -skip-update-check 2>&1 )
125+ save_patchline_version
126+ save_downloader_version
63127
64- if [ $? -ne 0 ] || [ -z " $DOWNLOADER_VERSION " ]; then
65- logger error " Failed to get downloader version."
66- exit 1
128+ extract_server_files
129+ logger success " Server has been updated successfully!"
67130 else
68- if [ -n " $LOCAL_VERSION " ]; then
69- logger info " Local version: $LOCAL_VERSION "
70- fi
71- logger info " Downloader version: $DOWNLOADER_VERSION "
72-
73- if [ " $LOCAL_VERSION " != " $DOWNLOADER_VERSION " ]; then
74- logger warn " Version mismatch, running update..."
75- $DOWNLOADER -check-update
76- $DOWNLOADER -patchline $PATCHLINE -download-path server.zip
77- echo " $DOWNLOADER_VERSION " > $VERSION_FILE
78- logger success " Saved version info!"
79- extract_server_files
80- logger success " Server has been updated successfully!"
81- else
82- logger info " Versions match, skipping update"
83- fi
131+ logger info " Versions match, skipping update"
84132 fi
85133 fi
86134}
87135
136+ save_patchline_version () {
137+ echo " $PATCHLINE " > $PATCHLINE_CACHE_FILE
138+ logger success " Selected patchline saved!"
139+ }
140+
141+ save_downloader_version () {
142+ local DOWNLOADER_VERSION=$( $DOWNLOADER -print-version -skip-update-check 2>&1 )
143+ if [ $? -eq 0 ] && [ -n " $DOWNLOADER_VERSION " ]; then
144+ echo " $DOWNLOADER_VERSION " > $VERSION_FILE
145+ logger success " Saved version info!"
146+ else
147+ logger error " Failed to get downloader version."
148+ exit 1
149+ fi
150+ }
151+
88152validate_server_files () {
89153 if [ ! -f " HytaleServer.jar" ]; then
90154 logger error " HytaleServer.jar not found!"
0 commit comments