-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgdiff.sh
executable file
·93 lines (80 loc) · 2.15 KB
/
pkgdiff.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
DEBUG=0
# Did we get *some* input? Hopefully it's a pkg
if [ "${1}xx" == "xx" ]; then
echo "Please supply a pkg file."
exit 1
fi
# ...does it at least end in ".pkg"?
PKGEXT="${1##*.}"
if [ $PKGEXT != "pkg" ]; then
echo "This doesn't look like a pkg."
echo "Extension is ${PKGEXT}"
exit 4
fi
# ...is it a bundle?
if file --mime-type "${1}" | grep -q directory$; then
if [ $DEBUG -eq 1 ]; then
echo "It is a bundle!"
fi
# No tmp dir needed
PKGBASE=${1}
fi
# ...is it a compressed flat file?
if file --mime-type "${1}" | grep -q x-xar$; then
if [ $DEBUG -eq 1 ]; then
echo "It is a compressed flat package"
fi
# Get temp directory for working
PKGBASE=$(mktemp -qd)
if [ $? -ne 0 ]; then
echo "${0}: Can not create temp dir, exiting..."
exit 10
fi
if [ $DEBUG -eq 1 ]; then
echo "Created ${PKGBASE}"
fi
# Unflatten package
xar -x -f "${1}" -C "${PKGBASE}"
fi
if [[ -f ${PKGBASE}/Bom ]]; then
while read -sr FULLPATH PERMS IDS SIZE CRC
do
# Strip the leading dot from the path
CURFILE=$(echo ${FULLPATH} | sed 's/\(^.\)\(.*\)/\2/')
#echo "Path = ${CURFILE}"
#echo "Perms = $PERMS, Size = $SIZE"
# Tests
# Does the file exist?
if [[ ! -f ${CURFILE} ]]; then
echo "${CURFILE} is a new install."
else
# It exists! Compare it.
# Get current perms
PFPERMS=$(stat -f "%Hp%Mp%Lp" ${CURFILE})
# Get IDs
PFIDS=$(stat -f "%u/%g" ${CURFILE})
# Get size
PFSIZE=$(stat -f "%z" ${CURFILE})
# Get CRC
PFCRC=$(cksum pkgdiff.sh | awk '{print $1}')
/bin/echo -n "${CURFILE} is changed: "
if [[ ${PERMS} != ${PFPERMS} ]]; then
/bin/echo -n "Perms was ${PERMS}, now ${PFPERMS} "
fi
if [[ ${IDS} != ${PFIDS} ]]; then
/bin/echo -n "Owners was ${IDS}, now ${PFIDS} "
fi
if [[ ${SIZE} != ${PFSIZE} ]]; then
/bin/echo -n "Size was ${SIZE}, now ${PFSIZE} "
fi
if [[ ${CRC} != ${PFCRC} ]]; then
/bin/echo -n "CRC was ${CRC}, now ${PFCRC} "
fi
echo
fi
done < <(lsbom -f ${PKGBASE}/Bom)
else
echo "There is no Bom file...is this a metapackage, perhaps?"
exit 50
fi