/
check.lunar
176 lines (151 loc) · 4.4 KB
/
check.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
#!/bin/bash
############################################################
# #
# check/lunar - module sanity checking functions #
# #
############################################################
# #
# Copyright 2005 Auke Kok under GPLv2 #
# #
############################################################
run_checks() {
debug_msg "run_checks ($@)"
verbose_msg "Running sanity checks for module \"$1\""
(
run_details $1
plugin_call MODULE_CHECK $1
if [ $? == 2 ]; then
return 0
fi
return 1
)
}
# rework_module : re-create depends database for a module
rework_module() {
local MODULE
debug_msg "rework_module ($@)"
# we declare these local to override the systems default ones:
optional_depends() {
local DEP
debug_msg " optional_depends ($@)"
DEP=$(NEVER_ASK=1 DEPS_ONLY= expand_alias $1)
if module_exiled $DEP ; then
echo "$MODULE:$DEP:off:optional:$2:$3"
else
# check for the current depend selection
if grep -q "^$MODULE:$DEP:on:" "$DEPENDS_STATUS_BACKUP" ; then
echo "$MODULE:$DEP:on:optional:$2:$3"
elif grep -q "^$MODULE:$DEP:off:" "$DEPENDS_STATUS_BACKUP" ; then
echo "$MODULE:$DEP:off:optional:$2:$3"
fi
# if we don't know the answer we leave it open for the user to decide
fi
}
depends() {
local DEP
debug_msg " depends ($@)"
DEP=$(NEVER_ASK=1 DEPS_ONLY= expand_alias $1)
echo "$MODULE:$DEP:on:required:$2:$3"
}
run_depends() {
debug_msg " run_depends ($@)"
(
if run_details $1 &> /dev/null ; then
if has_module_file $MODULE DEPENDS ; then
run_module_file $MODULE DEPENDS | grep -v '%'
fi
fi
)
}
# here starts the real work:
MODULE=$1
# remove whatever depends was residing in the depends state file and
# append the new output:
lock_file $DEPENDS_STATUS_BACKUP &&
lock_file $DEPENDS_STATUS &&
(
grep -v "^$MODULE:" "$DEPENDS_STATUS_BACKUP" > $DEPENDS_STATUS
run_depends $MODULE >> $DEPENDS_STATUS
cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
)
unlock_file $DEPENDS_STATUS
unlock_file $DEPENDS_STATUS_BACKUP
}
# fix_depends : single pass to fix depends database
fix_depends () {
local LIST
debug_msg "fix_depends ($@)"
if [ -n "$1" ] ; then
LIST="$@"
else
LIST=$(list_installed | grep -F -v -x moonbase)
fi
for MODULE in $LIST ; do
rework_module $MODULE
done
}
run_fix() {
local MODULES MODULE KEEP_OBSOLETE
debug_msg "run_fix ($@)"
KEEP_OBSOLETE=1
MODULES=$*
if [ -z "$MODULES" ] ; then
MODULES=$(list_installed | grep -F -v -x moonbase)
unset KEEP_OBSOLETE
fi
if [[ -n "$FIXDEPENDS" ]] ; then
for MODULE in $MODULES ; do
fix_depends $MODULE
done
return
fi
# discover BROKEN modules and note them if we plan on fixing them
if [[ ! -n "$NOFIX" ]] ; then
for MODULE in $MODULES ; do
if ! run_checks $MODULE ; then
BROKEN_MODULES=( ${BROKEN_MODULES[@]} $MODULE )
fi
done
else
for MODULE in $MODULES ; do
run_checks $MODULE
done
fi
# if we were called with --fixdepends then we may skip the rest
if [ -n "$FIXDEPENDS" ] ; then
return
fi
export TMP_LIN_SUCCESS=$(temp_create "successful")
export TMP_LIN_FAIL=$(temp_create "failed")
if [[ ! -n "$NOFIX" ]] ; then
for MODULE in $(sort_by_dependency ${BROKEN_MODULES[@]}) ; do
if module_installed $MODULE && ! module_held $MODULE ; then
if ! run_checks $MODULE ; then
NEVER_ASK=1 DEPS_ONLY= satisfy_depends &&
NEVER_ASK=1 DEPS_ONLY= FIX= satisfy_depends &&
if ! run_checks $MODULE ; then
verbose_msg "Attempting to recompile \"$MODULE\""
if ! FIX= lin --compile $MODULE ; then
verbose_msg "Attempt to recompile \"$MODULE\" FAILED"
continue
elif ! run_checks $MODULE ; then
verbose_msg "Attempt to recompile \"$MODULE\" succeeded but \"$MODULE\" still is broken!"
KEEP_OBSOLETE=1
continue
fi
fi
fi
fi
done
# Only remove OBSOLETE if `lunar fix` pass all checks
# not perfect but it will have to do for now
if [ ! -n "$KEEP_OBSOLETE" ]; then
remove_obsolete_libraries
fi
display_update_log fix
else
display_update_log nofix
fi
temp_destroy $TMP_LIN_SUCCESS
temp_destroy $TMP_LIN_FAIL
}