diff options
author | piernov <piernov@piernov.servegame.org> | 2011-06-02 15:08:03 +0200 |
---|---|---|
committer | piernov <piernov@piernov.servegame.org> | 2011-06-02 15:08:03 +0200 |
commit | 762f732c33432c9a6f488dd5618e19b26fe47609 (patch) | |
tree | 878104dccdc4389a1f523472f2f4e08a24e99777 /modules/ports | |
parent | ec823fb412e4574e4d2dcd4c0f58dff01ee549e6 (diff) | |
download | rbjbbot-762f732c33432c9a6f488dd5618e19b26fe47609.tar.gz rbjbbot-762f732c33432c9a6f488dd5618e19b26fe47609.tar.bz2 rbjbbot-762f732c33432c9a6f488dd5618e19b26fe47609.tar.xz rbjbbot-762f732c33432c9a6f488dd5618e19b26fe47609.zip |
Diffstat (limited to 'modules/ports')
-rwxr-xr-x | modules/ports/drivers/git | 28 | ||||
-rwxr-xr-x | modules/ports/drivers/hg | 27 | ||||
-rwxr-xr-x | modules/ports/drivers/httpup | 27 | ||||
-rwxr-xr-x | modules/ports/drivers/rsync | 143 | ||||
-rwxr-xr-x | modules/ports/ports | 188 | ||||
-rw-r--r-- | modules/ports/recipes.git | 2 |
6 files changed, 415 insertions, 0 deletions
diff --git a/modules/ports/drivers/git b/modules/ports/drivers/git new file mode 100755 index 0000000..e4b301b --- /dev/null +++ b/modules/ports/drivers/git @@ -0,0 +1,28 @@ +#!/bin/sh +# +# /etc/ports/drivers/git: git driver script for ports(8) +# + +if [ $# -ne 1 ]; then + echo "usage: $0 <file>" >&2 + exit 1 +fi + +. $1 + +if [ -z "$ROOT_DIR" ]; then + echo "ROOT_DIR not set in '$1'" >&2 + exit 2 +fi +if [ -z "$URL" ]; then + echo "URL not set in '$1'" >&2 + exit 2 +fi + +if [ -d $ROOT_DIR ]; then + cd $ROOT_DIR + git pull +else + git clone $URL $ROOT_DIR +fi +# End of file. diff --git a/modules/ports/drivers/hg b/modules/ports/drivers/hg new file mode 100755 index 0000000..776cb89 --- /dev/null +++ b/modules/ports/drivers/hg @@ -0,0 +1,27 @@ +#!/bin/sh +# +# /etc/ports/drivers/hg: mercurial driver script for ports(8) +# + +if [ $# -ne 1 ]; then + echo "usage: $0 <file>" >&2 + exit 1 +fi + +. $1 + +if [ -z "$ROOT_DIR" ]; then + echo "ROOT_DIR not set in '$1'" >&2 + exit 2 +fi +if [ -z "$URL" ]; then + echo "URL not set in '$1'" >&2 + exit 2 +fi + +for REPO in $URL; do + PORT=`echo $REPO | sed -n '/#.*$/s|^.*#||p'` + hg -v clone $REPO $ROOT_DIR/$PORT +done + +# End of file. diff --git a/modules/ports/drivers/httpup b/modules/ports/drivers/httpup new file mode 100755 index 0000000..5c8db84 --- /dev/null +++ b/modules/ports/drivers/httpup @@ -0,0 +1,27 @@ +#!/bin/sh +# +# /etc/ports/drivers/httpup: httpup driver script for ports(8) +# + +if [ $# -ne 1 ]; then + echo "usage: $0 <file>" >&2 + exit 1 +fi + +. $1 + +if [ -z "$ROOT_DIR" ]; then + echo "ROOT_DIR not set in '$1'" >&2 + exit 2 +fi +if [ -z "$URL" ]; then + echo "URL not set in '$1'" >&2 + exit 2 +fi + +for REPO in $URL; do + PORT=`echo $REPO | sed -n '/#.*$/s|^.*#||p'` + httpup sync $REPO $ROOT_DIR/$PORT +done + +# End of file. diff --git a/modules/ports/drivers/rsync b/modules/ports/drivers/rsync new file mode 100755 index 0000000..0908632 --- /dev/null +++ b/modules/ports/drivers/rsync @@ -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 <file>\n"; + exit 1; +} + +open(FILE, $ARGV[0]) or error("Couldn't open $ARGV[0]"); +while (<FILE>) +{ + 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 (<FILE>) + { + 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 rsync://' . $host . '/' . $collection . '|') or error("Couldn't open pipe to rsync"); +while (<PIPE>) +{ + 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 --exclude=.footprint.x86_64 --exclude=.md5sum.x86_64 --log-format "%o %n" rsync://' . $host . "/$collection $destination|") or error("Couldn't open pipe to rsync"); +while (<PIPE>) +{ + 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/modules/ports/ports b/modules/ports/ports new file mode 100755 index 0000000..ab44353 --- /dev/null +++ b/modules/ports/ports @@ -0,0 +1,188 @@ +#!/bin/bash +# +# ports +# +# Copyright (c) 2002-2004 Per Liden +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +# USA. +# + +VERSION="1.9-rbjbbot" +PORTS_DIR="./" + +check_ports_dir() { + if [ ! -d "$PORTS_DIR" ]; then + echo "$COMMAND: directory '$PORTS_DIR' not found" + exit 1 + fi +} + +update_ports() { + #if [ "`id -u`" != "0" ]; then + #echo "$COMMAND: only root can update ports" + #exit 1 + #fi + + shopt -s nullglob + export PORTS_DIR + + if [ "$OPT_COLLECTIONS" ]; then + # Update selected collections + for collection in $OPT_COLLECTIONS; do + collection_exists=no + for file in ./$collection.*; do + collection_exists=yes + done + if [ "$collection_exists" = "yes" ]; then + for driver in ./drivers/*; do + if [ -x $driver ]; then + suffix=`basename $driver` + file=./$collection.$suffix + if [ -f $file ]; then + $driver $file + fi + fi + done + else + echo "$COMMAND: collection '$collection' not found" + fi + done + else + # Update all collections + for driver in ./drivers/*; do + if [ -x $driver ]; then + suffix=`basename $driver` + for file in ./*.$suffix; do + $driver $file + done + fi + done + + if [ ! "$driver" ]; then + echo "$COMMAND: no driver(s) installed" + fi + fi +} + +list_ports() { + cd $PORTS_DIR && find . -name Pkgfile -follow -printf "%h\n" | sed 's|^./||g' | sort +} + +list_differences_at_exit() { + rm $installed_list $ports_list $output $output_sorted &> /dev/null +} + +list_differences() { + installed_list=`mktemp` || exit 1 + ports_list=`mktemp` || exit 1 + output=`mktemp` || exit 1 + output_sorted=`mktemp` || exit 1 + found_diff="no" + + trap list_differences_at_exit EXIT + + pkginfo -i >> $installed_list + ports -l >> $ports_list + + for package in `cat $installed_list | gawk '{ print $1 }'`; do + installed_version=`cat $installed_list | grep "^$package " | gawk '{ print $2 }'` + port_list=`cat $ports_list | grep "/$package\$"` + for port in $port_list; do + port_version=`cd $PORTS_DIR/$port; . Pkgfile; echo $version-$release` + if [ "$installed_version" != "$port_version" ]; then + echo "${port%/*} $package $port_version $installed_version" >> $output + found_diff="yes" + fi + done + done + + if [ "$found_diff" = "yes" ]; then + echo "Collection Name Port Installed" >> $output_sorted + sort $output >> $output_sorted + column -t $output_sorted + else + echo "No differences found" + fi +} + +print_try_help() { + echo "Try '$COMMAND --help' for more information." +} + +print_help() { + echo "usage: $COMMAND [options] [collection ...]" + echo "options:" + echo " -u, --update update ports" + echo " -l, --list list ports" + echo " -d, --diff list version differences" + echo " -v, --version print version and exit" + echo " -h, --help print help and exit" +} + +parse_options() { + OPT_MODE="" + OPT_COLLECTIONS="" + + for OPT in "$@"; do + case $OPT in + -u|--update) + OPT_MODE="update" ;; + -l|--list) + OPT_MODE="list" ;; + -d|--diff) + OPT_MODE="diff" ;; + -v|--version) + echo "$COMMAND $VERSION" + exit 0 ;; + -h|--help) + print_help + exit 0 ;; + -*) + echo "$COMMAND: invalid option $OPT" + print_try_help + exit 1 ;; + *) + OPT_COLLECTIONS="$OPT_COLLECTIONS $OPT" ;; + esac + done +} + +main() { + parse_options "$@" + + if [ "$OPT_MODE" = "update" ]; then + check_ports_dir + update_ports + elif [ "$OPT_MODE" = "list" ]; then + check_ports_dir + list_ports + elif [ "$OPT_MODE" = "diff" ]; then + check_ports_dir + list_differences + else + echo "$COMMAND: option missing" + print_try_help + exit 1 + fi + + exit 0 +} + +COMMAND=`basename $0` + +main "$@" + +# End of file diff --git a/modules/ports/recipes.git b/modules/ports/recipes.git new file mode 100644 index 0000000..2f9bf42 --- /dev/null +++ b/modules/ports/recipes.git @@ -0,0 +1,2 @@ +ROOT_DIR=./recipes +URL=git://upyum.com/recipes.git |