Create clean tool branch.
[Archlinux-Stable.git] / abs
blobc21e96f6dd9134113e5de350f8ab7e03370c1d03
1 #!/bin/bash -e
3 # abs - download a PKGBUILD tree from a CVS repository
5 # Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Script Exit Reasons
23 # -------------------
24 # E_OK : Everything worked :)
25 # E_MISSING_PROGRAM : A program the script depends on is not installed.
26 # E_CONFIG_ERROR : Missing/incorrect configuration.
27 # E_INVALID_OPTION : User has passed unknown/invalid option to script.
30 myver='1.0'
31 BUG_REPORT_EMAIL='pacman-dev@archlinux.org'
32 eval CONFDIR="~/abs/conf"
33 PASSIVE='m'
35 # Source config files
36 if [ -r "$CONFDIR/abs.conf" ]; then
37 source "$CONFDIR/abs.conf"
40 # User based overrides
41 if [ -r ~/.abs.conf ]; then
42 source ~/.abs.conf
46 msg() {
47 local mesg=$1; shift
48 printf "==> ${mesg}\n" "$@" >&2
51 error() {
52 local mesg=$1; shift
53 printf "==> ERROR: ${mesg}\n" "$@" >&2
57 usage() {
58 printf "abs (pacman) %s - download a PKGBUILD tree from a CVS repository\n\n" "$myver"
59 printf "Usage %s [options] [repository...]\n\n" "$0"
60 printf "Options:\n"
61 printf " -p, --passive The connection is opened in passive mode.\n"
62 echo
63 printf " -h, --help Display this help message then exit.\n"
64 printf " -V, --version Display version information then exit.\n"
65 echo
66 printf "\
67 abs will synchronize build scripts from the CVS repository\n\
68 into %s. You can follow different package trees by\n\
69 editing %s files. If no argument is given, abs\n\
70 will synchronize from supfiles specified in %s.\n\n" \
71 "$ABSROOT" "$CONFDIR/supfile.*" "$CONFDIR/abs.conf"
72 printf "Report bugs to <%s>.\n" "$BUG_REPORT_EMAIL"
75 version() {
76 printf "abs (pacman) %s\n" "$myver"
77 printf "\
78 Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\
79 This is free software; see the source for copying conditions.\n\
80 There is NO WARRANTY, to the extent permitted by law.\n"
85 # Signal Traps
87 trap 'error "TERM signal caught. Exiting..."; exit 1' TERM HUP QUIT
88 trap 'error "Aborted by user! Exiting..."; exit 1' INT
89 trap 'error "An unknown error has occured. Exiting..."; exit 1' ERR
92 # Parse Command Line Options.
93 OPT_SHORT="hpV"
94 OPT_LONG="help,passive,version"
95 OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')"
96 if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then
97 # This is a small hack to stop the script bailing with 'set -e'
98 echo; usage; exit 1 # E_INVALID_OPTION;
100 eval set -- "$OPT_TEMP"
101 unset OPT_SHORT OPT_LONG OPT_TEMP
103 while true; do
104 case "$1" in
105 -p|--passive) PASSIVE='-';;
107 -h|--help) usage; exit 0;; # E_OK
108 -V|--version) version; exit 0;; # E_OK
110 --) OPT_IND=0; shift; break;;
111 *) usage; exit 1;; # E_INVALID_OPTION
112 esac
113 shift
114 done
116 if [ $# -gt 0 ]; then
117 SUPFILES=("$@")
121 # Check permissions and programs.
122 if [ ! -d "$ABSROOT" ]; then
123 error "%s does not exist or is not a directory." "$ABSROOT"
124 exit 1 # E_CONFIG_ERROR
125 elif [ ! -w "$ABSROOT" ]; then
126 error "You do not have write permissions in %s." "$ABSROOT"
127 exit 1 # E_CONFIG_ERROR
131 if [ "$(type -p csup)" ]; then
132 CVSUP="csup"
133 elif [ "$(type -p cvsup)" ]; then
134 CVSUP="cvsup"
135 else
136 error "Missing CVS synchronization utility. Install csup or cvsup."
137 exit 1 # E_MISSING_PROGRAM
141 # Begin script.
142 for sup in ${SUPFILES[@]}; do
143 case "$sup" in
144 testing)
145 if [ ! -d "$ABSROOT/$sup" ]; then
146 mkdir "$ABSROOT/$sup"
148 workdir="$ABSROOT/$sup"
152 if [ "$sup" != "${sup#!}" ]; then
153 continue
155 workdir="$ABSROOT"
157 esac
159 msg "Updating %s..." "$sup"
160 cd "$workdir"
161 echo $CVSUP -L 1 -r 0 -g -b "$workdir" -P "$PASSIVE" -c .sup "$CONFDIR/supfile.$sup"
162 $CVSUP -L 1 -r 0 -g -b "$workdir" -P "$PASSIVE" -c .sup "$CONFDIR/supfile.$sup"
163 done
165 exit 0 # E_OK
167 # vim: set ts=2 sw=2 noet: