From 934caf8a322c40648530bd6d12c696ca450c03be Mon Sep 17 00:00:00 2001 From: emmett1 Date: Fri, 8 Dec 2017 21:13:21 +0800 Subject: [PATCH] updated --- extra/baseinstall | 19 +++++++---- extra/chroot-scratch | 11 +++++-- extra/depinstall | 75 ++++++++++++++++++++++++-------------------- extra/deplist | 17 +++++----- extra/libdepends | 18 ++++++----- extra/listinstall | 31 +++++++++--------- extra/revdep | 10 +++--- extra/sysupdate | 12 ++++--- functions/functions | 29 +---------------- functions/message | 29 +++++++++++++++++ 10 files changed, 140 insertions(+), 111 deletions(-) create mode 100644 functions/message diff --git a/extra/baseinstall b/extra/baseinstall index de415a0..5b4709b 100755 --- a/extra/baseinstall +++ b/extra/baseinstall @@ -1,6 +1,9 @@ -#!/bin/bash +#!/bin/bash -e -index_dir="/var/spkg/index" +INDEX_DIR="/var/lib/scratchpkg/index" + +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" basepkg=(linux-api-headers man-pages @@ -71,9 +74,10 @@ rc-init base-meta) for list in ${basepkg[@]}; do - if [ -d $index_dir/$list ]; then - echo "$list is installed" + if [ -d $INDEX_DIR/$list ]; then + msg "$list is installed" else + msg "Installing $list..." case $list in gcc | bash | perl | coreutils | filesystem ) scratch -p $list -i -id -ic @@ -82,9 +86,12 @@ for list in ${basepkg[@]}; do scratch -p $list -i -id ;; esac - if [ ! -d /var/spkg/index/$list ]; then - echo "ERROR $list" + if [ ! -d $INDEX_DIR/$list ]; then + msgerr "Failed installing $list." + msgerr "Press ENTER to skip and continue, press CTRL + C to cancel." read fi fi done + +exit 0 diff --git a/extra/chroot-scratch b/extra/chroot-scratch index f87d619..f6b5623 100755 --- a/extra/chroot-scratch +++ b/extra/chroot-scratch @@ -1,19 +1,22 @@ #!/bin/bash + +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" if [ "$UID" != "0" ]; then - echo "chroot need root access!" + msgerr "Chroot need root access!" exit 1 fi LFS=$1 if [ -z $1 ]; then - echo "Please set mount point for chroot!" + msgerr "Please set mount point for chroot!" exit 1 fi if [ ! -d $LFS ]; then - echo "Dir $LFS not exist" + msgerr "Dir '$LFS' not exist" exit 1 fi @@ -44,3 +47,5 @@ umount -v $LFS/dev umount -v $LFS/run umount -v $LFS/proc umount -v $LFS/sys + +exit $? diff --git a/extra/depinstall b/extra/depinstall index 5e048dd..b88c427 100755 --- a/extra/depinstall +++ b/extra/depinstall @@ -1,5 +1,23 @@ #!/bin/bash -e +INDEX_DIR="/var/lib/scratchpkg/index" +CONF_FILE="/etc/scratchpkg.conf" + +if [ ! "$1" ]; then + echo "Please specify package name to install." + exit 1 +fi + +if [ -d $INDEX_DIR/$1 ]; then + echo "Package $1 already installed" && exit 0 +fi + +source "$CONF_FILE" +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" + +pkgname=$1 + checkpkg() { for repo in ${PORT_REPO[@]}; do @@ -8,43 +26,32 @@ checkpkg() { break fi done - [ "$PORT_EXIST" ] || (echo "Port $pkgname not exist" && exit 1) + [ "$PORT_EXIST" ] || (msgerr "Port '$pkgname' not exist" && exit 1) } -index_dir="/var/spkg/index" - -if [ ! "$1" ]; then - echo "specify package name to install" - exit 1 -fi - -source /etc/scratchpkg.conf -pkgname=$1 -checkpkg - -if [ -d $index_dir/$1 ]; then - echo "Package $1 already installed" && exit 0 -fi - -for i in $(deplist $1 | awk '{print $1}'); do - if [ -d $index_dir/$i ]; then - continue - else - if [ $UID != 0 ]; then - if [ -x /usr/bin/fakeroot ]; then - echo "==> Build using fakeroot" - fakeroot scratch -p $i && sudo scratch -p $i -i || exit 1 - else - sudo scratch -p $i -i || exit 1 - fi +depinst() { + + for i in $(deplist $1 | awk '{print $1}'); do + if [ -d $INDEX_DIR/$i ]; then + continue else - scratch -p $i -i || exit 1 + msg "Installing $i..." + if [ $UID != 0 ]; then + sudo scratch -p $i -i + else + scratch -p $i -i + fi + if [ ! -d $INDEX_DIR/$i ]; then + msgerr "Failed installing $i." + msgerr "Press ENTER to skip and continue, press CTRL + C to cancel." + read + fi fi - if [ ! -d $index_dir/$i ]; then - echo "Error installing $i..." - read - fi - fi -done + done + +} + +checkpkg +depinst exit 0 diff --git a/extra/deplist b/extra/deplist index 5ab1a97..d62ec43 100755 --- a/extra/deplist +++ b/extra/deplist @@ -2,7 +2,7 @@ calcdep() { - dep=$(scratch -d $1 | awk '{print $3}') + dep=$(scratch -d $1 | grep -v "port not exist" | awk '{print $3}') for i in $dep; do deps="$deps $i" done @@ -34,23 +34,22 @@ checkpkg() { [ "$PORT_EXIST" ] || (echo "Port $pkgname not exist" && exit 1) } -index_dir="/var/spkg/index" +INDEX_DIR="/var/lib/scratchpkg/index" +CONF_FILE="/etc/scratchpkg.conf" if [ ! "$1" ]; then - echo "specify package name to list its dependencies" + echo "Please specify package name to list its dependencies" exit 1 fi -source /etc/scratchpkg.conf +source "$CONF_FILE" +source "/usr/share/scratchpkg/color" pkgname=$1 checkpkg # check for existence port calcdep $pkgname # calculate dependencies loop # loop through all dependencies -#echo $deps | tr ' ' '\n' -#read - # filter all same dependencies and sort backwards for i in $(echo $deps | tr ' ' '\n'); do [ $(echo $filterdep | tr ' ' '\n' | grep -x $i) ] || filterdep="$filterdep $i" @@ -59,8 +58,8 @@ done filterdep="$filterdep $pkgname" # add package to install to final dependency list for alldep in $(echo $filterdep | tr ' ' '\n'); do - if [ -d $index_dir/$alldep ]; then - echo "$alldep [installed]" + if [ -d $INDEX_DIR/$alldep ]; then + echo -e "$alldep ${color_green}[installed]${color_reset}" else echo "$alldep" fi diff --git a/extra/libdepends b/extra/libdepends index 97afb96..b0386f8 100755 --- a/extra/libdepends +++ b/extra/libdepends @@ -1,12 +1,17 @@ #!/bin/bash -e +INDEX_DIR="/var/lib/scratchpkg/index" + +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" + if [ ! $1 ]; then - echo -e "this script requires one arguments." - exit 1 + msgerr "This script requires one arguments." + exit 1 fi -if [ ! -d /var/spkg/index/$1 ]; then - echo "Package $1 not installed" +if [ ! -d $INDEX_DIR/$1 ]; then + msgerr "Package '$1' not installed." exit 1 fi @@ -18,11 +23,10 @@ pushd / >/dev/null for i in ${NEEDED_LIB[@]}; do if [ "$i" != "ld-linux-x86-64.so.2" ]; then libpath=$(ldd "$LINE" | grep -v "not found" | grep -w "$i" | awk '{print $3}') - #echo "==> $libpath" if [ "$libpath" ]; then FILEPATH=$(readlink -f $(echo $libpath)) FILENAME=$(echo $FILEPATH | sed -e '1s/^.//') - PKG_NAME=$(basename $(dirname $(grep -Rx $FILENAME /var/spkg/index | cut -d ':' -f1))) + PKG_NAME=$(basename $(dirname $(grep -Rx $FILENAME $INDEX_DIR | cut -d ':' -f1))) if [ "$PKG_NAME" != $1 ]; then if [ ! "$(echo "$deppkg" | grep -w "$PKG_NAME")" ]; then deppkg="$deppkg $PKG_NAME " @@ -34,7 +38,7 @@ pushd / >/dev/null fi done esac - done < <(tac /var/spkg/index/$1/.files | grep -E ^"(bin/|lib/|libexec/|sbin/|usr/bin/|usr/lib/|usr/libexec/|usr/sbin/)" | grep -v "/$") + done < <(tac $INDEX_DIR/$1/.files | grep -E ^"(bin/|lib/|libexec/|sbin/|usr/bin/|usr/lib/|usr/libexec/|usr/sbin/)" | grep -v "/$") popd >/dev/null echo "Shared lib from package(s):" diff --git a/extra/listinstall b/extra/listinstall index a63fe7f..a25ed53 100755 --- a/extra/listinstall +++ b/extra/listinstall @@ -1,37 +1,38 @@ -#!/bin/bash +#!/bin/bash -e -index_dir="/var/spkg/index" +INDEX_DIR="/var/lib/scratchpkg/index" + +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" if [ ! "$1" ]; then - echo "specify list file" + msgerr "Please specify list file." exit 1 fi if [ ! -f "$1" ]; then - echo "file $1 not exist" + msgerr "File '$1' not exist." exit 1 fi list=$(cat $1) for i in $list; do - if [ -d $index_dir/$i ]; then - echo "$i is installed" + if [ -d $INDEX_DIR/$i ]; then + msg "$i is installed" else - echo "installing $i..." + msg "installing $i..." if [ $UID != 0 ]; then - if [ -x /usr/bin/fakeroot ]; then - echo "==> Build using fakeroot" - fakeroot scratch -p $i && sudo scratch -p $i -i - else - sudo scratch -p $i -i - fi + sudo scratch -p $i -i else scratch -p $i -i fi - if [ ! -d $index_dir/$i ]; then - echo "Error installing $i..." + if [ ! -d $INDEX_DIR/$i ]; then + msgerr "Failed installing $i." + msgerr "Press ENTER to skip and continue, press CTRL + C to cancel." read fi fi done + +exit 0 diff --git a/extra/revdep b/extra/revdep index 5e0d913..d2bc84a 100755 --- a/extra/revdep +++ b/extra/revdep @@ -1,9 +1,9 @@ #!/bin/bash -e -INDEX_DIR="/var/spkg/index" -COLOR="/usr/share/scratchpkg/color" +INDEX_DIR="/var/lib/scratchpkg/index" -. $COLOR +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" onepkg() { @@ -58,14 +58,14 @@ allpkg() { echo -e "${color_green}>>>${color_reset} $rebuild" done else - echo "All packages is doing fine." + msg "All packages is doing fine." fi } if [ "$1" ]; then if [ ! -d "$INDEX_DIR/$1" ]; then - echo "Package '$1' not installed" + msgerr "Package '$1' not installed" exit 1 else onepkg $1 diff --git a/extra/sysupdate b/extra/sysupdate index 8e3f1e6..5301f63 100755 --- a/extra/sysupdate +++ b/extra/sysupdate @@ -1,5 +1,8 @@ #!/bin/bash -e +source "/usr/share/scratchpkg/color" +source "/usr/share/scratchpkg/message" + faileduppkg=() successuppkg=() @@ -10,27 +13,28 @@ if [[ ! $(scratch -cu | grep "up to date") ]]; then for i in ${outdatepkg[@]}; do if [ $UID != 0 ]; then if [ $(type -pa sudo) ]; then - echo -e "[ $count/$totalopkgs ] Updating package $i..." + echo -e "[ $count/$totalopkgs ] Updating $i..." sudo scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) else echo "Updating package need root access!" exit 1 fi else - echo -e "[ $count/$totalopkgs ] Updating package $i..." + echo -e "[ $count/$totalopkgs ] Updating $i..." scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i) fi echo ((count++)) done else - echo "All packages is up to date." + msg "All packages is up to date." exit 0 fi if [ "${#successuppkg[@]}" -gt 0 ]; then - echo "Success update this package(s):" + echo "Successfully update this package(s):" echo ${successuppkg[@]} | tr ' ' '\n' + echo fi if [ "${#faileduppkg[@]}" -gt 0 ]; then diff --git a/functions/functions b/functions/functions index 6b7404e..29d5c44 100644 --- a/functions/functions +++ b/functions/functions @@ -4,6 +4,7 @@ FUNCTIONS=${FUNCTIONS:-'/usr/share/scratchpkg'} source "$FUNCTIONS/options" source "$FUNCTIONS/color" +source "$FUNCTIONS/message" ### SET SOME VALUE ### CONF_FILE="/etc/scratchpkg.conf" @@ -49,34 +50,6 @@ popd() { command popd >/dev/null } -msg() { - echo -e "${color_green}==>${color_reset} $1" -} - -msginfo() { - echo -e "${color_cyan}==> INFO:${color_reset} $1" -} - -msgerr() { - echo -e "${color_red}==> ERROR:${color_reset} $1" -} - -msgwarn() { - echo -e "${color_yellow}==> WARNING:${color_reset} $1" -} - -msg2() { - echo -e "${color_blue} ->${color_reset} $1" -} - -msg3() { - echo -e "$1" -} - -msg4() { - echo -e " $1" -} - rmdir_silent() { command rmdir "$@" 2> /dev/null } diff --git a/functions/message b/functions/message new file mode 100644 index 0000000..b1ce9d3 --- /dev/null +++ b/functions/message @@ -0,0 +1,29 @@ +#!/bin/bash + +msg() { + echo -e "${color_green}==>${color_reset} $1" +} + +msginfo() { + echo -e "${color_cyan}==> INFO:${color_reset} $1" +} + +msgerr() { + echo -e "${color_red}==> ERROR:${color_reset} $1" +} + +msgwarn() { + echo -e "${color_yellow}==> WARNING:${color_reset} $1" +} + +msg2() { + echo -e "${color_blue} ->${color_reset} $1" +} + +msg3() { + echo -e "$1" +} + +msg4() { + echo -e " $1" +}