From 7453e0de64940c446a8f87f11d75a52348e49a1f Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 13 Nov 2015 11:57:26 +0000 Subject: [PATCH] rsync: added new port --- rsync/.footprint | 19 ++++++ rsync/.md5sum | 4 ++ rsync/Pkgfile | 30 ++++++++++ rsync/rsync.driver | 143 +++++++++++++++++++++++++++++++++++++++++++++ rsync/rsyncd | 36 ++++++++++++ rsync/rsyncd.conf | 15 +++++ 6 files changed, 247 insertions(+) create mode 100644 rsync/.footprint create mode 100644 rsync/.md5sum create mode 100644 rsync/Pkgfile create mode 100644 rsync/rsync.driver create mode 100644 rsync/rsyncd create mode 100644 rsync/rsyncd.conf diff --git a/rsync/.footprint b/rsync/.footprint new file mode 100644 index 0000000..655d7bc --- /dev/null +++ b/rsync/.footprint @@ -0,0 +1,19 @@ +drwxr-xr-x root/root etc/ +drwxr-xr-x root/root etc/ports/ +drwxr-xr-x root/root etc/ports/drivers/ +-rwxr-xr-x root/root etc/ports/drivers/rsync +drwxr-xr-x root/root etc/rc.d/ +-rwxr-xr-x root/root etc/rc.d/rsyncd +-rw-r--r-- root/root etc/rsyncd.conf +drwxr-xr-x root/root usr/ +drwxr-xr-x root/root usr/bin/ +-rwxr-xr-x root/root usr/bin/rsync +drwxr-xr-x root/root usr/share/ +drwxr-xr-x root/root usr/share/man/ +drwxr-xr-x root/root usr/share/man/man1/ +-rw-r--r-- root/root usr/share/man/man1/rsync.1.gz +drwxr-xr-x root/root usr/share/man/man5/ +-rw-r--r-- root/root usr/share/man/man5/rsyncd.conf.5.gz +drwxr-xr-x root/root var/ +drwxr-xr-x root/root var/log/ +-rw-r--r-- root/root var/log/rsyncd.log (EMPTY) diff --git a/rsync/.md5sum b/rsync/.md5sum new file mode 100644 index 0000000..ba89c4e --- /dev/null +++ b/rsync/.md5sum @@ -0,0 +1,4 @@ +43bd6676f0b404326eee2d63be3cdcfe rsync-3.1.1.tar.gz +bd6cc8e2c83d5e845af20a30e105fb5f rsync.driver +d20f1ca0fb415a6788808c75170d951a rsyncd +b4e95fa8c8f3ae13cfdf616abd6a3960 rsyncd.conf diff --git a/rsync/Pkgfile b/rsync/Pkgfile new file mode 100644 index 0000000..1588003 --- /dev/null +++ b/rsync/Pkgfile @@ -0,0 +1,30 @@ +# Description: Utility for incremental file transfers over networks +# URL: http://rsync.samba.org +# Maintainer: CRUX System Team, core-ports at crux dot nu +# Depends on: acl + +name=rsync +version=3.1.1 +release=3 +source=(http://rsync.samba.org/ftp/$name/src/$name-$version.tar.gz \ + rsyncd.conf rsyncd rsync.driver) + +build () { + cd $name-$version + + ./configure --build=$CHOST \ + --host=$CTARGET \ + --prefix=/usr \ + --with-rsh=ssh \ + --with-included-popt \ + --with-included-zlib + + make + make DESTDIR=$PKG install + + install -d $PKG/etc/{rc.d,ports/drivers} $PKG/var/log + install -m 755 $SRC/rsyncd $PKG/etc/rc.d + install -m 644 $SRC/rsyncd.conf $PKG/etc + install -m 755 $SRC/rsync.driver $PKG/etc/ports/drivers/rsync + touch $PKG/var/log/rsyncd.log +} diff --git a/rsync/rsync.driver b/rsync/rsync.driver new file mode 100644 index 0000000..14dd3e5 --- /dev/null +++ b/rsync/rsync.driver @@ -0,0 +1,143 @@ +#!/usr/bin/perl +# +# /etc/ports/drivers/rsync: rsync(1) driver script for ports(8) +# + +use warnings; +use strict; +use File::Basename; + +my $host = ''; +my $collection = ''; +my $destination = ''; +my %new_checkouts; +my %old_checkouts; + +sub error +{ + my $message = shift; + print "Error: $message ($!)\nUpdating failed\n"; + exit 1; +} + +sub warning +{ + my $message = shift; + print "Warning: $message ($!)\n"; +} + +if ($#ARGV < 0) +{ + print "Usage: $0 \n"; + exit 1; +} + +open(FILE, $ARGV[0]) or error("Couldn't open $ARGV[0]"); +while () +{ + chomp; + if (/^host=(.*)/) { $host = $1; } + elsif (/^collection=(.*)/) { $collection = $1; } + elsif (/^destination=(.*)/) { $destination = $1; } +} +close(FILE); + +if ($host eq '') { error("Host field not set in $ARGV[0]"); } +if ($collection eq '') { error("Collection field not set in $ARGV[0]"); } +if ($destination eq '') { error("Destination field not set in $ARGV[0]"); } + +if (-e "$destination/.checkouts") +{ + # read the old .checkouts file into memory + open(FILE, "$destination/.checkouts") or error("Couldn't read checkouts from $destination/.checkouts"); + while () + { + chomp; + $old_checkouts{$_} = 1; + } + close(FILE); +} + +print "Updating file list from " . $host . "::$collection\n"; + +# get the remote file list (new .checkouts) +open(PIPE, 'rsync -crz --no-human-readable ' . $host . '::' . $collection . '|') or error("Couldn't open pipe to rsync"); +while () +{ + chomp; + + next if /^MOTD:/; # ignore MOTD lines + s/^(.{43})//; # ignore the first 43 characters (mode, date etc...) + next if /^.$/; # ignore the . directory + + $new_checkouts{$_} = 1; +} +close(PIPE); +error("Running rsync failed") unless $? == 0; + +print "Updating collection " . basename($destination) . "\n"; + +# now really run rsync +open(PIPE, 'rsync -crz --no-human-readable --log-format "%o %n" ' . $host . "::$collection $destination|") or error("Couldn't open pipe to rsync"); +while () +{ + chomp; + + if (/^recv (.*)/) + { + if ($old_checkouts{$1}) + { + s/^recv/ Edit/; + } + else + { + s/^recv/ Checkout/; + } + } + + print $_ . "\n"; +} +close(PIPE); +error("Running rsync failed") unless $? == 0; + +# save new checkouts into .checkouts +open(FILE, ">$destination/.checkouts") or error("Couldn't save checkouts to $destination/.checkouts"); +foreach my $checkout (sort keys %new_checkouts) +{ + print FILE "$checkout\n"; +} +close(FILE); + +# use chroot as an additional safety measure when removing files +chroot($destination) or error("Couldn't chroot into $destination"); +chdir('/'); + +# iterate through old checkouts, remove obsolete files +foreach my $checkout (sort keys %old_checkouts) +{ + if (!$new_checkouts{$checkout}) + { + if (-f $checkout) + { + print " Delete $checkout\n"; + unlink($checkout) or warning("Couldn't delete $checkout"); + } + } +} + +# iterate through old checkouts, remove obsolete directories +foreach my $checkout (sort keys %old_checkouts) +{ + if (!$new_checkouts{$checkout}) + { + if (-d $checkout) + { + print " Delete $checkout\n"; + rmdir($checkout) or warning("Couldn't delete $checkout"); + } + } +} + +print "Finished successfully\n"; + +# End of file diff --git a/rsync/rsyncd b/rsync/rsyncd new file mode 100644 index 0000000..bd2e8b2 --- /dev/null +++ b/rsync/rsyncd @@ -0,0 +1,36 @@ +#!/bin/sh +# +# /etc/rc.d/rsyncd: start/stop rsyncd daemon +# + +SSD=/sbin/start-stop-daemon +PROG=/usr/bin/rsync +PID=/var/run/rsyncd.pid +OPTS="--daemon" + +case $1 in +start) + $SSD --start --pidfile $PID --exec $PROG -- $OPTS + ;; +stop) + $SSD --stop --retry 10 --pidfile $PID + ;; +restart) + $0 stop + $0 start + ;; +status) + $SSD --status --pidfile $PID + case $? in + 0) echo "$PROG is running with pid $(cat $PID)" ;; + 1) echo "$PROG is not running but the pid file $PID exists" ;; + 3) echo "$PROG is not running" ;; + 4) echo "Unable to determine the program status" ;; + esac + ;; +*) + echo "usage: $0 [start|stop|restart|status]" + ;; +esac + +# End of file diff --git a/rsync/rsyncd.conf b/rsync/rsyncd.conf new file mode 100644 index 0000000..02bbdc6 --- /dev/null +++ b/rsync/rsyncd.conf @@ -0,0 +1,15 @@ +# +# /etc/rsyncd.conf +# + +pid file = /var/run/rsyncd.pid +log file = /var/log/rsyncd.log + +[test] + path = /tmp + comment = test share for rsyncd + hosts allow = 192.168.0.0/24 + read only = true + use chroot = true + +# End of file -- 2.26.2