File: qTox-Mac-Deployer-ULTIMATE.sh

package info (click to toggle)
qtox 1.16.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • 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 (319 lines) | stat: -rwxr-xr-x 9,317 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/env bash

#
#    Copyright © 2015 by RowenStipe
#    Copyright © 2016-2018 by The qTox Project Contributors
#
#    This program is libre software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This uses the same process as doing it manually but with a few varients

# Use: ./qTox-Mac-Deployer-ULTIMATE.sh -h

set -e

# Your home DIR really (Most of this happens in it) {DONT USE: ~ }
SUBGIT="" #Change this to define a 'sub' git folder e.g. "-Patch"
          #Applies to $QTOX_DIR, $BUILD_DIR, and $DEPLOY_DIR folders for organization puropses

if [[ $TRAVIS = true ]]
then
    MAIN_DIR="${TRAVIS_BUILD_DIR}"
    QTOX_DIR="${MAIN_DIR}"
else
    MAIN_DIR="/Users/${USER}"
    QTOX_DIR="${MAIN_DIR}/qTox${SUBGIT}"
fi
QT_DIR="/usr/local/Cellar/qt5" # Folder name of QT install
# Figure out latest version
QT_VER=($(ls ${QT_DIR} | sed -n -e 's/^\([0-9]*\.([0-9]*\.([0-9]*\).*/\1/' -e '1p;$p'))
QT_DIR_VER="${QT_DIR}/${QT_VER[1]}"

TOXCORE_DIR="${MAIN_DIR}/toxcore" # Change to Git location
FILTERAUIO_DIR="${MAIN_DIR}/filter_audio" # Change to Git location

LIB_INSTALL_PREFIX="${QTOX_DIR}/libs"

[[ ! -e "${LIB_INSTALL_PREFIX}" ]] \
&& mkdir -p "${LIB_INSTALL_PREFIX}"

BUILD_DIR="${MAIN_DIR}/qTox-Mac_Build${SUBGIT}"
DEPLOY_DIR="${MAIN_DIR}/qTox-Mac_Deployed${SUBGIT}"

# helper function to "pretty-print"
fcho() {
    local msg="$1"; shift
    printf "\n$msg\n" "$@"
}

build_toxcore() {
    echo "Starting Toxcore build and install"
    cd $TOXCORE_DIR
    echo "Now working in: ${PWD}"

    local LS_DIR="/usr/local/Cellar/libsodium/"
    #Figure out latest version
    local LS_VER=($(ls ${LS_DIR} | sed -n -e 's/^\([0-9]*\.([0-9]*\.([0-9]*\).*/\1/' -e '1p;$p'))
    local LS_DIR_VER="${LS_DIR}/${LS_VER[1]}"

    [[ $TRAVIS != true ]] \
    && sleep 3

    autoreconf -if

    #Make sure the correct version of libsodium is used
    ./configure --with-libsodium-headers="${LS_DIR_VER}/include/" --with-libsodium-libs="${LS_DIR_VER}/lib/" --prefix="${LIB_INSTALL_PREFIX}"

    make clean &> /dev/null
    fcho "Compiling toxcore."
    make > /dev/null || exit 1
    fcho "Installing toxcore."
    make install > /dev/null || exit 1
}

install() {
    fcho "=============================="
    fcho "This script will install the necessary applications and libraries needed to compile qTox properly."
    fcho "Note that this is not a 100 percent automated install it just helps simplify the process for less experienced or lazy users."
    if [[ $TRAVIS = true ]]
    then
        echo "Oh... It's just Travis...."
    else
        read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
    fi

    #fcho "Installing x-code Command line tools ..."
    #xcode-select --install

    if [[ -e /usr/local/bin/brew ]]
    then
        fcho "Homebrew already installed!"
    else
        fcho "Installing homebrew ..."
        ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    fi
    if [[ $TRAVIS != true ]]
    then
        fcho "Updating brew formulas ..."
        brew update
    fi
    fcho "Getting home brew formulas ..."
    if [[ $TRAVIS != true ]]
    then
        sleep 3
        brew install git wget libtool autoconf automake pkgconfig
    fi
    brew install check libvpx opus libsodium

    fcho "Starting git repo checks ..."

    #cd $MAIN_DIR # just in case
    # Toxcore
    if [[ -e $TOX_DIR/.git/index ]]
    then
        fcho "Toxcore git repo already in place !"
        cd $TOX_DIR
        git pull
    else
        fcho "Cloning Toxcore git ... "
        git clone --branch v0.2.3 --depth=1 https://github.com/toktok/c-toxcore "$TOXCORE_DIR"
    fi
    # qTox
    if [[ $TRAVIS = true ]]
    then
        fcho "Travis... You already have qTox..."
    else
        if [[ -e $QTOX_DIR/.git/index ]]
        then
            fcho "qTox git repo already in place !"
            cd $QTOX_DIR
            git pull
        else
            fcho "Cloning qTox git ... "
            git clone https://github.com/qTox/qTox.git
        fi
    fi

    # toxcore build
    if [[ $TRAVIS = true ]]
    then
        build_toxcore
    else
        fcho "If all went well you should now have all the tools needed to compile qTox!"
        read -r -p "Would you like to install toxcore now? [y/N] " response
        if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
        then
            build_toxcore
        else
            fcho "You can simply use the -u command and say [Yes/n] when prompted"
        fi
    fi

    if [[ $TRAVIS = true ]]
    then
        fcho "Updating brew formulas ..."
        brew update > /dev/null
    else
        brew install cmake
    fi
    brew install ffmpeg libexif qrencode qt5 sqlcipher openal-soft

    fcho "Cloning filter_audio ... "
    git clone --branch v0.0.1 --depth=1 https://github.com/irungentoo/filter_audio "$FILTERAUIO_DIR"
    cd "$FILTERAUIO_DIR"
    fcho "Installing filter_audio ... "
    make install PREFIX="$LIB_INSTALL_PREFIX"

    QT_VER=($(ls ${QT_DIR} | sed -n -e 's/^\([0-9]*\.([0-9]*\.([0-9]*\).*/\1/' -e '1p;$p'))
    QT_DIR_VER="${QT_DIR}/${QT_VER[1]}"

    # put required by qTox libs/headers in `libs/`
    cd "${QTOX_DIR}"
    sudo ./bootstrap-osx.sh
}

update() {
    fcho "------------------------------"
    fcho "Starting update process ..."
    #First update Toxcore from git
    cd $TOXCORE_DIR
    fcho "Now in ${PWD}"
    fcho "Pulling ..."
    # make sure that pull can be applied, i.e. clean up files from any
    # changes that could have been applied to them
    git checkout -f
    git pull
    read -r -p "Did Toxcore update from git? [y/N] " response
    if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
    then
        build_toxcore
    else
        fcho "Moving on!"
    fi

    #Now let's update qTox!
    cd $QTOX_DIR
    fcho "Now in ${PWD}"
    fcho "Pulling ..."
    # make sure that pull can be applied, i.e. clean up files from any
    # changes that could have been applied to them
    git checkout -f
    git pull
    read -r -p "Did qTox update from git? [y/N] " response
    if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
    then
        fcho "Starting OSX bootstrap ..."
        sudo ./bootstrap-osx.sh
    else
        fcho "Moving on!"
    fi
}

build() {
    fcho "------------------------------"
    fcho "Starting build process ..."
    rm -rf $BUILD_DIR
    rm -rf $DEPLOY_DIR
    mkdir $BUILD_DIR
    cd $BUILD_DIR
    fcho "Now working in ${PWD}"
    fcho "Starting cmake ..."
    export CMAKE_PREFIX_PATH=$(brew --prefix qt5)
    cmake -H$QTOX_DIR -B.
    make -j$(sysctl -n hw.ncpu)
}

deploy() {
    fcho "------------------------------"
    fcho "starting deployment process ..."
    cd $BUILD_DIR
    if [ ! -d $BUILD_DIR ]
    then
        fcho "Error: Build directory not detected, please run -ubd, or -b before deploying"
        exit 0
    fi
    mkdir $DEPLOY_DIR
    make install
    cp -r $BUILD_DIR/qTox.app $DEPLOY_DIR/qTox.app
}

bootstrap() {
    fcho "------------------------------"
    fcho "starting bootstrap process ..."

    #Toxcore
    build_toxcore

    #Boot Strap
    fcho "Running: sudo ${QTOX_DIR_VER}/bootstrap-osx.sh"
    cd $QTOX_DIR
    sudo ./bootstrap-osx.sh
}

dmgmake() {
    fcho "------------------------------"
    fcho "Starting DMG creation"
    cp $BUILD_DIR/qTox.dmg $QTOX_DIR/
}

helpme() {
    echo "This script was created to help ease the process of compiling and creating a distributable qTox package for OSX systems."
    echo "The available commands are:"
    echo "-h  | --help      -- This help text."
    echo "-i  | --install   -- A slightly automated process for getting an OSX machine ready to build Toxcore and qTox."
    echo "-u  | --update    -- Check for updates and build Toxcore from git & update qTox from git."
    echo "-b  | --build     -- Builds qTox in: ${BUILD_DIR}"
    echo "-d  | --deploy    -- Makes a distributable qTox.app file in: ${DEPLOY_DIR}"
    echo "-bs | --bootstrap -- Performs bootstrap steps."
    fcho "Issues with Toxcore or qTox should be reported to their respective repos: https://github.com/toktok/c-toxcore | https://github.com/qTox/qTox"
    exit 0
}

case "$1" in
    -h | --help)
    helpme
    exit
    ;;
    -i | --install)
    install
    exit
    ;;
    -u | --update)
    update
    exit
    ;;
    -b | --build)
    build
    exit
    ;;
    -d | --deploy)
    deploy
    exit
    ;;
    -bs | --bootstrap)
    bootstrap
    exit
    ;;
    -dmg)
    dmgmake
    exit
    ;;
    *)
    ;;
esac

fcho "Oh dear! You seemed to of started this script improperly! Use -h to get available commands and information!"
echo " "
say -v Kathy -r 255 "Oh dear! You seemed to of started this script improperly! Use -h to get available commands and information!"
exit 0