aboutsummaryrefslogtreecommitdiff
path: root/apkg
diff options
context:
space:
mode:
authoremmett1 <emmett1.2miligrams@protonmail.com>2024-05-22 00:04:45 +0800
committeremmett1 <emmett1.2miligrams@protonmail.com>2024-05-22 00:04:45 +0800
commit7f803249b673228189421c37c5f5fbf4b3d79c3f (patch)
treedcb532a3ecab23589f54843c48194afd48f93656 /apkg
parentcf7e15afc0af0b15436a79d125703af5105be67b (diff)
downloadautils-7f803249b673228189421c37c5f5fbf4b3d79c3f.tar.gz
autils-7f803249b673228189421c37c5f5fbf4b3d79c3f.zip
updated
Diffstat (limited to 'apkg')
-rwxr-xr-xapkg153
1 files changed, 106 insertions, 47 deletions
diff --git a/apkg b/apkg
index f64e6d0..6fa0257 100755
--- a/apkg
+++ b/apkg
@@ -70,7 +70,7 @@ detect_buildtype() {
build_type=python_build
elif [ -f Makefile.PL ]; then
build_type=perlmodule_build
- elif [ -f Makefile ] || [ -f makefile ]; then
+ elif [ -f Makefile ] || [ -f makefile ] || [ -f GNUmakefile ]; then
build_type=makefile_build
else
msg "failed to detect buildtype"
@@ -79,7 +79,15 @@ detect_buildtype() {
}
_makefile_build() {
- make
+ make \
+ PREFIX=/usr \
+ prefix=/usr \
+ SYSCONFDIR=/etc \
+ sysconfdir=/etc \
+ MANDIR=/usr/share/man \
+ mandir=/usr/share/man \
+ LIBDIR=/usr/lib \
+ PKGCONFIGDIR=/usr/lib/pkgconfig
make \
PREFIX=/usr \
prefix=/usr \
@@ -105,7 +113,6 @@ _cmake_build() {
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_SYSCONFDIR=/etc \
-DCMAKE_INSTALL_LIBDIR=lib \
- -DCMAKE_INSTALL_LIBEXECDIR=lib \
-DCMAKE_BUILD_TYPE=Release \
-DFETCHCONTENT_FULLY_DISCONNECTED=ON \
-DCMAKE_C_FLAGS_RELEASE="$CFLAGS" \
@@ -132,7 +139,6 @@ _configure_build() {
--sysconfdir=/etc \
--localstatedir=/var \
--libdir=/usr/lib \
- --libexecdir=/usr/lib \
--infodir=/usr/share/info \
--mandir=/usr/share/man \
$build_opt $@
@@ -144,7 +150,6 @@ _meson_build() {
meson setup _meson_build \
--prefix=/usr \
--libdir=/usr/lib \
- --libexecdir=/usr/lib \
--includedir=/usr/include \
--datadir=/usr/share \
--mandir=/usr/share/man \
@@ -260,7 +265,10 @@ build_src() {
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 ; rm $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
# compress info pages
@@ -299,6 +307,17 @@ build_src() {
find $PKG | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs ${CROSS_COMPILE}strip --strip-unneeded 2>/dev/null
find $PKG | xargs file | grep "current ar archive" | cut -f 1 -d : | xargs ${CROSS_COMPILE}strip --strip-debug 2>/dev/null
fi
+
+ # usrmerge
+ if [ "$APKG_BINMERGE" ]; then
+ for b in bin sbin usr/sbin; do
+ if [ -d $PKG/$b ]; then
+ mkdir -p $PKG/usr/bin
+ mv $PKG/$b/* $PKG/usr/bin
+ rm -rf $PKG/$b
+ fi
+ done
+ fi
# runit service
for s in $sv; do
@@ -387,23 +406,28 @@ pkg_deplist() {
echo $DEPS | tr ' ' '\n'
}
+pkg_fsearch() {
+ #set -x
+ for r in $APKG_REPO; do
+ rr="$rr $r/*/.files"
+ done
+ grep $1 $rr 2>/dev/null | tr ':' ' ' | awk '{print $1,$4}' | sed 's,/.files,,g' #| rev | cut -d / -f 2 | rev
+ #cut -d ' ' -f3- $rr | grep $1
+}
+
+pkg_dependents() {
+ for r in $APKG_REPO; do
+ rr="$rr $r/*/depends"
+ done
+ grep -x $1 $rr 2>/dev/null | rev | cut -d / -f 2 | rev
+}
+
pkg_depends() {
_path=$(pkg_path $1) >/dev/null || return 1
[ -s $_path/depends ] || return
grep -Ev ^'(#|$)' $_path/depends | awk '{print $1}'
}
-parsesubopt() {
- # loop opts until found '-*'
- shift; while [ "$1" ]; do
- case $1 in
- -*) break;;
- *) echo $1;;
- esac
- shift
- done
-}
-
pkg_outdate() {
spm -a | while read -r n v; do
[ "$(pkg_path $n)" ] || continue
@@ -413,6 +437,12 @@ pkg_outdate() {
done
}
+pkg_remove() {
+ for i in $@; do
+ spm -r $i
+ done
+}
+
pkg_sysup() {
msg "Checking for outdated packages..."
od=$(pkg_outdate | awk '{print $1}')
@@ -433,11 +463,8 @@ pkg_sysup() {
echo
fi
totalpkg=$(echo $pu | tr ' ' '\n' | wc -l)
- msg "Upgrading $totalpkg package(s)."
- echo
- echo $pu
- echo
- prompt_user
+ msg "Upgrading $totalpkg package(s): $pu"
+ rompt_user
if [ "$ni" ]; then
$APKG -i $ni || die
fi
@@ -451,12 +478,19 @@ pkg_search() {
exit 1
fi
[ "$1" ] && grep=grep || grep=cat
- find $APKG_REPO -type f -name info -printf '%h\n' | rev | awk -F / '{print $1}' | rev | $grep $1
+ find $APKG_REPO -type f -name info 2>/dev/null | sed 's|/info||' | rev | awk -F / '{print $1}' | rev | $grep $1
}
pkg_depinstalll() {
for p in $@; do
- [ -s $SPM_PKGDB/$p ] && continue
+ if [ -s $SPM_PKGDB/$p ]; then
+ msg "Package '$p' is installed"
+ continue
+ fi
+ if ! pkg_path $p >/dev/null; then
+ msg "Package '$p' not found"
+ continue
+ fi
pkg="$pkg $p"
done
set -- $pkg
@@ -470,14 +504,16 @@ pkg_depinstalll() {
exit 0
fi
totalpkg=$(echo $installthis | tr ' ' '\n' | wc -l)
- msg "Installing $totalpkg package(s)."
- echo
- echo $installthis
- echo
+ msg "Installing $totalpkg package(s): $installthis"
prompt_user
$APKG -i $installthis || die
}
+pkg_allinstalled() {
+ [ "$1" ] && grep="grep $1" || grep=cat
+ ls -1 $SPM_PKGDB | $grep
+}
+
prompt_user() {
if [ ! "$APKG_NOPROMPT" ]; then
msg "Press ENTER to continue operation."
@@ -487,28 +523,53 @@ prompt_user() {
}
runscript() {
- if [ -x ./$1-install ]; then
- msg "Running $1-install script..."
+ if [ -x ./${1}install ]; then
+ msg "Running ${1}install script..."
if [ "$APKG_ROOT" ]; then
- cat ./$1-install > "$APKG_ROOT"/.runscript
+ cat ./${1}install > "$APKG_ROOT"/.runscript
chmod +x "$APKG_ROOT"/.runscript
chroot "$APKG_ROOT" /.runscript
rm -f "$APKG_ROOT"/.runscript
else
- ./$1-install
+ ./${1}install
fi
fi
}
+parsesubopt() {
+ # loop opts until found '-*'
+ shift; while [ "$1" ]; do
+ case $1 in
+ -*) break;;
+ *) echo $1;;
+ esac
+ shift
+ done
+}
+
+updateopts() {
+ while [ "$1" ]; do
+ case $1 in
+ -*) newopt="$newopt $1";;
+ esac
+ shift
+ done
+ echo $newopt
+}
+
parseopts() {
while [ "$1" ]; do
case $1 in
-I) pkg_depinstalll $(parsesubopt $@); exit 0;;
-D) pkg_deplist $(parsesubopt $@); exit 0;;
+ -r) pkg_remove $(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;;
+ -a) pkg_allinstalled $2; exit 0;;
-h) apkg_help; exit 0;;
-l) pkg_outdate; exit 0;;
-k) updatefiles=1;;
@@ -523,16 +584,6 @@ parseopts() {
done
}
-updateopts() {
- while [ "$1" ]; do
- case $1 in
- -*) newopt="$newopt $1";;
- esac
- shift
- done
- echo $newopt
-}
-
apkg_help() {
cat << EOF
usage: ${0##*/} <option> <arg(s)>
@@ -569,7 +620,10 @@ main() {
if [ "$pkg" ]; then
for p in $pkg; do
- pkg_path $p >/dev/null || continue
+ pkg_path $p >/dev/null || {
+ msg "Package '$p' not found"
+ continue
+ }
#echo "[$p] package build starts..."
(cd $(pkg_path $p) && $APKG $@)
[ "$?" = 0 ] || exit 1
@@ -609,7 +663,14 @@ main() {
pkg_updatefiles
exit 0
fi
+
+ if [ "$(id -u)" != 0 ]; then
+ msg "Packages need to build as root. Aborted."
+ exit 1
+ fi
+ # run preinstall script before build
+ runscript pre
if [ -f "$packagefile" ] && [ ! "$forcerebuild" ]; then
if [ ! "$install" ] && [ ! "$upgrade" ]; then
msg "Package '$packagefile' found."
@@ -621,14 +682,12 @@ main() {
fi
if [ "$install" ]; then
- runscript pre
SPM_ROOT=${APKG_ROOT%/} spm -i "$packagefile" || exit $?
- runscript post
elif [ "$upgrade" ]; then
- runscript pre
SPM_ROOT=${APKG_ROOT%/} spm -u "$packagefile" || exit $?
- runscript post
fi
+ # run postinstall script after installed/upgraded
+ runscript post
}
umask 022