summaryrefslogtreecommitdiffstats
path: root/scripts/gensync
blob: 1839655dced9977a87c2c5626ddecda83915504f (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
#!/bin/bash
# 
#   gensync
#  
#   Copyright (c) 2002-2003 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.
#

myver='2.6.3'

usage() {
  echo "gensync $myver"
  echo "usage: $0 <root> <destfile>"
	echo
	echo "gensync will generate a sync database by reading all PKGBUILD files"
	echo "from <root>.  gensync builds the database in /tmp/.gensync and then"
	echo "compresses it to <destfile>."
	echo
	echo "note: The <destfile> name is important.  It must be of the form"
	echo "      {treename}.db.tar.gz where {treename} is the name of the custom"
	echo "      package repository you configured in /etc/pacman.conf.  The"
	echo "      generated database must reside in the same directory as your"
	echo "      custom packages (also configured in /etc/pacman.conf)"
	echo
	echo "example:  gensync /var/abs/local /home/mypkgs/custom.db.tar.gz"
	echo
  echo
  exit 0
}

db_write_entry()
{
	unset pkgname pkgver pkgrel pkgdesc
	unset groups replaces provides depends conflicts
	source $1 || return 1
	cd /tmp/.gensync
	mkdir $pkgname-$pkgver-$pkgrel
	cd $pkgname-$pkgver-$pkgrel
	# desc
	: >desc
	echo "%NAME%" >>desc
	echo "$pkgname" >>desc
	echo "" >>desc
	echo "%VERSION%" >>desc
	echo "$pkgver-$pkgrel" >>desc
	echo "" >>desc
	echo "%DESC%" >>desc
	echo "$pkgdesc" >>desc
	echo "" >>desc
	if [ ${#groups[*]} -gt 0 ]; then
		echo "%GROUPS%" >>desc
		for it in "${groups[@]}"; do
			echo "$it" >>desc
		done
		echo "" >>desc
	fi
	if [ ${#replaces[*]} -gt 0 ]; then
		echo "%REPLACES%" >>desc
		for it in "${replaces[@]}"; do
			echo "$it" >>desc
		done
		echo "" >>desc
	fi
	# depends
	: >depends
	if [ ${#depends[*]} -gt 0 ]; then
		echo "%DEPENDS%" >>depends
		for it in "${depends[@]}"; do
		  echo "$it" >>depends
		done
		echo "" >>depends
	fi
	if [ ${#conflicts[*]} -gt 0 ]; then
		echo "%CONFLICTS%" >>depends
		for it in "${conflicts[@]}"; do
		  echo "$it" >>depends
		done
		echo "" >>depends
	fi
	if [ ${#provides[*]} -gt 0 ]; then
		echo "%PROVIDES%" >>depends
		for it in "${provides[@]}"; do
		  echo "$it" >>depends
		done
		echo "" >>depends
	fi
}

if [ $# -lt 2 ]; then
	usage
	exit 0
fi

if [ "$1" = "-h" -o "$1" = "--help" ]; then
	usage
	exit 0
fi

d=`dirname $1`
rootdir=`cd $d && pwd`
rootdir="$rootdir/`basename $1`"
d=`dirname $2`
destfile=`cd $d && pwd`
destfile="$destfile/`basename $2`"

rm -rf /tmp/.gensync || exit 1
mkdir -p /tmp/.gensync || exit 1

if [ ! -d $rootdir ]; then
	echo "gensync: invalid root dir: $rootdir" >&2
	rm -rf /tmp/.gensync
	exit 1
fi

echo "gensync: building database entries..." >&2
#for category in `find $rootdir/* -type d -maxdepth 0`; do
for file in `find $rootdir/* -name PKGBUILD`; do
	db_write_entry $file
	if [ $? -gt 0 ]; then
		echo "gensync: error writing entry for $file" >&2
		rm -rf /tmp/.gensync
		exit 1
	fi
done

echo "gensync: compressing to $destfile..." >&2
cd /tmp/.gensync
tar c * | gzip -9 >$destfile
if [ $? -gt 0 ]; then
	echo "gensync: error writing to $destfile" >&2
	rm -rf /tmp/.gensync
	exit 1
fi

rm -rf /tmp/.gensync

exit 0