summaryrefslogtreecommitdiffstats
path: root/build_tools/bin/kmsync.sh
blob: ab1e1dc0987d08ba3a25cff0e7113ed3549445ca (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
#This script will create and synchronize a local package mirror with the repository (as defined below) on knoppmyth.net, it will also update the database.
#This script uses a shared account on knoppmyth.net.  DO NOT change the account name
# and dont' ask for the password, instead setup ssh keys.
#


if  [ -e /etc/makepkg.conf ]
then
    . /etc/makepkg.conf
else
    echo "couldn't find /etc/makepkg.conf"
fi
cwd=`dirname $0`
REMOTE_DIR=/mount/repository/repo
DOCROOT=/data/pkg_repo/$CARCH
#export UNISON="/root/.unison"
export UNISON="/data/pkg_repo/.unison"
cp -f /build_tools/bin/km-up.prf  $UNISON/km-up.prf
cp -f /build_tools/bin/km-down.prf  $UNISON/km-down.prf
function sync_dirs {
    REMOTE=$1
    LOCAL=$2

    echo "                     Updating $3                        "
    echo "________________________________________________________"

    #first bring down new changes from knoppmyth.net
    echo "--------"
    echo
    echo "Syncing the  packages with knoppmyth.net"
    echo
    echo "--------"
    unison km-down  -logfile /tmp/unison-down.log -auto -batch  -numericids ssh://reposync@knoppmyth.net/$REMOTE $LOCAL

    if [ ! $? = 0 ]
    then
        echo "#######################################################"
        echo "##             ERRORS OCCURED                        ##"
        echo "#######################################################"
        exit 1

    fi
    #update the local database
    update_db_repo.sh $LOCAL $3

    #push the database back
    echo "--------"
    echo
    echo "Pushing the pkg database to knoppmyth.net"
    echo
    echo "--------"
    unison km-up  -logfile /tmp/unison-up.log -auto -batch -numericids -force $LOCAL  $LOCAL ssh://reposync@knoppmyth.net/$REMOTE 
    #scp $LOCAL/*.db.tar.gz reposync@knoppmyth.net:$REMOTE/  

    echo "-------------------------------------------------------"
    echo "-----------         Finished with $3        -----------"
    echo "-------------------------------------------------------"
}


function source_sync () {
    src_repo=$1
    case $1 in 
        testing )
            echo "updating source packages"
            REMOTE_DIR=/mount/repository/repo/src_packages/core-testing
            LOCAL=/data/pkg_repo/src_packages/core-testing
            unison km-down  -logfile /tmp/unison-down.log -auto -batch  -numericids ssh://reposync@knoppmyth.net/$REMOTE_DIR $LOCAL
            
            REMOTE_DIR=/mount/repository/repo/src_packages/extra-testing
            LOCAL=/data/pkg_repo/src_packages/extra-testing
            unison km-down  -logfile /tmp/unison-down.log -auto -batch  -numericids ssh://reposync@knoppmyth.net/$REMOTE_DIR $LOCAL
            ;;

          release )
            echo "updating source packages"
            REMOTE_DIR=/mount/repository/repo/src_packages/core
            LOCAL=/data/pkg_repo/src_packages/core
            unison km-down  -logfile /tmp/unison-down.log -auto -batch  -numericids ssh://reposync@knoppmyth.net/$REMOTE_DIR $LOCAL
            
            REMOTE_DIR=/mount/repository/repo/src_packages/extra
            LOCAL=/data/pkg_repo/src_packages/extra
            unison km-down  -logfile /tmp/unison-down.log -auto -batch  -numericids ssh://reposync@knoppmyth.net/$REMOTE_DIR $LOCAL
            ;;
         chroot-devel )
            echo "updating source packages"
            REMOTE_DIR=/mount/repository/repo/src_packages/chroot-devel
            LOCAL=/data/pkg_repo/src_packages/chroot-devel
            unison km-down  -logfile /tmp/unison-down.log -auto -batch  -numericids ssh://reposync@knoppmyth.net/$REMOTE_DIR $LOCAL
            ;;



    *)  
            echo "need to know the source repository [testing|release|chroot-devel]"
            exit 1
        ;;  
esac
}


function pacman_sync () {
    echo "running 'pacman -Sy' to sync repos"
    pacman -Sy
}

#---------------------------------------------------------------
if [ ! -d $UNISON ]
then
    mkdir $UNISON
fi

if [ ! -f $UNISON/km-down.prf ]
then
    cp -f $cwd/km-down.prf $UNISON/
fi

if [ ! -f $UNISON/km-up.prf ]
then
    cp -f $cwd/km-up.prf $UNISON/
fi





clear
case $1 in
    testing)
        #sync_dirs $REMOTE $LOCAL
        sync_dirs $REMOTE_DIR/$CARCH/core-testing $DOCROOT/core-testing  core-testing
        sync_dirs $REMOTE_DIR/$CARCH/extra-testing $DOCROOT/extra-testing extra-testing
        source_sync testing
	pacman_sync
        ;;

    release)
        sync_dirs $REMOTE_DIR/$CARCH/core $DOCROOT/core  core
        sync_dirs $REMOTE_DIR/$CARCH/extra $DOCROOT/extra extra
        source_sync release
	pacman_sync
        ;;

    chroot-devel)
        echo "will update chroot-devel"
        sync_dirs $REMOTE_DIR/$CARCH/chroot-devel $DOCROOT/chroot-devel  chroot-devel
        source_sync chroot-devel
	pacman_sync
        ;;

    source)
        if [ x = x$2 ]
        then
            echo "need to know the source repository [testing|release|chroot-devel]"
            exit 1
        fi
        source_sync $2
	pacman_sync
        ;;
    *)
        echo "invalid options"
        echo "kmsync.sh (testing|release|chroot-devel|source[testing|release|chroot-devel]) "
        echo
        echo "EX:  kmsync.sh testing  <= will sync the testing repo with km.net update the local database and resync with km.net"
        #echo "kmsync.sh testing oneway <= will syncthe testing repo with km.net update the local database"

        ;;
esac
echo "Finished."
# End