summaryrefslogtreecommitdiff
path: root/build-repo.sh
blob: 71ef23c82778616251d1ad4fe7b9e63ec5f139b5 (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
172
173
174
#!/bin/bash

XIBUILD=./xibuild

fetch () {
    git clone https://git.davidovski.xyz/xilinux/xipkgs

    mkdir dist
}

build () {

    REPOS_INDEX=dist/repo/index.html
    rm $REPOS_INDEX

    echo-head "repo" >> $REPOS_INDEX
    echo "<h1>repo</h1>" >> $REPOS_INDEX

    for REPO in $(du -h xipkgs/repo/* | awk '{print $2}' | sort -r ); do
        REPO_NAME=$(echo $REPO | cut -d"/" -f2-)

        REPO_INDEX=dist/$REPO_NAME/index.html
        REPO_LIST_OLD=dist/$REPO_NAME/packages.txt
        REPO_LIST=dist/$REPO_NAME/packages.list
        
        start-index $REPO_NAME $REPO_INDEX

        printf "" > xibuild.report.log
        for BUILD_FILE in $REPO/*; do
            DEST=dist/$REPO_NAME

            $XIBUILD -o $DEST $BUILD_FILE
            
            extend-index $BUILD_FILE $REPO_INDEX
        done;

        rm xibuild.report.log
        conclude-index $REPO_INDEX

        generate-package-list
        add-additional 
        
        echo "<a href='/$REPO_NAME'><h2>$REPO_NAME</h2><a> " >> $REPOS_INDEX


        echo "<p>package count: <strong>$(ls dist/$REPO_NAME/*.xipkg | wc -l)</strong></p>" >> $REPOS_INDEX
    done;

    echo ""
}

echo-head () {
    echo "<html>
    <head>
        <title>$1</title>
        <style>$(cat style.css)</style>
        </head>
        <body>"
}

start-index() {
    echo-head "packages for $1" > $2
    echo "
    <h1>Packages in <a href='../'>$1</a></h1>
    <table>
    <tr>
        <td>name</td>
        <td>xibuild</td>
        <td>build log</td>
        <td>description</td>
        <td>file</td>
        <td>info file</td>
    </tr>
    " >> $2
}

extend-index () {
    PKG_NAME=$(basename $1 .xibuild)
    DESC=$(grep $PKG_NAME xibuild.report.log | cut -d" " -f3-)

    COLOR="none"
    if grep $PKG_NAME xibuild.report.log | grep -q new; then 
        COLOR="pass"
    fi
    if grep $PKG_NAME xibuild.report.log | grep -q fail; then
        if [ -f dist/$REPO_NAME/$PKG_NAME.xipkg ]; then 
            COLOR="warning"
        else
            COLOR="fail"
        fi
    fi
    echo "
        <tr class='$COLOR'>
            <td>$PKG_NAME</td>
            <td><a href='src/$PKG_NAME.xibuild'>src</a></td>
            <td><a href='logs/$PKG_NAME.log'>log</a></td>
            <td>$DESC</td>
            <td><a href='$PKG_NAME.xipkg'>$PKG_NAME.xipkg</a></td>
            <td><a href='$PKG_NAME.xipkg.info'>.info</a></td>
        </tr>
    " >> $2
}

conclude-index () {
    echo "</table>

    <p>Latest builds: <b>$(date)</b></p>

    <h3>Legend:</h3>
    <ul>
        <li>build skipped; no updates</li>
        <li class='fail'>build failed; no previous version</li>
        <li class='warning'>build failed; previous version exists</li>
        <li class='pass'>build passed: new update</li>
    </ul>
    </body>
    </html>
    " >> $1
}

generate-package-list () {
    cd dist/$REPO_NAME
    ls -1 *.xipkg.info > packages.txt

    echo "" > packages.list
    for file in $(ls -1 *.xipkg); do
        echo "$file $(md5sum $file)" >> packages.list
    done;
    cd -
}

add-additional () {
    # move logs and sources
    mv logs/* dist/$REPO_NAME/logs
    
    mkdir -p dist/$REPO_NAME/src
    mv $REPO/* dist/$REPO_NAME/src/
    
    # add key for whole repo
    mkdir dist/keychain
    cp keychain/keys.list dist/keychain/
    cp keychain/*.pub dist/keychain/
}

clean () {
    rm -rf xipkgs
    rm -rf logs
    rm -rf tmp
    rm -rf xibuild.log
}

sync () {
    for i in $@; do
        [[ $# = 0 ]] || rsync -vLta --no-perms --no-owner --no-group --delete -z -e ssh ./dist/ $i
    done;
}

index () {
    INDEX=dist/index.html
    rm $INDEX

    echo-head "xilinux" >> $INDEX
    cat index.html >> $INDEX
}


# update the repository

clean
fetch
build
index
clean
sync $@