Skip to content

Commit 8691210

Browse files
author
emmett1
committed
updated
1 parent d56e9e4 commit 8691210

File tree

2 files changed

+57
-40
lines changed

2 files changed

+57
-40
lines changed

pkgadd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ parse_opts $(extract_opts "$@")
133133

134134
SCRATCHPKG_DIR="var/lib/scratchpkg"
135135
PKGDB_DIR="$SCRATCHPKG_DIR/db"
136+
PKGDBPERMS_DIR="$PKGDB_DIR.perms"
136137
LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock"
137138

138139
ROOT_DIR="${ROOT_DIR%/}" # remove trailing slash
@@ -216,7 +217,7 @@ TMP_PKGINSTALL="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkginstall"
216217
TMP_CONFLICT="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_conflict"
217218

218219
# check integrity of package and save list file/dirs to install in the meantime
219-
tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null || {
220+
tar -tvf $PKGNAME > $TMP_PKGADD 2>/dev/null || {
220221
msgerr "Package '$1' is corrupted!"
221222
ret 1
222223
}
@@ -230,7 +231,7 @@ echo "$opr: $name-$version-$release..."
230231

231232
# check for file conflict
232233
if [ ! "$IGNORE_CONFLICT" ]; then
233-
grep -v '/$' "$TMP_PKGADD" | while read -r line; do
234+
grep -v '/$' "$TMP_PKGADD" | awk '{print $6}' | while read -r line; do
234235
if [ "$line" = "${line%.*}.spkgnew" ]; then
235236
line=${line%.*}
236237
fi
@@ -284,6 +285,13 @@ fi
284285
# register package into database
285286
echo "$version $release" > "$ROOT_DIR/$PKGDB_DIR/$name"
286287
cat "$TMP_PKGINSTALL" >> "$ROOT_DIR/$PKGDB_DIR/$name"
288+
mkdir -p "$ROOT_DIR/$PKGDBPERMS_DIR"
289+
grep '/$' $TMP_PKGADD | while read -r perms own junk1 junk2 junk3 dir; do
290+
if [ "$perms" != drwxr-xr-x ] || [ "$own" != root/root ]; then
291+
echo "$perms $own $dir" >> "$ROOT_DIR/$PKGDBPERMS_DIR/$name"
292+
[ -s "$ROOT_DIR/$PKGDBPERMS_DIR/$name" ] || rm "$ROOT_DIR/$PKGDBPERMS_DIR/$name"
293+
fi
294+
done
287295

288296
# running ldconfig
289297
if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then

scratch

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,48 @@ scratch_sync() {
227227
portsync
228228
}
229229

230+
cvperms() {
231+
# converts symbolic to numeric permissions
232+
# required an input (symbolic, eg: drwxr-xr-x)
233+
s=0; n=0; count=0
234+
for i in $(echo "$1" | sed -e 's/\(.\)/\1\n/g'); do
235+
count=$((count+1))
236+
case $i in
237+
d) ;;
238+
r) n=$((n+4));;
239+
w) n=$((n+2));;
240+
x) n=$((n+1));;
241+
s) [ $count = 4 ] && s=$((s+4)) || s=$((s+2)); n=$((n+1));;
242+
t) s=$((s+1));n=$((n+1));;
243+
S) s=$((s+2));;
244+
T) s=$((s+1));;
245+
esac
246+
[ "$count" = 4 ] && {
247+
user=$n; n=0
248+
}
249+
[ "$count" = 7 ] && {
250+
group=$n; n=0
251+
}
252+
[ "$count" = 10 ] && {
253+
other=$n; n=0
254+
}
255+
done
256+
echo "$s$user$group$other"
257+
}
258+
259+
fixperms() {
260+
needroot "Fix permissions"
261+
for i in $PKGDBPERMS_DIR/*; do
262+
[ -s $i ] || continue
263+
while read -r perms own dir; do
264+
chmod $(cvperms $perms) /$dir
265+
echo $own | while IFS=/ read -r o g; do
266+
chown $o:$g /$dir
267+
done
268+
done < $i
269+
done
270+
}
271+
230272
scratch_trigger() {
231273
needroot "Run trigger"
232274
if [ -z "$*" ]; then
@@ -239,27 +281,7 @@ scratch_trigger() {
239281
post_triggers
240282
}
241283

242-
post_triggers() {
243-
if [ "$trig_12" = 1 ]; then
244-
echo "trigger: Running mkdirs..."
245-
for mkd in $PKGDB_DIR/*/.pkgmkdirs; do
246-
[ -s $mkd ] || continue
247-
grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do
248-
if [ -e "$dir" ]; then
249-
if [ "$uid" != '-' ]; then
250-
getent passwd $uid >/dev/null && chown "$uid" "$dir"
251-
fi
252-
if [ "$gid" != '-' ]; then
253-
getent group $gid >/dev/null && chgrp "$gid" "$dir"
254-
fi
255-
if [ "$mode" != '-' ]; then
256-
chmod "$mode" "$dir"
257-
fi
258-
fi
259-
done
260-
done
261-
fi
262-
284+
post_triggers() {
263285
if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then
264286
echo "trigger: Updating fontconfig cache..."
265287
fc-cache -s
@@ -327,6 +349,9 @@ post_triggers() {
327349
echo "trigger: Updating the MIME type database..."
328350
update-mime-database /usr/share/mime
329351
fi
352+
353+
echo "trigger: Fix files ownership and permissions..."
354+
fixperms
330355
}
331356

332357
pre_triggers() {
@@ -439,16 +464,6 @@ pre_triggers() {
439464
fi
440465
done
441466
fi
442-
443-
# makedirs
444-
if [ "$trig_12" != "1" ]; then
445-
for pkg in $@; do
446-
if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then
447-
trig_12=1
448-
break
449-
fi
450-
done
451-
fi
452467
}
453468

454469
scratch_build() {
@@ -899,7 +914,6 @@ scratch_outdate() {
899914
fi
900915
iversion=$(get_iver $pkg)
901916
irelease=$(get_irelease $pkg)
902-
[ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]"
903917
if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then
904918
ITSLOCK="[masked]"
905919
fi
@@ -1270,12 +1284,6 @@ scratch_missingdep() {
12701284
done
12711285
}
12721286

1273-
scratch_locked() {
1274-
for pkg in $(allinstalled); do
1275-
[ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg"
1276-
done
1277-
}
1278-
12791287
scratch_orphan() {
12801288
tmpallpkg="/tmp/.pkgquery_allpkg.$$"
12811289
tmpalldep="/tmp/.pkgquery_alldep.$$"
@@ -1430,6 +1438,7 @@ done
14301438

14311439
BUILD_SCRIPT="spkgbuild"
14321440
PKGDB_DIR="$(pkgadd --print-dbdir)"
1441+
PKGDBPERMS_DIR=${PKGDB_DIR}.perms
14331442
REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}"
14341443
ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}"
14351444
MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}"

0 commit comments

Comments
 (0)