summaryrefslogtreecommitdiff
path: root/.tools/scripts/init.sh
blob: 44b63d9448fa762bb8bae04c71dc2dfabfe6ead1 (plain) (blame)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash

mkdir logs

export dir=$(pwd)
export ERRFILE=${dir}/logs/${LOGFILE}

cat /etc/os-release

rm ${ERRFILE}

function check_error {
    if [ "$1" != 0 ]; then
        echo "Error $1"
        exit $1
    fi
}

function update_repos {
    if [ "$CI_SERVER" == "" ];
    then
        return
    fi

    export DATA=$(cat /etc/resolv.conf|grep "nameserver 1.10.100.101")
    if [ "$DATA" != "" ];
    then
        echo "Detected local runner"
        sed -i 's!http://httpredir.debian.org/debian!http://1.10.100.103/debian!' /etc/apt/sources.list
    else
        echo "Detected non local runner"
    fi
}

function gitclone1 {
    echo git clone $2 $3
    git clone $2 $3
    if [ "$?" != 0 ]; then
        echo git clone $1 $3
        git clone $1 $3
        return $?
    fi
    return $?
}

function gitclone {
    export name1=$1/$2
    export name2=${CI_BUILD_REPO##*@}
    export name2=https://${name2%/*}/$2

    gitclone1 "$name1" "$name2" $3
    if [ "$?" != 0 ]; then
        sleep 1s
        gitclone1 "$name1" "$name2" $3
        if [ "$?" != 0 ]; then
            sleep 3s
            gitclone1 "$name1" "$name2" $3
            if [ "$?" != 0 ]; then
                sleep 5s
                gitclone1 "$name1" "$name2" $3
            fi
        fi
    fi
    check_error $?
}

function update_repos {
    if [ "$CI_SERVER" == "" ];
    then
        return
    fi

    export DATA=$(cat /etc/resolv.conf|grep "nameserver 1.10.100.101")
    if [ "$DATA" != "" ];
    then
        echo "Detected local runner"
        sed -i 's!http://httpredir.debian.org/debian!http://1.10.100.103/debian!' /etc/apt/sources.list
    else
        echo "Detected non local runner"
    fi
}

function aptget_update {
    update_repos
    apt-get update
    if [ "$?" != 0 ]; then
        sleep 1s
        apt-get update
        if [ "$?" != 0 ]; then
            sleep 1s
            apt-get update
        fi
    fi
    check_error $?
}

function aptget_install {
    apt-get -y -qq install $*
    if [ "$?" != 0 ]; then
        sleep 1s
        apt-get -y -qq install $*
        if [ "$?" != 0 ]; then
            sleep 2s
            apt-get -y -qq install $*
        fi
    fi
    check_error $?
}

function make_server {
    ls -la ../server-data
    ls -la ../server-data/plugins
    echo source src/evol/tools/vars.sh
    source ./src/evol/tools/vars.sh
    check_error $?
    export CPPFLAGS="$CPPFLAGS -DI_AM_AWARE_OF_THE_RISK_AND_STILL_WANT_TO_RUN_HERCULES_AS_ROOT"
    echo "autoreconf -i"
    autoreconf -i
    check_error $?
    echo ./configure $1 CPPFLAGS=\"${CPPFLAGS}\"
    ./configure $1 CPPFLAGS="$CPPFLAGS"
    export err="$?"
    if [ "$err" != 0 ]; then
        echo "Error $err"
        echo cat config.log
        cat config.log
        exit $err
    fi
    echo "make -j2"
    make -j2
    check_error $?
    echo "make -j2 plugin.script_mapquit"
    make -j2 plugin.script_mapquit
    check_error $?
    make install
    check_error $?

    cd src/evol
    echo "autoreconf -i"
    mkdir m4
    autoreconf -i
    check_error $?
    mkdir build
    cd build
    echo ../configure $2 CPPFLAGS=\"${VARS}\"
    ../configure $2  CPPFLAGS="${VARS}"
    check_error $?
    echo "make -j2 V=0"
    make -j2 V=0
    check_error $?
    cd ../../../..
    ls -la server-data/plugins
}

function do_init_data {
    mkdir shared
    cd ..
    rm -rf server-data
    cp -r serverdata server-data
    ls -la server-data
    check_error $?
}

function do_init_tools {
    cd ..
    rm -rf tools
    gitclone https://gitlab.com/TMW2 evol-tools.git tools
}

function do_init {
    do_init_data
    rm -rf server-code
    gitclone https://gitlab.com/evol hercules.git server-code
    check_error $?
    cd server-code/src
    check_error $?
    gitclone https://gitlab.com/evol evol-hercules.git evol
    check_error $?
    cd ../..
    check_error $?
    mkdir -p server-data/plugins
}

function build_init {
    if [ "$CI_SERVER" == "" ];
    then
        return
    fi
    mkdir -p /local/bin
    echo "#!/bin/bash" > /local/bin/id
    echo "echo 1000" >> /local/bin/id
    export PATH="/local/bin:$PATH"
    chmod +x /local/bin/id
    echo "fake id check"
    id

    cd server-code/src/evol
    source tools/vars.sh
    check_error $?
    cd ../../..
    check_error $?
    echo $CC --version
    $CC --version
    check_error $?
}

function init_configs {
    cd tools/localserver
    ./installconfigs.sh
    cd ../..
    cp server-data/.tools/conf/$1/* server-data/conf/import/
    cp server-data/.tools/npc/motd-* server-data/npc/commands/
    ls -la server-data/conf/import
    cat server-data/conf/import/inter_conf.txt
}