summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-dev/lhsync.sh
blob: e8cd8b19f181c0b05dc8617e17b22031fbd58033 (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
#!/bin/bash

#This script will create and synchronize a local package mirror with the repository
#(as defined below) on linhes.org, and will also update the database.
#This script uses a shared account on linhes.org.
#DO NOT change the account name and don't ask for the password,
#instead setup ssh keys and run ssh-agent.

if  [ -e /etc/makepkg.conf ]
then
    . /etc/makepkg.conf
else
    echo "Couldn't find /etc/makepkg.conf"
fi

LOCAL_DIR=/data/dev
REMOTE_DIR=/srv/www/repo
PKGROOT=$LOCAL_DIR/pkg_repo/$CARCH

function sync_dirs {
    REMOTE=$1
    LOCAL=$2
    echo "--------------------------------------------------------"
    echo "      Syncing $3 packages with linhes.org"
    echo "--------------------------------------------------------"
    echo "Remote: $REMOTE"
    echo "Local: $LOCAL"
    case $4 in
        resync)
            rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --resync --copy-links
            ;;
        force)
            rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --force --copy-links
            ;;
        *)
            rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --copy-links
            ;;
    esac

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

    #update the local database
    if [ "$4" == "update_db" ]
    then
        echo "--------"
        echo "Updating the whole package db..."
        echo "--------"
        update_db_repo.sh $LOCAL $3

        echo "--------"
        echo "Pushing the package db to linhes.org"
        echo "--------"
        rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE $LOCAL --verbose --copy-links
    fi

    echo "--------------------------------------------------------"
    echo "      Finished syncing $3 packages"
    echo "--------------------------------------------------------"
}

function source_sync () {
    echo "--------------------------------------------------------"
    echo "      Syncing $1 sources"
    echo "--------------------------------------------------------"
    REMOTE_SRC=$REMOTE_DIR/src_packages/$1/
    LOCAL_SRC=$LOCAL_DIR/pkg_repo/src_packages/$1/
    echo "Remote: $REMOTE_SRC"
    echo "Remote: $LOCAL_SRC"
    case $2 in
        resync)
            rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE_SRC $LOCAL_SRC --verbose --resync --copy-links
            ;;
        force)
            rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE_SRC $LOCAL_SRC --verbose --force --copy-links
            ;;
        *)
            rclone bisync :sftp,host=linhes.org,user=reposync:$REMOTE_SRC $LOCAL_SRC --verbose --copy-links
            ;;
    esac
    echo "--------------------------------------------------------"
    echo "      Finished syncing $3 sources"
    echo "--------------------------------------------------------"
}

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

#---------------------------------------------------------------
case $1 in
    testing)
        sync_dirs $REMOTE_DIR/$CARCH/linhes-testing/ $PKGROOT/linhes-testing/ linhes-testing $2
        source_sync linhes-testing $2
        pacman_sync
        ;;
    release)
        sync_dirs $REMOTE_DIR/$CARCH/linhes/ $PKGROOT/linhes/ linhes $2
        source_sync linhes $2
        pacman_sync
        ;;
    source)
        if [ x = x$2 ]
        then
            echo "Missing source repository [testing|release]"
            exit 1
        fi
        source_sync $1 $2
        pacman_sync
        ;;
    *)
        echo "Invalid Options"
        echo "lhsync.sh (testing|release|source[testing|release]) (update_db|resync|force)"
        echo
        echo "force: force rclone to sync when too many deletes are detected"
        echo "resync: overwrites the local package and source repos with ones from linhes.org"
        echo "update_db: recreate the db files in the repo and syncs to linhes.org"
        echo "EXAMPLE: lhsync.sh testing update_db <= will sync the testing repo with linhes.org update the local database and resync with linhes.org"
        ;;
esac