-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.sh
executable file
·254 lines (228 loc) · 6.86 KB
/
build.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
# python -m neurodesk $@
set -e
_script="$(readlink -f ${BASH_SOURCE[0]})" ## who am i? ##
_base="$(dirname $_script)" ## Delete last component from $_script ##
source ${_base}/neurodesk/configparser.sh ${_base}/config.ini
args=""
# Arguments
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--init)
init=true
shift # past argument
;;
--edit)
edit=true
shift # past argument
;;
--lxde)
lxde=true
shift # past argument
;;
--cli)
cli=true
shift # past argument
;;
--update)
update=true
shift # past argument
;;
--runsudo)
runsudo=true
shift # past argument
;;
--default)
DEFAULT=YES
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ "$lxde" = true ]; then
neurodesk_deskenv=lxde
neurodesk_installdir="$(pwd -P)/local"
neurodesk_appmenu=/etc/xdg/menus/lxde-applications.menu
neurodesk_appdir=/usr/share/applications/
neurodesk_deskdir=/usr/share/desktop-directories/
neurodesk_edit=n
echo "deskenv> lxde preset"
echo
fi
if [ "$edit" = true ]; then
neurodesk_edit=y
echo "edit> Yes"
echo
fi
if [ "$cli" = true ]; then
neurodesk_deskenv=cli
neurodesk_installdir="$(pwd -P)/local"
echo "deskenv> cli preset"
echo
fi
if [ "$init" = true ]; then
# Installation Directory [./local]
echo "Enter Installation Directory. Blank for default [./local]"
read -e -p "installdir> " neurodesk_installdir
neurodesk_installdir="${neurodesk_installdir/#\~/$HOME}"
if [ -z "$neurodesk_installdir" ]; then
neurodesk_installdir="$(pwd -P)"
fi
if [ ! -d "$neurodesk_installdir" ]; then
echo "Installation directory does not exist"
echo "Creating $neurodesk_installdir"
mkdir -p $neurodesk_installdir
fi
neurodesk_installdir=$(readlink -f ${neurodesk_installdir})
if [ "$neurodesk_installdir" == $(pwd -P) ]; then
neurodesk_installdir="$(pwd -P)/local"
mkdir -p $neurodesk_installdir
fi
echo "Installation directory at $neurodesk_installdir"
echo
# Desktop Environment [cli/lxde/mate]
echo "Enter Desktop Environment [cli/lxde/mate]"
read -p "deskenv> " neurodesk_deskenv
neurodesk_deskenv=$(echo "$neurodesk_deskenv" | tr '[:upper:]' '[:lower:]')
case "$neurodesk_deskenv" in
cli|lxde|mate)
echo "Environment set to $neurodesk_deskenv"
;;
*)
echo "Defaulting to cli environment"
neurodesk_deskenv="cli"
;;
esac
echo
if [ $neurodesk_deskenv != "cli" ]; then
# Applications Menu
read -e -p "appmenu: " neurodesk_appmenu
neurodesk_appmenu=$(resolve_abs_path $neurodesk_appmenu)
echo "Applications Menu at $neurodesk_appmenu"
echo
# Applications Directory
read -e -p "appdir: " neurodesk_appdir
neurodesk_appdir=$(resolve_abs_path $neurodesk_appdir)
echo "Installation directory at $neurodesk_installdir"
echo
# Desktop Directories
read -e -p "deskdir: " neurodesk_deskdir
neurodesk_deskdir=$(resolve_abs_path $neurodesk_deskdir)
echo "Installation directory at $neurodesk_installdir"
echo
# neurodesk_edit mode [y/n]
read -p "edit : " neurodesk_edit
case "$neurodesk_edit" in
y/n)
echo "edit set to $neurodesk_edit"
;;
*)
echo "Defaulting to no edit"
neurodesk_edit="n"
;;
esac
fi
fi
args="${args} --installdir=$neurodesk_installdir"
args="${args} --deskenv=$neurodesk_deskenv"
mkdir -p $neurodesk_installdir
function build_apps () {
_script="$(readlink -f ${BASH_SOURCE[0]})" ## who am i? ##
_base="$(dirname $_script)" ## Delete last component from $_script ##
source ${_base}/neurodesk/configparser.sh ${_base}/config.ini
if [ $neurodesk_deskenv != "cli" ]; then
# Test Applications Menu
echo "Checking appmenu> $neurodesk_appmenu"
validfile=false
if [ ! -f "$neurodesk_appmenu" ]; then
echo "Applications Menu not found"
exit 1
fi
mkdir -p $neurodesk_installdir/desktop-directories
mkdir -p $neurodesk_installdir/icons
cp $neurodesk_appmenu $neurodesk_installdir/local-applications.menu.template
cp neurodesk/icons/*.png $neurodesk_installdir/icons
# Test Applications Directory
echo "Checking appdir> $neurodesk_appdir"
validfile=false
for i in $neurodesk_appdir/*.desktop; do
if [[ -e $i ]]; then
echo " - contains *.desktop file(s)"
validfile=true
break
fi
done
if [ "$validfile" = false ]; then
echo " - missing *.desktop file(s)"
echo "Invalid Applications Directory"
exit 1
fi
echo
# Test Desktop Directory
echo "Checking deskdir> $neurodesk_deskdir"
validfile=false
for i in $neurodesk_deskdir/*.directory; do
if [[ -e $i ]]; then
echo " - contains *.directory file(s)"
validfile=true
break
fi
done
if [ "$validfile" = false ]; then
echo " - missing *.directory file(s)"
echo "Invalid Desktop Directory"
exit 1
fi
echo
args="${args} --appmenu=$neurodesk_appmenu"
args="${args} --appdir=$neurodesk_appdir"
args="${args} --deskdir=$neurodesk_deskdir"
args="${args} --edit=$neurodesk_edit"
fi
# Symlink neurocommand directory into installdir
# Used for neurocommand updater
ln -vfns ${_base} $neurodesk_installdir/neurocommand
python3 -m neurodesk $args
err=$?
if [ $err -eq 0 ] ; then
echo "-----------------------------------------"
echo "| Neurocommand has updated successfully |"
echo "-----------------------------------------"
fi
}
if [ "$runsudo" = "true" ]; then
runsudo="y"
elif [ -w "$neurodesk_installdir" ]; then
runsudo="n"
else
echo
echo "[WARNING]"
echo "Installation directory is not writable by current user"
echo "($neurodesk_installdir)"
echo
read -r -p "Run app builder as sudo? [Y/n] " runsudo
fi
echo
case "$runsudo" in
[nN][oO]|[nN])
echo $neurodesk_installdir
if [ "$update" = true ]; then
git pull
fi
build_apps
;;
*)
echo $neurodesk_installdir
if [ "$update" = true ]; then
sudo git pull
fi
sudo bash -c "$(declare -f build_apps); build_apps"
;;
esac