forked from venomlinux/scratchpkg
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpkgfix
More file actions
executable file
·152 lines (135 loc) · 3.37 KB
/
pkgfix
File metadata and controls
executable file
·152 lines (135 loc) · 3.37 KB
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
#!/bin/sh
#
# Copyright (c) 2019 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# script to detect broken kernel modules after kernel update
# need to use with 'scratchpkg'
#
export LANG=C
get_pythonmodules() {
command -v python3 >/dev/null || return
pylibpath=$(python3 -c "import sys; print(':'.join(x for x in sys.path if x))" | tr ':' '\n' | sort | head -n1)
for i in /usr/lib/python3.*; do
[ -d "$i" ] || continue
[ "$i" = "$pylibpath" ] && continue
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
get_perlmodules() {
command -v perl >/dev/null || return
perlpath=$(dirname $(perl -V:sitearch | grep -o "'.*'" | sed "s/'//g"))
for i in $(dirname $perlpath)/*; do
[ "$perlpath" = "$i" ] && continue
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
get_modules() {
[ -f /lib/modules/KERNELVERSION ] || return
KERVER=$(cat /lib/modules/KERNELVERSION)
for i in /lib/modules/*; do
case $i in
/lib/modules/KERNELVERSION|/lib/modules/$KERVER) continue ;;
esac
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
get_rubygem() {
command -v gem >/dev/null || return
gempath=$(gem env gemdir)
for i in $(dirname $gempath)/*; do
[ "$gempath" = "$i" ] && continue
brokenpkg="$brokenpkg $(scratch provide $i/$ | awk '{print $1}')"
done
}
sort_modules() {
for all in $(scratch deplist $brokenpkg | cut -d ' ' -f2); do
for r in $brokenpkg; do
if [ $r = $all ]; then
if [ -z "$order" ]; then
order="$all"
else
order="$order $all"
fi
break
fi
done
done
}
confirm() {
printf "$1 (Y/n) "
read -r response
case "$response" in
[Nn][Oo]|[Nn]) echo "$2"; return 2 ;;
*) : ;;
esac
return 0
}
usage() {
cat << EOF
Usage:
$(basename $0) [options]
Options:
-r rebuild & reinstall broken package
-y dont ask user confirmation to rebuild package (use with -r)
-h print this help message
EOF
}
parse_opt() {
while [ "$1" ]; do
case $1 in
-r) REBUILD=1 ;;
-y) YES=1 ;;
-h) usage; exit 0 ;;
*) echo "Invalid option ($1)"; exit 1 ;;
esac
shift
done
}
parse_opt $@
if [ "$REBUILD" ] && [ "$(id -u)" != 0 ]; then
echo "Rebuild broken packages required root!"
exit 1
fi
get_modules
get_perlmodules
get_rubygem
get_pythonmodules
if [ "$brokenpkg" ]; then
sort_modules
else
echo "No broken packages found."
exit 0
fi
if [ "$REBUILD" = 1 ]; then
[ "$YES" ] || {
echo
echo "Package will be rebuilt & reinstalled in this order:"
echo " $order"
echo
confirm "Continue rebuild & reinstall of broken packages?" "Operation cancelled."
}
for p in $order; do
scratch build -f $p || exit 1
scratch install -r $p || exit 1
done
else
echo "Broken packages:"
for p in $order; do
echo " $p"
done
fi
exit 0