forked from lunar-linux/lunar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lunar
373 lines (320 loc) · 11 KB
/
main.lunar
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/main.lunar #
# contains all main handling code, aka the long complex #
# functions like renew, update, fix, etc. One day they all #
# will be in here. #
# #
############################################################
# #
# Copyrighted Auke Kok 2003 under GPLv2 #
# #
############################################################
# function : renew
# usage : renew
# purpose : frontend function that includes all renewing code
renew() {
debug_msg "renew ($@)"
message "${MESSAGE_COLOR}Starting update of installed modules${DEFAULT_COLOR}"
replace_modules
purge_modules
export TMP_LIN_SUCCESS=$(temp_create "successful")
export TMP_LIN_FAIL=$(temp_create "failed")
update_modules
# Only run this if there was something to update
if [ $? -ne "255" ]; then
if [ "$AUTOFIX" == "on" ] ; then
message "${MESSAGE_COLOR}Executing AUTOFIX : lunar fix${DEFAULT_COLOR}"
run_fix
fi
if [ "$AUTOPRUNE" == "on" ] ; then
message "${MESSAGE_COLOR}Executing AUTOPRUNE : lunar prune${DEFAULT_COLOR}"
prune
fi
display_update_log renew
fi
temp_destroy $TMP_LIN_SUCCESS
temp_destroy $TMP_LIN_FAIL
}
update() {
debug_msg "update ($@)"
if ps -C lin > /dev/null ; then
error_message "${PROBLEM_COLOR}Unable to update lunar concurrently while installing.${DEFAULT_COLOR}"
return 1
fi
# test if $LUNAR_MODULE is installed (for old boxes)
if [ -z "$LUNAR_MODULE" ] ; then
for ALT in $LUNAR_MODULES ; do
if module_installed $ALT ; then
lunar set LUNAR_MODULE $ALT
export LUNAR_MODULE=$ALT
verbose_msg "LUNAR_MODULE set to \"$ALT\""
fi
done
if [ -z "$LUNAR_MODULE" ] ; then
error_message "${PROBLEM_COLOR}Error:${DEFAULT_COLOR} ${MESSAGE_COLOR}No core code installed: install one of the following first:${DEFAULT_COLOR}"
error_message $LUNAR_MODULES
error_message "${MESSAGE_COLOR}then try again (I can't update if I don't know which toolset I use)${DEFAULT_COLOR}"
return 1
fi
fi
if lin moonbase ; then
if (( $(lvu installed $LUNAR_MODULE) < $(lvu version $LUNAR_MODULE) ))
then
lin $LUNAR_MODULE && lunar renew
else
lunar renew
fi
fi
}
rebuild() {
local LIST QUEUE TMP_QUEUE
debug_msg "rebuild ($@)"
message "${MESSAGE_COLOR}Starting non-recursive rebuild${DEFAULT_COLOR}"
message "${MESSAGE_COLOR}Running FIX on all modules${DEFAULT_COLOR}"
run_fix
LIST=$(list_installed | grep -F -v -x -e moonbase -e "$LUNAR_MODULE")
message "${MESSAGE_COLOR}Sorting modules by dependency${DEFAULT_COLOR}"
QUEUE=$(sort_by_dependency $LIST)
TMP_QUEUE=$(temp_create "rebuild-queue")
for MODULE in $QUEUE ; do
echo $MODULE >> $TMP_QUEUE
done
unset MODULE
if query "Edit rebuild queue?" n ; then
edit_file $TMP_QUEUE
fi
QUEUE=$(cat "$TMP_QUEUE")
temp_destroy $TMP_QUEUE
if [ -n "$QUEUE" ] ; then
export TMP_LIN_SUCCESS=$(temp_create "successful")
export TMP_LIN_FAIL=$(temp_create "failed")
message "${MESSAGE_COLOR}Starting rebuild of modules${DEFAULT_COLOR}"
lin -c $QUEUE
display_update_log rebuild
temp_destroy $TMP_LIN_SUCCESS
temp_destroy $TMP_LIN_FAIL
fi
}
expand_cache_safe() {(
debug_msg "expand_cache_safe ($@)"
export SOURCE_DIRECTORY=$BUILD_DIRECTORY/resurrect-$MODULE-$VERSION
mk_source_dir $SOURCE_DIRECTORY
# untar the file so we can compare first
tar -pkxf $1 -C $SOURCE_DIRECTORY 1>/dev/null 2>&1
# make a md5sum list of files
TMP_TARGETS=$(temp_create "resurrect.targets.$MODULE")
tar tf $1 > $TMP_TARGETS
TMP_TARGETS_OK=$(temp_create "resurrect.targets_OK.$MODULE")
# do directories: we don`t care here
# the sed trick is advanced: a non-greedy pattern that returns all
# directory names listed in the input
for TARGET in $(cat "$TMP_TARGETS" | sed 's/\/[^\/]*$/\//g' ) ; do
if [ ! -d $TARGET ]; then
debug_msg "mkdir -p $TARGET"
mkdir -p $TARGET
fi
done
# do links
for TARGET in $(find $SOURCE_DIRECTORY -type l | sed "s:$SOURCE_DIRECTORY::g" ) ; do
# wipe the current link cos it ruins things
if [ -h "$TARGET" ] ; then
rm -f "$TARGET"
fi
debug_msg "ln -s $(readlink $SOURCE_DIRECTORY$TARGET) $TARGET"
echo "$TARGET" >> $TMP_TARGETS_OK
done
# do files - bulk process the normal ones
cat "$TMP_TARGETS" | grep -v -f "$EXCLUDED" >> $TMP_TARGETS_OK
# now double check the EXCLUDED ones
for TARGET in $(cat "$TMP_TARGETS" | grep -f "$EXCLUDED" ) ; do
if [ -e "$TARGET" ] ; then
debug_msg "Cowardishly not overwriting \"$TARGET\""
else
echo "$TARGET" >> $TMP_TARGETS_OK
fi
done
debug_msg "tar xjf $1 -P -k -T $TMP_TARGETS_OK"
tar xf $1 -P -k -T $TMP_TARGETS_OK > /dev/null 2>&1
temp_destroy $TMP_TARGETS
temp_destroy $TMP_TARGETS_OK
rm_source_dir $SOURCE_DIRECTORY
)}
resurrect() {
(
debug_msg "resurrect ($@)"
if [ -s /etc/lunar/local/optimizations ] ; then
. /etc/lunar/local/optimizations
fi
if ! run_details $1 ; then
return 1
fi
run_conflicts &&
satisfy_depends &&
STATUS=installed &&
CACHE_XZ=$(xzbz_file "$INSTALL_CACHE/$MODULE-$VERSION-$BUILD.tar") &&
if [ -f "$CACHE_XZ" ] && xzbz -t $CACHE_XZ ; then
if module_held $MODULE ; then
VERSION=$(installed_version $MODULE) &&
STATUS="installed+held" &&
lrm --keepconfig $MODULE
elif module_installed $MODULE ; then
lrm --keepconfig $MODULE
fi &&
message "${RESURRECT_COLOR}Resurrecting ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR} ${MESSAGE_COLOR}version ${VERSION_COLOR}${VERSION}${DEFAULT_COLOR}" &&
expand_cache_safe $CACHE_XZ &&
add_module $MODULE $STATUS $VERSION &&
verbose_msg "running \"lunar fix $MODULE\"" &&
if run_fix $MODULE ; then
report $INSTALL_LOGS/$MODULE-$VERSION "install log" $MODULE $VERSION &&
sound SUCCESS
activity_log "lin" "$MODULE" "$VERSION" "success" "resurrected"
message "${RESURRECT_COLOR}Resurrected ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR} ${MESSAGE_COLOR}successfully${DEFAULT_COLOR}"
else
sound FAILURE
activity_log "lin" "$MODULE" "$VERSION" "failed" "resurrect failed"
false
fi
else
if [ ! -f "$CACHE_XZ" ]; then
message "${RESURRECT_COLOR}Resurrection ${PROBLEM_COLOR}failed for ${MODULE_COLOR}${MODULE} ${MESSAGE_COLOR}version ${VERSION_COLOR}${VERSION}${DEFAULT_COLOR} - ${MESSAGE_COLOR}missing cache tarball.${DEFAULT_COLOR}"
fi
# do not log an error in case we tried autoresurrect:
if [ "$AUTORESURRECT" == "off" -o -n "$COMPILE" ] ; then
sound FAILURE
activity_log "lin" "$MODULE" "$VERSION" "failed" "resurrect failed"
false
fi
false
fi
)
}
resurrect_modules() {
debug_msg "resurrect_modules ($@)"
for MODULE in $@ ; do
if run_details $MODULE ; then
resurrect $MODULE
fi
done
}
lin_module() {
(
debug_msg "lin_module ($@)"
xterm_msg "compiling $1"
# make sure we got all the info
if ! run_details $1 ; then
return 1
fi
# resurrect if we can, but not is -c was issued
if [ "$AUTORESURRECT" == "on" -a -z "$COMPILE" ] ; then
# we also do not resurrect if $MODULE is currently installed!
if ! module_installed $MODULE ; then
if resurrect $MODULE ; then
return 0
fi
fi
fi
# set the installwatchfile
export INSTALLWATCHFILE=$(temp_create "$MODULE.installwatch")
# TODO: clean up DESTDIR_BUILD feature toggle
if [[ "${DESTDIR_BUILD:-off}" == "on" ]]; then
save_old_install_log
fi
# lock the module for installation, check for moonbase call
linING="/var/lock/installing.$MODULE"
if [ "$MODULE" == "moonbase" ] ; then
if ! current_locked && ! solo_locked ; then
echo $$ > $linING &&
lget moonbase &&
rm -f $linING &&
return
else
exit 1
fi
fi
check_blacklist &&
# here we run CONFLICTS, DEPENDS and CONFIGURE stuff
run_conflicts &&
satisfy_depends &&
show_downloading &&
OPTS="$OPTS `grep "^$MODULE:" "$TEMP_CONFIGOPTS" | cut -d: -f2`" &&
# last minute source code presence check:
(
for SOURCE in $(sources $MODULE) ; do
if [ ! -f $SOURCE_CACHE/$SOURCE ] ; then
lget $MODULE
break
fi
done
) &&
# only download and verify ?
if [ -n "$DOWNLOAD_ONLY" ] ; then
verify_all_sources $MODULE
# now entering the physical BUILD stage
elif ! current_locked && ! solo_locked ; then
echo $$ > $linING &&
start_logging
if ! run_pre_build ; then
LIN_ERROR="PRE_BUILD"
else
if ! run_build ; then
LIN_ERROR="BUILD"
else
if ! run_post_build ; then
LIN_ERROR="POST_BUILD"
fi
fi
fi
stop_logging
if [ -n "$LIN_ERROR" ] ; then
if [ -f "$INSTALLWATCHFILE" ] ; then
temp_destroy $INSTALLWATCHFILE
fi
sound FAILURE
message "${PROBLEM_COLOR}! Problem detected during ${FILE_COLOR}$LIN_ERROR${DEFAULT_COLOR}"
rm -f $linING
report $COMPILE_LOGS/$MODULE-$VERSION.${COMPRESS_METHOD} "compile log" $MODULE $VERSION
activity_log "lin" "$MODULE" "$VERSION" "failed" "Due to build errors during $LIN_ERROR"
return 1
fi
if ! finish_install ; then
LIN_ERROR="POST_BUILD"
else
# unlock module before runing POST_INSTALL
rm -f $linING &&
if ! run_post_install ; then
LIN_ERROR="POST_INSTALL"
fi
fi
if [ -f "$INSTALLWATCHFILE" ] ; then
verbose_msg "removing installwatch file"
temp_destroy $INSTALLWATCHFILE
fi
if [ -n "$LIN_ERROR" ] ; then
sound FAILURE
message "${PROBLEM_COLOR}! Problem detected during ${FILE_COLOR}$LIN_ERROR${DEFAULT_COLOR}"
rm -f $linING
report $COMPILE_LOGS/$MODULE-$VERSION.${COMPRESS_METHOD} "compile log" $MODULE $VERSION
activity_log "lin" "$MODULE" "$VERSION" "failed" "Due to build errors during $LIN_ERROR"
return 1
fi
rm_source_dir &&
report $INSTALL_LOGS/$MODULE-$VERSION "install log" $MODULE $VERSION &&
sound SUCCESS &&
activity_log "lin" "$MODULE" "$VERSION" "success"
if [ "$?" != 0 ] ; then
sound FAILURE
message "${PROBLEM_COLOR}! Problem detected${DEFAULT_COLOR}"
rm -f $linING
report $COMPILE_LOGS/$MODULE-$VERSION.${COMPRESS_METHOD} "compile log" $MODULE $VERSION
activity_log "lin" "$MODULE" "$VERSION" "failed" "Due to build errors during or after $LIN_ERROR"
return 1
fi
fi
)
}