makepkg: Move .PKGINFO creation into a function.
[pacman-ng.git] / contrib / updatesync
blobf88e8237c36909016b0b1ca4783f72cd12dba2f5
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 "Usage: %s <action> <destfile> <option> [package_directory]\n\n" "$0"
29 printf "\
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 "There are two types of actions:\n\n"
34 printf "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 "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 "\
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 "Example: updatesync upd /home/mypkgs/custom.db.tar.gz PKGBUILD"
43 version() {
44 printf "updatesync (pacman) %s\n" "$myver"
45 printf "\
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 # PROGRAM START
63 if [ "$1" = "-h" -o "$1" = "--help" ]; then
64 usage
65 exit 0
68 if [ "$1" = "-V" -o "$1" = "--version" ]; then
69 version
70 exit 0
73 if [ $# -lt 3 ]; then
74 usage
75 exit 1
78 # source system and user makepkg.conf
79 if [ -r /etc/makepkg.conf ]; then
80 source /etc/makepkg.conf
81 else
82 die "/etc/makepkg.conf not found. Cannot continue."
85 if [ -r ~/.makepkg.conf ]; then
86 source ~/.makepkg.conf
89 if [ "$1" != "upd" -a "$1" != "del" ]; then
90 usage
91 exit 1
94 action=$1
95 pkgdb=$2
96 option=$3
97 pkgdir="$(pwd)"
98 if [ "$4" != "" ]; then
99 pkgdir="$4"
102 if [ "$action" = "upd" ]; then # INSERT / UPDATE
103 if [ ! -f "$option" ]; then
104 die "$option not found"
107 unset pkgname pkgver pkgrel options
109 source $option || die "failed to parse $option"
110 if [ "$arch" = 'any' ]; then
111 CARCH='any'
113 pkgfile="$pkgdir/$pkgname-$pkgver-$pkgrel-${CARCH}${PKGEXT}"
115 if [ ! -f "$pkgfile" ]; then
116 die "could not find %s-%s-%s-%s%s - aborting" $pkgname $pkgver $pkgrel $CARCH $PKGEXT
119 repo-add "$pkgdb" "$pkgfile"
120 else # DELETE
121 fname="$(basename $option)"
122 if [ "$fname" = "PKGBUILD" ]; then
123 if [ ! -f "$option" ]; then
124 die "%s not found" $option
127 unset pkgname pkgver pkgrel options
128 source $option
129 else
130 pkgname=$option
133 repo-remove "$pkgdb" "$pkgname"
136 exit 0
137 # vim: set ts=2 sw=2 noet: