-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller.sh
96 lines (79 loc) · 2.06 KB
/
installer.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
#!/usr/bin/env bash
#
# nar-installer - Simple Bash script to install packages like using `npm install -g`
# Code: https://github.com/h2non/nar-installer
# License: wtfpl
#
while [[ $# > 0 ]]; do
case $1 in
-f|--force)
FORCE=1
;;
-p|--path)
shift
INSTALL_PATH=$1
;;
*)
VERSION=$1
;;
esac
shift
done
# Customize this!
NAME="package"
URL="https://github.com/you/$NAME/releases/download/$VERSION/$NAME-$VERSION"
os=`uname`
if [[ "$os" == 'Linux' ]]; then
platform='linux'
elif [[ "$os" == 'Darwin' ]]; then
platform='darwin'
else
echo "Unsupported operative system. Only Linux and OSX are supported" && exit 1
fi
if [ `uname -m` != 'x86_64' ]; then
echo "Unsupported processor architecture. Only x64 is supported" && exit 1
fi
if [ -z `which curl` ]; then
echo "Cannot find curl binary in PATH. Install it to continue" && exit 1
fi
if [ -z $INSTALL_PATH ]; then
if [ -d "$HOME/.npm" ]; then
INSTALL_PATH="$HOME/.npm/$NAME"
else
INSTALL_PATH="$HOME/.$NAME"
fi
fi
if [ -z $FORCE]; then
if [ -d "$INSTALL_PATH" ]; then
echo "Package $NAME is already installed in $INSTALL_PATH"
echo "Remove it to continue or pass the --force flag"
exit 1
fi
fi
echo "Downloading package $NAME v.$VERSION"
echo
download="$URL-$platform-x64.nar"
curl -k -L --fail -1 $download -o $NAME.nar
if [ $? -ne 0 ]; then
echo
echo "Error while downloading archive from $download"
exit 1
fi
bash $NAME.nar extract -o $INSTALL_PATH
mv .nar/bin/node $INSTALL_PATH/bin
echo "#!/usr/bin/env bash" > $INSTALL_PATH/bin/_run
echo 'script="$(readlink ${BASH_SOURCE[0]})"' >> $INSTALL_PATH/bin/_run
echo 'base="$(dirname $script)"' >> $INSTALL_PATH/bin/_run
echo '$base/node $base/'"$NAME "'$*' >> $INSTALL_PATH/bin/_run
if [ -L "/usr/bin/$NAME" ]; then
rm -f /usr/bin/$NAME
fi
ln -s $INSTALL_PATH/bin/_run /usr/bin/$NAME
chmod +x $INSTALL_PATH/bin/$NAME
chmod +x /usr/bin/$NAME
rm -f $NAME.nar
rm -rf .nar
echo
echo "The installation of $NAME was completed"
echo "$NAME command-line is also available from PATH"
echo