From c905b41b43c594bb4e53dd078d7efeb1fb2dabbe Mon Sep 17 00:00:00 2001 From: simonzack Date: Fri, 16 Jan 2015 07:51:43 +1100 Subject: [PATCH 1/3] removed space from HEREDOC so it works with the sublime text syntax highlighter --- pacmatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pacmatic b/pacmatic index 5f08248..e2f2e93 100755 --- a/pacmatic +++ b/pacmatic @@ -153,7 +153,7 @@ pacnew_count() # none : int docs() # none : docs { - cat << END + cat < Date: Fri, 16 Jan 2015 09:18:40 +1100 Subject: [PATCH 2/3] better commandline option parsing, to work with aur package managers --- pacmatic | 131 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 60 deletions(-) diff --git a/pacmatic b/pacmatic index e2f2e93..7390e22 100755 --- a/pacmatic +++ b/pacmatic @@ -180,50 +180,72 @@ To use Pacmatic's functionality in a script, source with END } +explode_args() +{ + unset OPTS + local arg=$1 + while [[ $arg ]]; do + [[ $arg = "--" ]] && OPTS+=("$@") && break; + if [[ ${arg:0:1} = "-" && ${arg:1:1} != "-" ]]; then + OPTS+=("-${arg:1:1}") + (( ${#arg} > 2 )) && arg="-${arg:2}" || { shift; arg=$1; } + else + OPTS+=("$arg"); shift; arg=$1 + fi + done +} + if [ $# -eq 0 ]; then docs exit fi -[ $1 == "--as-lib" ] && return +orig_args=$* +explode_args "$@" +set -- "${OPTS[@]}" +unset OPTS + +while [[ $1 ]]; do + case "$1" in + --as-lib) return;; + --arch|--assume-installed|--cachedir|--color|--config|--gpgdir|--ignore|--ignoregroup|\ + --logfile|--print-format|-b|--dbpath|-o|--owns|-r|--root|-s|--search) shift;; + -S|--sync) SYNC=1;; + -U|--upgrade) UPGRADE=1;; + -y|--refresh) REFRESH=1;; + -u|--sysupgrade) SYSUPGRADE=1;; + -*) ;; + *) NAME=1;; + esac + shift +done -current_time=$(date +%s) -sync_time=$(last_sync) +if [ -z $REFRESH ]; then + sync_time=$(last_sync) +else + sync_time=$(date +%s) +fi upgrade_time=$(last_upgrade) -case "$1" in - -Syu|-Su|-Suy|-Syyu|-Syuy|-Suyy|-S|-Sy|-Syy) - # do not like this threading - check_news & - mail_summary - wait - echo "Recent ML chatter: $mail_counts" - if ( ! check_checkspace ); then - echo -e "\nPlease enable CheckSpace in pacman.conf" - fi - ;; -esac - -case "$1" in - -Syu|-Su|-Suy|-Syyu|-Syuy|-Suyy) - #check_news - ;; - -S) - #check_news - if [ $(( $sync_time - $upgrade_time )) -gt $(( $warn_time )) ]; then - echo -e "\nWarning: stale installation, rerun with '-Syu'\n" - fi - ;; - -Sy|-Syy) - #check_news - if [ $(( $current_time - $upgrade_time )) -gt $(( $warn_time )) ]; then - echo -e "\nWarning: stale installation, rerun with '-Syu'\n" - fi - ;; -esac +if [ ! -z $SYNC ]; then + # do not like this threading + check_news & + mail_summary + wait + echo "Recent ML chatter: $mail_counts" + if ( ! check_checkspace ); then + echo -e "\nPlease enable CheckSpace in pacman.conf" + fi +fi + +if [ ! -z $SYNC ] && [ -z $REFRESH ]; then + if [ $(( $sync_time - $upgrade_time )) -gt $(( $warn_time )) ]; then + echo -e "\nWarning: stale installation, rerun with '-Syu'\n" + fi +fi old_pc=$(pacnew_count) -$pacman_program $* +$pacman_program $orig_args exit_code=$? exit_time=$(date "+[%F %H:%M]") if [ -w "$pacman_log" ]; then @@ -232,30 +254,19 @@ fi new_pc=$(pacnew_count) add_pc=$(( $new_pc - $old_pc )) -# this section is a little clumsy - -if [ "$new_pc" = "0" ]; then - echo "No pacnew files to update." - exit 0 -fi - -case "$1" in - -Syu|-Su|-S|-Sy|-Syyu|-Syy) - echo -en "\n$new_pc pacnew files found ($add_pc added). Update files now? (Y/n) " - read char - if [ -z "$char" ]; then - $pacdiff_program - fi - case "$char" in - Y|y) +if [ ! -z $UPGRADE ] || ([ ! -z $SYNC ] && ([ ! -z $NAME ] || [ ! -z $SYSUPGRADE ])); then + if [ "$new_pc" = "0" ]; then + echo "No pacnew files to update." + else + echo -en "\n$new_pc pacnew files found ($add_pc added). Update files now? (Y/n) " + read char + if [ -z "$char" ]; then $pacdiff_program - ;; - N|n) - ;; - *) - ;; - esac - ;; - *) - ;; -esac + fi + case "$char" in + Y|y) $pacdiff_program;; + N|n) ;; + *) ;; + esac + fi +fi From 53bde1f24b49def75d0afb2a5488821a6ab7fced Mon Sep 17 00:00:00 2001 From: simonzack Date: Thu, 22 Jan 2015 17:33:00 +1100 Subject: [PATCH 3/3] html2text was made obsolete by the python package, which doesn't have a `-style` option --- pacmatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pacmatic b/pacmatic index 7390e22..32cf21b 100755 --- a/pacmatic +++ b/pacmatic @@ -129,7 +129,7 @@ check_news() # none : news (logfile) if [ $(( $this_date )) -gt $(( $last_news_date )) ]; then line3=$(cut -d ' ' -f 2- <<< "$line2") if which html2text >& /dev/null; then - echo "$line3" | html2text -style pretty | sed 's/\\n$//' + echo "$line3" | html2text | sed 's/\\n$//' else echo "$line3" | sed -e 's|
|\n|g' -e 's|\\n||g' -e 's|

|\n|g' -e 's|

||g' fi