forked from mattanger/ckb-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickinstall
executable file
·232 lines (222 loc) · 7.74 KB
/
quickinstall
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
# ckb auto build/install script
# Temporary files for program output
TMPFILE=$(mktemp /tmp/ckb.XXXXXXXX)
function newtmp {
rm -f "$TMPFILE"
TMPFILE=$(mktemp /tmp/ckb.XXXXXXXX)
}
# Check for failure, quit if unsuccessful
function checkfail {
if [[ $1 -ne 0 ]]; then
cat "$TMPFILE"
finish "$1"
fi
}
# Exit function
function finish {
rm -f "$TMPFILE"
echo ""
echo "Press enter to exit."
read -rs dummy
exit "$1"
}
# Directories
cd "$(dirname "$0")" || exit
SRCDIR="src"
BINDIR="bin"
[[ "$OSTYPE" == "darwin"* ]] && BINDIR="ckb.app"
# This script respects the PREFIX variable on Linux (always /Applications on OSX)
[[ $PREFIX == "" ]] && PREFIX="/usr/bin"
[[ "$OSTYPE" == "darwin"* ]] && PREFIX="/Applications"
tab=$'\t'
bad_chars=" |'|$tab" # characters needed to be escaped
if [[ "$(pwd)" =~ $bad_chars ]]; then
echo "Error: you must compile ckb in a directory with no spaces/single quotes/tabs."
echo "Move or rename the folder and try again."
finish 1
fi
# Install command line tools if missing
if [[ "$OSTYPE" == "darwin"* ]]; then
if xcode-select --install 2>&1 | grep -q "installed"; then
echo "Command line tools are already installed."
else
# check if user installed them after the gui prompt and prompt him once again
if xcode-select --install 2>&1 | grep -q "installed"; then
echo "Command line tools are installed."
else
echo "Please install command line tools and rerun the script."
finish 1
fi
fi
# Check for Xcode presence
if xcodebuild -version 2>&1 | grep "error"; then
echo "Please install Xcode and rerun the script."
finish 1
fi
fi
if [[ -d $SRCDIR ]]; then
echo "Preparing build files..."
# Clean first
make clean >/dev/null 2>&1
rm Makefile Makefile.* ./*/*/Makefile ./*/*/Makefile.* >/dev/null 2>&1
# Generate makefiles
./qmake-auto "$QMAKEFLAGS" > "$TMPFILE" 2>&1
checkfail $?
make clean >/dev/null 2>&1
# Run make with command arguments
echo "Compiling binaries..."
echo "(This can take a while, please be patient)"
newtmp
# Find out how many cores the system has, for make
JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
# Default to 2 jobs if something went wrong earlier
if [[ -z "$JOBS" ]]; then
JOBS=2
fi
make -j "$JOBS" "$@" 2>"$TMPFILE"
checkfail $?
echo ""
echo "Finished!"
fi
if [[ ! -d $BINDIR ]]; then
# No binaries and no source ($SRCDIR branch will surely create $BINDIR or die trying)
echo "There is nothing to do."
finish 0
fi
# Offer to install ckb at a standard location
shopt -s nocasematch
read -rp "Install ckb system-wide [Y/n]? " doinstall
if [[ $doinstall =~ no? ]]; then
if [[ "$OSTYPE" != "darwin"* ]]; then
# Install icon and .desktop locally
echo "Installing icon and application launcher for the local user..."
xdg-icon-resource install --novendor --size 512 usr/ckb.png 2>"$TMPFILE"
checkfail $?
xdg-desktop-menu install --novendor usr/ckb.desktop 2>"$TMPFILE"
checkfail $?
fi
echo "ckb will not be installed system-wide or run as a service."
echo "Re-run this script if you change your mind."
finish 0
fi
# Run sudo once to authenticate
sudo echo "" >/dev/null
[[ $? -ne 0 ]] && exit 0
if [[ "$OSTYPE" == "darwin"* ]]; then
# OSX
newtmp
# Run macdeployqt to avoid linking problems
[[ $MACDEPLOYQT == "" ]] && MACDEPLOYQT=$(find ~/Qt/*/clang_64/bin ~/Applications/Qt/*/clang_64/bin /Applications/Qt/*/clang_64/bin -name macdeployqt -print -quit 2>/dev/null)
$MACDEPLOYQT ckb.app >/dev/null 2>"$TMPFILE"
# Install
sudo rm -Rf /Applications/ckb.app 2>"$TMPFILE"
sudo cp -R ckb.app /Applications 2>"$TMPFILE"
checkfail $?
echo "Installed at /Applications/ckb.app"
else
# Linux
newtmp
# Install apps
sudo mkdir -p "$PREFIX"
checkfail $?
sudo install bin/ckb "$PREFIX"/ckb 2>"$TMPFILE"
checkfail $?
sudo install bin/ckb-daemon "$PREFIX"/ckb-daemon 2>"$TMPFILE"
checkfail $?
sudo mkdir -p "$PREFIX"/ckb-animations 2>"$TMPFILE"
checkfail $?
sudo install bin/ckb-animations/* "$PREFIX"/ckb-animations 2>"$TMPFILE"
checkfail $?
# Install icon and .desktop
sudo xdg-icon-resource install --novendor --size 512 usr/ckb.png 2>"$TMPFILE"
checkfail $?
sudo xdg-desktop-menu install --novendor usr/ckb.desktop 2>"$TMPFILE"
checkfail $?
echo "Installed in $PREFIX"
fi
# Offer to run as a system service
systemd=$(systemctl --version 2>/dev/null)
systemdc=$?
upstart=$(service --version 2>/dev/null)
upstartc=$?
launchd=$(launchctl help 2>/dev/null)
launchdc=$?
echo ""
if [[ $systemdc -eq 0 && $(echo "$systemd" | wc -l) -ge 1 ]]; then
echo "System service: systemd detected"
read -rp "Run the driver as a startup service [Y/n]? " doservice
if [[ $doservice =~ no? ]]; then
echo "You will need to start the driver manually."
echo "Re-run this script if you change your mind."
else
# Running the driver immediately can cause enter to get spammed. Wait for the key to release first.
sleep 0.5
sudo systemctl stop ckb-daemon >/dev/null 2>&1
sudo mkdir -p /usr/lib/systemd/system
checkfail $?
sudo install -m 0644 service/systemd/ckb-daemon.service /usr/lib/systemd/system 2>"$TMPFILE"
checkfail $?
sudo systemctl daemon-reload >/dev/null 2>&1
sudo systemctl enable ckb-daemon 2>"$TMPFILE"
checkfail $?
sudo systemctl start ckb-daemon 2>"$TMPFILE"
checkfail $?
fi
elif [[ $upstartc -eq 0 && $(echo "$upstart" | wc -l) -ge 1 ]]; then
echo "System service: Upstart detected"
read -rp "Run the driver as a startup service [Y/n]? " doservice
if [[ $doservice =~ no? ]]; then
echo "You will need to start the driver manually."
echo "Re-run this script if you change your mind."
else
sleep 0.5
sudo service ckb-daemon stop >/dev/null 2>&1
sudo mkdir -p /etc/init
checkfail $?
sudo install service/upstart/ckb-daemon.conf /etc/init 2>"$TMPFILE"
checkfail $?
sudo service ckb-daemon start 2>"$TMPFILE"
fi
elif [[ $launchdc -eq 0 && $(echo "$launchd" | wc -l) -ge 1 ]]; then
echo "System service: launchd detected"
read -rp "Run the driver as a startup service [Y/n]? " doservice
if [[ $doservice =~ no? ]]; then
echo "You will need to start the driver manually."
echo "Re-run this script if you change your mind."
else
sleep 0.5
sudo launchctl unload /Library/LaunchDaemons/com.ckb.daemon.plist >/dev/null 2>&1
sudo mkdir -p /Library/LaunchDaemons
checkfail $?
sudo cp -f service/launchd/com.ckb.daemon.plist /Library/LaunchDaemons 2>"$TMPFILE"
checkfail $?
sudo chown root:wheel /Library/LaunchDaemons/com.ckb.daemon.plist 2>"$TMPFILE"
checkfail $?
sudo chmod 0700 /Library/LaunchDaemons/com.ckb.daemon.plist 2>"$TMPFILE"
checkfail $?
sudo launchctl load /Library/LaunchDaemons/com.ckb.daemon.plist 2>"$TMPFILE"
checkfail $?
fi
else
echo "No supported system service daemons detected."
echo "You will need to start the driver manually."
read -rp "Start it now [Y/n]? " dodriver
if [[ ! $dodriver =~ no? ]]; then
sleep 0.5
sudo nohup "$PREFIX"/ckb-daemon >/dev/null 2>&1 &
checkfail $?
fi
fi
sleep 1
echo ""
read -rp "Start ckb now [Y/n]? " dolaunch
[[ $dolaunch =~ no? ]] && exit 0
APP="$PREFIX"/ckb
[[ "$OSTYPE" == "darwin"* ]] && APP="$APP".app/Contents/MacOS/ckb
# Ask ckb to close if there's an instance already running
"$APP" --close >/dev/null 2>&1
sleep 0.5
# Launch
nohup "$APP" >/dev/null 2>&1 &
exit 0