1
1
#! /usr/bin/env bash
2
+ # install_helper allows for easy installation of code-server on Linux systems
3
+ # the latest official release is pulled from the Github API, where the proper asset
4
+ # is then unpackaged and installed into ~/.local/share/code-server/<version>
5
+
6
+ # The code-server binary is linked to ~/.local/share/code-server/bin/code-server
7
+
2
8
set -euo pipefail
3
9
4
- RED=' \033[0;31m'
5
- NC=' \033[0m' # No Color
10
+ RED=1
6
11
7
12
get_releases () {
8
13
curl --silent " https://api.github.com/repos/cdr/code-server/releases/latest" |
@@ -35,8 +40,10 @@ linux_install() {
35
40
rm code-server* .tar.gz
36
41
37
42
if [ -d $lib_path ]; then
38
- echo -e " ${RED} -- ERROR: v$version already found in $lib_path ${NC} "
39
- echo -e " ${RED} -- ERROR: To reinstall, first delete this directory${NC} "
43
+ tput setaf $RED
44
+ echo " -- ERROR: v$version already found in $lib_path "
45
+ echo " -- ERROR: To reinstall, first delete this directory"
46
+ tput sgr 0
40
47
rm -rf -f $temp_path
41
48
exit 1
42
49
fi
@@ -48,60 +55,19 @@ linux_install() {
48
55
mkdir -p $bin_dir
49
56
ln -f -s $lib_path /code-server $bin_path
50
57
51
- rm -rf -f $temp_path
52
-
53
- if [ $bin_dir != * " $PATH " * ]; then
54
- echo -e " ${RED} -- WARNING: $bin_dir is not in your \$ PATH${NC} "
58
+ code_server_bin=$( which code-server || true)
59
+ if [ " $code_server_bin " == " " ]; then
60
+ tput setaf $RED
61
+ echo " -- WARNING: $bin_dir is not in your \$ PATH"
62
+ tput sgr 0
55
63
fi
56
64
57
- echo " -- Successfully installed code-server at $bin_path "
58
- }
59
-
60
- mac_install () {
61
- bin_path=/usr/local/bin
62
- lib_path=/usr/local/lib
63
-
64
- releases=$( get_releases)
65
- package=$( echo " $releases " | grep ' darwin' | sed -E ' s/.*"([^"]+)".*/\1/' )
66
- version=$( echo $releases | sed -E ' s/.*"tag_name": "([^"]+)".*/\1/' )
67
-
68
- temp_path=/tmp/code-server-$version
69
-
70
- if [ -d $temp_path ]; then
71
- rm -rf $temp_path
72
- fi
73
-
74
- mkdir $temp_path
75
- cd $temp_path
76
-
77
- echo " -- Downloading code-server v$version "
78
- wget $package > /dev/null
79
-
80
- echo " -- Unpacking release"
81
- unzip code-server-* > /dev/null
82
- rm code-server-* .zip
83
-
84
- echo " -- Installing binary"
85
- if [ -d $lib_path /code-server ]; then
86
- backup=$lib_path /BACKUP_$( date +%s) _code-server/
87
- mv $lib_path /code-server/ $backup
88
- echo " -- INFO: moved old code-server lib directory to $backup "
89
- fi
90
- mkdir -p $lib_path /code-server
91
- mv ./code-server-* /* $lib_path /code-server/
92
-
93
- rm -f $bin_path /code-server
94
- ln -s $lib_path /code-server/code-server $bin_path /code-server
95
-
96
65
rm -rf -f $temp_path
97
-
98
- echo " -- Successfully installed code-server at $bin_path /code-server"
66
+ echo " -- Successfully installed code-server at $bin_path "
99
67
}
100
68
101
69
if [[ $OSTYPE == " linux-gnu" ]]; then
102
70
linux_install
103
- elif [[ $OSTYPE == " darwin" * ]]; then
104
- mac_install
105
71
else
106
72
echo " Unknown operating system. Not installing."
107
73
exit 1
0 commit comments