Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding a -as-lib switch to pacmatic, adding cron-pacmatic

  • Loading branch information...
commit cc4021e7f1ba16e721d66856e6913fbf2c519b37 1 parent 33fb40d
@chmduquesne authored
Showing with 116 additions and 74 deletions.
  1. +38 −0 cron-pacmatic
  2. +78 −74 pacmatic
View
38 cron-pacmatic
@@ -0,0 +1,38 @@
+#!/usr/bin/env sh
+
+. /usr/bin/pacmatic --as-lib
+
+if [ $# -eq 0 ]; then
+ echo "usage $0 <your@mail.tld>"
+ echo "for this to work, you need to set the mail command correctly"
+ echo "for example, see https://bbs.archlinux.org/viewtopic.php?id=66822"
+ exit
+fi
+
+init_fakeroot_db()
+{
+ mkdir -p /tmp/localsync
+ ln -s /var/lib/pacman/local /tmp/localsync &>/dev/null
+}
+
+[ -d /tmp/localsync/ ] || init_fakeroot_db
+
+pending_updates() # none : list of packages
+{
+ pacman -Qqu --dbpath /tmp/localsync/ | egrep -vi '^(Checking|warning|Remove|Total)' | tr '\n' ' '
+}
+
+# Get pending updates, but only dowload them
+fakeroot pacman -Syy --dbpath /tmp/localsync/ &> /dev/null
+
+packages=`pending_updates`
+
+if [[ -n $packages ]]; then
+ mail_body=`mktemp`
+ check_news >> $mail_body
+ mail_summary >> $mail_body
+ echo "Recent ML chatter: $mail_counts" >> $mail_body
+ echo "Pacman updates: $packages" >> $mail_body
+ cat $mail_body |\
+ mail -s "Updates available on $(hostname)" $1
+fi
View
152 pacmatic
@@ -25,7 +25,7 @@
# Backup db.
# Conf file for vars.
-# sledgehammer says to watch arch-dev-public and arch-commits
+# sledgehammer says to watch arch-dev-public and arch-commits
# (sledgehammer also reads no MLs)
mail_summary() # None : None, set $mail_counts and save new stamp
@@ -119,13 +119,13 @@ check_news() # none : news (logfile)
fi
# paste is much happier with files
paste "$pubdates" "$descriptions" | tac | while read -r line ; do
- line2=`xml_decode "$line"`
- this_date=`echo -n "$line2" | cut -d ' ' -f 1 | sed 's/ //g'`
- if [ $(( $this_date )) -gt $(( $last_news_date )) ]; then
- echo "$line2" | cut -d ' ' -f 2- | sed -e 's|<br />|\n|g' -e 's|\\n||g' -e 's|<p>|\n|g' -e 's|</p>||g'
- echo ""
- echo "$line2" >> $log_file
- fi
+ line2=`xml_decode "$line"`
+ this_date=`echo -n "$line2" | cut -d ' ' -f 1 | sed 's/ //g'`
+ if [ $(( $this_date )) -gt $(( $last_news_date )) ]; then
+ echo "$line2" | cut -d ' ' -f 2- | sed -e 's|<br />|\n|g' -e 's|\\n||g' -e 's|<p>|\n|g' -e 's|</p>||g'
+ echo ""
+ echo "$line2" >> $log_file
+ fi
done
rm "$pubdates"
rm "$descriptions"
@@ -166,77 +166,81 @@ if [ $# -eq 0 ]; then
docs
exit
fi
-current_time=`date +%s`
-sync_time=`last_sync`
-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
+if [ $1 != "--as-lib" ]; then
+
+ current_time=`date +%s`
+ sync_time=`last_sync`
+ 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
;;
- -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
-
-old_pc=`pacnew_count`
-$pacman_program $*
-exit_code=$?
-exit_time=`date "+[%F %H:%M]"`
-if [ -w "$pacman_log" ]; then
- echo "$exit_time Exited with code $exit_code" >> "$pacman_log"
-fi
-new_pc=`pacnew_count`
-add_pc=$(( $new_pc - $old_pc ))
+ -Sy|-Syy)
+ #check_news
+ if [ $(( $current_time - $upgrade_time )) -gt $(( $warn_time )) ]; then
+ echo -e "\nWarning: stale installation, rerun with '-Syu'\n"
+ fi
+ ;;
+ esac
+
+ old_pc=`pacnew_count`
+ $pacman_program $*
+ exit_code=$?
+ exit_time=`date "+[%F %H:%M]"`
+ if [ -w "$pacman_log" ]; then
+ echo "$exit_time Exited with code $exit_code" >> "$pacman_log"
+ fi
+ new_pc=`pacnew_count`
+ add_pc=$(( $new_pc - $old_pc ))
-# this section is a little clumsy
+ # this section is a little clumsy
-if [ "$new_pc" = "0" ]; then
- echo "No pacnew files to update."
- exit 0
-fi
+ if [ "$new_pc" = "0" ]; then
+ echo "No pacnew files to update."
+ exit 0
+ fi
-case "$1" in
- -Syu|-Su|-S|-Sy)
- 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)
- $pacdiff_program
- ;;
- N|n)
- ;;
- *)
- ;;
- esac
- ;;
- *)
+ case "$1" in
+ -Syu|-Su|-S|-Sy)
+ 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)
+ $pacdiff_program
+ ;;
+ N|n)
+ ;;
+ *)
+ ;;
+ esac
;;
-esac
+ *)
+ ;;
+ esac
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.