-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.sh
executable file
·70 lines (54 loc) · 1.37 KB
/
rm.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
#!/usr/bin/busybox sh
# Script to remove a package
fail() {
echo "ERROR: $1" >&2
if [ -z "$2" ]; then
exit 1
fi
exit "$2"
}
if [ $# -ne 1 ]; then
echo "Usage: $0 PKGNAME"
fail "Wrong number of arguments"
fi
if [ ! -z "$ROOTFS" ]; then
if [ ! -d "$ROOTFS" ]; then
fail "$ROOTFS does not exist or is not a directory"
fi
fi
if [ -z "$LPKGDIR" ]; then
echo "LPKGDIR not set. Assuming $ROOTFS/etc/lpkg.d"
LPKGDIR="$ROOTFS/etc/lpkg.d"
fi
if [ ! -d "$LPKGDIR" ]; then
fail "$LPKGDIR does not exist" 2
fi
# Acquire lock
mkdir "$LPKGDIR/lpkg.lock" || fail "Failed to acquire lock"
NAME="$1"
dbd="$LPKGDIR/db/$NAME"
if [ ! -d "$dbd" ]; then
rm -rf "$LPKGDIR/lpkg.lock"
fail "$NAME is not installed" 2
fi
scanlists() {
cd "$LPKGDIR/db"
for i in $(ls); do
if [ "$i" != "$NAME" ]; then
if [ -e "$i/files.list" ]; then
cat "$i/files.list" || return 3
fi
fi
done
}
tdel=$(scanlists | grep -xFvf - "$dbd/files.list")
if [ $? -gt 1 ]; then
fail "Error searching for files to delete" 2
fi
if [ -e "$dbd/hook" ]; then
"$dbd/hook" remove || fail "Removal hook returned error code $?" 3
fi
rm -rf $tdel || fail "Failed to delete files" 3
rm -r "$dbd" || fail "Failed to remove database entry" 3
rm -rf "$LPKGDIR/lpkg.lock"
echo "Successfully removed package $NAME"