1616
1717export VERSION
1818
19+ MODE=" install"
20+
1921HAS_CURL=" $( type " curl" & > /dev/null && echo true || echo false) "
2022HAS_WGET=" $( type " wget" & > /dev/null && echo true || echo false) "
2123HAS_DOCKER=" $( type " docker" & > /dev/null && echo true || echo false) "
@@ -24,6 +26,7 @@ parseArgs() {
2426 CONFIG_ARGS=()
2527
2628 DESTINATION=" "
29+ MODE=" install"
2730
2831 if [[ $1 != " -" * ]]; then
2932 DESTINATION=" $1 "
@@ -36,6 +39,10 @@ parseArgs() {
3639 outputUsage
3740 exit 0
3841 ;;
42+ -u|--update)
43+ MODE=" update"
44+ shift
45+ ;;
3946 * )
4047 CONFIG_ARGS+=(" $1 " )
4148 shift
@@ -48,15 +55,19 @@ parseArgs() {
4855
4956validateArgs () {
5057 if [ -d " $DESTINATION " ]; then
51- [ " $( ls -A " $DESTINATION " ) " ] && echo " The target folder \" $DESTINATION \" is not empty." && exit 1
58+ if [ " $( ls -A " $DESTINATION " ) " -a " $MODE " != " update" ]; then
59+ echo " The target folder \" $DESTINATION \" is not empty. Add \" -u\" to update an existed Higress instance." && exit 1
60+ fi
5261 if [ ! -w " $DESTINATION " ]; then
53- echo " The target folder \" $DESTINATION \" is not writeable."
54- exit 1
62+ echo " The target folder \" $DESTINATION \" is not writeable." && exit 1
5563 fi
5664 else
65+ if [ " $MODE " == " update" ]; then
66+ echo " The target folder \" $DESTINATION \" for update doesn't exist." && exit 1
67+ fi
5768 mkdir -p " $DESTINATION "
5869 if [ $? -ne 0 ]; then
59- exit - 1
70+ exit 1
6071 fi
6172 fi
6273
@@ -67,7 +78,7 @@ validateArgs() {
6778
6879outputUsage () {
6980 echo " Usage: $( basename -- " $0 " ) [DIR] [OPTIONS...]"
70- echo ' Install Higress (standalone version) into the DIR (the current directory by default).'
81+ echo ' Install Higress (standalone version) into the DIR ("./higress" by default).'
7182 echo '
7283 -c, --config-url=URL URL of the config storage
7384 Use Nacos with format: nacos://192.168.0.1:8848
@@ -104,6 +115,8 @@ outputUsage() {
104115 --console-port=CONSOLE-PORT
105116 the port used to visit Higress Console
106117 default to 8080 if unspecified
118+ -u, --update update an existed Higress instance.
119+ no user configuration will be changed during update.
107120 -h, --help give this help list'
108121}
109122
@@ -191,17 +204,45 @@ download() {
191204# install installs the product.
192205install () {
193206 tar -zx --exclude=" docs" --exclude=" src" --exclude=" test" -f " $HIGRESS_TMP_FILE " -C " $DESTINATION " --strip-components=1
207+ echo -n " $VERSION " > " $DESTINATION /VERSION"
194208 bash " $DESTINATION /bin/configure.sh" --auto-start ${CONFIG_ARGS[@]}
195209}
196210
211+ # update updates the product.
212+ update () {
213+ CURRENT_VERSION=" 0.0.0"
214+ if [ -f " $DESTINATION /VERSION" ]; then
215+ CURRENT_VERSION=" $( cat " $DESTINATION /VERSION" ) "
216+ fi
217+ if [ " $CURRENT_VERSION " == " $VERSION " ]; then
218+ echo " Higress is already up-to-date."
219+ exit 0
220+ fi
221+
222+ BACKUP_FOLDER=" $( cd ${DESTINATION} /.. ; pwd) "
223+ BACKUP_FILE=" ${BACKUP_FOLDER} /higress_backup_$( date ' +%Y%m%d%H%M%S' ) .tar.gz"
224+ tar -zc -f " $BACKUP_FILE " -C " $DESTINATION " .
225+ echo " The current version is packed here: $BACKUP_FILE "
226+ echo " "
227+
228+ download
229+ echo " "
230+
231+ tar -zx --exclude=" docs" --exclude=" src" --exclude=" test" --exclude=" compose/.env" -f " $HIGRESS_TMP_FILE " -C " $DESTINATION " --strip-components=1
232+ tar -zx -f " $HIGRESS_TMP_FILE " -C " $DESTINATION " --transform=' s/env/env_new/g' --strip-components=1 " higress-standalone-${VERSION# v} /compose/.env"
233+ bash " $DESTINATION /bin/update.sh"
234+ echo -n " $VERSION " > " $DESTINATION /VERSION"
235+ return
236+ }
237+
197238# fail_trap is executed if an error occurs.
198239fail_trap () {
199240 result=$?
200241 if [ " $result " != " 0" ]; then
201242 if [ -n " $INPUT_ARGUMENTS " ]; then
202- echo " Failed to install Higress with the arguments provided: $INPUT_ARGUMENTS "
243+ echo " Failed to ${MODE} Higress with the arguments provided: $INPUT_ARGUMENTS "
203244 else
204- echo " Failed to install Higress"
245+ echo " Failed to ${MODE} Higress"
205246 fi
206247 echo -e " \tFor support, go to https://github.com/alibaba/higress."
207248 fi
@@ -227,6 +268,13 @@ initOS
227268verifySupported
228269
229270checkDesiredVersion
230- download
231- install
271+ case " $MODE " in
272+ update)
273+ update
274+ ;;
275+ * )
276+ download
277+ install
278+ ;;
279+ esac
232280cleanup
0 commit comments