From 9715efd33102d532e4f4244869c0b646eeb9d293 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Sun, 12 Nov 2017 23:15:14 +0800 Subject: [PATCH] updated --- buildpkg | 13 ++----------- functions/functions | 22 ++++++++++++++++++++++ installpkg | 27 ++++++++++++++------------- removepkg | 20 ++------------------ scratch | 29 ++++++++++++++++++++++++----- 5 files changed, 64 insertions(+), 47 deletions(-) diff --git a/buildpkg b/buildpkg index 9e3caff..5801b67 100755 --- a/buildpkg +++ b/buildpkg @@ -81,16 +81,7 @@ getsource() { downloadsource $sources fi done -} - -checkforwget() { - - if [ ! -e /usr/bin/wget ]; then - msgerr "Wget not installed." - exitscript1 - fi -} - +} downloadsource(){ @@ -114,7 +105,7 @@ downloadsource(){ if [ -f $SOURCE_DIR/$tarballname ]; then msg "Source file ${color_green}$tarballname${color_reset} found." else - checkforwget + checktool wget if [ -f $SOURCE_DIR/$tarballname.partial ]; then msg "Resuming ${color_green}$1${color_reset}." $WGETRESUME $tarballurl && mv $SOURCE_DIR/$tarballname.partial $SOURCE_DIR/$tarballname || exitscript1 diff --git a/functions/functions b/functions/functions index fec5068..ad480d3 100644 --- a/functions/functions +++ b/functions/functions @@ -74,6 +74,28 @@ rm_silent() { command rm "$@" 2> /dev/null } +needroot() { + + if [ $UID != 0 ]; then + if [ "$#" -eq 0 ]; then + needroot "This operation" + else + msgerr "$@ need root access!" + fi + exit 1 + fi + +} + +checktool() { + + if ! type -pa $1 &>/dev/null; then + msgerr "$1 not exist in your system!" + exit 1 + fi + +} + updmimedb() { # msg2 "Update mime database..." diff --git a/installpkg b/installpkg index fb76ee6..ee5a9cb 100755 --- a/installpkg +++ b/installpkg @@ -449,7 +449,7 @@ parse_options() { NO_ORPHAN_CHECK=yes ;; *.spkg.txz) - [ -f "$1" ] && PKGNAME="$1" || msg "${color_red}$1${color_reset} not exist." + PKGNAME="$1" ;; -h|--help) SHOW_HELP=yes @@ -470,6 +470,18 @@ main() { parse_options "$@" + ### NOT STATED PACKAGE ### + if [ -z $PKGNAME ]; then + msgerr "Please state the package to install." + exit 1 + fi + + ### CHECK EXISTANT OF PACKAGE FILE ### + if [ ! -f $PKGNAME ]; then + msgerr "Package ${color_red}$1${color_reset} not exist!" + exit 1 + fi + ### DISABLE COLOR ### if [ "$NO_COLOR" ]; then nocolor @@ -481,12 +493,7 @@ main() { exit 0 fi - ### CHECK FOR ROOT ACCESS ### - if [ "$UID" != "0" ]; then - msgerr "${color_red}Installing package need root access!${color_reset}" - exit 1 - fi - + needroot "Installing package" check_directory ### CHECK FOR LOCK FILE ### @@ -496,12 +503,6 @@ main() { exit 1 fi - ### NOT STATED PACKAGE ### - if [ -z $PKGNAME ]; then - msgerr "${color_red}Please state the package to install.${color_reset}" - exit 1 - fi - ### GET NAME, VERSION, RELEASE FROM PACKAGE ### getname # get info from package diff --git a/removepkg b/removepkg index 82389e0..44015be 100755 --- a/removepkg +++ b/removepkg @@ -108,18 +108,6 @@ run_postremove() { } -updateinfopages() { - - pushd /usr/share/info - if [ -f dir ]; then - rm dir - fi - for f in *; do - install-info $f dir 2>/dev/null - done - popd -} - getoldname() { iname=$(cat $INDEX_DIR/$1/.pkginfo | grep ^name | cut -d " " -f3) @@ -254,17 +242,13 @@ main() { nocolor fi + needroot "Removing package" + if [ -z $RMNAME ]; then msgerr "Please state package name for remove." exit 1 fi - ### CHECK FOR ROOT ACCESS ### - if [ "$UID" != "0" ]; then - msgerr "Removing package need root access." - exit 1 - fi - check_directory ### CHECK FOR LOCK FILE ### diff --git a/scratch b/scratch index 67dd1e4..d239058 100755 --- a/scratch +++ b/scratch @@ -382,11 +382,7 @@ pkgcache() { clearpkgcache() { - ### CHECK FOR ROOT ACCESS ### - if [ "$UID" != "0" ]; then - msgerr "${color_red}Removing package & source cache need root access!${color_reset}" - exit 1 - fi + needroot "Removing package & source cache" getpkgcache @@ -404,6 +400,20 @@ clearpkgcache() { } +updports() { + + needroot "Updating ports" + + for repo in ${PORT_REPO[@]}; do + portname=$(basename $(echo $repo)) + if [ -f /etc/ports/$portname.httpup ]; then + . /etc/ports/$portname.httpup + httpup sync $URL $repo + fi + done + +} + interrupted() { exit 1 } @@ -512,6 +522,9 @@ parse_options() { --clear-cache) CLEAR_PKG_CACHE=yes ;; + -up|--update-ports) + UPD_PORTS=yes + ;; -c|--cat-port) if [ ! "$2" ]; then msg "Option '$1' require an argument (package to show its port script)" @@ -637,6 +650,12 @@ main() { nocolor fi + ### UPDATE PORTS ### + if [ $UPD_PORTS ]; then + updports + exit 0 + fi + ### LIST PACKAGES & SOURCE CACHE ### if [ $PKG_CACHE ]; then pkgcache