summaryrefslogtreecommitdiff
path: root/apps/installer/includes/functions.sh
blob: b9bdd95500bcb0d028f709ef7315a69b0ea7a183 (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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
function inst_configureOS() {
    echo "Platform: $OSTYPE"
    case "$OSTYPE" in
        solaris*) echo "Solaris is not supported yet" ;;
        darwin*)  source "$AC_PATH_INSTALLER/includes/os_configs/osx.sh" ;;
        linux*)
            # If $OSDISTRO is set, use this value (from config.sh)
            if [ ! -z "$OSDISTRO" ]; then
                DISTRO=$OSDISTRO
            # If available, use LSB to identify distribution
            elif command -v lsb_release >/dev/null 2>&1 ; then
                DISTRO=$(lsb_release -is)
            # Otherwise, use release info file
            else
                DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1)
            fi

            case $DISTRO in
            # add here distro that are debian or ubuntu based
            # TODO: find a better way, maybe checking the existance
            # of a package manager
                "neon" | "ubuntu" | "Ubuntu")
                    DISTRO="ubuntu"
                ;;
                "debian" | "Debian")
                    DISTRO="debian"
                ;;
                *)
                    echo "Distro: $DISTRO, is not supported. If your distribution is based on debian or ubuntu,
                        please set the 'OSDISTRO' environment variable to one of these distro (you can use config.sh file)"
                ;;
            esac


            DISTRO=${DISTRO,,}

            echo "Distro: $DISTRO"

            # TODO: implement different configurations by distro
            source "$AC_PATH_INSTALLER/includes/os_configs/$DISTRO.sh"
        ;;
        bsd*)     echo "BSD is not supported yet" ;;
        msys*)    source "$AC_PATH_INSTALLER/includes/os_configs/windows.sh" ;;
        *)        echo "This platform is not supported" ;;
    esac
}

function inst_updateRepo() {
    cd "$AC_PATH_ROOT"
    if [ ! -z $INSTALLER_PULL_FROM ]; then
        git pull "$ORIGIN_REMOTE" "$INSTALLER_PULL_FROM"
    else
        git pull "$ORIGIN_REMOTE" $(git rev-parse --abbrev-ref HEAD)
    fi
}

function inst_resetRepo() {
    cd "$AC_PATH_ROOT"
    git reset --hard $(git rev-parse --abbrev-ref HEAD)
    git clean -f
}

function inst_compile() {
    comp_configure
    comp_build
}

function inst_cleanCompile() {
    comp_clean
    inst_compile
}

function inst_allInOne() {
    inst_configureOS
    inst_compile
    dbasm_import true true true
}

function inst_getVersionBranch() {
    local res="master"
    local v="not-defined"
    local MODULE_MAJOR=0
    local MODULE_MINOR=0
    local MODULE_PATCH=0
    local MODULE_SPECIAL=0;
    local ACV_MAJOR=0
    local ACV_MINOR=0
    local ACV_PATCH=0
    local ACV_SPECIAL=0;
    local curldata=$(curl -f --silent -H 'Cache-Control: no-cache' "$1" || echo "{}")
    local parsed=$(echo "$curldata" | "$AC_PATH_DEPS/jsonpath/JSONPath.sh" -b '$.compatibility.*.[version,branch]')

    semverParseInto "$ACORE_VERSION" ACV_MAJOR ACV_MINOR ACV_PATCH ACV_SPECIAL

    if [[ ! -z "$parsed" ]]; then
        readarray -t vers < <(echo "$parsed")
        local idx
        res="none"
        # since we've the pair version,branch alternated in not associative and one-dimensional
        # array, we've to simulate the association with length/2 trick
        for idx in `seq 0 $((${#vers[*]}/2-1))`; do
            semverParseInto "${vers[idx*2]}" MODULE_MAJOR MODULE_MINOR MODULE_PATCH MODULE_SPECIAL
            if [[ $MODULE_MAJOR -eq $ACV_MAJOR && $MODULE_MINOR -le $ACV_MINOR ]]; then
                res="${vers[idx*2+1]}"
                v="${vers[idx*2]}"
            fi
        done
    fi

    echo "$v" "$res"
}

function inst_module_search {

    local res="$1"
    local idx=0;

    if [ -z "$1" ]; then
        echo "Type what to search or leave blank for full list"
        read -p "Insert name: " res
    fi

    local search="+$res"

    echo "Searching $res..."
    echo "";

    readarray -t MODS < <(curl --silent "https://api.github.com/search/repositories?q=org%3Aazerothcore${search}+fork%3Atrue+topic%3Acore-module+sort%3Astars&type=" \
        | "$AC_PATH_DEPS/jsonpath/JSONPath.sh" -b '$.items.*.name')
    while (( ${#MODS[@]} > idx )); do
        mod="${MODS[idx++]}"
        read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/azerothcore/$mod/master/acore-module.json")

        if [[ "$b" != "none" ]]; then
            echo "-> $mod (tested with AC version: $v)"
        else
            echo "-> $mod (no revision available for AC v$AC_VERSION, it could not work!)"
        fi
    done

    echo "";
    echo "";
}

function inst_module_install {
    local res
    if [ -z "$1" ]; then
        echo "Type the name of the module to install"
        read -p "Insert name: " res
    else
        res="$1"
    fi

    read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/azerothcore/$res/master/acore-module.json")

    if [[ "$b" != "none" ]]; then
        Joiner:add_repo "https://github.com/azerothcore/$res" "$res" "$b" && echo "Done, please re-run compiling and db assembly. Read instruction on module repository for more information"
    else
        echo "Cannot install $res module: it doesn't exists or no version compatible with AC v$ACORE_VERSION are available"
    fi

    echo "";
    echo "";
}

function inst_module_update {
    local res;
    local _tmp;
    local branch;
    local p;

    if [ -z "$1" ]; then
        echo "Type the name of the module to update"
        read -p "Insert name: " res
    else
        res="$1"
    fi

    _tmp=$PWD

    if [ -d "$J_PATH_MODULES/$res/" ]; then
        read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/azerothcore/$res/master/acore-module.json")

        cd "$J_PATH_MODULES/$res/"

        # use current branch if something wrong with json
        if [[ "$v" == "none" || "$v" == "not-defined" ]]; then
            b=`git rev-parse --abbrev-ref HEAD`
        fi

        Joiner:upd_repo "https://github.com/azerothcore/$res" "$res" "$b" && echo "Done, please re-run compiling and db assembly" || echo "Cannot update"
        cd $_tmp
    else
        echo "Cannot update! Path doesn't exist"
    fi;

    echo "";
    echo "";
}

function inst_module_remove {
    if [ -z "$1" ]; then
        echo "Type the name of the module to remove"
        read -p "Insert name: " res
    else
        res="$1"
    fi

    Joiner:remove "$res" && echo "Done, please re-run compiling"  || echo "Cannot remove"

    echo "";
    echo "";
}


function inst_simple_restarter {
    echo "Running $1 ..."
    bash "$AC_PATH_APPS/startup-scripts/simple-restarter" "$AC_BINPATH_FULL" "$1"
    echo
    #disown -a
    #jobs -l
}

function inst_download_client_data {
    # change the following version when needed
    local VERSION=v16

    echo "#######################"
    echo "Client data downloader"
    echo "#######################"

    # first check if it's defined in env, otherwise use the default
    local path="${DATAPATH:-$AC_BINPATH_FULL}"
    local zipPath="${DATAPATH_ZIP:-"$path/data.zip"}"

    dataVersionFile="$path/data-version"

    [ -f "$dataVersionFile" ] && source "$dataVersionFile"

    # create the path if doesn't exists
    mkdir -p "$path"

    if [ "$VERSION" == "$INSTALLED_VERSION" ]; then
        echo "Data $VERSION already installed. If you want to force the download remove the following file: $dataVersionFile"
        return
    fi

    echo "Downloading client data in: $zipPath ..."
    curl -L https://github.com/wowgaming/client-data/releases/download/$VERSION/data.zip > "$zipPath" \
        && echo "unzip downloaded file in $path..." && unzip -q -o "$zipPath" -d "$path/" \
        && echo "Remove downloaded file" && rm "$zipPath" \
        && echo "INSTALLED_VERSION=$VERSION" > "$dataVersionFile"
}