File: bootstrap.sh

package info (click to toggle)
qtox 1.16.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 24,048 kB
  • sloc: cpp: 35,612; xml: 10,669; sh: 2,108; ansic: 1,520; objc: 208; perl: 28; makefile: 13
file content (216 lines) | stat: -rwxr-xr-x 5,979 bytes parent folder | download
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
#!/usr/bin/env bash

# This script's purpose is to ease compiling qTox for users.
#
# NO AUTOMATED BUILDS SHOULD DEPEND ON IT.
#
# This script is and will be a subject to breaking changes, and at no time one
# should expect it to work - it's something that you could try to use but
# don't expect that it will work for sure.
#
# If script doesn't work, you should use instructions provided in INSTALL.md
# before reporting issues like “qTox doesn't compile”.
#
# With that being said, reporting that this script doesn't work would be nice.
#
# If you are contributing code to qTox that change its dependencies / the way
# it's being build, please keep in mind that changing just bootstrap.sh
# *IS NOT* and will not be sufficient - you should update INSTALL.md first.

set -eu -o pipefail


################ parameters ################
# directory where the script is located
readonly SCRIPT_DIR=$( cd $(dirname $0); pwd -P)

# directory where dependencies will be installed
readonly INSTALL_DIR=libs

# just for convenience
readonly BASE_DIR="${SCRIPT_DIR}/${INSTALL_DIR}"

# versions of libs to checkout
readonly TOXCORE_VERSION="v0.2.3"
readonly SQLCIPHER_VERSION="v3.4.2"

# directory names of cloned repositories
readonly TOXCORE_DIR="libtoxcore-$TOXCORE_VERSION"
readonly SQLCIPHER_DIR="sqlcipher-$SQLCIPHER_VERSION"

# default values for user given parameters
INSTALL_TOX=true
INSTALL_SQLCIPHER=false
SYSTEM_WIDE=true
KEEP_BUILD_FILES=false

# if Fedora, by default install sqlcipher
if which dnf &> /dev/null
then
    INSTALL_SQLCIPHER=true
fi


print_help() {
    echo "Use this script to install/update libtoxcore"
    echo ""
    echo "usage:"
    echo "    ${0} PARAMETERS"
    echo ""
    echo "parameters:"
    echo "    --with-tox             : install/update libtoxcore"
    echo "    --without-tox          : do not install/update libtoxcore"
    echo "    --with-sqlcipher       : install/update sqlcipher"
    echo "    --without-sqlcipher    : do not install/update sqlcipher"
    echo "    -h|--help              : displays this help"
    echo "    -l|--local             : install packages into ${INSTALL_DIR}"
    echo "    -k|--keep              : keep build files after installation/update"
    echo ""
    echo "example usages:"
    echo "    ${0}    -- install libtoxcore"
}

############ print debug output ############
print_debug_output() {
    echo "with tox                    : ${INSTALL_TOX}"
    echo "with sqlcipher              : ${INSTALL_SQLCIPHER}"
    echo "install system-wide         : ${SYSTEM_WIDE}"
    echo "keep build files            : ${KEEP_BUILD_FILES}"
}

# remove not needed dirs
remove_build_dirs() {
    rm -rf "${BASE_DIR}/${TOXCORE_DIR}"
    rm -rf "${BASE_DIR}/${SQLCIPHER_DIR}"
}

install_toxcore() {
    if [[ $INSTALL_TOX = "true" ]]
    then
        git clone https://github.com/toktok/c-toxcore.git \
            --branch $TOXCORE_VERSION \
            --depth 1 \
            "${BASE_DIR}/${TOXCORE_DIR}"

        pushd ${BASE_DIR}/${TOXCORE_DIR}

        # compile and install
        if [[ $SYSTEM_WIDE = "false" ]]
        then
            cmake . -DCMAKE_INSTALL_PREFIX=${BASE_DIR}
            make -j $(nproc)
            make install
        else
            cmake .
            make -j $(nproc)
            sudo make install
            sudo ldconfig
        fi

        popd
    fi
}


install_sqlcipher() {
    if [[ $INSTALL_SQLCIPHER = "true" ]]
    then
        git clone https://github.com/sqlcipher/sqlcipher.git \
            "${BASE_DIR}/${SQLCIPHER_DIR}" \
            --branch $SQLCIPHER_VERSION \
            --depth 1

        pushd "${BASE_DIR}/${SQLCIPHER_DIR}"
        autoreconf -if

        if [[ $SYSTEM_WIDE = "false" ]]
        then
            ./configure --prefix="${BASE_DIR}" \
                --enable-tempstore=yes \
                CFLAGS="-DSQLITE_HAS_CODEC"
            make -j$(nproc)
            make install || \
                echo "" && \
                echo "Sqlcipher failed to install locally." && \
                echo "" && \
                echo "Try without \"-l|--local\"" && \
                exit 1
        else
            ./configure \
                --enable-tempstore=yes \
                CFLAGS="-DSQLITE_HAS_CODEC"
            make -j$(nproc)
            sudo make install
            sudo ldconfig
        fi

        popd
    fi
}


main() {
    ########## parse input parameters ##########
    while [ $# -ge 1 ]
    do
        if [ ${1} = "--with-tox" ]
        then
            INSTALL_TOX=true
            shift
        elif [ ${1} = "--without-tox" ]
        then
            INSTALL_TOX=false
            shift
        elif [ ${1} = "--with-sqlcipher" ]
        then
            INSTALL_SQLCIPHER=true
            shift
        elif [ ${1} = "--without-sqlcipher" ]
        then
            INSTALL_SQLCIPHER=false
            shift
        elif [ ${1} = "-l" -o ${1} = "--local" ]
        then
            SYSTEM_WIDE=false
            shift
        elif [ ${1} = "-k" -o ${1} = "--keep" ]
        then
            KEEP_BUILD_FILES=true
            shift
        else
            if [ ${1} != "-h" -a ${1} != "--help" ]
            then
                echo "[ERROR] Unknown parameter \"${1}\""
                echo ""
                print_help
                exit 1
            fi

            print_help
            exit 0
        fi
    done

    print_debug_output

    ############### prepare step ###############
    # create BASE_DIR directory if necessary
    mkdir -p "${BASE_DIR}"

    # maybe an earlier run of this script failed
    # thus we should remove the cloned repositories
    # if they exist, otherwise cloning them may fail
    remove_build_dirs

    ############### install step ###############
    install_toxcore
    install_sqlcipher

    ############### cleanup step ###############
    # remove cloned repositories
    if [[ $KEEP_BUILD_FILES = "false" ]]
    then
        remove_build_dirs
    fi
}
main $@