|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Builds and uploads DB Browser for SQLite nightlies, |
| 4 | +# after updating the Homebrew dependencies |
| 5 | + |
| 6 | +BRANCH="master" |
| 7 | +BREW="/opt/homebrew/bin/brew" |
| 8 | +BUILD_TYPE="release" |
| 9 | +CMAKE="/opt/homebrew/bin/cmake" |
| 10 | +DATE=`date "+%Y%m%d"` |
| 11 | +LOG="$HOME/db4s_nightlies/nightly-$DATE.log" |
| 12 | +PATH="$PATH:/opt/homebrew/bin:/usr/sbin" |
| 13 | +QT5_DIR="/opt/homebrew/opt/qt5" |
| 14 | +MACDEPLOYQT="$QT5_DIR/bin/macdeployqt" |
| 15 | + |
| 16 | +# Add the sensitive values we don't want to store in this script file |
| 17 | +source ~/.db4s_secure |
| 18 | + |
| 19 | +# Load NVM, for appdmg to work |
| 20 | +export NVM_DIR="$HOME/.nvm" |
| 21 | +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" |
| 22 | + |
| 23 | +# Update the branch to build, if specified on the command line with "-b [branch name]" |
| 24 | +if [ "$1" = "-b" ]; then |
| 25 | + if [ ! -z "$2" ]; then |
| 26 | + BRANCH="$2" |
| 27 | + echo "New branch = ${BRANCH}" >>$LOG 2>&1 |
| 28 | + else |
| 29 | + # Warn on missing branch name override |
| 30 | + echo "Missing branch name after the '-b'" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +fi |
| 34 | + |
| 35 | +# Determine if a Release or Debug build is to be built |
| 36 | +if [ "$3" = "-t" ]; then |
| 37 | + if [ ! -z "$4" ]; then |
| 38 | + BUILD_TYPE="$4" |
| 39 | + echo "Build type = ${BUILD_TYPE}" >>$LOG 2>&1 |
| 40 | + else |
| 41 | + # Warn on missing build type override |
| 42 | + echo "Missing build type after the '-t'" |
| 43 | + exit 2 |
| 44 | + fi |
| 45 | +fi |
| 46 | + |
| 47 | +# Verify the build type is valid |
| 48 | +if [ "${BUILD_TYPE}" != "debug" -a "${BUILD_TYPE}" != "release" ]; then |
| 49 | + echo "Unknown build type" |
| 50 | + exit 3 |
| 51 | +fi |
| 52 | + |
| 53 | +# Ensure Homebrew is owned by my user |
| 54 | +echo Ensure Homebrew is owned by my user >>$LOG 2>&1 |
| 55 | +sudo chown -Rh $USER: /opt/homebrew >>$LOG 2>&1 |
| 56 | + |
| 57 | +# Update Homebrew |
| 58 | +echo Update Homebrew >>$LOG 2>&1 |
| 59 | +$BREW update >>$LOG 2>&1 |
| 60 | + |
| 61 | +### Build standard version |
| 62 | + |
| 63 | +# Remove any existing Homebrew installed packages |
| 64 | +echo Remove any existing Homebrew installed packages >>$LOG 2>&1 |
| 65 | +$BREW remove `$BREW list --formula` --force >>$LOG 2>&1 |
| 66 | + |
| 67 | +# Install CMake |
| 68 | +$BREW install --formula cmake >>$LOG 2>&1 |
| 69 | + |
| 70 | +# Install Qt5 |
| 71 | +$BREW install --formula qt5 >>$LOG 2>&1 |
| 72 | + |
| 73 | +# Install SQLite3 |
| 74 | +# Note - `brew tap sqlitebrowser/homebrew-sqlite3` needs to have been run at least once (manually) first |
| 75 | +echo Install SQLite3 >>$LOG 2>&1 |
| 76 | +$BREW install sqlitefts5 >>$LOG 2>&1 |
| 77 | + |
| 78 | +# Update the sqlitebrowser source |
| 79 | +echo Update the sqlitebrowser source >>$LOG 2>&1 |
| 80 | +cd $HOME/git_repos/sqlitebrowser >>$LOG 2>&1 |
| 81 | +git reset --hard HEAD >>$LOG 2>&1 |
| 82 | +git clean -dffx >>$LOG 2>&1 |
| 83 | +git pull >>$LOG 2>&1 |
| 84 | +git checkout $BRANCH >>$LOG 2>&1 |
| 85 | +git reset --hard HEAD >>$LOG 2>&1 |
| 86 | +git clean -dffx >>$LOG 2>&1 |
| 87 | +git pull >>$LOG 2>&1 |
| 88 | + |
| 89 | +# Build and package standard sqlitebrowser nightly |
| 90 | +echo Build and package standard sqlitebrowser nightly >>$LOG 2>&1 |
| 91 | +mkdir build >>$LOG 2>&1 |
| 92 | +cd build >>$LOG 2>&1 |
| 93 | +if [ "${BUILD_TYPE}" = "debug" ]; then |
| 94 | + $CMAKE -DCMAKE_BUILD_TYPE=Debug .. >>$LOG 2>&1 |
| 95 | +else |
| 96 | + $CMAKE .. >>$LOG 2>&1 |
| 97 | +fi |
| 98 | +make -j9 >>$LOG 2>&1 |
| 99 | +cd .. >>$LOG 2>&1 |
| 100 | + |
| 101 | +# Include the depencencies in the .app bundle |
| 102 | +$MACDEPLOYQT build/DB\ Browser\ for\ SQLite.app -verbose=2 -sign-for-notarization="${DEV_ID}">>$LOG 2>&1 |
| 103 | + |
| 104 | +# Add the extensions to the .dmg |
| 105 | +echo Add the extensions to the .dmg >>$LOG 2>&1 |
| 106 | +mkdir build/DB\ Browser\ for\ SQLite.app/Contents/Extensions >>$LOG 2>&1 |
| 107 | +clang -I/opt/homebrew/opt/sqlitefts5/include -L/opt/homebrew/opt/sqlitefts5/lib -fno-common -dynamiclib src/extensions/extension-formats.c -o build/DB\ Browser\ for\ SQLite.app/Contents/Extensions/formats.dylib >>$LOG 2>&1 |
| 108 | +clang -I/opt/homebrew/opt/sqlitefts5/include -L/opt/homebrew/opt/sqlitefts5/lib -fno-common -dynamiclib src/extensions/extension-functions.c -o build/DB\ Browser\ for\ SQLite.app/Contents/Extensions/math.dylib >>$LOG 2>&1 |
| 109 | +# fileio.c extension |
| 110 | +curl -L -o src/extensions/fileio.c 'https://sqlite.org/src/raw?filename=ext/misc/fileio.c&ci=trunk' >>$LOG 2>&1 |
| 111 | +curl -L -o src/extensions/test_windirent.c 'https://sqlite.org/src/raw?filename=src/test_windirent.c&ci=trunk' >>$LOG 2>&1 |
| 112 | +curl -L -o src/extensions/test_windirent.h 'https://sqlite.org/src/raw?filename=src/test_windirent.h&ci=trunk' >>$LOG 2>&1 |
| 113 | +clang -I/opt/homebrew/opt/sqlitefts5/include -L/opt/homebrew/opt/sqlitefts5/lib -fno-common -dynamiclib src/extensions/fileio.c src/extensions/test_windirent.c -o build/DB\ Browser\ for\ SQLite.app/Contents/Extensions/fileio.dylib >>$LOG 2>&1 |
| 114 | + |
| 115 | +# Copy the license files to the .dmg |
| 116 | +echo Copying the license files to the .dmg >>$LOG 2>&1 |
| 117 | +cp LICENSE LICENSE-PLUGINS build/DB\ Browser\ for\ SQLite.app/Contents/Resources/ >>$LOG 2>&1 |
| 118 | + |
| 119 | +# Copy the translation files to the .dmg |
| 120 | +mkdir -p build/DB\ Browser\ for\ SQLite.app/Contents/translations >>$LOG 2>&1 |
| 121 | +for i in ar zh_CN zh_TW cs en fr de it ko pl pt pt_BR ru es uk; do |
| 122 | + cp -v $QT5_DIR/translations/qt_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 123 | + cp -v $QT5_DIR/translations/qtbase_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 124 | + cp -v $QT5_DIR/translations/qtmultimedia_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 125 | + cp -v $QT5_DIR/translations/qtquick1_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 126 | + cp -v $QT5_DIR/translations/qtscript_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 127 | + cp -v $QT5_DIR/translations/qtxmlpatterns_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 128 | +done |
| 129 | + |
| 130 | +# Add the icon file |
| 131 | +cp installer/macos/macapp.icns build/DB\ Browser\ for\ SQLite.app/Contents/Resources/ >>$LOG 2>&1 |
| 132 | +/usr/libexec/PlistBuddy -c "Set :CFBundleIconFile macapp.icns" build/DB\ Browser\ for\ SQLite.app/Contents/Info.plist >>$LOG 2>&1 |
| 133 | + |
| 134 | +# Sign the added libraries |
| 135 | +codesign --sign "${DEV_ID}" --verbose --deep --force --keychain "/Library/Keychains/System.keychain" --options runtime --timestamp build/DB\ Browser\ for\ SQLite.app >>$LOG 2>&1 |
| 136 | + |
| 137 | +# Make a .dmg file from the .app |
| 138 | +mv build/DB\ Browser\ for\ SQLite.app $HOME/appdmg/ >>$LOG 2>&1 |
| 139 | +cd $HOME/appdmg >>$LOG 2>&1 |
| 140 | +appdmg --quiet nightly.json DB\ Browser\ for\ SQLite-arm64_${DATE}.dmg >>$LOG 2>&1 |
| 141 | +codesign --sign "${DEV_ID}" --verbose --deep --keychain "/Library/Keychains/System.keychain" --options runtime --timestamp DB\ Browser\ for\ SQLite-arm64_${DATE}.dmg >>$LOG 2>&1 |
| 142 | +mv DB\ Browser\ for\ SQLite-arm64_${DATE}.dmg $HOME/db4s_nightlies/ >>$LOG 2>&1 |
| 143 | +rm -rf $HOME/appdmg/DB\ Browser\ for\ SQLite.app >>$LOG 2>&1 |
| 144 | + |
| 145 | +### Build SQLCipher version |
| 146 | +# Remove any existing Homebrew installed packages |
| 147 | +echo Remove any existing Homebrew installed packages >>$LOG 2>&1 |
| 148 | +$BREW remove `$BREW list --formula` --force >>$LOG 2>&1 |
| 149 | + |
| 150 | +# Install CMake |
| 151 | +$BREW install --formula cmake >>$LOG 2>&1 |
| 152 | + |
| 153 | +# Install Qt5 |
| 154 | +$BREW install --formula qt5 >>$LOG 2>&1 |
| 155 | + |
| 156 | +# Install SQLCipher |
| 157 | +echo Install SQLCipher >>$LOG 2>&1 |
| 158 | +$BREW install sqlcipherdb4s >>$LOG 2>&1 |
| 159 | + |
| 160 | +# Clean the sqlitebrowser source |
| 161 | +echo Clean the sqlitebrowser source >>$LOG 2>&1 |
| 162 | +cd $HOME/git_repos/sqlitebrowser >>$LOG 2>&1 |
| 163 | +git reset --hard HEAD >>$LOG 2>&1 |
| 164 | +git clean -dffx >>$LOG 2>&1 |
| 165 | +git checkout $BRANCH >>$LOG 2>&1 |
| 166 | +git reset --hard HEAD >>$LOG 2>&1 |
| 167 | +git clean -dffx >>$LOG 2>&1 |
| 168 | + |
| 169 | +# Build and package sqlitebrowser with SQLCipher support |
| 170 | +echo Build and package sqlitebrowser with SQLCipher support >>$LOG 2>&1 |
| 171 | +mkdir build >>$LOG 2>&1 |
| 172 | +cd build >>$LOG 2>&1 |
| 173 | +if [ "${BUILD_TYPE}" = "debug" ]; then |
| 174 | + $CMAKE -DCMAKE_BUILD_TYPE=Debug -Dsqlcipher=1 .. >>$LOG 2>&1 |
| 175 | +else |
| 176 | + $CMAKE -Dsqlcipher=1 .. >>$LOG 2>&1 |
| 177 | +fi |
| 178 | +make -j3 >>$LOG 2>&1 |
| 179 | +cd .. >>$LOG 2>&1 |
| 180 | + |
| 181 | +# Include the depencencies in the .app bundle |
| 182 | +$MACDEPLOYQT build/DB\ Browser\ for\ SQLite.app -verbose=2 -sign-for-notarization="${DEV_ID}">>$LOG 2>&1 |
| 183 | + |
| 184 | +# Add the extensions to the .dmg |
| 185 | +echo Add the extensions to the .dmg >>$LOG 2>&1 |
| 186 | +mkdir build/DB\ Browser\ for\ SQLite.app/Contents/Extensions >>$LOG 2>&1 |
| 187 | +clang -I/opt/homebrew/opt/sqlcipherdb4s/include -L/opt/homebrew/opt/sqlcipherdb4s/lib -fno-common -dynamiclib -lsqlcipher src/extensions/extension-formats.c -o build/DB\ Browser\ for\ SQLite.app/Contents/Extensions/formats.dylib >>$LOG 2>&1 |
| 188 | +clang -I/opt/homebrew/opt/sqlcipherdb4s/include -L/opt/homebrew/opt/sqlcipherdb4s/lib -fno-common -dynamiclib -lsqlcipher src/extensions/extension-functions.c -o build/DB\ Browser\ for\ SQLite.app/Contents/Extensions/math.dylib >>$LOG 2>&1 |
| 189 | +# fileio.c extension |
| 190 | +curl -L -o src/extensions/fileio.c 'https://sqlite.org/src/raw?filename=ext/misc/fileio.c&ci=trunk' >>$LOG 2>&1 |
| 191 | +curl -L -o src/extensions/test_windirent.c 'https://sqlite.org/src/raw?filename=src/test_windirent.c&ci=trunk' >>$LOG 2>&1 |
| 192 | +curl -L -o src/extensions/test_windirent.h 'https://sqlite.org/src/raw?filename=src/test_windirent.h&ci=trunk' >>$LOG 2>&1 |
| 193 | +clang -I/opt/homebrew/opt/sqlcipherdb4s/include -L/opt/homebrew/opt/sqlcipherdb4s/lib -fno-common -dynamiclib -lsqlcipher src/extensions/fileio.c src/extensions/test_windirent.c -o build/DB\ Browser\ for\ SQLite.app/Contents/Extensions/fileio.dylib >>$LOG 2>&1 |
| 194 | + |
| 195 | +# Copy the license files to the .dmg |
| 196 | +echo Copying the license files to the .dmg >>$LOG 2>&1 |
| 197 | +cp LICENSE LICENSE-PLUGINS build/DB\ Browser\ for\ SQLite.app/Contents/Resources/ >>$LOG 2>&1 |
| 198 | + |
| 199 | +# Copy the translation files to the .dmg |
| 200 | +mkdir -p build/DB\ Browser\ for\ SQLite.app/Contents/translations >>$LOG 2>&1 |
| 201 | +for i in ar zh_CN zh_TW cs en fr de it ko pl pt pt_BR ru es uk; do |
| 202 | + cp -v $QT5_DIR/translations/qt_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 203 | + cp -v $QT5_DIR/translations/qtbase_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 204 | + cp -v $QT5_DIR/translations/qtmultimedia_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 205 | + cp -v $QT5_DIR/translations/qtquick1_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 206 | + cp -v $QT5_DIR/translations/qtscript_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 207 | + cp -v $QT5_DIR/translations/qtxmlpatterns_${i}.qm build/DB\ Browser\ for\ SQLite.app/Contents/translations/ >>$LOG 2>&1 |
| 208 | +done |
| 209 | + |
| 210 | +# Add the icon file |
| 211 | +cp installer/macos/macapp.icns build/DB\ Browser\ for\ SQLite.app/Contents/Resources/ >>$LOG 2>&1 |
| 212 | +/usr/libexec/PlistBuddy -c "Set :CFBundleIconFile macapp.icns" build/DB\ Browser\ for\ SQLite.app/Contents/Info.plist >>$LOG 2>&1 |
| 213 | + |
| 214 | +# Sign the .app |
| 215 | +codesign --sign "${DEV_ID}" --verbose --deep --force --keychain "/Library/Keychains/System.keychain" --options runtime --timestamp build/DB\ Browser\ for\ SQLite.app >>$LOG 2>&1 |
| 216 | + |
| 217 | +# Make a .dmg file from the .app |
| 218 | +mv build/DB\ Browser\ for\ SQLite.app $HOME/appdmg/ >>$LOG 2>&1 |
| 219 | +cd $HOME/appdmg >>$LOG 2>&1 |
| 220 | +appdmg --quiet nightly.json DB\ Browser\ for\ SQLite-sqlcipher-arm64_${DATE}.dmg >>$LOG 2>&1 |
| 221 | +codesign --sign "${DEV_ID}" --verbose --deep --keychain "/Library/Keychains/System.keychain" --options runtime --timestamp DB\ Browser\ for\ SQLite-sqlcipher-arm64_${DATE}.dmg >>$LOG 2>&1 |
| 222 | +mv DB\ Browser\ for\ SQLite-sqlcipher-arm64_${DATE}.dmg $HOME/db4s_nightlies/ >>$LOG 2>&1 |
| 223 | +rm -rf $HOME/appdmg/DB\ Browser\ for\ SQLite.app >>$LOG 2>&1 |
| 224 | + |
| 225 | +# If building a non-master branch, remove it now that we're finished |
| 226 | +if [ "${BRANCH}" != "master" ]; then |
| 227 | + echo "Removing non-master branch, now we're finihed" >>$LOG 2>&1 |
| 228 | + cd $HOME/git_repos/sqlitebrowser >>$LOG 2>&1 |
| 229 | + git reset --hard HEAD >>$LOG 2>&1 |
| 230 | + git clean -dffx >>$LOG 2>&1 |
| 231 | + git checkout master >>$LOG 2>&1 |
| 232 | + git branch -D "${BRANCH}" >>$LOG 2>&1 |
| 233 | +fi |
| 234 | + |
| 235 | +# Upload nightly builds and the build log thus far |
| 236 | +echo Upload nightly builds >>$LOG 2>&1 |
| 237 | +rsync -aP $HOME/db4s_nightlies/DB\ Browser\ for\ SQLite*${DATE}.dmg ${LOG} ${UPLOAD_SERVER}:/nightlies/macos-arm64/ >>$LOG 2>&1 |
| 238 | +ssh -q ${UPLOAD_SERVER} "cd /nightlies/latest; rm -f *arm64*dmg" >>$LOG 2>&1 |
| 239 | +ssh -q ${UPLOAD_SERVER} "cd /nightlies/latest; cp /nightlies/macos-arm64/DB\ Browser\ for\ SQLite-arm64_${DATE}.dmg /nightlies/latest/DB.Browser.for.SQLite-arm64.dmg" >>$LOG 2>&1 |
| 240 | +ssh -q ${UPLOAD_SERVER} "cd /nightlies/latest; cp /nightlies/macos-arm64/DB\ Browser\ for\ SQLite-sqlcipher-arm64_${DATE}.dmg /nightlies/latest/DB.Browser.for.SQLite-sqlcipher-arm64.dmg" >>$LOG 2>&1 |
| 241 | + |
| 242 | +echo Done! >>$LOG 2>&1 |
0 commit comments