summaryrefslogtreecommitdiff
path: root/db-move
blob: 8609459e01efd546d20f572621b1f1e37eb19b55 (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
#!/bin/bash

if [ $# -ne 4 ]; then
	echo "usage: $(basename $0) <pkgname|pkgbase> <repo-from> <repo-to> <arch>"
	exit 1
fi

. "$(dirname $0)/db-functions"
. "$(dirname $0)/config"

packagebase="$1"
repofrom="$2"
repoto="$3"
_arch="$4"
if [ "${_arch}" == 'any' ]; then
	_tarches=('i686' 'x86_64')
else
	_tarches=("${_arch}")
fi

ftppath_from="$FTP_BASE/$repofrom/os/"
ftppath_to="$FTP_BASE/$repoto/os/"
svnrepo_from="$repofrom-$_arch"
svnrepo_to="$repoto-$_arch"

[ "$UID" = "" ] && UID=$(uid)

WORKDIR="$TMPDIR/db-move.$svnrepo_from.$svnrepo_to.$UID"

cleanup() {
	trap '' 0 2
	# unlock
	repo_unlock $repoto $_arch
	repo_unlock $repofrom $_arch
	rm -rf "$WORKDIR"
	[ "$1" ] && exit $1
}

ctrl_c() {
	echo "Interrupted" >&2
	cleanup 0
}

die() {
	echo "$*" >&2
	cleanup 1
}

trap ctrl_c 2
trap cleanup 0

repo_lock $repoto $_arch || exit 1
repo_lock $repofrom $_arch || exit 1

/bin/mkdir -p "$WORKDIR"

cd "$WORKDIR"
/usr/bin/svn checkout -N $SVNREPO checkout
cd checkout

/usr/bin/svn up -q $packagebase
if [ -d "$packagebase/repos/$svnrepo_from" ]; then
	. "$packagebase/repos/$svnrepo_from/$BUILDSCRIPT"

	if [ -d "$packagebase/repos/$svnrepo_to" ]; then
		echo "    Removing existing package from subversion"
		/usr/bin/svn rm --force -q "$packagebase/repos/$svnrepo_to"
		/usr/bin/svn commit -q -m "$(basename $0): $packagebase removed by $(id -un) for move to $repoto"
	fi

	echo "    Moving svn entries"
	/usr/bin/svn mv -r HEAD "$packagebase/repos/$svnrepo_from" "$packagebase/repos/$svnrepo_to"
	/usr/bin/svn commit -m "$(basename $0): moved $packagebase from [$repofrom] to [$repoto] ($_arch)"

	_pkgfiles=''
	for i in ${pkgname[@]}; do
		for _tarch in ${_tarches[@]}; do
			_pkgpath=$(getpkgfile "$ftppath_from/${_tarch}/"$i-$pkgver-$pkgrel-$_arch$PKGEXT)
			_pkgfile=$(basename "${_pkgpath}")

			# copy package to pool if needed
			# TODO: can be removed once every package has been moved to the package pool
			if [ ! -f $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/$_pkgfile ]; then
				cp $_pkgpath $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/
			fi
			ln -s "../../../$(get_pkgpool_for_host)/${_arch}/${_pkgfile}" $ftppath_to/${_tarch}/
		done

		_pkgfiles="${_pkgfiles} $FTP_BASE/$(get_pkgpool_for_host)/${_arch}/${_pkgfile}"
	done

	for _tarch in ${_tarches[@]}; do
		/usr/bin/repo-add -q "$ftppath_to/${_tarch}/$repoto$DBEXT" ${_pkgfiles} || die "Error in repo-add $_pkgfiles"
		/usr/bin/repo-remove -q "$ftppath_from/${_tarch}/$repofrom$DBEXT" ${pkgname[@]} || die "Error in repo-remove ${pkgname[@]}"
	done
else
	die "Error: $packagebase is not in repo $repofrom"
fi