-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·167 lines (152 loc) · 3.06 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env sh
version="0.0.11"
info() {
echo -e "\e[92m$1\e[0m"
}
error() {
echo -e "\e[91mError! $1\e[0m"
}
run() {
command="$@"
if [ -z ${noroot+x} ]; then
if [ -x "$(command -v sudo)" ]; then
sudo $command
else
su root -c "$command"
fi
else
$command
fi
}
checkdeps() {
if ! { [ -x "$(command -v fetch)" ] || [ -x "$(command -v wget)" ] || [ -x "$(command -v curl)" ]; }; then
error "This script needs one of: fetch, wget or curl"
exit 1
elif ! { [ -x "$(command -v npm)" ] && [ -x "$(command -v node)" ]; }; then
error "This script needs npm and node"
exit 1
elif ! [ -x "$(command -v cmake)" ]; then
error "This script needs cmake"
exit 1
elif ! [ -x "$(command -v tar)" ]; then
error "This script needs tar"
exit 1
elif ! [ -x "$(command -v whoami)" ]; then
error "This script needs whoami"
exit 1
fi
}
getvars() {
bundle="bundle.tar.gz"
dirname="alien*"
tarball="https://github.com/alien-sh/alien/archive/v$version.tar.gz"
if [ -d "./.git" ]; then
checkout="YES"
fi
}
getargs() {
while [ "$#" -gt 0 ]
do
case "$1" in
-p|--prefix)
shift
prefix="$1"
;;
-p=*|--prefix=*)
prefix="${1#*=}"
;;
-np|--no-plugins)
noplugins="YES"
;;
-nr|--no-root)
noroot="YES"
;;
*)
error "Unknown option '$key'"
exit 1
;;
esac
shift
done
}
checkargs() {
if [ -z ${prefix+x} ]; then
info "Prefix not set, setting to /usr/local"
prefix="/usr/local"
fi
}
download() {
if ! [ -z ${checkout+x} ]; then
info "Skipping download"
return 0
fi
info "Downloading: $tarball"
if [ -x "$(command -v fetch)" ]; then
fetch $tarball -o $bundle
elif [ -x "$(command -v wget)" ]; then
wget $tarball -O $bundle
elif [ -x "$(command -v curl)" ]; then
curl $tarball --output $bundle
fi
}
maketemp() {
if ! [ -z ${checkout+x} ]; then
info "Skipping temp dir creation"
return 0
fi
tmpdir=$(mktemp -d -t al-XXXXXXXXXX)
info "Created temp dir: $tmpdir"
cd $tmpdir
}
untar() {
if ! [ -z ${checkout+x} ]; then
return 0
fi
tar xzf $bundle
cd $dirname
}
install() {
if ! [ -z ${checkout+x} ]; then
info "Installing from checkout"
fi
info "Installing dependencies"
npm install
info "Installing in $prefix"
run "npm install --prefix $prefix -g ."
run "node build.js $prefix"
}
homesetup() {
cd ~
if ! [ -d ".alien" ]; then
mkdir ".alien"
fi
if ! [ -z ${noplugins+x} ]; then
info "Skipping plugin install"
return 0
fi
cd ".alien"
if ! [ -f "package.json" ]; then
configdir="$(whoami)-alien-config"
mkdir $configdir
cd $configdir
npm init -y
mv "package.json" ..
cd ..
rm -rf $configdir
fi
npm i -S "@alien.sh/core-plugins"
echo 'module.exports = [require("@alien.sh/core-plugins")];' > "plugins.js"
}
main() {
checkdeps
getvars
getargs $@
checkargs
maketemp
download
untar
install
homesetup
info "Install done."
}
main $@