Skip to content

Commit af398c4

Browse files
committed
Workaround lack of builtin in /bin/sh
1 parent 29e5c4a commit af398c4

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

install.sh

+36-35
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ usage() {
1313
"
1414
fi
1515

16-
cat << EOF
16+
cath << EOF
1717
Installs code-server for Linux and macOS.
1818
It tries to use the system package manager if possible.
1919
After successful installation it explains how to start using code-server.
@@ -67,8 +67,8 @@ echo_latest_version() {
6767
}
6868

6969
echo_standalone_postinstall() {
70-
echo
71-
cat << EOF
70+
echoh
71+
cath << EOF
7272
Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION
7373
Please extend your path to use code-server:
7474
PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH"
@@ -78,8 +78,8 @@ EOF
7878
}
7979

8080
echo_systemd_postinstall() {
81-
echo
82-
cat << EOF
81+
echoh
82+
cath << EOF
8383
To have systemd start code-server now and restart on boot:
8484
systemctl --user enable --now code-server
8585
Or, if you don't want/need a background service you can run:
@@ -163,7 +163,7 @@ main() {
163163
echoerr 'Please rerun without the "--method standalone" flag to install from npm.'
164164
exit 1
165165
fi
166-
echo "No precompiled releases for $(uname -m)."
166+
echoh "No precompiled releases for $(uname -m)."
167167
install_npm
168168
return
169169
fi
@@ -190,7 +190,7 @@ main() {
190190
install_aur
191191
;;
192192
*)
193-
echo "Unsupported package manager."
193+
echoh "Unsupported package manager."
194194
install_standalone
195195
;;
196196
esac
@@ -233,7 +233,7 @@ fetch() {
233233
FILE="$2"
234234

235235
if [ -e "$FILE" ]; then
236-
echo "+ Reusing $CACHE_DIR/${URL##*/}"
236+
echoh "+ Reusing $CACHE_DIR/${URL##*/}"
237237
return
238238
fi
239239

@@ -247,22 +247,22 @@ fetch() {
247247

248248
install_macos() {
249249
if command_exists brew; then
250-
echo "Installing from Homebrew."
251-
echo
250+
echoh "Installing from Homebrew."
251+
echoh
252252

253253
sh_c brew install code-server
254254

255255
return
256256
fi
257257

258-
echo "Homebrew not installed."
258+
echoh "Homebrew not installed."
259259

260260
install_standalone
261261
}
262262

263263
install_deb() {
264-
echo "Installing v$VERSION deb package from GitHub releases."
265-
echo
264+
echoh "Installing v$VERSION deb package from GitHub releases."
265+
echoh
266266

267267
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server_${VERSION}_$ARCH.deb" \
268268
"$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
@@ -272,8 +272,8 @@ install_deb() {
272272
}
273273

274274
install_rpm() {
275-
echo "Installing v$VERSION rpm package from GitHub releases."
276-
echo
275+
echoh "Installing v$VERSION rpm package from GitHub releases."
276+
echoh
277277

278278
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$ARCH.rpm" \
279279
"$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
@@ -283,27 +283,28 @@ install_rpm() {
283283
}
284284

285285
install_aur() {
286-
echo "Installing from the AUR."
287-
echo
286+
echoh "Installing from the AUR."
287+
echoh
288288

289289
tmp_dir="$(mktemp -d)"
290290

291-
echo "+ Downloading PKGBUILD into $tmp_dir from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz"
291+
echoh "+ Downloading PKGBUILD into $tmp_dir from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz"
292292
curl -fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xzC "$tmp_dir"
293293
VERSION="$(. "$tmp_dir/code-server/PKGBUILD" && echo "$pkgver")"
294-
rm -R "$tmp_dir"
295294

296295
sh_c mkdir -p "$CACHE_DIR/code-server-$VERSION-aur"
297296
sh_c cp -a "$tmp_dir/code-server/*" "$CACHE_DIR/code-server-$VERSION-aur"
298297
sh_c cd "$CACHE_DIR/code-server-$VERSION-aur"
299298
sh_c makepkg -si
300299

300+
rm -R "$tmp_dir"
301+
301302
echo_systemd_postinstall
302303
}
303304

304305
install_standalone() {
305-
echo "Installing standalone release archive v$VERSION"
306-
echo
306+
echoh "Installing standalone release archive v$VERSION"
307+
echoh
307308

308309
fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" \
309310
"$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz"
@@ -314,9 +315,9 @@ install_standalone() {
314315
fi
315316

316317
if [ -e "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then
317-
echo
318-
echo "code-server-$VERSION is already installed at $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION"
319-
echo "Remove it to reinstall."
318+
echoh
319+
echoh "code-server-$VERSION is already installed at $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION"
320+
echoh "Remove it to reinstall."
320321
exit 0
321322
fi
322323

@@ -334,21 +335,21 @@ install_npm() {
334335
if [ ! -w "$(yarn global bin)" ]; then
335336
sh_c="sudo_sh_c"
336337
fi
337-
echo "Installing with yarn."
338-
echo
338+
echoh "Installing with yarn."
339+
echoh
339340
"$sh_c" yarn global add code-server --unsafe-perm
340341
return
341342
elif command_exists npm; then
342343
sh_c="sh_c"
343344
if [ ! -w "$(npm config get prefix)" ]; then
344345
sh_c="sudo_sh_c"
345346
fi
346-
echo "Installing with npm."
347-
echo
347+
echoh "Installing with npm."
348+
echoh
348349
"$sh_c" npm install -g code-server --unsafe-perm
349350
return
350351
fi
351-
echo
352+
echoh
352353
echoerr "Please install npm or yarn to install code-server!"
353354
echoerr "You will need at least node v12 and a few C dependencies."
354355
echoerr "See the docs https://github.com/cdr/code-server#yarn-npm"
@@ -433,7 +434,7 @@ command_exists() {
433434
}
434435

435436
sh_c() {
436-
echo "+ $*"
437+
echoh "+ $*"
437438
if [ ! "${DRY_RUN-}" ]; then
438439
sh -c "$*"
439440
fi
@@ -447,7 +448,7 @@ sudo_sh_c() {
447448
elif command_exists su; then
448449
sh_c "su -c '$*'"
449450
else
450-
echo
451+
echoh
451452
echoerr "This script needs to run the following command as root."
452453
echoerr " $*"
453454
echoerr "Please install sudo or su."
@@ -465,16 +466,16 @@ echo_cache_dir() {
465466
fi
466467
}
467468

468-
echo() {
469-
builtin echo "$@" | humanpath
469+
echoh() {
470+
echo "$@" | humanpath
470471
}
471472

472-
cat() {
473+
cath() {
473474
humanpath
474475
}
475476

476477
echoerr() {
477-
echo "$@" >&2
478+
echoh "$@" >&2
478479
}
479480

480481
# humanpath replaces all occurances of $HOME with ~

0 commit comments

Comments
 (0)