Skip to content

Loading…

cron-pacmatic #3

Merged
merged 11 commits into from

2 participants

@chmduquesne

Hi,

(7 months later)

Today I took the time to fix my code as suggested in https://bbs.archlinux.org/viewtopic.php?pid=974952#p974952. Does it fit your standards? Also, there are also a lot of blank space fixes (the scripts I have in my editor for auto-correcting myself are to blame). If you prefer tabs over spaces (or less spaces to indent), let me know, I can easily fix that.

I essentially added a --as-lib switch to pacmatic in order to be able to source it easily (as you suggested).
I am also using the --dbpath trick you suggested for avoiding messing with pacman's db.

I did not modify the manpage nor the PKGBUILD.

The suggested topic is the first link I could think of, but if you have a better suggestion, any other link is fine.

@keenerd
Owner
@chmduquesne

Glad you like this!

For the exit stuff, I thought about this, but I could not find a different way to proceed: if I add "exit" when the "--as-libs" flag is present, then when I source the script, "exit" is called and the caller exists too. If you know a workaround, I'd be glad to learn about it.

@chmduquesne

and the caller exits too

@keenerd
Owner
@chmduquesne

I did not realize I could use return! Thank you.

@keenerd
Owner
@chmduquesne

At first I was using #!env sh, but I saw you were using #!/bin/bash in pacmatic, so I changed it to comply with your code. It's guaranteed to work in standard sh, though. Feel free to modify as you want.

@keenerd keenerd merged commit 806da84 into keenerd:master
@chmduquesne

Hey,

About that pull request, I forgot to add myself in the list of contributors in the manpage. Could you add me as "Christophe-Marie Duquesne" in the next release?

Thank you

@keenerd
Owner
@chmduquesne

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 68 additions and 28 deletions.
  1. +1 −0 PKGBUILD
  2. +38 −0 cron-pacmatic
  3. +29 −28 pacmatic
View
1 PKGBUILD
@@ -16,6 +16,7 @@ md5sums=('d1e225b855bebfe6e7f031af1a392e14')
package() {
cd "$srcdir/$pkgname"
install -D -m 0755 $pkgname "$pkgdir/usr/bin/$pkgname"
+ #install -D -m 0755 cron-$pkgname "$pkgdir/usr/bin/cron-$pkgname"
install -D -m 0644 $pkgname.1 "$pkgdir/usr/share/man/man1/$pkgname.1"
}
View
38 cron-pacmatic
@@ -0,0 +1,38 @@
+#! /bin/bash
+
+. /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 "See https://wiki.archlinux.org/index.php/Msmtp#Using_the_mail_command"
+ 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 in a safe directory
+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
57 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,6 +166,9 @@ if [ $# -eq 0 ]; then
docs
exit
fi
+
+[ $1 == "--as-lib" ] && return
+
current_time=`date +%s`
sync_time=`last_sync`
upgrade_time=`last_upgrade`
@@ -183,7 +186,7 @@ case "$1" in
;;
esac
-case "$1" in
+case "$1" in
-Syu|-Su|-Suy|-Syyu|-Syuy|-Suyy)
#check_news
;;
@@ -192,13 +195,13 @@ case "$1" in
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`
@@ -220,23 +223,21 @@ 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
- ;;
+ 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
-
-
Something went wrong with that request. Please try again.