summaryrefslogtreecommitdiff
path: root/scripts/abs.sh.in
blob: 491b965acbff2060c2dcc93c9e3815d1c32667d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash -e
#
#   abs - download a PKGBUILD tree from a CVS repository
#   @configure_input@
#
#   Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
#
#   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.
#

##
# Script Exit Reasons
# -------------------
#              E_OK : Everything worked :)
# E_MISSING_PROGRAM : A program the script depends on is not installed.
#    E_CONFIG_ERROR : Missing/incorrect configuration.
#  E_INVALID_OPTION : User has passed unknow/invalid option to script.
##

# gettext initialization
export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='@localedir@'

myver='@PACKAGE_VERSION@'
BUG_REPORT_EMAIL='@PACKAGE_BUGREPORT@'
CONFDIR="@sysconfdir@/abs"
PASSIVE='m'

# Source config files
if [ -r "$CONFDIR/abs.conf" ]; then
	source "$CONFDIR/abs.conf"
fi

# User based overrides
if [ -r ~/.abs.conf ]; then
	source ~/.abs.conf
fi


msg() {
	local mesg=$1; shift
	printf "==> ${mesg}\n" "$@" >&2
}

error() {
	local mesg=$1; shift
	printf  "==> $(gettext "ERROR:") ${mesg}\n" "$@" >&2
}


usage() {
	printf "$(gettext "abs (pacman) %s - download a PKGBUILD tree from a CVS repository")\n" "$myver"
	echo
	printf "$(gettext "Usage %s [options] [repository...]")\n" "$0"
	echo
	printf "$(gettext "Options:")\n"
	printf "$(gettext "  -p, --passive  The connection is opened in passive mode.")\n"
	echo
	printf "$(gettext "  -h, --help     Display this help message then exit.")\n"
	printf "$(gettext "  -V, --version  Display version information then exit.")\n"
	echo
	printf "$(gettext "abs will synchronize build scripts from the CVS repository")\n"
	printf "$(gettext "into %s. You can follow different package trees by")\n" "$ABSROOT"
	printf "$(gettext "editing %s files. If no argument is given, abs")\n" "$CONFDIR/supfile.*"
	printf "$(gettext "will synchronize from supfiles specified in %s.")\n" "$CONFDIR/abs.conf"
	echo
	printf "$(gettext "Report bugs to <%s>.")\n" "$BUG_REPORT_EMAIL"
}

version() {
	printf "abs (pacman) %s\n" "$myver"
	printf "$(gettext "Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>").\n"
	echo
	printf "$(gettext "This is free software; see the source for copying conditions.")\n"
	printf "$(gettext "There is NO WARRANTY, to the extent permitted by law.")\n"
	echo
}


##
# Signal Traps
##
trap 'error "$(gettext "TERM signal caught. Exiting...")"; exit 1' TERM HUP QUIT
trap 'error "$(gettext "Aborted by user! Exiting...")"; exit 1' INT
trap 'error "$(gettext "An unknown error has occured. Exiting...")"; exit 1' ERR


# Parse Command Line Options.
OPT_SHORT="hpV"
OPT_LONG="help,passive,version"
OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')"
if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then
	# This is a small hack to stop the script bailing with 'set -e'
	echo; usage; exit 1 # E_INVALID_OPTION;
fi
eval set -- "$OPT_TEMP"
unset OPT_SHORT OPT_LONG OPT_TEMP

while true; do
	case "$1" in
		-p|--passive)  PASSIVE='-';;

		-h|--help)     usage; exit 0;; # E_OK
		-V|--version)  version; exit 0;; # E_OK

		--)            OPT_IND=0; shift; break;;
		*)             usage; exit 1;; # E_INVALID_OPTION
	esac
	shift
done

if [ $# -gt 0 ]; then
	SUPFILES=("$@")
fi


# Check permissions and programs.
if [ ! -d "$ABSROOT" ]; then
	error "$(gettext "%s does not exist or is not a directory.")" "$ABSROOT"
	exit 1 # E_CONFIG_ERROR
elif [ ! -w "$ABSROOT" ]; then
	error "$(gettext "You do not have write permissions in %s.")" "$ABSROOT"
	exit 1 # E_CONFIG_ERROR
fi


if [ "$(type -p cvsup)" ]; then
	CVSUP="cvsup"
elif [ "$(type -p csup)" ]; then
	CVSUP="csup"
else
	error "$(gettext "Missing CVS synchronization utility. Install cvsup or csup.")"
	exit 1 # E_MISSING_PROGRAM
fi


# Begin script.
for sup in ${SUPFILES[@]}; do
	case "$sup" in
		testing)
			if [ ! -d "$ABSROOT/$sup" ]; then
				mkdir "$ABSROOT/$sup"
			fi
			workdir="$ABSROOT/$sup"
			;;

		*)
			if [ "$sup" != "${sup#!}" ]; then
				continue
			fi
			workdir="$ABSROOT"
			;;
	esac

	msg "$(gettext "Updating %s...")" "$sup"
	cd "$workdir"
	$CVSUP -L 1 -r 0 -g -b "$workdir" -P "$PASSIVE" -c .sup "$CONFDIR/supfile.$sup"
done

exit 0 # E_OK

# vim: set ts=2 sw=2 noet: