22set -eu
33
44usage () {
5- cat << EOF
5+ cat << EOF
66$0 [--dry-run] [--version X.X.X] [--static <install-prefix>=~/.local]
77
88Installs latest code-server on any macOS or Linux system preferring to use the OS package manager.
@@ -48,18 +48,18 @@ echo_latest_version() {
4848
4949echo_static_postinstall () {
5050 echo
51- cat << EOF
52- Static release has been installed into $STATIC_INSTALL_PREFIX /code-server-$VERSION
51+ cat << EOF
52+ Static release has been installed into $STATIC_INSTALL_PREFIX /lib/ code-server-$VERSION
5353Please extend your path to use code-server:
54- PATH="$STATIC_INSTALL_PREFIX /code-server- $VERSION / bin:\$ PATH"
54+ PATH="$STATIC_INSTALL_PREFIX /bin:\$ PATH"
5555Then you can run:
5656 code-server
5757EOF
5858}
5959
6060echo_systemd_postinstall () {
6161 echo
62- cat << EOF
62+ cat << EOF
6363To have systemd start code-server now and restart on boot:
6464 systemctl --user enable --now code-server
6565Or, if you don't want/need a background service you can run:
@@ -76,7 +76,7 @@ main() {
7676 DRY_RUN \
7777 STATIC \
7878 STATIC_INSTALL_PREFIX \
79- SKIP_LOG \
79+ SKIP_ECHO \
8080 VERSION \
8181 OPTIONAL
8282
@@ -118,12 +118,7 @@ main() {
118118 done
119119
120120 VERSION=" ${VERSION-$(echo_latest_version)} "
121- STATIC_INSTALL_PREFIX=" ${STATIC_INSATLL_PREFIX-$HOME / .local} "
122-
123- echo " ${DRY_RUN-} "
124- echo " ${STATIC_INSTALL_PREFIX-} "
125- echo " ${VERSION-} "
126- exit 1
121+ STATIC_INSTALL_PREFIX=" ${STATIC_INSTALL_PREFIX-$HOME / .local} "
127122
128123 OS=" $( os) "
129124 if [ ! " $OS " ]; then
@@ -144,7 +139,7 @@ main() {
144139 exit 0
145140 fi
146141
147- CACHE_DIR=" $( cache_dir ) "
142+ CACHE_DIR=" $( echo_cache_dir ) "
148143 mkdir -p " $CACHE_DIR "
149144
150145 if [ " ${STATIC-} " ]; then
@@ -217,7 +212,7 @@ fetch() {
217212 -Ro " $FILE .incomplete" \
218213 -C - \
219214 " $URL "
220- mv " $FILE .incomplete" " $FILE "
215+ SKIP_ECHO=1 sh_c mv " $FILE .incomplete" " $FILE "
221216}
222217
223218install_macos () {
@@ -260,7 +255,7 @@ install_aur() {
260255 tmp_dir=" $( mktemp -d) "
261256 (
262257 cd " $tmp_dir "
263- tar -xzf " $CACHE_DIR /code-server-aur.tar.gz" --strip-components 1
258+ SKIP_ECHO=1 sh_c tar -xzf " $CACHE_DIR /code-server-aur.tar.gz" --strip-components 1
264259 sh_c makepkg -si
265260 )
266261 rm -Rf " $tmp_dir "
@@ -285,11 +280,16 @@ install_static() {
285280 if [ ! -w " $STATIC_INSTALL_PREFIX " ]; then
286281 sh_c=" sudo_sh_c"
287282 fi
283+ SKIP_ECHO=1 sh_c mkdir -p " $STATIC_INSTALL_PREFIX /lib" " $STATIC_INSTALL_PREFIX /bin"
288284
289- " $sh_c " tar -C " $STATIC_INSTALL_PREFIX " -xzf " $CACHE_DIR /code-server-$VERSION -$OS -$ARCH .tar.gz"
290- # In case previously installed.
291- SKIP_LOG=1 " $sh_c " rm -Rf " $STATIC_INSTALL_PREFIX /code-server-$VERSION "
292- " $sh_c " mv -f " $STATIC_INSTALL_PREFIX /code-server-$VERSION -$OS -$ARCH " " $STATIC_INSTALL_PREFIX /code-server-$VERSION "
285+ if [[ -e " $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION " ]]; then
286+ echo
287+ echoerr " code-server-$VERSION is already installed at $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION "
288+ echoerr " Please remove it to reinstall."
289+ exit 1
290+ fi
291+ " $sh_c " tar -C " $STATIC_INSTALL_PREFIX /lib" -xzf " $CACHE_DIR /code-server-$VERSION -$OS -$ARCH .tar.gz"
292+ " $sh_c " mv -f " $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION -$OS -$ARCH " " $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION "
293293
294294 echo_static_postinstall
295295}
@@ -386,11 +386,11 @@ arch() {
386386}
387387
388388command_exists () {
389- command -v " $@ " > /dev/null 2>&1
389+ command -v " $@ " > /dev/null 2>&1
390390}
391391
392392sh_c () {
393- if [ ! " ${SKIP_LOG -} " ]; then
393+ if [ ! " ${SKIP_ECHO -} " ]; then
394394 echo
395395 echo " + $* "
396396 fi
0 commit comments