From cf7e15afc0af0b15436a79d125703af5105be67b Mon Sep 17 00:00:00 2001 From: emmett1 Date: Mon, 15 Apr 2024 11:38:09 +0800 Subject: updated --- apkg | 223 +++++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 149 insertions(+), 74 deletions(-) (limited to 'apkg') diff --git a/apkg b/apkg index 776447f..f64e6d0 100755 --- a/apkg +++ b/apkg @@ -12,7 +12,7 @@ fetch_src() { http://*|https://*|ftp://*) if [ ! -f $APKG_SOURCE_DIR/$sn ]; then [ -f $APKG_SOURCE_DIR/$sn.tmp ] && resume="-C -" - msg "fetching ${i#*::} to $APKG_SOURCE_DIR/$sn.tmp" + msg "fetching ${i#*::}" curl $resume -L -o $APKG_SOURCE_DIR/$sn.tmp ${i#*::} || { msg "Failed downloading source '$sn'." exit 1 @@ -67,7 +67,7 @@ detect_buildtype() { elif [ -f CMakeLists.txt ]; then build_type=cmake_build elif [ -f setup.py ]; then - build_type=python3_build + build_type=python_build elif [ -f Makefile.PL ]; then build_type=perlmodule_build elif [ -f Makefile ] || [ -f makefile ]; then @@ -121,7 +121,7 @@ _cmake_build() { fi } -_python3_build() { +_python_build() { python3 setup.py build python3 setup.py install --prefix=/usr --root=$PKG --optimize=1 } @@ -229,22 +229,22 @@ build_src() { if [ ! "$source" ]; then # dummy pkg mkdir -p $PKG/usr - elif [ "$(command -v pkg_build)" ]; then - (set -e -x; pkg_build) - buildstatus pkg_build + elif [ -s $HERE/build ]; then + sh -e -x $HERE/build + buildstatus build else - if [ "$(command -v pre_build)" ]; then - (set -e -x; pre_build) - buildstatus pre_build + if [ -s $HERE/prebuild ]; then + sh -e -x $HERE/prebuild + buildstatus prebuild fi if [ ! "${build_type}" ]; then detect_buildtype fi (set -e -x; _${build_type}) buildstatus _${build_type} - if [ "$(command -v post_build)" ]; then - (set -e -x; post_build) - buildstatus post_build + if [ -s $HERE/postbuild ]; then + sh -e -x $HERE/postbuild + buildstatus postbuild fi fi @@ -328,7 +328,7 @@ build_src() { exit 1 } - if [ ! -f "$HERE"/.files ]; then + if [ ! -f "$HERE"/.files ] || [ "$HERE"/info -nt "$HERE"/.files ]; then pkg_updatefiles fi @@ -341,13 +341,13 @@ pkg_updatefiles() { msg "Package '$packagefile' not found." exit 1 fi - msg "'.files' updated." + 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 ] && { + [ -f $r/$1/info ] && { echo $r/$1 break } @@ -355,7 +355,7 @@ pkg_path() { } die() { - echo "error: $1" + [ "$1" ] && echo "error: $1" exit 1 } @@ -389,7 +389,8 @@ pkg_deplist() { pkg_depends() { _path=$(pkg_path $1) >/dev/null || return 1 - grep '# Depends' $_path/abuild | awk -F : '{print $2}' | tr ' ' '\n' | sed '/^$/d' + [ -s $_path/depends ] || return + grep -Ev ^'(#|$)' $_path/depends | awk '{print $1}' } parsesubopt() { @@ -406,7 +407,7 @@ parsesubopt() { pkg_outdate() { spm -a | while read -r n v; do [ "$(pkg_path $n)" ] || continue - nv="$(grep ^version= $(pkg_path $n)/abuild | awk -F = '{print $2}')-$(grep ^release= $(pkg_path $n)/abuild | awk -F = '{print $2}')" + nv="$(grep ^version= $(pkg_path $n)/info | awk -F = '{print $2}')-$(grep ^release= $(pkg_path $n)/info | awk -F = '{print $2}')" [ "$nv" ] || continue [ "$v" = "$nv" ] || echo "$n $v -> $nv" done @@ -418,55 +419,39 @@ pkg_sysup() { if [ ! "$od" ]; then msg "No outdated packages." exit 0 - else - totalpkg=$(echo $od | tr ' ' '\n' | wc -l) + else + msg "Solving dependencies..." + for p in $(pkg_deplist $od); do + [ -s $SPM_PKGDB/$p ] || ni="$ni $p" + echo $od | tr ' ' '\n' | grep -qx $p && pu="$pu $p" + done + if [ "$ni" ]; then + newpkg=$(echo $ni | tr ' ' '\n' | wc -l) + msg "Installing $newpkg new package(s)." + echo + echo $ni + echo + fi + totalpkg=$(echo $pu | tr ' ' '\n' | wc -l) + msg "Upgrading $totalpkg package(s)." echo - echo $od + echo $pu echo - msg "Press ENTER to continue upgrade $totalpkg packages." - msg "Press Ctrl + C to abort." - read -r null - apkg -u $od || die + prompt_user + if [ "$ni" ]; then + $APKG -i $ni || die + fi + $APKG -u $pu || die fi } -parseopts() { - while [ "$1" ]; do - case $1 in - -I) pkg_depinstalll $(parsesubopt $@); exit 0;; - -D) pkg_deplist $(parsesubopt $@); exit 0;; - -f) forcerebuild=1;; - -i) install=1;; - -u) upgrade=1;; - -o) downloadonly=1;; - -U) pkg_sysup; exit 0;; - -d) pkg_depends $2; exit 0;; - -p) pkg_path $2; exit 0;; - -s) pkg_search $2; exit 0;; - -*) msg "invalid option '$1'"; exit 1;; - *) pkg="$pkg $1";; - esac - shift - done -} - -updateopts() { - while [ "$1" ]; do - case $1 in - -*) newopt="$newopt $1";; - esac - shift - done - echo $newopt -} - pkg_search() { if [ ! "$APKG_REPO" ]; then msg "No repo configured." exit 1 fi [ "$1" ] && grep=grep || grep=cat - find $APKG_REPO -type f -name abuild -printf '%h\n' | rev | awk -F / '{print $1}' | rev | $grep $1 + find $APKG_REPO -type f -name info -printf '%h\n' | rev | awk -F / '{print $1}' | rev | $grep $1 } pkg_depinstalll() { @@ -485,29 +470,94 @@ pkg_depinstalll() { exit 0 fi totalpkg=$(echo $installthis | tr ' ' '\n' | wc -l) + msg "Installing $totalpkg package(s)." echo echo $installthis echo - msg "Press ENTER to continue install $totalpkg packages." - msg "Press Ctrl + C to abort." - read -r null - apkg -i $installthis || die + prompt_user + $APKG -i $installthis || die +} + +prompt_user() { + if [ ! "$APKG_NOPROMPT" ]; then + msg "Press ENTER to continue operation." + msg "Press Ctrl + C to abort." + read -r null + fi } runscript() { if [ -x ./$1-install ]; then msg "Running $1-install script..." - if [ "$ROOT" ]; then - cat ./$1-install > "$ROOT"/.runscript - chmod +x "$ROOT"/.runscript - chroot "$ROOT" /.runscript - rm -f "$ROOT"/.runscript + if [ "$APKG_ROOT" ]; then + cat ./$1-install > "$APKG_ROOT"/.runscript + chmod +x "$APKG_ROOT"/.runscript + chroot "$APKG_ROOT" /.runscript + rm -f "$APKG_ROOT"/.runscript else ./$1-install fi fi } +parseopts() { + while [ "$1" ]; do + case $1 in + -I) pkg_depinstalll $(parsesubopt $@); exit 0;; + -D) pkg_deplist $(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;; + -h) apkg_help; exit 0;; + -l) pkg_outdate; exit 0;; + -k) updatefiles=1;; + -f) forcerebuild=1;; + -i) install=1;; + -u) upgrade=1;; + -o) downloadonly=1;; + -*) msg "invalid option '$1'"; exit 1;; + *) pkg="$pkg $1";; + esac + shift + done +} + +updateopts() { + while [ "$1" ]; do + case $1 in + -*) newopt="$newopt $1";; + esac + shift + done + echo $newopt +} + +apkg_help() { + cat << EOF +usage: ${0##*/}