From b287a29632afb4740e7e417bd70504f589f2a581 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Tue, 5 Jun 2018 16:55:42 +0800 Subject: [PATCH] updated --- INSTALL.sh | 2 +- extra/{baseinstall => s-baseinstall} | 0 extra/{chroot-scratch => s-chroot} | 0 extra/{deplist => s-deplist} | 7 ++ extra/{libdepends => s-libdepends} | 0 extra/{scratchcreate => s-portcretae} | 0 extra/{scratchdiff => s-updateconf} | 6 +- extra/sysupdate | 64 -------------- functions/message | 10 ++- removepkg | 40 +-------- extra/revdep => revdep | 0 scratch | 119 ++++++++++++++++++++++---- 12 files changed, 127 insertions(+), 121 deletions(-) rename extra/{baseinstall => s-baseinstall} (100%) rename extra/{chroot-scratch => s-chroot} (100%) rename extra/{deplist => s-deplist} (91%) rename extra/{libdepends => s-libdepends} (100%) rename extra/{scratchcreate => s-portcretae} (100%) rename extra/{scratchdiff => s-updateconf} (91%) delete mode 100755 extra/sysupdate rename extra/revdep => revdep (100%) diff --git a/INSTALL.sh b/INSTALL.sh index 773855c..c4f0508 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -9,7 +9,7 @@ INDEX_DIR=/var/lib/scratchpkg PORT_DIR=/usr/ports mkdir -pv ${DESTDIR}{${BINDIR},${FUNCDIR},${CONFDIR},${HOOK_DIR},${PORT_DIR}} -install -m755 buildpkg installpkg removepkg scratch ${DESTDIR}${BINDIR} +install -m755 revdep buildpkg installpkg removepkg scratch ${DESTDIR}${BINDIR} install -m644 functions/* ${DESTDIR}${FUNCDIR} install -m644 scratchpkg.conf scratchpkg.repo ${DESTDIR}${CONFDIR} install -m755 extra/* ${DESTDIR}${BINDIR} diff --git a/extra/baseinstall b/extra/s-baseinstall similarity index 100% rename from extra/baseinstall rename to extra/s-baseinstall diff --git a/extra/chroot-scratch b/extra/s-chroot similarity index 100% rename from extra/chroot-scratch rename to extra/s-chroot diff --git a/extra/deplist b/extra/s-deplist similarity index 91% rename from extra/deplist rename to extra/s-deplist index b28a2aa..3887dc3 100755 --- a/extra/deplist +++ b/extra/s-deplist @@ -7,6 +7,13 @@ if [ ! "$1" ]; then exit 1 fi +while read repodir repourl junk; do + case $repodir in + ""|"#"*) continue ;; + esac + PORT_REPO+=($repodir) +done < /etc/scratchpkg.repo + checkdep() { if getportpath "$1" >/dev/null; then diff --git a/extra/libdepends b/extra/s-libdepends similarity index 100% rename from extra/libdepends rename to extra/s-libdepends diff --git a/extra/scratchcreate b/extra/s-portcretae similarity index 100% rename from extra/scratchcreate rename to extra/s-portcretae diff --git a/extra/scratchdiff b/extra/s-updateconf similarity index 91% rename from extra/scratchdiff rename to extra/s-updateconf index 4dd8e4f..7175dfe 100755 --- a/extra/scratchdiff +++ b/extra/s-updateconf @@ -43,9 +43,13 @@ for file in $spkgnew; do echo "Replace '$currentfile' with '$file'." mv "$file" "$currentfile" else - echo "Do nothing." + echo "Doing nothing." fi sleep 1 done +clear + +echo "Done updating package's configuration files." + exit 0 diff --git a/extra/sysupdate b/extra/sysupdate deleted file mode 100755 index c4351ec..0000000 --- a/extra/sysupdate +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -e - -source "/usr/share/scratchpkg/color" -source "/usr/share/scratchpkg/message" - -faileduppkg=() -successuppkg=() - -case "$1" in - -up|--update-ports) - msg "Updating ports..." - if [ $UID != 0 ]; then - if [ $(type -p sudo) ]; then - sudo scratch portup - else - msgerr "Updating package need root access!" - exit 1 - fi - else - scratch portup - fi ;; -esac - -if [[ ! $(scratch -cu | grep "up to date") ]]; then - outdatepkg=($(scratch query --outdate | awk '{print $2}')) - totalopkgs=$(echo ${#outdatepkg[@]}) - count=1 - for i in ${outdatepkg[@]}; do - if [ $UID != 0 ]; then - if [ $(type -p sudo) ]; then - echo -e "[ $count/$totalopkgs ] Updating $i..." - sudo scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) - else - msgerr "Updating package need root access!" - exit 1 - fi - else - echo -e "[ $count/$totalopkgs ] Updating $i..." - scratch upgrade $i && successuppkg+=($i) || faileduppkg+=($i) - fi - echo - ((count++)) - done -else - msg "All packages is up to date." - exit 0 -fi - -if [ "${#successuppkg[@]}" -gt 0 ]; then - echo "Successfully update this package(s):" - for ok in ${successuppkg[@]}; do - echo -e "${GREEN}>>>${CRESET} $ok" - done -fi - -if [ "${#faileduppkg[@]}" -gt 0 ]; then - [ "${#successuppkg[@]}" -gt 0 ] && echo # make space between success and failed - echo "Failed update this package(s):" - for ko in ${faileduppkg[@]}; do - echo -e "${RED}>>>${CRESET} $ko" - done -fi - -exit 0 diff --git a/functions/message b/functions/message index 3ce8f5e..75f64d2 100644 --- a/functions/message +++ b/functions/message @@ -32,10 +32,18 @@ msginst() { echo -e "[${GREEN}*${CRESET}] $@" } +msgnew() { + echo -e "[${GREEN}N${CRESET}] $@" +} + +msgupg() { + echo -e "[${GREEN}U${CRESET}] $@" +} + msgnoinst() { echo -e "[ ] $@" } msgmiss() { - echo -e "[${RED}m${CRESET}] $@" + echo -e "[${RED}M${CRESET}] $@" } diff --git a/removepkg b/removepkg index e666767..fa8b973 100755 --- a/removepkg +++ b/removepkg @@ -151,40 +151,6 @@ checkdeps() { fi } -checkneworphan() { - - for dpd in ${idepends[@]}; do - saferemove $dpd - done - - for mdpd in ${imakedepends[@]}; do - saferemove $mdpd - done - - if [ "${#neworphan[@]}" -gt 0 ]; then - msg "New orphaned package:" - for list in ${neworphan[@]}; do - msg2 $list - done - fi -} - -saferemove() { - - ORPHAN="yes" - for all_installed in $(ls $INDEX_DIR); do - depend=$(cat $INDEX_DIR/$all_installed/.pkginfo | grep ^depends | cut -d " " -f3-) - for dep in ${depend[@]}; do - if [ $dep = $1 ]; then - ORPHAN="no" - fi - done - done - - [ "$ORPHAN" = "yes" ] && [ -d $INDEX_DIR/$1 ] && neworphan+=($1) - -} - runremovehooks() { if [ "${#runthishook[@]}" -gt 0 ]; then @@ -267,7 +233,6 @@ parse_opts() { --no-preremove) NO_PREREMOVE=yes ;; --no-postremove) NO_POSTREMOVE=yes ;; --no-color) NOCOLOR=yes ;; - --no-orphan-check) NO_ORPHAN_CHECK=yes ;; -*) msg "Invalid option: ($1)"; exit 1 ;; *) RMNAME+=($1) ;; esac @@ -316,10 +281,7 @@ main() { for pkg in ${RMNAME[@]}; do getoldname $pkg ### GET NAME, VERSION, RELEASE FROM INSTALLED PACKAGE DATABASE ### - removepkg $pkg ### REMOVE PACKAGE ### - #if [ ! "$NO_ORPHAN_CHECK" ]; then # check for orphan package - #checkneworphan - #fi + removepkg $pkg ### REMOVE PACKAGE ### done # running ldconfig diff --git a/extra/revdep b/revdep similarity index 100% rename from extra/revdep rename to revdep diff --git a/scratch b/scratch index 1b9f175..a8712f0 100755 --- a/scratch +++ b/scratch @@ -142,11 +142,10 @@ missingdep() { showportpath() { - if getportpath "$1" >/dev/null; then - echo -e "$(getportpath $1)" - exit 0 + if PPATH=$(getportpath "$1"); then + echo "$PPATH" else - msgerr "Port '$1' not exist" + msgerr "Port '$1' not exist." exit 1 fi @@ -239,11 +238,24 @@ showdependent2() { catport() { - if getportpath "$1" >/dev/null; then - cat "$(getportpath $1)/$BUILD_SCRIPT" - exit 0 + if PPATH=$(getportpath "$1"); then + cat "$PPATH/$BUILD_SCRIPT" else - msgerr "Port '$1' not exist" + msgerr "Port '$1' not exist." + exit 1 + fi +} + +printreadme() { + + if PPATH=$(getportpath "$1"); then + if [ -f "$PPATH/readme" ]; then + cat "$PPATH/readme" + else + msgerr "Port '$1' does not have readme." + fi + else + msgerr "Port '$1' not exist." exit 1 fi } @@ -365,6 +377,60 @@ pkgcache() { } +sysup() { + + needroot "Upgrading package" + + PKGOUTDATE=$(outdatepkg) + + if [ ! "$PKGOUTDATE" ]; then + msg "All package is up to date." + exit 0 + fi + + for i in ${PKGOUTDATE[@]}; do + echo -ne "Calculating '$i' dependencies...\033[0K\r" + deplist $i + done + echo -ne "\033[0K" + for d in ${DEP[@]}; do + if [ "$(echo ${PKGOUTDATE[@]} | tr ' ' '\n' | grep -x $d)" = "$d" ]; then + msgupg "$d" + WILLINSTALL+=($d) + elif [ ! -e "$INDEX_DIR/$d/.pkginfo" ] && getportpath $d >/dev/null; then + msgnew "$d" + WILLINSTALL+=($d) + fi + done + + echo + echo "These package(s) will be upgrade and installed..." + echo + confirm "Continue upgrade and install these package(s)?" "Package upgrade cancelled." + echo + for inst in ${WILLINSTALL[@]}; do # install all required dependencies and target packages itself + if [ ! -e "$INDEX_DIR/$inst/.pkginfo" ]; then + portinstall $inst -i || exit 1 + else + portinstall $inst -u || exit 1 + fi + done + +} + +outdatepkg() { + for pkg in $(allinstalled); do + if [ ! -e "$INDEX_DIR/$pkg/.lock" ] && getportpath $pkg >/dev/null; then + . $(getportpath $pkg)/$BUILD_SCRIPT + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then + echo $name + fi + fi + done +} + checkupdate() { for pkg in $(allinstalled); do @@ -552,6 +618,10 @@ deplist() { fi fi + #if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "$i" ]]; then + #return 0 + #fi + # add package to currently process CHECK+=($1) @@ -563,7 +633,9 @@ deplist() { done # add dependency to list checked dep - DEP+=($1) + if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $1) = "" ]]; then + DEP+=($1) + fi # delete process package array for i in "${!CHECK[@]}"; do @@ -631,7 +703,9 @@ mode: pkgtree show list files of installed package path show package's buildscripts path sync update port's repo + sysup full system update dup print duplicate ports in repo + readme print readme file if exist listinst list installed package in system listorphan list orphan package integrity check integrity of package's files @@ -713,12 +787,14 @@ done checkdirexist "$INDEX_DIR" -while read repodir repourl junk; do - case $repodir in - ""|"#"*) continue ;; - esac - PORT_REPO+=($repodir) -done < /etc/scratchpkg.repo +if [ -f /etc/scratchpkg.repo ]; then + while read repodir repourl junk; do + case $repodir in + ""|"#"*) continue ;; + esac + PORT_REPO+=($repodir) + done < /etc/scratchpkg.repo +fi # build mode if [ "$mode" = "build" ]; then @@ -1045,6 +1121,19 @@ if [ "$mode" = "search" ]; then exit 0 fi +# print readme for ports +if [ "$mode" = "readme" ]; then + needarg "$ARG" || exit 1 + printreadme $ARG + exit 0 +fi + +# update all ports +if [ "$mode" = "sysup" ]; then + sysup + exit 0 +fi + echo "Run '$(basename $0) help' to see available mode and options" exit 0