aboutsummaryrefslogtreecommitdiff
path: root/apkg
diff options
context:
space:
mode:
authoremmett1 <emmett1.2miligrams@protonmail.com>2024-06-26 00:05:19 +0800
committeremmett1 <emmett1.2miligrams@protonmail.com>2024-06-26 00:05:19 +0800
commit33696ea737b5f3451df242a818e484f8e760bc71 (patch)
treeb4ffd87195675dc8bc2f3b11ec61690e083ff571 /apkg
parentd1817ea579b6ca637b9d422e859be57f12ac0a88 (diff)
downloadautils-33696ea737b5f3451df242a818e484f8e760bc71.tar.gz
autils-33696ea737b5f3451df242a818e484f8e760bc71.zip
updated apkg -p and remove workdir on error
Diffstat (limited to 'apkg')
-rwxr-xr-xapkg76
1 files changed, 45 insertions, 31 deletions
diff --git a/apkg b/apkg
index b9abb9a..00e1f51 100755
--- a/apkg
+++ b/apkg
@@ -24,8 +24,7 @@ fetch_src() {
}
extract_src() {
- rm -rf $PKG $SRC
- mkdir -p $PKG $SRC
+ prepare_workdir
[ "$source" ] || return 0
for i in $source; do
case $i in
@@ -41,24 +40,41 @@ extract_src() {
i=${i%::noextract}
cp $S/$sn $SRC || {
msg "Failed copy '$S/$sn' to '$SRC'."
- exit 1
+ ret 1
};;
*.tar.bz2|*.tar.gz|*.tar.lz|*.tar.lzma|*.tar.lzo|*.tar.xz|*.tar.Z|*.tb2|*.tbz|*.tbz2|*.tz2|*.taz|*.tgz|*.tlz|*.txz|*.tZ|*.taZ)
msg "Unpacking '$S/$sn'..."
tar -p -o -C $SRC -xf $S/$sn || {
msg "Failed unpacking source '${i##*/}'."
- exit 1
+ ret 1
};;
*)
i=${i%::noextract}
cp $S/$sn $SRC || {
msg "Failed copy '$S/$sn' to '$SRC'."
- exit 1
+ ret 1
};;
esac
done
}
+prepare_workdir() {
+ export SRC=$APKG_WORK_DIR/apkg-src-${PWD##*/}
+ export PKG=$APKG_WORK_DIR/apkg-pkg-${PWD##*/}
+
+ remove_workdir
+ mkdir -p "$PKG" "$SRC"
+}
+
+remove_workdir() {
+ rm -rf "$PKG" "$SRC"
+}
+
+ret() {
+ [ "$APKG_KEEP_WORKDIR" ] || remove_workdir
+ exit $1
+}
+
detect_buildtype() {
if [ -f meson.build ]; then
build_type=meson_build
@@ -74,7 +90,7 @@ detect_buildtype() {
build_type=makefile_build
else
msg "failed to detect buildtype"
- exit 1
+ ret 1
fi
}
@@ -183,7 +199,7 @@ apply_patch() {
case $pn in
*.patch|*.diff)
msg "applying path '$SRC/$pn'."
- patch ${patch_opt:--p1} -t -i $SRC/$pn || exit 1;;
+ patch ${patch_opt:--p1} -t -i $SRC/$pn || ret 1;;
esac
done
fi
@@ -194,14 +210,10 @@ msg() {
echo "[${name:-...}] $@" | fold -sw $ttysize
}
-exitonerror() {
- [ "$?" = 0 ] || { echo "error status $?"; exit 1; }
-}
-
buildstatus() {
[ "$?" = 0 ] || {
msg "build package '$name-$version-$release' failed on '$1'."
- exit 1
+ ret 1
}
}
@@ -211,7 +223,7 @@ build_src() {
if [ "$build_dir" ]; then
if [ ! -d "$build_dir" ]; then
msg "Source directory '$build_dir' not found."
- exit 1
+ ret 1
fi
elif [ -d $name-$version ]; then
build_dir=$name-$version
@@ -265,9 +277,12 @@ build_src() {
esac
rm -rf $m
done
- find $PKG/usr/share/man -type f -exec gzip -9 {} \;
- for i in $( find $PKG/usr/share/man -type l ) ; do
- ln -s $( readlink $i ).gz ${i%.gz}.gz
+ for i in $(find $PKG/usr/share/man -type f); do
+ [ $i = ${i%%.gz} ] || continue
+ gzip -9 $i
+ done
+ for i in $(find $PKG/usr/share/man -type l) ; do
+ ln -s $(readlink $i).gz ${i%.gz}.gz
rm $i
done
fi
@@ -322,7 +337,7 @@ build_src() {
# runit service
for s in $sv; do
- [ -f $SRC/$s ] || exit 1
+ [ -f $SRC/$s ] || ret 1
case $s in
run) install -Dm755 $SRC/$s $PKG/etc/sv/$name/run
ln -s ../../../run/runit/supervise.$name $PKG/etc/sv/$name/supervise;;
@@ -337,7 +352,7 @@ build_src() {
if [ ! "$(ls -1 $PKG)" ]; then
msg "\$PKG is empty"
- exit 1
+ ret 1
fi
cd $APKG_PACKAGE_DIR
@@ -345,7 +360,7 @@ build_src() {
mv package.spm $packagefile
} || {
msg "Failed packaging $packagefile"
- exit 1
+ ret 1
}
if [ ! -f "$HERE"/.files ] || [ "$HERE"/abuild -nt "$HERE"/.files ]; then
@@ -353,30 +368,31 @@ build_src() {
fi
cd $HERE
- rm -rf $SRC $PKG
+ remove_workdir
}
pkg_updatefiles() {
if [ ! -f "$packagefile" ]; then
msg "Package '$packagefile' not found."
- exit 1
+ ret 1
fi
msg "filelist updated."
tar -tvf $packagefile | awk '{$3=$4=$5=""; print $0}' | sort -k 3 > "$HERE"/.files
}
pkg_path() {
- for r in $APKG_REPO; do
- [ -f $r/$1/abuild ] && {
- echo $r/$1
- break
- }
+ for p in $@; do
+ for r in $APKG_REPO; do
+ [ -f $r/$p/abuild ] && {
+ echo $r/$p
+ }
+ done
done
}
die() {
[ "$1" ] && echo "error: $1"
- exit 1
+ ret 1
}
checkdep() {
@@ -564,9 +580,9 @@ parseopts() {
-I) pkg_depinstalll $(parsesubopt $@); exit 0;;
-D) pkg_deplist $(parsesubopt $@); exit 0;;
-r) pkg_remove $(parsesubopt $@); exit 0;;
+ -p) pkg_path $(parsesubopt $@); exit 0;;
-U) pkg_sysup; exit 0;;
-d) pkg_depends $2; exit 0;;
- -p) pkg_path $2; exit 0;;
-s) pkg_search $2; exit 0;;
-S) pkg_fsearch $2; exit 0;;
-j) pkg_dependents $2; exit 0;;
@@ -594,6 +610,7 @@ options:
-I <pkg(s)> install packages(s) with dependencies
-d <pkg> list <pkg> dependencies
-D <pkg(s)> list all dependencies
+ -j <pkg> list all dependents
-u <pkg(s)> upgrade package(s)
-U update system
-f force rebuild
@@ -727,9 +744,6 @@ APKG_REPO=${O_APKG_REPO:-$APKG_REPO}
APKG_PACKAGE_DIR=${O_APKG_PACKAGE_DIR:-$APKG_PACKAGE_DIR}
APKG_SOURCE_DIR=${O_APKG_SOURCE_DIR:-$APKG_SOURCE_DIR}
APKG_WORK_DIR=${O_APKG_WORK_DIR:-$APKG_WORK_DIR}
-
-export SRC=$APKG_WORK_DIR/apkg-src-${PWD##*/}
-export PKG=$APKG_WORK_DIR/apkg-pkg-${PWD##*/}
main $@