This commit is contained in:
emmett1
2020-02-08 17:50:37 +08:00
parent 0a9cfce26a
commit cfaca4e65f
4 changed files with 32 additions and 26 deletions

32
pkgadd
View File

@@ -119,19 +119,20 @@ isinstalled() {
fi
}
run_scripts() {
if [ "$ROOT_DIR" ]; then
xchroot "$ROOT_DIR" sh $@
else
sh $@
fi
}
parse_opts $(extract_opts "$@")
PKG_DB="/var/lib/scratchpkg/index"
INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index"
LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock"
# disable pre/post install/upgrade script when install to custom root location
if [ "$ROOT_DIR" != "" ]; then
NO_PREINSTALL=yes
NO_POSTINSTALL=yes
NO_PREUPGRADE=yes
NO_POSTUPGRADE=yes
fi
# show help page
[ "$SHOWHELP" ] || [ -z "$PKGNAME" ] && {
help
@@ -244,19 +245,20 @@ fi
# pre-install and pre-upgrade script
if grep -qx .pkginstall $TMP_PKGADD; then
TMP_PKGINSTALL_SCRIPT="/tmp/.tmp_pkgadd_installscript.$$"
tar -xf "$PKGNAME" .pkginstall -O > "$TMP_PKGINSTALL_SCRIPT"
SCRATCHPKG_DIR="/var/lib/scratchpkg/"
TMP_PKGINSTALL_SCRIPT="$SCRATCHPKG_DIR/pkgadd_installscript"
tar -xf "$PKGNAME" .pkginstall -O > "$ROOT_DIR/$TMP_PKGINSTALL_SCRIPT"
if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/
sh "$TMP_PKGINSTALL_SCRIPT" pre-install "$version"
run_scripts "$TMP_PKGINSTALL_SCRIPT" pre-install "$version"
)
fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then
(cd "$ROOT_DIR"/
sh "$TMP_PKGINSTALL_SCRIPT" pre-upgrade "$version" "$iversion"
run_scripts "$TMP_PKGINSTALL_SCRIPT" pre-upgrade "$version" "$iversion"
)
fi
rm -f "$TMP_PKGINSTALL_SCRIPT"
rm -f "$ROOT_DIR/$TMP_PKGINSTALL_SCRIPT"
fi
# exclude .pkg* files when extract into system
@@ -321,12 +323,12 @@ fi
if [ -f "$INDEX_DIR/$name/.pkginstall" ]; then
if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-install "$version"
run_scripts "$PKG_DB/$name/.pkginstall" post-install "$version"
)
fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion"
run_scripts "$PKG_DB/$name/.pkginstall" post-upgrade "$version" "$iversion"
)
fi
fi

View File

@@ -665,6 +665,7 @@ main() {
abort 0
fi
else
msg "Building '$name-$version-$release'..."
download_src
prepare_src
run_build

23
pkgdel
View File

@@ -107,16 +107,19 @@ isinstalled() {
fi
}
run_scripts() {
if [ "$ROOT_DIR" ]; then
xchroot "$ROOT_DIR" sh $@
else
sh $@
fi
}
parse_opts $(extract_opts "$@")
PKG_DB="/var/lib/scratchpkg/index"
INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index"
LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock"
# disable pre/post remove script when remove from custom root location
if [ "$ROOT_DIR" != "" ]; then
NO_PREREMOVE=yes
NO_POSTREMOVE=yes
fi
# show help page
[ "$SHOWHELP" ] || [ -z "$RMNAME" ] && {
@@ -124,8 +127,8 @@ fi
ret 0
}
# check for root access, non-root only allowed if use custom --root= location
[ "$(id -u)" = "0" ] || [ "$ROOT_DIR" ] || {
# check for root access
[ "$(id -u)" = "0" ] || {
echo "Removing package need root access!"
ret 1
}
@@ -172,7 +175,7 @@ echo "remove: $name-$version-$release..."
# pre-remove script
if [ ! "$NO_PREREMOVE" ] && [ -f "$INDEX_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" pre-remove "$version"
run_scripts "$PKG_DB/$name/.pkginstall" pre-remove "$version"
)
fi
@@ -187,7 +190,7 @@ rm -f "$reserve" "$dirs" "$remove" "$files"
# post-remove script
if [ ! "$NO_POSTREMOVE" ] && [ -f "$INDEX_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-remove "$version"
run_scripts "$PKG_DB/$name/.pkginstall" post-remove "$version"
)
fi

View File

@@ -5,5 +5,5 @@
# <real package> <aliased package>
#
# example:
# <openssl> <libressl>
# openssl libressl
#