Remove gensync and updatesync from normal distribution
[pacman-ng.git] / contrib / updatesync
blob4df02ef982f15baf6cd393fdbe82dfe5feaa02a9
1 #!/bin/bash
3 # updatesync
5 # Copyright (c) 2004 by Jason Chu <jason@archlinux.org>
6 # Derived from gensync (c) 2002-2006 Judd Vinet <jvinet@zeroflux.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 myver='3.1.1'
24 # functions
26 usage() {
27 printf "updatesync (pacman) %s\n\n" "$myver"
28 printf "$(gettext "Usage: %s <action> <destfile> <option> [package_directory]")\n\n" "$0"
29 printf "$(gettext "\
30 updatesync will update a sync database by reading a PKGBUILD and\n\
31 modifying the destfile. updatesync updates the database in a temporary\n\
32 directory and then compresses it to <destfile>.\n\n")"
33 printf "$(gettext "There are two types of actions:\n\n")"
34 printf "$(gettext "upd - Will update a package's entry or create it if it doesn't exist.\n It takes the package's PKGBUILD as an option.\n")"
35 printf "$(gettext "del - Will remove a package's entry from the db. It takes the package's\n name as an option.\n")"
36 echo
37 printf "$(gettext "\
38 updatesync will calculate md5sums of packages in the same directory as\n\
39 <destfile>, unless an alternate [package_directory] is specified.\n\n")"
40 echo "$(gettext "Example: updatesync upd /home/mypkgs/custom.db.tar.gz PKGBUILD")"
43 version() {
44 printf "updatesync (pacman) %s\n" "$myver"
45 printf "$(gettext "\
46 Copyright (C) 2004 Jason Chu <jason@archlinux.org>.\n\n\
47 This is free software; see the source for copying conditions.\n\
48 There is NO WARRANTY, to the extent permitted by law.\n")"
51 error () {
52 local mesg=$1; shift
53 printf "==> ERROR: ${mesg}\n" "$@" >&2
56 die () {
57 error $*
58 exit 1
61 check_force () {
62 local i
63 for i in ${options[@]}; do
64 local lc=$(echo $i | tr [:upper:] [:lower:])
65 if [ "$lc" = "force" ]; then
66 true
68 done
69 false
72 # PROGRAM START
74 if [ "$1" = "-h" -o "$1" = "--help" ]; then
75 usage
76 exit 0
79 if [ "$1" = "-V" -o "$1" = "--version" ]; then
80 version
81 exit 0
84 if [ $# -lt 3 ]; then
85 usage
86 exit 1
89 # source system and user makepkg.conf
90 if [ -r /etc/makepkg.conf ]; then
91 source /etc/makepkg.conf
92 else
93 die "/etc/makepkg.conf not found. Cannot continue."
96 if [ -r ~/.makepkg.conf ]; then
97 source ~/.makepkg.conf
100 if [ "$1" != "upd" -a "$1" != "del" ]; then
101 usage
102 exit 1
105 action=$1
106 pkgdb=$2
107 option=$3
108 pkgdir="$(pwd)"
109 if [ "$4" != "" ]; then
110 pkgdir="$4"
112 opt_force=""
114 if [ "$action" = "upd" ]; then # INSERT / UPDATE
115 if [ ! -f "$option" ]; then
116 die "$(gettext "%s not found")" $option
119 unset pkgname pkgver pkgrel options
121 source $option || die "$(gettext "failed to parse %s")" $option
122 if [ "$arch" = 'any' ]; then
123 CARCH='any'
125 pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-${CARCH}${PKGEXT}"
127 if [ ! -f "$pkgfile" ]; then
128 die "$(gettext "could not find %s-%s-%s-%s%s - aborting")" $pkgname $pkgver $pkgrel $CARCH $PKGEXT
131 if check_force; then
132 opt_force="--force"
135 repo-add "$pkgdb" $opt_force "$pkgfile"
136 else # DELETE
137 fname="$(basename $option)"
138 if [ "$fname" = "PKGBUILD" ]; then
139 if [ ! -f "$option" ]; then
140 die "$(gettext "%s not found")" $option
143 unset pkgname pkgver pkgrel options
144 source $option
145 else
146 pkgname=$option
149 repo-remove "$pkgdb" "$pkgname"
152 exit 0
153 # vim: set ts=2 sw=2 noet: