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

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

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

source_makepkg

packagebase="$1"
repofrom="$2"
repoto="$3"
_arch="$4"

export CARCH="$_arch"

ftppath_from="$FTP_BASE/$repofrom/os/"
ftppath_to="$FTP_BASE/$repoto/os/"
svnrepo_from="$repofrom-$_arch"
svnrepo_to="$repoto-$_arch"
svnpath="$(get_svnpath $repoto)"
if [ "$svnpath" != "$(get_svnpath $repofrom)" ]; then
    echo "ERROR: Cannot move packages across SVN repos"
    echo "       A move must be within the same svn repo"
fi

[ "$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
repo_lock $repofrom $_arch

/bin/mkdir -p "$WORKDIR"

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

/usr/bin/svn up -q $packagebase
if [ -d "$packagebase/repos/$svnrepo_from" ]; then
    . "$packagebase/repos/$svnrepo_from/$BUILDSCRIPT"
    
    for i in ${pkgname[@]}; do
        _pkgfile="$i-$pkgver-$pkgrel-$_arch$PKGEXT"
        if [ ! -f "$ftppath_from/${_arch}/$_pkgfile" ]; then
            die "error: package file '$_pkgfile' not found in repo '$repofrom'"
        fi
    done

    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)"

    echo "    Moving package file and updating DBs"
    cd "$WORKDIR"
    [ -d build/ ] || mkdir build
    cd build/

	if [ "${_arch}" == "any" ]; then
		arches="i686 x86_64"
	else
		arches="${_arch}"
	fi

    for architecture in $arches; do
		# copy the db file into our working area
		if [ -f "$ftppath_from/$architecture/$repofrom.db.tar.$DB_COMPRESSION" ]; then
		    /bin/cp "$ftppath_from/$architecture/$repofrom.db.tar.$DB_COMPRESSION" .
		    for i in ${pkgname[@]}; do
			/usr/bin/repo-remove -q "$repofrom.db.tar.$DB_COMPRESSION" $i || die "Error in repo-remove $i"
		    done
		    #use '*' to move the old DB too
		    mv $repofrom.db.tar.$DB_COMPRESSION* "$ftppath_from/$architecture"
		    echo "    Package files will be cleaned up automatically"
		fi

		if [ -f "$ftppath_to/$architecture/$repoto.db.tar.$DB_COMPRESSION" ]; then
		    /bin/cp "$ftppath_to/$architecture/$repoto.db.tar.$DB_COMPRESSION" .
		fi

		for i in ${pkgname[@]}; do
			_pkgfile="$i-$pkgver-$pkgrel-$_arch$PKGEXT"
			/bin/cp "$ftppath_from/$architecture/$_pkgfile" .
			/usr/bin/repo-add -q "$repoto.db.tar.$DB_COMPRESSION" $_pkgfile || die "Error in repo-add $_pkgfile"
		done
		#use '*' to move the old DB too
		mv $repoto.db.tar.$DB_COMPRESSION* $ftppath_to/$architecture
		if [ "${_arch}" == "any" ]; then
			for i in ${pkgname[@]}; do
				_pkgfile="$i-$pkgver-$pkgrel-$_arch$PKGEXT"
				mv ${_pkgfile} $ftppath_to/any
				ln -s ../any/${_pkgfile} $ftppath_to/$architecture/
			done
		else
			for i in ${pkgname[@]}; do
				_pkgfile="$i-$pkgver-$pkgrel-$_arch$PKGEXT"
				mv ${_pkgfile} $ftppath_to/$architecture
			done
		fi
	done
else
    die "Error: $packagebase is not in repo $repofrom"
fi

cleanup