forked from lunar-linux/lunar
/
check.lunar
171 lines (146 loc) · 4.16 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
#!/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 : check 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= unalias $1)
if module_exiled $DEP ; then
echo "$MODULE:$DEP:off:optional:$2:$3"
else
if module_installed $DEP || module_held $DEP ; then
echo "$MODULE:$DEP:on:optional:$2:$3"
else
echo "$MODULE:$DEP:off:optional:$2:$3"
fi
fi
}
depends() {
local DEP
debug_msg " depends ($@)"
DEP=$(NEVER_ASK=1 DEPS_ONLY= unalias $1)
if ! module_installed $DEP && ! module_held $DEP ; then
if ! is_depends $DEP && module_exiled $DEP ; then
return 1
else
CHANGED_MODULES="$CHANGED_MODULES $DEP"
fi
fi
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
cat "$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=$(grep -v moonbase: "$MODULE_STATUS" | cut -d: -f1 | sort )
fi
for MODULE in $LIST ; do
module_exiled $MODULE || rework_module $MODULE
done
}
run_fix() {
local MODULES MODULE
debug_msg "run_fix ($@)"
MODULES=$*
if [ -z "$MODULES" ] ; then
MODULES=$(list_installed | grep -v moonbase)
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!"
continue
fi
fi
fi
fi
done
display_update_log fix
else
display_update_log nofix
fi
temp_destroy $TMP_LIN_SUCCESS
temp_destroy $TMP_LIN_FAIL
}