Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
emmett1 committed Apr 27, 2020
1 parent 34b9568 commit 552e0c7
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 71 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Available options:
### pkgadd
`pkgadd` is a tool to install and upgrade package created by `pkgbuild`. Install package is simply extract
`<name>-<version>-<release>.spkg.txz` by using tar into real system then save list extracted file into package `INDEX_DIR`.
`<name>-<version>-<release>.spkg.txz` by using tar into real system then save list extracted file into package `PKGDB_DIR`.
Upgrading package is also using same extract as install, it will replace old files then compare list file from old and new
package and remove old file which not exist in new package (like Slackware pkgtool does).

Expand All @@ -154,7 +154,7 @@ package and remove old file which not exist in new package (like Slackware pkgto
old configuration files and skip conflict check
### pkgdel
`pkgdel` is a tool to remove package from system. It will read file listed in package `INDEX_DIR` and remove it.
`pkgdel` is a tool to remove package from system. It will read file listed in package `PKGDB_DIR` and remove it.

Usage:
pkgdel [ <options> <package name> ]
Expand Down
49 changes: 29 additions & 20 deletions pkgadd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Options:
--no-preupgrade skip preupgrade script before upgrade package
--no-postupgrade skip postupgrade script after upgrade package
--no-backup skip backup when upgrading package
--print-dbdir print package database path
--root=<path> install to custom root directory
EOF
Expand Down Expand Up @@ -96,6 +97,7 @@ parse_opts() {
--no-preupgrade) NO_PREUPGRADE=yes ;;
--no-postupgrade) NO_POSTUPGRADE=yes ;;
--no-backup) NO_BACKUP=yes ;;
--print-dbdir) PRINTDBDIR=yes ;;
--root=*) ROOT_DIR="${1#*=}" ;;
*.spkg.tar.*) PKGNAME="$(realpath $1)" ;;
*) msg "Invalid option! ($1)"; exit 1 ;;
Expand All @@ -112,7 +114,7 @@ ret() {
}

isinstalled() {
if [ -s "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo"; then
if [ -s "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo"; then
return 0
else
return 1
Expand All @@ -130,17 +132,24 @@ run_scripts() {
parse_opts $(extract_opts "$@")

SCRATCHPKG_DIR="var/lib/scratchpkg"
INDEX_DIR="$SCRATCHPKG_DIR/index"
PKGDB_DIR="$SCRATCHPKG_DIR/index"
LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock"

ROOT_DIR="${ROOT_DIR%/}" # remove trailing slash

[ "$PRINTDBDIR" ] && {
echo "$ROOT_DIR/$PKGDB_DIR"
ret 0
}

# show help page
[ "$SHOWHELP" ] || [ -z "$PKGNAME" ] && {
help
ret 0
}

[ -d "$ROOT_DIR/$INDEX_DIR" ] || {
msgerr "Package's database directory not exist: $ROOT_DIR/$INDEX_DIR"
[ -d "$ROOT_DIR/$PKGDB_DIR" ] || {
msgerr "Package's database directory not exist: $ROOT_DIR/$PKGDB_DIR"
ret 1
}

Expand Down Expand Up @@ -178,8 +187,8 @@ name=${noextname%-*}

# get package information if installed
if isinstalled $name; then
iversion=$(grep ^version $ROOT_DIR/$INDEX_DIR/$name/.pkginfo | cut -d " " -f3-)
irelease=$(grep ^release $ROOT_DIR/$INDEX_DIR/$name/.pkginfo | cut -d " " -f3-)
iversion=$(grep ^version $ROOT_DIR/$PKGDB_DIR/$name/.pkginfo | cut -d " " -f3-)
irelease=$(grep ^release $ROOT_DIR/$PKGDB_DIR/$name/.pkginfo | cut -d " " -f3-)
ALREADYINSTALLED=yes
fi

Expand Down Expand Up @@ -227,7 +236,7 @@ if [ ! "$IGNORE_CONFLICT" ]; then
fi
if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
if ! grep -Fqx "$line" "$ROOT_DIR/$INDEX_DIR/$name/.files"; then
if ! grep -Fqx "$line" "$ROOT_DIR/$PKGDB_DIR/$name/.files"; then
echo "$line"
touch "$TMP_CONFLICT"
fi
Expand Down Expand Up @@ -290,12 +299,12 @@ if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
rmlist_dir="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_dir"
reserve_dir="$ROOT_DIR/$SCRATCHPKG_DIR/.reserve_dir"
rmlist_all="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_all"
grep '/$' $ROOT_DIR/$INDEX_DIR/*/.files \
| grep -v $ROOT_DIR/$INDEX_DIR/$name/.files \
grep '/$' $ROOT_DIR/$PKGDB_DIR/*/.files \
| grep -v $ROOT_DIR/$PKGDB_DIR/$name/.files \
| awk -F : '{print $2}' \
| sort \
| uniq > $reserve_dir # get list reserved dirs
grep -Fxv -f "$TMP_PKGINSTALL" $ROOT_DIR/$INDEX_DIR/$name/.files > $rmlist_all # get list files and dirs to remove
grep -Fxv -f "$TMP_PKGINSTALL" $ROOT_DIR/$PKGDB_DIR/$name/.files > $rmlist_all # get list files and dirs to remove
grep -v '/$' "$rmlist_all" | tac > "$rmlist_file" # get files only to remove
grep -Fxv -f "$reserve_dir" "$rmlist_all" | grep '/$' | tac > "$rmlist_dir" # get dirs only (safe) to remove
(cd "$ROOT_DIR"/
Expand All @@ -306,30 +315,30 @@ if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
fi

# register package into database
rm -fr "$ROOT_DIR/$INDEX_DIR/$name"
mkdir "$ROOT_DIR/$INDEX_DIR/$name"
echo "name = $name" > "$ROOT_DIR/$INDEX_DIR/$name/.pkginfo"
echo "version = $version" >> "$ROOT_DIR/$INDEX_DIR/$name/.pkginfo"
echo "release = $release" >> "$ROOT_DIR/$INDEX_DIR/$name/.pkginfo"
install -m644 "$TMP_PKGINSTALL" "$ROOT_DIR/$INDEX_DIR/$name/.files"
rm -fr "$ROOT_DIR/$PKGDB_DIR/$name"
mkdir "$ROOT_DIR/$PKGDB_DIR/$name"
echo "name = $name" > "$ROOT_DIR/$PKGDB_DIR/$name/.pkginfo"
echo "version = $version" >> "$ROOT_DIR/$PKGDB_DIR/$name/.pkginfo"
echo "release = $release" >> "$ROOT_DIR/$PKGDB_DIR/$name/.pkginfo"
install -m644 "$TMP_PKGINSTALL" "$ROOT_DIR/$PKGDB_DIR/$name/.files"

for ii in $(grep ^.pkg* $TMP_PKGADD); do
pkgfiles="$pkgfiles $ii"
done

if [ "$pkgfiles" ]; then
tar -x -f "$PKGNAME" -C "$ROOT_DIR/$INDEX_DIR/$name" $pkgfiles >/dev/null 2>&1
tar -x -f "$PKGNAME" -C "$ROOT_DIR/$PKGDB_DIR/$name" $pkgfiles >/dev/null 2>&1
fi

if [ -f "$ROOT_DIR/$INDEX_DIR/$name/.pkginstall" ]; then
if [ -f "$ROOT_DIR/$PKGDB_DIR/$name/.pkginstall" ]; then
if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/
run_scripts "$INDEX_DIR/$name/.pkginstall" post-install "$version"
run_scripts "$PKGDB_DIR/$name/.pkginstall" post-install "$version"
)
fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then
(cd "$ROOT_DIR"/
run_scripts "$INDEX_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion"
run_scripts "$PKGDB_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion"
)
fi
fi
Expand Down
34 changes: 20 additions & 14 deletions pkgdel
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ret() {
}

isinstalled() {
if [ -s "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo"; then
if [ -s "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$PKGDB_DIR/$1/.pkginfo"; then
return 0
else
return 1
Expand All @@ -115,9 +115,15 @@ run_scripts() {
fi
}

command -v pkgadd >/dev/null 2>&1 || {
msgerr "'pkgadd' not found in \$PATH!"
exit 1
}

parse_opts $(extract_opts "$@")

INDEX_DIR="var/lib/scratchpkg/index"
PKGDB_DIR="$(pkgadd --print-dbdir)"
PKGDB_DIR="${PKGDB_DIR##/}" # remove leading /
LOCK_FILE="var/lib/scratchpkg/spkg.lock"

# show help page
Expand Down Expand Up @@ -149,9 +155,9 @@ if ! isinstalled "$RMNAME"; then
ret 1
fi

name=$(grep ^name $ROOT_DIR/$INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
version=$(grep ^version $ROOT_DIR/$INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
release=$(grep ^release $ROOT_DIR/$INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
name=$(grep ^name $ROOT_DIR/$PKGDB_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
version=$(grep ^version $ROOT_DIR/$PKGDB_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
release=$(grep ^release $ROOT_DIR/$PKGDB_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)

if [ -z "$name" ] && [ -z "$version" ] && [ -z "$release" ]; then
msgerr "Package '$RMNAME' not installed but exist in database."
Expand All @@ -164,21 +170,21 @@ remove="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_remove"
dirs="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_dirs"
files="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_files"

grep '/$' $ROOT_DIR/$INDEX_DIR/*/.files \
| grep -v "$ROOT_DIR/$INDEX_DIR/$name" \
grep '/$' $ROOT_DIR/$PKGDB_DIR/*/.files \
| grep -v "$ROOT_DIR/$PKGDB_DIR/$name" \
| awk -F : '{print $2}' \
| sort \
| uniq > "$reserve"
grep '/$' "$ROOT_DIR/$INDEX_DIR/$name/.files" > "$remove"
grep '/$' "$ROOT_DIR/$PKGDB_DIR/$name/.files" > "$remove"
grep -Fxv -f "$reserve" "$remove" | tac > "$dirs"
grep -v '/$' "$ROOT_DIR/$INDEX_DIR/$name/.files" | tac >> "$files"
grep -v '/$' "$ROOT_DIR/$PKGDB_DIR/$name/.files" | tac >> "$files"

echo "remove: $name-$version-$release..."

# pre-remove script
if [ ! "$NO_PREREMOVE" ] && [ -f "$ROOT_DIR/$INDEX_DIR/$name/.pkginstall" ]; then
if [ ! "$NO_PREREMOVE" ] && [ -f "$ROOT_DIR/$PKGDB_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/
run_scripts "$INDEX_DIR/$name/.pkginstall" pre-remove "$version"
run_scripts "$PKGDB_DIR/$name/.pkginstall" pre-remove "$version"
)
fi

Expand All @@ -191,14 +197,14 @@ fi
rm -f "$reserve" "$dirs" "$remove" "$files"

# post-remove script
if [ ! "$NO_POSTREMOVE" ] && [ -f "$ROOT_DIR/$INDEX_DIR/$name/.pkginstall" ]; then
if [ ! "$NO_POSTREMOVE" ] && [ -f "$ROOT_DIR/$PKGDB_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/
run_scripts "$INDEX_DIR/$name/.pkginstall" post-remove "$version"
run_scripts "$PKGDB_DIR/$name/.pkginstall" post-remove "$version"
)
fi

# remove from database
rm -rf "$ROOT_DIR/$INDEX_DIR/$name"
rm -rf "$ROOT_DIR/$PKGDB_DIR/$name"

# running ldconfig
if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then
Expand Down
13 changes: 9 additions & 4 deletions revdep
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ rev_exclude() {
trap "interrupted" 1 2 3 15
command -v pkgadd >/dev/null 2>&1 || {
echo "'pkgadd' not found in \$PATH!"
exit 1
}
# package database directory
INDEX_DIR="/var/lib/scratchpkg/index"
PKGDB_DIR="$(pkgadd --print-dbdir)"
SEARCH_DIRS="/bin /usr/bin /sbin /usr/sbin /lib /usr/lib /lib64 /usr/lib64 /usr/libexec"
parse_opt $(extract_opts "$@")
Expand All @@ -175,7 +180,7 @@ if [ "$(id -u)" != 0 ] && [ "$REBUILD" = 1 ]; then
exit 1
fi
if [ "$PKG" ] && [ ! -f "$INDEX_DIR/$PKG/.files" ]; then
if [ "$PKG" ] && [ ! -f "$PKGDB_DIR/$PKG/.files" ]; then
echo "ERROR: Package '$PKG' not installed"
cleanup
exit 1
Expand Down Expand Up @@ -250,7 +255,7 @@ if [ "$PKG" ]; then
filterdir=cat
fi
printf "Find '$PKG' files... "
sed 's/^/\//' $INDEX_DIR/$PKG/.files | grep $gx | $filterfile | $filterdir > $FILE_LIST
sed 's/^/\//' $PKGDB_DIR/$PKG/.files | grep $gx | $filterfile | $filterdir > $FILE_LIST
else
printf "Find all files... "
find $SEARCH_DIRS $EXCLUDED_DIRS $EXCLUDED_FILES -type f \( -perm /+u+x -o -name '*.so' -o -name '*.so.*' \) -print 2> /dev/null | sort -u > $FILE_LIST
Expand Down Expand Up @@ -279,7 +284,7 @@ while read -r line; do
LIB_NAME=$NEW_LIB_NAME
[ "$LIB_NAME" ] || continue
PKG_NAME=$(echo $line | sed 's#^/##')
PKG_NAME=$(grep -Rx $PKG_NAME "$INDEX_DIR"/*/.files | cut -d : -f1)
PKG_NAME=$(grep -Rx $PKG_NAME "$PKGDB_DIR"/*/.files | cut -d : -f1)
[ "$PKG_NAME" ] || continue
PKG_NAME=$(dirname $PKG_NAME)
PKG_NAME=$(basename $PKG_NAME)
Expand Down
Loading

0 comments on commit 552e0c7

Please sign in to comment.