-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngrest.sh
More file actions
180 lines (152 loc) · 3.67 KB
/
ngrest.sh
File metadata and controls
180 lines (152 loc) · 3.67 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
set -eu
TO_INSTALL=
TO_INSTALL_OPT=
# detect OS
OS=
case $(uname -s) in
MSYS*|MINGW*)
OS=MSYS
export PATH="/mingw64/bin:$PATH"
;;
Linux)
OS=Linux
;;
Darwin)
OS=Darwin
;;
*)
echo "This OS is not supported: $(uname -s)" >&2
exit 1
esac
for app in git make cmake g++
do
$app --version >/dev/null 2>&1 || TO_INSTALL+="$app "
done
if [ $OS = Linux ]
then
inotifywait --help >/dev/null 2>&1 || ERR=$?
if [ $ERR == 127 ] # command not found
then
TO_INSTALL_OPT+="inotify-tools "
fi
fi
[ $OS = MSYS ] && SUDO= || SUDO=sudo
if [ -n "$TO_INSTALL" ]
then
pkg=
# detect package manager
for p in apt-get yum port brew pacman
do
if which $p >/dev/null 2>&1
then
pkg=$p
break
fi
done
if [ -z "$pkg" ]
then
echo "Cannot detect package manager"
exit 1
fi
case $pkg in
brew|port)
YES=
INSTALL=install
[ $pkg != brew ] || SUDO=
;;
pacman)
YES=--noconfirm
INSTALL=-S
TO_INSTALL=${TO_INSTALL//g++/mingw-w64-$(uname -m)-gcc}
;;
*)
YES=-y
INSTALL=install
;;
esac
if [ -n "$SUDO" ]
then
echo "This script will install missing dependencies for you: $TO_INSTALL$TO_INSTALL_OPT..."
echo "To continue please enter your password, or press Ctrl+C to install it manually."
fi
$SUDO $pkg $INSTALL $YES $TO_INSTALL </dev/null
[ -n "$TO_INSTALL_OPT" ] || $SUDO $pkg $INSTALL $YES $TO_INSTALL_OPT </dev/null || true
[ $pkg != brew ] || SUDO=sudo
fi
if [ $OS = MSYS ]
then
export NGREST_HOME=$APPDATA/ngrest
else
export NGREST_HOME=$HOME/.ngrest
fi
mkdir -p "$NGREST_HOME"
cd "$NGREST_HOME"
SRC_DIR=$NGREST_HOME/ngrest
BUILD_DIR=$SRC_DIR-build
rm -rf "$BUILD_DIR"
if [ -z "${UPGRADE:-}" ]
then
test ! -e "$SRC_DIR" || mv "$SRC_DIR" "$SRC_DIR~$(date +%Y%m%d-%H%M%S)"
git clone https://github.com/loentar/ngrest.git
fi
mkdir "$BUILD_DIR"
cd "$BUILD_DIR"
rm -f .build_ok
echo "Configuring ngrest for the build..."
if [ $OS = MSYS ]
then
# supress platform warnings
touch /usr/share/cmake-$(cmake --version | sed '1{s/cmake version //;q}')/Modules/Platform/$(uname -s).cmake 2>/dev/null || true
cmake ${CMAKE_FLAGS:-} -GUnix\ Makefiles -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc ../ngrest >cmake-build.log
else
cmake ${CMAKE_FLAGS:-} ../ngrest >cmake-build.log
fi
echo "Building ngrest. It may take few minutes..."
make >make-build.log
touch .build_ok
echo "Build OK"
if [ $OS = MSYS ]
then
mkdir -p "$APPDATA/ngrest/bin/"
cp -f "$SRC_DIR/scripts/ngrest" "$SRC_DIR/scripts/ngrest.cmd" "$APPDATA/ngrest/bin/"
cp -f "$SRC_DIR/scripts/ngrest" /usr/bin/ # to be accessible from msys terminal
else
# install to ~/bin if user already created it
if [[ $PATH =~ ~/bin ]]
then
USERINST=1
fi
if [ -z "${USERINST:-}" ]
then
#ln -nsf $BUILD_DIR/deploy ngrest
echo "Installing ngrest script into /usr/local/bin/"
sudo cp -f $SRC_DIR/scripts/ngrest /usr/local/bin/
sudo chown 0:0 /usr/local/bin/ngrest
sudo chmod 755 /usr/local/bin/ngrest
else
echo "Installing ngrest script into ~/bin/"
if [[ ! $PATH =~ ~/bin ]]
then
cat << EOF
*** Please note: You must re-login after installation completed. Else 'ngrest' command may not work ***
If you cannot access 'ngrest' command after re-login you need to add this line into your startup scripts: ~/.bashrc or ~/.profile
PATH="$HOME/bin:$PATH"
EOF
fi
mkdir -p ~/bin
cp -f $SRC_DIR/scripts/ngrest ~/bin/
chmod 755 ~/bin/ngrest
fi
fi
if [ -z "${UPGRADE:-}" ]
then
cat << EOF
Installation completed.
Now you can create your first project by typing:
ngrest create myproject
EOF
else
echo "Upgrade completed."
killall -HUP ngrest
fi