@@ -95,7 +95,6 @@ main() {
9595 DRY_RUN \
9696 METHOD \
9797 ARCHIVE_INSTALL_PREFIX \
98- SKIP_ECHO \
9998 VERSION \
10099 OPTIONAL
101100
@@ -199,7 +198,9 @@ main() {
199198parse_arg () {
200199 case " $1 " in
201200 * =* )
202- opt=" ${1# =* } "
201+ # Remove everything after first equal sign.
202+ opt=" ${1%% =* } "
203+ # Remove everything before first equal sign.
203204 optarg=" ${1#* =} "
204205 if [ ! " $optarg " ] && [ ! " ${OPTIONAL-} " ]; then
205206 echoerr " $opt requires an argument"
@@ -230,23 +231,17 @@ fetch() {
230231 URL=" $1 "
231232 FILE=" $2 "
232233
233- echo " + Downloading $URL "
234-
235234 if [ -e " $FILE " ]; then
236- echo " + Using cached $FILE "
235+ echo " + Reusing $CACHE_DIR / ${URL ##*/ } "
237236 return
238237 fi
239238
240- SKIP_ECHO=1
241239 sh_c curl \
242240 -#fL \
243241 -o " $FILE .incomplete" \
244242 -C - \
245243 " $URL "
246244 sh_c mv " $FILE .incomplete" " $FILE "
247- unset SKIP_ECHO
248-
249- echo " + Downloaded into $FILE "
250245}
251246
252247install_macos () {
@@ -290,18 +285,20 @@ install_aur() {
290285 echo " Installing from the AUR."
291286 echo
292287
293- prev_dir=" $PWD "
294288 tmp_dir=" $( mktemp -d) "
295- cd " $tmp_dir "
296289
297- echo " + Downloading PKGBUILD from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz"
298- SKIP_ECHO=1 sh_c ' curl -fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xz --strip-components 1'
299- unset SKIP_ECHO
300- echo " + Downloaded into $tmp_dir "
301- sh_c makepkg -si
290+ echo " + Downloading PKGBUILD into $tmp_dir from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz"
291+ curl -fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xzC " $tmp_dir "
292+ VERSION=" $( . " $tmp_dir /code-server/PKGBUILD" && echo " $pkgver " ) "
293+ rm -R " $tmp_dir "
302294
303- cd " $prev_dir "
304- rm -Rf " $tmp_dir "
295+ mkdir -p " $CACHE_DIR /code-server-$VERSION -aur"
296+ sh_c cp -a " $tmp_dir /code-server/*" " $CACHE_DIR /code-server-$VERSION -aur"
297+
298+ echo " + Installing $CACHE_DIR /code-server-$VERSION -aur"
299+
300+ cd " $CACHE_DIR /code-server-$VERSION -aur"
301+ sh_c makepkg -si
305302
306303 echo_systemd_postinstall
307304}
@@ -318,15 +315,14 @@ install_archive() {
318315 sh_c=" sudo_sh_c"
319316 fi
320317
321- SKIP_ECHO=1 sh_c mkdir -p " $ARCHIVE_INSTALL_PREFIX /lib" " $ARCHIVE_INSTALL_PREFIX /bin"
322- unset SKIP_ECHO
323-
324318 if [ -e " $ARCHIVE_INSTALL_PREFIX /lib/code-server-$VERSION " ]; then
325319 echo
326320 echo " code-server-$VERSION is already installed at $ARCHIVE_INSTALL_PREFIX /lib/code-server-$VERSION "
327321 echo " Remove it to reinstall."
328322 exit 0
329323 fi
324+
325+ " $sh_c " mkdir -p " $ARCHIVE_INSTALL_PREFIX /lib" " $ARCHIVE_INSTALL_PREFIX /bin"
330326 " $sh_c " tar -C " $ARCHIVE_INSTALL_PREFIX /lib" -xzf " $CACHE_DIR /code-server-$VERSION -$OS -$ARCH .tar.gz"
331327 " $sh_c " mv -f " $ARCHIVE_INSTALL_PREFIX /lib/code-server-$VERSION -$OS -$ARCH " " $ARCHIVE_INSTALL_PREFIX /lib/code-server-$VERSION "
332328 " $sh_c " ln -fs " $ARCHIVE_INSTALL_PREFIX /lib/code-server-$VERSION /bin/code-server" " $ARCHIVE_INSTALL_PREFIX /bin/code-server"
@@ -336,14 +332,22 @@ install_archive() {
336332
337333install_npm () {
338334 if command_exists yarn; then
335+ sh_c=" sh_c"
336+ if [ ! -w " $( yarn global bin) " ]; then
337+ sh_c=" sudo_sh_c"
338+ fi
339339 echo " Installing with yarn."
340340 echo
341- sh_c yarn global add code-server --unsafe-perm
341+ " $ sh_c" yarn global add code-server --unsafe-perm
342342 return
343343 elif command_exists npm; then
344+ sh_c=" sh_c"
345+ if [ ! -w " $( npm config get prefix) " ]; then
346+ sh_c=" sudo_sh_c"
347+ fi
344348 echo " Installing with npm."
345349 echo
346- sh_c npm install -g code-server --unsafe-perm
350+ " $ sh_c" npm install -g code-server --unsafe-perm
347351 return
348352 fi
349353 echo
@@ -431,9 +435,7 @@ command_exists() {
431435}
432436
433437sh_c () {
434- if [ ! " ${SKIP_ECHO-} " ]; then
435- echo " + $* "
436- fi
438+ echo " + $* "
437439 if [ ! " ${DRY_RUN-} " ]; then
438440 sh -c " $* "
439441 fi
@@ -465,8 +467,21 @@ echo_cache_dir() {
465467 fi
466468}
467469
470+ echo () {
471+ builtin echo " $@ " | humanpath
472+ }
473+
474+ cat () {
475+ humanpath
476+ }
477+
468478echoerr () {
469479 echo " $@ " >&2
470480}
471481
482+ # humanpath replaces all occurances of $HOME with ~
483+ humanpath () {
484+ sed " s#$HOME #~#g"
485+ }
486+
472487main " $@ "
0 commit comments