2017-01-28 16:11:05 -05:00
#!/usr/bin/env bash
2018-09-26 16:46:59 -04:00
#
2017-01-28 16:11:05 -05:00
# KeePassXC Release Preparation Helper
2021-09-29 10:25:52 -04:00
# Copyright (C) 2021 KeePassXC team <https://keepassxc.org/>
2017-01-28 16:11:05 -05:00
#
# This program is free 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 2 or (at your option)
# version 3 of the License.
#
# 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/>.
2017-02-11 11:05:28 -05:00
printf "\e[1m\e[32mKeePassXC\e[0m Release Preparation Helper\n"
2021-09-29 10:25:52 -04:00
printf "Copyright (C) 2021 KeePassXC Team <https://keepassxc.org/>\n\n"
2017-01-28 16:11:05 -05:00
2021-09-29 10:25:52 -04:00
set -eE -o pipefail
2017-01-28 16:11:05 -05:00
2022-03-17 18:26:06 -04:00
if [ "$(uname -s)" == "Linux" ]; then
OS_LINUX="1"
elif [ "$(uname -s)" == "Darwin" ]; then
OS_MACOS="1"
elif [ "$(uname -o)" == "Msys" ]; then
OS_WINDOWS="1"
fi
2017-01-28 16:11:05 -05:00
# -----------------------------------------------------------------------
# global default values
# -----------------------------------------------------------------------
RELEASE_NAME=""
APP_NAME="KeePassXC"
SRC_DIR="."
GPG_KEY="CFB4C2166397D0D2"
GPG_GIT_KEY=""
OUTPUT_DIR="release"
SOURCE_BRANCH=""
TARGET_BRANCH="master"
TAG_NAME=""
DOCKER_IMAGE=""
DOCKER_CONTAINER_NAME="keepassxc-build-container"
2022-03-17 18:26:06 -04:00
CMAKE_GENERATOR="Unix Makefiles"
2017-01-28 16:11:05 -05:00
CMAKE_OPTIONS=""
2019-01-30 15:00:47 -05:00
CPACK_GENERATORS="WIX;ZIP"
2017-01-28 16:11:05 -05:00
COMPILER="g++"
2021-01-29 18:39:36 -05:00
MAKE_OPTIONS="-j$(getconf _NPROCESSORS_ONLN)"
2017-11-27 22:46:03 -05:00
BUILD_PLUGINS="all"
2017-01-28 16:11:05 -05:00
INSTALL_PREFIX="/usr/local"
ORIG_BRANCH=""
ORIG_CWD="$(pwd)"
2021-01-31 19:23:11 -05:00
MACOSX_DEPLOYMENT_TARGET=10.13
2021-01-31 16:47:35 -05:00
TIMESTAMP_SERVER="http://timestamp.sectigo.com"
2017-01-28 16:11:05 -05:00
# -----------------------------------------------------------------------
# helper functions
# -----------------------------------------------------------------------
printUsage() {
local cmd
2021-09-29 10:25:52 -04:00
if [ -z "$1" ] || [ "help" == "$1" ]; then
2017-01-28 16:11:05 -05:00
cmd="COMMAND"
2021-09-28 05:22:15 -04:00
elif [ "check" == "$1" ] || [ "merge" == "$1" ] || [ "build" == "$1" ] || [ "gpgsign" == "$1" ] || \
[ "appsign" == "$1" ] || [ "notarize" == "$1" ] || [ "appimage" == "$1" ] || [ "i18n" == "$1" ]; then
2017-01-28 16:11:05 -05:00
cmd="$1"
else
2017-01-28 17:17:48 -05:00
logError "Unknown command: '$1'\n"
2017-01-28 16:11:05 -05:00
cmd="COMMAND"
fi
2017-12-13 16:38:44 -05:00
2021-09-28 05:22:15 -04:00
printf "\e[1mUsage:\e[0m $(basename "$0") $cmd [OPTIONS, ...]\n"
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
if [ "COMMAND" == "$cmd" ]; then
cat << EOF
Commands:
2017-06-06 10:35:16 -04:00
check Perform a dry-run check, nothing is changed
2017-01-28 16:19:23 -05:00
merge Merge release branch into main branch and create release tags
2017-01-28 16:11:05 -05:00
build Build and package binary release from sources
2017-12-13 16:38:44 -05:00
gpgsign Sign previously compiled release packages with GPG
appsign Sign binaries with code signing certificates on Windows and macOS
2021-01-29 18:39:36 -05:00
notarize Submit macOS application DMG for notarization
2017-01-28 16:11:05 -05:00
help Show help for the given command
2021-09-28 05:22:15 -04:00
i18n Update translation files and pull from or push to Transifex
2017-01-28 16:11:05 -05:00
EOF
elif [ "merge" == "$cmd" ]; then
cat << EOF
2017-01-29 06:52:05 -05:00
Merge release branch into main branch and create release tags
2017-01-28 16:11:05 -05:00
Options:
-v, --version Release version number or name (required)
-a, --app-name Application name (default: '${APP_NAME}')
-s, --source-dir Source directory (default: '${SRC_DIR}')
2018-07-08 19:47:35 -04:00
-k, --key GPG key used to sign the merge commit and release tag,
2017-01-28 16:11:05 -05:00
leave empty to let Git choose your default key
(default: '${GPG_GIT_KEY}')
-r, --release-branch Source release branch to merge from (default: 'release/VERSION')
--target-branch Target branch to merge to (default: '${TARGET_BRANCH}')
-t, --tag-name Override release tag name (defaults to version number)
-h, --help Show this help
EOF
elif [ "build" == "$cmd" ]; then
cat << EOF
2017-01-29 06:52:05 -05:00
Build and package binary release from sources
2017-01-28 16:11:05 -05:00
Options:
-v, --version Release version number or name (required)
-a, --app-name Application name (default: '${APP_NAME}')
-s, --source-dir Source directory (default: '${SRC_DIR}')
-o, --output-dir Output directory where to build the release
(default: '${OUTPUT_DIR}')
-t, --tag-name Release tag to check out (defaults to version number)
-b, --build Build sources after exporting release
-d, --docker-image Use the specified Docker image to compile the application.
The image must have all required build dependencies installed.
This option has no effect if --build is not set.
--container-name Docker container name (default: '${DOCKER_CONTAINER_NAME}')
The container must not exist already
2018-05-16 22:39:39 -04:00
--snapcraft Create and use docker image to build snapcraft distribution.
This option has no effect if --docker-image is not set.
2018-09-26 16:46:59 -04:00
--appimage Build a Linux AppImage after compilation.
If this option is set, --install-prefix has no effect
2018-07-08 19:47:35 -04:00
--appsign Perform platform specific App Signing before packaging
2021-01-31 16:47:35 -05:00
--timestamp Explicitly set the timestamp server to use for appsign (default: '${TIMESTAMP_SERVER}')
2021-09-06 22:26:00 -04:00
--vcpkg Specify VCPKG toolchain file (example: ~/vcpkg/scripts/buildsystems/vcpkg.cmake)
2018-07-08 19:47:35 -04:00
-k, --key Specify the App Signing Key/Identity
2021-09-06 22:26:00 -04:00
--cmake-generator Override the default CMake generator (Default: Ninja)
2017-01-28 16:11:05 -05:00
-c, --cmake-options Additional CMake options for compiling the sources
--compiler Compiler to use (default: '${COMPILER}')
-m, --make-options Make options for compiling sources (default: '${MAKE_OPTIONS}')
2018-07-10 21:43:01 -04:00
-g, --generators Additional CPack generators (default: '${CPACK_GENERATORS}')
2017-01-28 16:11:05 -05:00
-i, --install-prefix Install prefix (default: '${INSTALL_PREFIX}')
-p, --plugins Space-separated list of plugins to build
(default: ${BUILD_PLUGINS})
2017-11-27 22:46:03 -05:00
--snapshot Don't checkout the release tag
2017-01-28 16:11:05 -05:00
-n, --no-source-tarball Don't build source tarball
-h, --help Show this help
EOF
2017-12-13 16:38:44 -05:00
elif [ "gpgsign" == "$cmd" ]; then
2017-01-28 16:11:05 -05:00
cat << EOF
2017-12-13 16:38:44 -05:00
Sign previously compiled release packages with GPG
2017-01-29 06:52:05 -05:00
2017-01-28 16:11:05 -05:00
Options:
2017-10-05 18:04:41 -04:00
-f, --files Files to sign (required)
2018-07-08 19:47:35 -04:00
-k, --key GPG key used to sign the files (default: '${GPG_KEY}')
2017-12-13 16:38:44 -05:00
-h, --help Show this help
EOF
elif [ "appsign" == "$cmd" ]; then
cat << EOF
Sign binaries with code signing certificates on Windows and macOS
Options:
-f, --files Files to sign (required)
2019-11-09 18:08:20 -05:00
-k, --key, -i, --identity
Signing Key or Apple Developer ID (required)
2021-01-31 16:47:35 -05:00
--timestamp Explicitly set the timestamp server to use for appsign (default: '${TIMESTAMP_SERVER}')
-u, --username Apple username for notarization (required on macOS)
2021-01-29 18:39:36 -05:00
-h, --help Show this help
EOF
elif [ "notarize" == "$cmd" ]; then
cat << EOF
Submit macOS application DMG for notarization
Options:
-f, --files Files to notarize (required)
-u, --username Apple username for notarization (required)
2019-11-09 18:08:20 -05:00
-c, --keychain Apple keychain entry name storing the notarization
app password (default: 'AC_PASSWORD')
2017-10-05 18:04:41 -04:00
-h, --help Show this help
2018-09-26 16:46:59 -04:00
EOF
elif [ "appimage" == "$cmd" ]; then
cat << EOF
Generate Linux AppImage from 'make install' AppDir
Options:
-a, --appdir Input AppDir (required)
-v, --version KeePassXC version
-o, --output-dir Output directory where to build the AppImage
(default: '${OUTPUT_DIR}')
-d, --docker-image Use the specified Docker image to build the AppImage.
The image must have all required build dependencies installed.
--container-name Docker container name (default: '${DOCKER_CONTAINER_NAME}')
The container must not exist already
--appsign Embed a PGP signature into the AppImage
-k, --key The PGP Signing Key
--verbosity linuxdeploy verbosity (default: 3)
-h, --help Show this help
2021-09-28 05:22:15 -04:00
EOF
elif [ "i18n" == "$cmd" ]; then
cat << EOF
Update translation files and pull from or push to Transifex
Subcommands:
tx-push Push source translation file to Transifex
tx-pull Pull updated translations from Transifex
lupdate Update source translation file from C++ sources
2017-01-28 16:11:05 -05:00
EOF
fi
}
logInfo() {
2017-02-11 11:05:28 -05:00
printf "\e[1m[ \e[34mINFO\e[39m ]\e[0m $1\n"
2017-01-28 16:11:05 -05:00
}
2019-11-09 18:08:20 -05:00
logWarn() {
printf "\e[1m[ \e[33mWARNING\e[39m ]\e[0m $1\n"
}
2017-01-28 16:11:05 -05:00
logError() {
2017-02-11 11:05:28 -05:00
printf "\e[1m[ \e[31mERROR\e[39m ]\e[0m $1\n" >&2
2017-01-28 16:11:05 -05:00
}
init() {
2021-09-29 10:25:52 -04:00
if [ -z "$RELEASE_NAME" ]; then
2017-06-06 10:35:16 -04:00
logError "Missing arguments, --version is required!\n"
printUsage "check"
exit 1
fi
2021-09-29 10:25:52 -04:00
if [ -z "$TAG_NAME" ]; then
2017-06-06 10:35:16 -04:00
TAG_NAME="$RELEASE_NAME"
fi
2018-09-26 16:46:59 -04:00
2021-09-29 10:25:52 -04:00
if [ -z "$SOURCE_BRANCH" ]; then
2017-06-06 10:35:16 -04:00
SOURCE_BRANCH="release/${RELEASE_NAME}"
fi
2017-01-28 16:11:05 -05:00
ORIG_CWD="$(pwd)"
2017-06-06 10:35:16 -04:00
SRC_DIR="$(realpath "$SRC_DIR")"
2017-01-28 16:11:05 -05:00
cd "$SRC_DIR" > /dev/null 2>&1
ORIG_BRANCH="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
cd "$ORIG_CWD"
}
cleanup() {
logInfo "Checking out original branch..."
if [ "" != "$ORIG_BRANCH" ]; then
git checkout "$ORIG_BRANCH" > /dev/null 2>&1
fi
logInfo "Leaving source directory..."
cd "$ORIG_CWD"
}
exitError() {
cleanup
2022-03-17 18:26:06 -04:00
logError "$1"
2017-01-28 16:11:05 -05:00
exit 1
}
2018-09-26 16:46:59 -04:00
cmdExists() {
command -v "$1" &> /dev/null
}
2017-01-28 16:11:05 -05:00
checkSourceDirExists() {
if [ ! -d "$SRC_DIR" ]; then
exitError "Source directory '${SRC_DIR}' does not exist!"
fi
}
checkOutputDirDoesNotExist() {
if [ -e "$OUTPUT_DIR" ]; then
exitError "Output directory '$OUTPUT_DIR' already exists. Please choose a different location!"
fi
}
checkGitRepository() {
2019-09-08 07:30:51 -04:00
if [ ! -d .git ] || [ ! -f CHANGELOG.md ]; then
2017-01-28 16:11:05 -05:00
exitError "Source directory is not a valid Git repository!"
fi
}
checkReleaseDoesNotExist() {
2022-03-17 18:26:06 -04:00
if ! git tag | grep -q "^$TAG_NAME$"; then
2017-01-28 16:11:05 -05:00
exitError "Release '$RELEASE_NAME' (tag: '$TAG_NAME') already exists!"
fi
}
checkWorkingTreeClean() {
2021-09-29 10:25:52 -04:00
if ! git diff-index --quiet HEAD --; then
2017-01-28 16:11:05 -05:00
exitError "Current working tree is not clean! Please commit or unstage any changes."
fi
}
checkSourceBranchExists() {
2021-09-29 10:25:52 -04:00
if ! git rev-parse "$SOURCE_BRANCH" > /dev/null 2>&1; then
2017-01-28 16:11:05 -05:00
exitError "Source branch '$SOURCE_BRANCH' does not exist!"
fi
}
checkTargetBranchExists() {
2021-09-29 10:25:52 -04:00
if ! git rev-parse "$TARGET_BRANCH" > /dev/null 2>&1; then
2017-01-28 16:11:05 -05:00
exitError "Target branch '$TARGET_BRANCH' does not exist!"
fi
}
checkVersionInCMake() {
local app_name_upper="$(echo "$APP_NAME" | tr '[:lower:]' '[:upper:]')"
2017-06-06 10:35:16 -04:00
local major_num="$(echo ${RELEASE_NAME} | cut -f1 -d.)"
local minor_num="$(echo ${RELEASE_NAME} | cut -f2 -d.)"
2018-02-17 11:46:19 -05:00
local patch_num="$(echo ${RELEASE_NAME} | cut -f3 -d. | cut -f1 -d-)"
2017-06-06 10:35:16 -04:00
2022-03-17 18:26:06 -04:00
if ! grep -q "${app_name_upper}_VERSION_MAJOR \"${major_num}\"" CMakeLists.txt; then
2017-06-06 10:35:16 -04:00
exitError "${app_name_upper}_VERSION_MAJOR not updated to '${major_num}' in CMakeLists.txt!"
2017-01-28 16:11:05 -05:00
fi
2022-03-17 18:26:06 -04:00
if ! grep -q "${app_name_upper}_VERSION_MINOR \"${minor_num}\"" CMakeLists.txt; then
2017-06-06 10:35:16 -04:00
exitError "${app_name_upper}_VERSION_MINOR not updated to '${minor_num}' in CMakeLists.txt!"
fi
2022-03-17 18:26:06 -04:00
if ! grep -q "${app_name_upper}_VERSION_PATCH \"${patch_num}\"" CMakeLists.txt; then
2017-06-06 10:35:16 -04:00
exitError "${app_name_upper}_VERSION_PATCH not updated to '${patch_num}' in CMakeLists.txt!"
2017-01-28 16:11:05 -05:00
fi
}
checkChangeLog() {
2019-09-08 07:30:51 -04:00
if [ ! -f CHANGELOG.md ]; then
2017-01-28 16:11:05 -05:00
exitError "No CHANGELOG file found!"
fi
2018-09-26 16:46:59 -04:00
2022-03-17 18:26:06 -04:00
if ! grep -qzo "## ${RELEASE_NAME} \([0-9]{4}-[0-9]{2}-[0-9]{2}\)\n" CHANGELOG.md; then
2019-09-08 07:30:51 -04:00
exitError "'CHANGELOG.md' has not been updated to the '${RELEASE_NAME}' release!"
2017-01-28 16:11:05 -05:00
fi
}
2017-10-17 08:36:18 -04:00
checkAppStreamInfo() {
2017-10-26 07:00:50 -04:00
if [ ! -f share/linux/org.keepassxc.KeePassXC.appdata.xml ]; then
2017-10-17 08:36:18 -04:00
exitError "No AppStream info file found!"
2017-01-28 17:02:26 -05:00
fi
2017-06-06 10:35:16 -04:00
2022-03-17 18:26:06 -04:00
if ! grep -qEzo "<release version=\"${RELEASE_NAME}\" date=\"[0-9]{4}-[0-9]{2}-[0-9]{2}\">" share/linux/org.keepassxc.KeePassXC.appdata.xml; then
2017-10-26 07:00:50 -04:00
exitError "'share/linux/org.keepassxc.KeePassXC.appdata.xml' has not been updated to the '${RELEASE_NAME}' release!"
2017-06-06 10:35:16 -04:00
fi
}
checkSnapcraft() {
2019-11-11 11:44:12 -05:00
if [ ! -f snap/snapcraft.yaml ]; then
echo "Could not find snap/snapcraft.yaml!"
2017-06-06 10:35:16 -04:00
return
fi
2022-03-17 18:26:06 -04:00
if ! grep -qEzo "version: ${RELEASE_NAME}" snap/snapcraft.yaml; then
2017-10-17 08:36:18 -04:00
exitError "'snapcraft.yaml' has not been updated to the '${RELEASE_NAME}' release!"
fi
2019-03-19 18:54:56 -04:00
2022-03-17 18:26:06 -04:00
if ! grep -qEzo "KEEPASSXC_BUILD_TYPE=Release" snap/snapcraft.yaml; then
2019-03-19 18:54:56 -04:00
exitError "'snapcraft.yaml' is not set for a release build!"
fi
2017-10-17 08:36:18 -04:00
}
checkTransifexCommandExists() {
2018-09-26 16:46:59 -04:00
if ! cmdExists tx; then
2017-12-13 16:38:44 -05:00
exitError "Transifex tool 'tx' not installed! Please install it using 'pip install transifex-client'."
fi
}
2017-11-27 22:46:03 -05:00
checkSigntoolCommandExists() {
2018-09-26 16:46:59 -04:00
if ! cmdExists signtool; then
2017-11-27 22:46:03 -05:00
exitError "signtool command not found on the PATH! Add the Windows SDK binary folder to your PATH."
fi
}
2019-11-09 18:08:20 -05:00
checkXcodeSetup() {
if ! cmdExists xcrun; then
exitError "xcrun command not found on the PATH! Please check that you have correctly installed Xcode."
fi
if ! xcrun -f codesign > /dev/null 2>&1; then
exitError "codesign command not found. You may need to run 'sudo xcode-select -r' to set up Xcode."
fi
if ! xcrun -f altool > /dev/null 2>&1; then
exitError "altool command not found. You may need to run 'sudo xcode-select -r' to set up Xcode."
fi
if ! xcrun -f stapler > /dev/null 2>&1; then
exitError "stapler command not found. You may need to run 'sudo xcode-select -r' to set up Xcode."
2017-12-13 16:38:44 -05:00
fi
}
2017-10-17 08:54:11 -04:00
checkQt5LUpdateExists() {
2022-03-17 18:26:06 -04:00
if cmdExists lupdate && ! $(lupdate -version | grep -q "lupdate version 5\."); then
2018-09-26 16:46:59 -04:00
if ! cmdExists lupdate-qt5; then
2017-10-17 08:54:11 -04:00
exitError "Qt Linguist tool (lupdate-qt5) is not installed! Please install using 'apt install qttools5-dev-tools'"
fi
2017-06-06 10:35:16 -04:00
fi
}
performChecks() {
logInfo "Performing basic checks..."
2018-09-26 16:46:59 -04:00
2017-06-06 10:35:16 -04:00
checkSourceDirExists
logInfo "Changing to source directory..."
cd "${SRC_DIR}"
2018-09-26 16:46:59 -04:00
2017-06-06 10:35:16 -04:00
logInfo "Validating toolset and repository..."
checkTransifexCommandExists
2017-10-17 08:54:11 -04:00
checkQt5LUpdateExists
2017-06-06 10:35:16 -04:00
checkGitRepository
checkReleaseDoesNotExist
checkWorkingTreeClean
checkSourceBranchExists
checkTargetBranchExists
2018-09-26 16:46:59 -04:00
2017-06-06 10:35:16 -04:00
logInfo "Checking out '${SOURCE_BRANCH}'..."
2021-01-29 18:39:36 -05:00
git checkout "$SOURCE_BRANCH" > /dev/null 2>&1
2018-09-26 16:46:59 -04:00
2017-06-06 10:35:16 -04:00
logInfo "Attempting to find '${RELEASE_NAME}' in various files..."
checkVersionInCMake
checkChangeLog
2017-10-17 08:36:18 -04:00
checkAppStreamInfo
2017-06-06 10:35:16 -04:00
checkSnapcraft
2018-09-26 16:46:59 -04:00
2017-06-06 10:35:16 -04:00
logInfo "\e[1m\e[32mAll checks passed!\e[0m"
2017-01-28 17:02:26 -05:00
}
2017-01-31 13:25:15 -05:00
# re-implement realpath for OS X (thanks mschrag)
2017-01-31 19:03:30 -05:00
# https://superuser.com/questions/205127/
2018-09-26 16:46:59 -04:00
if ! cmdExists realpath; then
2017-01-31 13:25:15 -05:00
realpath() {
pushd . > /dev/null
if [ -d "$1" ]; then
2017-01-31 19:03:30 -05:00
cd "$1"
dirs -l +0
else
cd "$(dirname "$1")"
cur_dir=$(dirs -l +0)
2018-09-26 16:46:59 -04:00
2017-01-31 13:25:15 -05:00
if [ "$cur_dir" == "/" ]; then
2017-01-31 19:03:30 -05:00
echo "$cur_dir$(basename "$1")"
2017-01-31 13:25:15 -05:00
else
2017-01-31 19:03:30 -05:00
echo "$cur_dir/$(basename "$1")"
2017-01-31 13:25:15 -05:00
fi
fi
popd > /dev/null
}
fi
2017-01-28 16:11:05 -05:00
2022-03-17 18:26:06 -04:00
trap 'exitError "Exited upon user request."' SIGINT SIGTERM
trap 'exitError "Error occurred!"' ERR
2017-01-28 16:11:05 -05:00
2017-06-06 10:35:16 -04:00
# -----------------------------------------------------------------------
# check command
# -----------------------------------------------------------------------
check() {
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-v|--version)
RELEASE_NAME="$2"
shift ;;
esac
shift
done
init
performChecks
cleanup
logInfo "Congrats! You can successfully merge, build, and sign KeepassXC."
}
2017-01-28 16:11:05 -05:00
# -----------------------------------------------------------------------
# merge command
# -----------------------------------------------------------------------
2018-09-26 16:46:59 -04:00
merge() {
2017-01-28 16:11:05 -05:00
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-v|--version)
RELEASE_NAME="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-a|--app-name)
APP_NAME="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-s|--source-dir)
SRC_DIR="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2018-07-08 19:47:35 -04:00
-k|--key|-g|--gpg-key)
2017-01-28 16:11:05 -05:00
GPG_GIT_KEY="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2021-01-31 16:47:35 -05:00
--timestamp)
TIMESTAMP_SERVER="$2"
shift ;;
2017-01-28 16:11:05 -05:00
-r|--release-branch)
SOURCE_BRANCH="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
--target-branch)
TARGET_BRANCH="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-t|--tag-name)
TAG_NAME="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-h|--help)
printUsage "merge"
exit ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
*)
logError "Unknown option '$arg'\n"
printUsage "merge"
exit 1 ;;
esac
shift
done
init
2017-06-06 10:35:16 -04:00
performChecks
2018-09-26 16:46:59 -04:00
2021-09-28 05:22:15 -04:00
# Update translations
i18n lupdate
i18n tx-pull
2017-01-28 17:02:26 -05:00
if [ 0 -ne $? ]; then
exitError "Updating translations failed!"
fi
2021-09-29 10:25:52 -04:00
if ! git diff-index --quiet HEAD --; then
2020-07-06 19:08:30 -04:00
git add -A ./share/translations/
2017-01-28 17:02:26 -05:00
logInfo "Committing changes..."
2021-09-29 10:25:52 -04:00
if [ -z "$GPG_GIT_KEY" ]; then
2017-01-28 17:02:26 -05:00
git commit -m "Update translations"
else
git commit -m "Update translations" -S"$GPG_GIT_KEY"
fi
fi
2017-01-28 16:11:05 -05:00
2022-03-17 18:26:06 -04:00
CHANGELOG=$(grep -Ezo "## ${RELEASE_NAME} \([0-9]{4}-[0-9]{2}-[0-9]{2}\)\n\n(.|\n)+?\n\n## " CHANGELOG.md \
| tail -n+3 | sed '$d' | sed 's/^### //')
2017-02-11 11:19:46 -05:00
COMMIT_MSG="Release ${RELEASE_NAME}"
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "Checking out target branch '${TARGET_BRANCH}'..."
2021-01-29 18:39:36 -05:00
git checkout "$TARGET_BRANCH" > /dev/null 2>&1
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "Merging '${SOURCE_BRANCH}' into '${TARGET_BRANCH}'..."
git merge "$SOURCE_BRANCH" --no-ff -m "$COMMIT_MSG" -m "${CHANGELOG}" "$SOURCE_BRANCH" -S"$GPG_GIT_KEY"
logInfo "Creating tag '${TAG_NAME}'..."
2021-09-29 10:25:52 -04:00
if [ -z "$GPG_GIT_KEY" ]; then
2017-01-28 16:11:05 -05:00
git tag -a "$TAG_NAME" -m "$COMMIT_MSG" -m "${CHANGELOG}" -s
else
git tag -a "$TAG_NAME" -m "$COMMIT_MSG" -m "${CHANGELOG}" -s -u "$GPG_GIT_KEY"
fi
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
cleanup
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "All done!"
logInfo "Please merge the release branch back into the develop branch now and then push your changes."
logInfo "Don't forget to also push the tags using \e[1mgit push --tags\e[0m."
}
2018-09-26 16:46:59 -04:00
# -----------------------------------------------------------------------
# appimage command
# -----------------------------------------------------------------------
appimage() {
local appdir
local build_appsign=false
local build_key
local verbosity="1"
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-v|--version)
RELEASE_NAME="$2"
shift ;;
-a|--appdir)
appdir="$2"
shift ;;
-o|--output-dir)
OUTPUT_DIR="$2"
shift ;;
-d|--docker-image)
DOCKER_IMAGE="$2"
shift ;;
--container-name)
DOCKER_CONTAINER_NAME="$2"
shift ;;
--appsign)
build_appsign=true ;;
--verbosity)
verbosity=$2
shift ;;
-k|--key)
build_key="$2"
shift ;;
-h|--help)
printUsage "appimage"
exit ;;
*)
logError "Unknown option '$arg'\n"
printUsage "appimage"
exit 1 ;;
esac
shift
done
if [ -z "${appdir}" ]; then
logError "Missing arguments, --appdir is required!\n"
printUsage "appimage"
exit 1
fi
if [ ! -d "${appdir}" ]; then
2020-01-20 16:46:50 -05:00
exitError "AppDir does not exist, please create one with 'make install'!"
2018-09-26 16:46:59 -04:00
elif [ -e "${appdir}/AppRun" ]; then
2020-01-20 16:46:50 -05:00
exitError "AppDir has already been run through linuxdeploy, please create a fresh AppDir with 'make install'."
2018-09-26 16:46:59 -04:00
fi
appdir="$(realpath "$appdir")"
local out="${OUTPUT_DIR}"
2021-09-29 10:25:52 -04:00
if [ -z "$out" ]; then
2018-09-26 16:46:59 -04:00
out="."
fi
mkdir -p "$out"
local out_real="$(realpath "$out")"
cd "$out"
local linuxdeploy="linuxdeploy"
local linuxdeploy_cleanup
local linuxdeploy_plugin_qt="linuxdeploy-plugin-qt"
local linuxdeploy_plugin_qt_cleanup
local appimagetool="appimagetool"
local appimagetool_cleanup
logInfo "Testing for AppImage tools..."
local docker_test_cmd
if [ "" != "$DOCKER_IMAGE" ]; then
2021-09-29 10:25:52 -04:00
docker_test_cmd="docker run -it --user $(id -u):$(id -g) --rm ${DOCKER_IMAGE}"
2018-09-26 16:46:59 -04:00
fi
# Test if linuxdeploy and linuxdeploy-plugin-qt are installed
# on the system or inside the Docker container
2021-09-29 10:25:52 -04:00
if ! ${docker_test_cmd} which ${linuxdeploy} > /dev/null; then
2018-09-26 16:46:59 -04:00
logInfo "Downloading linuxdeploy..."
linuxdeploy="./linuxdeploy"
linuxdeploy_cleanup="rm -f ${linuxdeploy}"
2020-01-20 16:46:50 -05:00
if ! curl -Lf "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" > "$linuxdeploy"; then
exitError "linuxdeploy download failed."
fi
2018-09-26 16:46:59 -04:00
chmod +x "$linuxdeploy"
fi
2021-09-29 10:25:52 -04:00
if ! ${docker_test_cmd} which ${linuxdeploy_plugin_qt} > /dev/null; then
2018-09-26 16:46:59 -04:00
logInfo "Downloading linuxdeploy-plugin-qt..."
linuxdeploy_plugin_qt="./linuxdeploy-plugin-qt"
linuxdeploy_plugin_qt_cleanup="rm -f ${linuxdeploy_plugin_qt}"
2020-01-20 16:46:50 -05:00
if ! curl -Lf "https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage" > "$linuxdeploy_plugin_qt"; then
exitError "linuxdeploy-plugin-qt download failed."
fi
2018-09-26 16:46:59 -04:00
chmod +x "$linuxdeploy_plugin_qt"
fi
# appimagetool is always run outside a Docker container, so we can access our GPG keys
if ! cmdExists ${appimagetool}; then
logInfo "Downloading appimagetool..."
appimagetool="./appimagetool"
appimagetool_cleanup="rm -f ${appimagetool}"
2020-01-20 16:46:50 -05:00
if ! curl -Lf "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" > "$appimagetool"; then
exitError "appimagetool download failed."
fi
2018-09-26 16:46:59 -04:00
chmod +x "$appimagetool"
fi
# Create custom AppRun wrapper
2021-09-29 10:25:52 -04:00
cat << 'EOF' > "${out_real}/KeePassXC-AppRun"
2018-09-26 16:46:59 -04:00
#!/usr/bin/env bash
2021-09-29 10:25:52 -04:00
export PATH="$(dirname $0)/usr/bin:${PATH}"
export LD_LIBRARY_PATH="$(dirname $0)/usr/lib:${LD_LIBRARY_PATH}"
2018-09-26 16:46:59 -04:00
2021-09-29 10:25:52 -04:00
if [ "$1" == "cli" ]; then
2018-09-26 16:46:59 -04:00
shift
2021-09-29 10:25:52 -04:00
exec keepassxc-cli "$@"
elif [ "$1" == "proxy" ]; then
2018-09-26 16:46:59 -04:00
shift
2021-09-29 10:25:52 -04:00
exec keepassxc-proxy "$@"
2018-09-26 16:46:59 -04:00
elif [ -v CHROME_WRAPPER ] || [ -v MOZ_LAUNCHED_CHILD ]; then
2021-09-29 10:25:52 -04:00
exec keepassxc-proxy "$@"
2018-09-26 16:46:59 -04:00
else
2021-09-29 10:25:52 -04:00
exec keepassxc "$@"
2018-09-26 16:46:59 -04:00
fi
EOF
chmod +x "${out_real}/KeePassXC-AppRun"
# Find .desktop files, icons, and binaries to deploy
local desktop_file="$(find "$appdir" -name "org.keepassxc.KeePassXC.desktop" | head -n1)"
2021-09-29 10:25:52 -04:00
local icon="$(find "$appdir" -path '*/application/256x256/apps/keepassxc.png' | head -n1)"
local executables="$(find "$appdir" -type f -executable -path '*/bin/keepassxc*' -print0 | xargs -0 -i printf " --executable={}")"
2018-09-26 16:46:59 -04:00
logInfo "Collecting libs and patching binaries..."
2021-09-29 10:25:52 -04:00
if [ -z "$DOCKER_IMAGE" ]; then
2018-09-26 16:46:59 -04:00
"$linuxdeploy" --verbosity=${verbosity} --plugin=qt --appdir="$appdir" --desktop-file="$desktop_file" \
2021-09-29 10:25:52 -04:00
--custom-apprun="${out_real}/KeePassXC-AppRun" --icon-file="$icon" ${executables}
2018-09-26 16:46:59 -04:00
else
docker run --name "$DOCKER_CONTAINER_NAME" --rm \
2021-09-29 10:25:52 -04:00
--cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse -it \
-v "${out_real}:${out_real}:rw" \
-v "${appdir}:${appdir}:rw" \
-w "$out_real" \
--user $(id -u):$(id -g) \
2018-09-26 16:46:59 -04:00
"$DOCKER_IMAGE" \
2021-09-29 10:25:52 -04:00
bash -c "${linuxdeploy} --verbosity=${verbosity} --plugin=qt \
--appdir='${appdir}' --custom-apprun='${out_real}/KeePassXC-AppRun' \
--desktop-file='${desktop_file}' --icon-file='${icon}' ${executables}"
2018-09-26 16:46:59 -04:00
fi
2020-01-20 16:46:50 -05:00
if [ $? -ne 0 ]; then
exitError "AppDir deployment failed."
fi
2018-09-26 16:46:59 -04:00
logInfo "Creating AppImage..."
local appsign_flag=""
local appsign_key_flag=""
if ${build_appsign}; then
appsign_flag="--sign"
appsign_key_flag="--sign-key ${build_key}"
fi
local appimage_name="KeePassXC-x86_64.AppImage"
if [ "" != "$RELEASE_NAME" ]; then
appimage_name="KeePassXC-${RELEASE_NAME}-x86_64.AppImage"
2020-06-10 05:31:08 -04:00
echo "X-AppImage-Version=${RELEASE_NAME}" >> "$desktop_file"
2018-09-26 16:46:59 -04:00
fi
# Run appimagetool to package (and possibly sign) AppImage
# --no-appstream is required, since it may crash on newer systems
# see: https://github.com/AppImage/AppImageKit/issues/856
2020-01-20 16:46:50 -05:00
if ! "$appimagetool" --updateinformation "gh-releases-zsync|keepassxreboot|keepassxc|latest|KeePassXC-*-x86_64.AppImage.zsync" \
${appsign_flag} ${appsign_key_flag} --no-appstream "$appdir" "${out_real}/${appimage_name}"; then
exitError "AppImage creation failed."
fi
2018-09-26 16:46:59 -04:00
logInfo "Cleaning up temporary files..."
${linuxdeploy_cleanup}
${linuxdeploy_plugin_qt_cleanup}
${appimagetool_cleanup}
rm -f "${out_real}/KeePassXC-AppRun"
}
2017-01-28 16:11:05 -05:00
# -----------------------------------------------------------------------
# build command
# -----------------------------------------------------------------------
2018-07-08 19:47:35 -04:00
build() {
local build_source_tarball=true
local build_snapshot=false
local build_snapcraft=false
2018-09-26 16:46:59 -04:00
local build_appimage=false
2018-07-08 19:47:35 -04:00
local build_generators=""
local build_appsign=false
local build_key=""
2021-09-06 22:26:00 -04:00
local build_vcpkg=""
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-v|--version)
RELEASE_NAME="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-a|--app-name)
APP_NAME="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-s|--source-dir)
SRC_DIR="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-o|--output-dir)
OUTPUT_DIR="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-t|--tag-name)
TAG_NAME="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-d|--docker-image)
DOCKER_IMAGE="$2"
shift ;;
2018-07-08 19:47:35 -04:00
2018-09-26 16:46:59 -04:00
--container-name)
DOCKER_CONTAINER_NAME="$2"
shift ;;
2018-07-08 19:47:35 -04:00
--appsign)
build_appsign=true ;;
2021-01-31 16:47:35 -05:00
--timestamp)
TIMESTAMP_SERVER="$2"
shift ;;
2018-07-08 19:47:35 -04:00
-k|--key)
build_key="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2018-05-16 22:39:39 -04:00
--snapcraft)
2018-07-08 19:47:35 -04:00
build_snapcraft=true ;;
2018-09-26 16:46:59 -04:00
--appimage)
build_appimage=true ;;
2021-09-06 22:26:00 -04:00
--cmake-generator)
CMAKE_GENERATOR="$2"
shift ;;
2017-01-28 16:11:05 -05:00
-c|--cmake-options)
CMAKE_OPTIONS="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
--compiler)
COMPILER="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2021-09-06 22:26:00 -04:00
--vcpkg)
build_vcpkg="$2"
shift ;;
2017-01-28 16:11:05 -05:00
-m|--make-options)
MAKE_OPTIONS="$2"
shift ;;
2018-07-08 19:47:35 -04:00
-g|--generators)
2018-07-10 21:43:01 -04:00
build_generators="$2"
2018-07-08 19:47:35 -04:00
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-i|--install-prefix)
INSTALL_PREFIX="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-p|--plugins)
BUILD_PLUGINS="$2"
shift ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-n|--no-source-tarball)
2018-07-08 19:47:35 -04:00
build_source_tarball=false ;;
2017-11-27 22:46:03 -05:00
--snapshot)
2018-07-08 19:47:35 -04:00
build_snapshot=true ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
-h|--help)
printUsage "build"
exit ;;
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
*)
logError "Unknown option '$arg'\n"
printUsage "build"
exit 1 ;;
esac
shift
done
2017-06-06 10:35:16 -04:00
2017-01-28 16:11:05 -05:00
init
2019-03-21 16:21:45 -04:00
# Resolve appsign key to absolute path if under Windows
2022-03-17 18:26:06 -04:00
if [[ "${build_key}" && -n "$OS_WINDOWS" ]]; then
2019-03-21 16:21:45 -04:00
build_key="$(realpath "${build_key}")"
fi
2017-10-05 18:04:41 -04:00
2021-09-06 22:26:00 -04:00
if [[ -f ${build_vcpkg} ]]; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_TOOLCHAIN_FILE=${build_vcpkg} -DX_VCPKG_APPLOCAL_DEPS_INSTALL=ON"
fi
2018-07-08 19:47:35 -04:00
if ${build_snapshot}; then
2017-11-27 22:46:03 -05:00
TAG_NAME="HEAD"
local branch=`git rev-parse --abbrev-ref HEAD`
logInfo "Using current branch ${branch} to build..."
RELEASE_NAME="${RELEASE_NAME}-snapshot"
2019-03-21 16:21:45 -04:00
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_BUILD_TYPE=Snapshot -DOVERRIDE_VERSION=${RELEASE_NAME}"
2017-11-27 22:46:03 -05:00
else
2018-02-17 11:46:19 -05:00
checkWorkingTreeClean
2022-03-17 18:26:06 -04:00
if echo "$TAG_NAME" | grep -qE '\-(alpha|beta)[0-9]+$'; then
2018-02-17 11:46:19 -05:00
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_BUILD_TYPE=PreRelease"
logInfo "Checking out pre-release tag '${TAG_NAME}'..."
else
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_BUILD_TYPE=Release"
logInfo "Checking out release tag '${TAG_NAME}'..."
fi
2022-03-17 18:26:06 -04:00
if ! git checkout "$TAG_NAME" > /dev/null 2>&1; then
exitError "Failed to check out target branch."
fi
2017-11-27 22:46:03 -05:00
fi
2017-10-05 18:04:41 -04:00
2021-09-29 10:25:52 -04:00
OUTPUT_DIR="$(realpath "$OUTPUT_DIR")"
if ! ${build_snapshot} && [ -d "$OUTPUT_DIR" ]; then
exitError "Output dir '${OUTPUT_DIR}' already exists."
fi
2017-01-28 16:11:05 -05:00
2021-09-29 10:25:52 -04:00
logInfo "Creating output directory..."
if ! mkdir -p "$OUTPUT_DIR"; then
2017-01-28 16:11:05 -05:00
exitError "Failed to create output directory!"
fi
2018-07-08 19:47:35 -04:00
if ${build_source_tarball}; then
2017-01-28 16:11:05 -05:00
logInfo "Creating source tarball..."
local app_name_lower="$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]')"
2018-02-22 15:53:29 -05:00
local prefix="${app_name_lower}-${RELEASE_NAME}"
local tarball_name="${prefix}-src.tar"
git archive --format=tar "$TAG_NAME" --prefix="${prefix}/" --output="${OUTPUT_DIR}/${tarball_name}"
2019-03-21 16:21:45 -04:00
# add .version and .gitrev files to tarball
mkdir "${prefix}"
echo -n ${RELEASE_NAME} > "${prefix}/.version"
echo -n `git rev-parse --short=7 HEAD` > "${prefix}/.gitrev"
tar --append --file="${OUTPUT_DIR}/${tarball_name}" "${prefix}/.version" "${prefix}/.gitrev"
rm "${prefix}/.version" "${prefix}/.gitrev"
rmdir "${prefix}" 2> /dev/null
2018-02-22 15:53:29 -05:00
2019-11-09 18:08:20 -05:00
local xz="xz"
if ! cmdExists xz; then
logWarn "xz not installed. Falling back to bz2..."
xz="bzip2"
fi
2022-03-17 18:26:06 -04:00
$xz -6 -f "${OUTPUT_DIR}/${tarball_name}"
2017-01-28 16:11:05 -05:00
fi
2018-02-17 11:46:19 -05:00
2017-01-28 16:11:05 -05:00
logInfo "Creating build directory..."
mkdir -p "${OUTPUT_DIR}/build-release"
cd "${OUTPUT_DIR}/build-release"
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "Configuring sources..."
2018-02-17 11:46:19 -05:00
for p in ${BUILD_PLUGINS}; do
2017-01-28 16:11:05 -05:00
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_XC_$(echo $p | tr '[:lower:]' '[:upper:]')=On"
done
2022-03-17 18:26:06 -04:00
if [ -n "$OS_LINUX" ] && ${build_appimage}; then
2018-09-26 16:46:59 -04:00
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DKEEPASSXC_DIST_TYPE=AppImage"
# linuxdeploy requires /usr as install prefix
INSTALL_PREFIX="/usr"
fi
2019-03-21 16:21:45 -04:00
# Do not build tests cases
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_TESTS=OFF"
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
if [ "$COMPILER" == "g++" ]; then
export CC=gcc
elif [ "$COMPILER" == "clang++" ]; then
export CC=clang
2021-09-06 22:26:00 -04:00
else
export CC="$COMPILER"
2017-01-28 16:11:05 -05:00
fi
export CXX="$COMPILER"
2018-09-26 16:46:59 -04:00
2021-09-29 10:25:52 -04:00
if [ -z "$DOCKER_IMAGE" ]; then
2022-03-17 18:26:06 -04:00
if [ -n "$OS_MACOS" ]; then
2018-02-21 15:35:17 -05:00
# Building on macOS
2019-11-09 18:08:20 -05:00
export MACOSX_DEPLOYMENT_TARGET
2018-02-21 15:35:17 -05:00
2017-01-29 14:46:57 -05:00
logInfo "Configuring build..."
2021-09-06 22:26:00 -04:00
cmake -G "${CMAKE_GENERATOR}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="$(uname -m)" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" ${CMAKE_OPTIONS} "$SRC_DIR"
2018-02-21 15:35:17 -05:00
2017-01-29 14:46:57 -05:00
logInfo "Compiling and packaging sources..."
2021-09-06 22:26:00 -04:00
cmake --build . -- ${MAKE_OPTIONS}
cpack -G "DragNDrop"
2018-09-26 16:46:59 -04:00
# Appsign the executables if desired
2019-03-19 21:12:39 -04:00
if ${build_appsign}; then
2018-09-26 16:46:59 -04:00
logInfo "Signing executable files"
appsign "-f" "./${APP_NAME}-${RELEASE_NAME}.dmg" "-k" "${build_key}"
fi
2021-01-29 18:39:36 -05:00
mv "./${APP_NAME}-${RELEASE_NAME}.dmg" "../${APP_NAME}-${RELEASE_NAME}-$(uname -m).dmg"
2022-03-17 18:26:06 -04:00
elif [ -n "$OS_WINDOWS" ]; then
2018-02-21 15:35:17 -05:00
# Building on Windows with Msys2
2017-01-28 16:19:23 -05:00
logInfo "Configuring build..."
2021-09-06 22:26:00 -04:00
cmake -DCMAKE_BUILD_TYPE=Release -G "${CMAKE_GENERATOR}" -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
${CMAKE_OPTIONS} "$SRC_DIR"
2018-09-26 16:46:59 -04:00
2017-01-28 16:45:07 -05:00
logInfo "Compiling and packaging sources..."
2021-09-06 22:26:00 -04:00
cmake --build . --config "Release" -- ${MAKE_OPTIONS}
2018-07-08 19:47:35 -04:00
# Appsign the executables if desired
2019-03-21 16:21:45 -04:00
if ${build_appsign} && [ -f "${build_key}" ]; then
2018-07-08 19:47:35 -04:00
logInfo "Signing executable files"
2022-03-17 18:26:06 -04:00
appsign "-f" $(find src | grep -Ei 'keepassxc.*(\.exe|\.dll)$') "-k" "${build_key}"
2018-07-08 19:47:35 -04:00
fi
2017-12-09 09:02:57 -05:00
# Call cpack directly instead of calling make package.
# This is important because we want to build the MSI when making a
# release.
2018-07-08 19:47:35 -04:00
cpack -G "${CPACK_GENERATORS};${build_generators}"
mv "${APP_NAME}-"*.* ../
2017-01-29 14:46:57 -05:00
else
2018-09-26 16:46:59 -04:00
mkdir -p "${OUTPUT_DIR}/KeePassXC.AppDir"
2017-01-29 14:46:57 -05:00
# Building on Linux without Docker container
2017-01-28 16:19:23 -05:00
logInfo "Configuring build..."
2019-03-21 16:21:45 -04:00
cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS} \
2018-09-26 16:46:59 -04:00
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" "$SRC_DIR"
2017-01-28 16:19:23 -05:00
logInfo "Compiling sources..."
2018-09-26 16:46:59 -04:00
make ${MAKE_OPTIONS}
2017-01-28 16:11:05 -05:00
logInfo "Installing to bin dir..."
2018-09-26 16:46:59 -04:00
make DESTDIR="${OUTPUT_DIR}/KeePassXC.AppDir" install/strip
2017-01-28 16:11:05 -05:00
fi
else
2018-08-24 08:40:41 -04:00
if ${build_snapcraft}; then
2018-05-16 22:39:39 -04:00
logInfo "Building snapcraft docker image..."
2018-09-26 16:46:59 -04:00
2018-05-16 22:39:39 -04:00
sudo docker image build -t "$DOCKER_IMAGE" "$(realpath "$SRC_DIR")/ci/snapcraft"
logInfo "Launching Docker contain to compile snapcraft..."
2018-09-26 16:46:59 -04:00
2021-09-29 10:25:52 -04:00
sudo docker run --name "$DOCKER_CONTAINER_NAME" --rm -it --user $(id -u):$(id -g) \
2018-05-16 22:39:39 -04:00
-v "$(realpath "$SRC_DIR"):/keepassxc" -w "/keepassxc" \
2018-09-26 16:46:59 -04:00
"$DOCKER_IMAGE" snapcraft
2018-05-16 22:39:39 -04:00
else
2018-09-26 16:46:59 -04:00
mkdir -p "${OUTPUT_DIR}/KeePassXC.AppDir"
2018-05-16 22:39:39 -04:00
logInfo "Launching Docker container to compile sources..."
2018-09-26 16:46:59 -04:00
2018-05-16 22:39:39 -04:00
docker run --name "$DOCKER_CONTAINER_NAME" --rm \
--cap-add SYS_ADMIN --security-opt apparmor:unconfined --device /dev/fuse \
2021-09-29 10:25:52 -04:00
--user $(id -u):$(id -g) \
-e "CC=${CC}" -e "CXX=${CXX}" -it \
2018-05-16 22:39:39 -04:00
-v "$(realpath "$SRC_DIR"):/keepassxc/src:ro" \
-v "$(realpath "$OUTPUT_DIR"):/keepassxc/out:rw" \
"$DOCKER_IMAGE" \
bash -c "cd /keepassxc/out/build-release && \
2019-03-21 16:21:45 -04:00
cmake -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS} \
2018-09-26 16:46:59 -04:00
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} /keepassxc/src && \
make ${MAKE_OPTIONS} && make DESTDIR=/keepassxc/out/KeePassXC.AppDir install/strip"
2018-05-16 22:39:39 -04:00
fi
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
if [ 0 -ne $? ]; then
exitError "Docker build failed!"
fi
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "Build finished, Docker container terminated."
fi
2018-09-26 16:46:59 -04:00
2022-03-17 18:26:06 -04:00
if [ -n "$OS_LINUX" ] && ${build_appimage}; then
2018-09-26 16:46:59 -04:00
local appsign_flag=""
local appsign_key_flag=""
local docker_image_flag=""
local docker_container_name_flag=""
if ${build_appsign}; then
appsign_flag="--appsign"
appsign_key_flag="-k ${build_key}"
fi
if [ "" != "${DOCKER_IMAGE}" ]; then
docker_image_flag="-d ${DOCKER_IMAGE}"
docker_container_name_flag="--container-name ${DOCKER_CONTAINER_NAME}"
fi
2021-09-29 10:25:52 -04:00
appimage -a "${OUTPUT_DIR}/KeePassXC.AppDir" -o "${OUTPUT_DIR}" \
2018-09-26 16:46:59 -04:00
${appsign_flag} ${appsign_key_flag} ${docker_image_flag} ${docker_container_name_flag}
fi
2017-01-28 16:11:05 -05:00
cleanup
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "All done!"
}
# -----------------------------------------------------------------------
2017-12-13 16:38:44 -05:00
# gpgsign command
2017-01-28 16:11:05 -05:00
# -----------------------------------------------------------------------
2017-12-13 16:38:44 -05:00
gpgsign() {
local sign_files=()
2017-01-28 16:11:05 -05:00
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-f|--files)
while [ "${2:0:1}" != "-" ] && [ $# -ge 2 ]; do
2017-12-13 16:38:44 -05:00
sign_files+=("$2")
2017-01-28 16:11:05 -05:00
shift
done ;;
2017-12-13 16:38:44 -05:00
2018-07-08 19:47:35 -04:00
-k|--key|-g|--gpg-key)
2017-01-28 16:11:05 -05:00
GPG_KEY="$2"
shift ;;
2017-10-05 18:04:41 -04:00
2017-01-28 16:11:05 -05:00
-h|--help)
2017-12-13 16:38:44 -05:00
printUsage "gpgsign"
2017-01-28 16:11:05 -05:00
exit ;;
2017-12-13 16:38:44 -05:00
2017-01-28 16:11:05 -05:00
*)
logError "Unknown option '$arg'\n"
2017-12-13 16:38:44 -05:00
printUsage "gpgsign"
2017-01-28 16:11:05 -05:00
exit 1 ;;
esac
shift
done
2018-09-26 16:46:59 -04:00
2017-12-13 16:38:44 -05:00
if [ -z "${sign_files}" ]; then
2017-01-28 16:11:05 -05:00
logError "Missing arguments, --files is required!\n"
2017-12-13 16:38:44 -05:00
printUsage "gpgsign"
2017-01-28 16:11:05 -05:00
exit 1
fi
2017-10-05 18:04:41 -04:00
2017-12-13 16:38:44 -05:00
for f in "${sign_files[@]}"; do
2017-01-28 16:11:05 -05:00
if [ ! -f "$f" ]; then
2017-12-13 16:38:44 -05:00
exitError "File '${f}' does not exist or is not a file!"
2017-01-28 16:11:05 -05:00
fi
2017-10-05 18:04:41 -04:00
logInfo "Signing file '${f}' using release key..."
2017-01-28 16:11:05 -05:00
gpg --output "${f}.sig" --armor --local-user "$GPG_KEY" --detach-sig "$f"
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
if [ 0 -ne $? ]; then
exitError "Signing failed!"
fi
2017-12-13 16:38:44 -05:00
2017-01-28 16:11:05 -05:00
logInfo "Creating digest for file '${f}'..."
2017-02-17 11:21:27 -05:00
local rp="$(realpath "$f")"
local bname="$(basename "$f")"
(cd "$(dirname "$rp")"; sha256sum "$bname" > "${bname}.DIGEST")
2017-01-28 16:11:05 -05:00
done
2018-09-26 16:46:59 -04:00
2017-01-28 16:11:05 -05:00
logInfo "All done!"
}
2017-12-13 16:38:44 -05:00
# -----------------------------------------------------------------------
# appsign command
# -----------------------------------------------------------------------
appsign() {
local sign_files=()
2018-07-08 19:47:35 -04:00
local key
2017-12-13 16:38:44 -05:00
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-f|--files)
while [ "${2:0:1}" != "-" ] && [ $# -ge 2 ]; do
sign_files+=("$2")
shift
done ;;
2018-07-08 19:47:35 -04:00
-k|--key|-i|--identity)
key="$2"
2017-12-13 16:38:44 -05:00
shift ;;
-h|--help)
printUsage "appsign"
exit ;;
*)
logError "Unknown option '$arg'\n"
printUsage "appsign"
exit 1 ;;
esac
shift
done
2018-07-08 19:47:35 -04:00
if [ -z "${key}" ]; then
logError "Missing arguments, --key is required!\n"
printUsage "appsign"
exit 1
fi
2017-12-13 16:38:44 -05:00
if [ -z "${sign_files}" ]; then
logError "Missing arguments, --files is required!\n"
printUsage "appsign"
exit 1
fi
for f in "${sign_files[@]}"; do
2021-01-29 18:39:36 -05:00
if [ ! -e "${f}" ]; then
exitError "File '${f}' does not exist!"
2017-12-13 16:38:44 -05:00
fi
done
2022-03-17 18:26:06 -04:00
if [ -n "$OS_MACOS" ]; then
2019-11-09 18:08:20 -05:00
checkXcodeSetup
2017-12-13 16:38:44 -05:00
local orig_dir="$(pwd)"
2019-11-09 18:08:20 -05:00
local real_src_dir="$(realpath "${SRC_DIR}")"
2017-12-13 16:38:44 -05:00
for f in "${sign_files[@]}"; do
if [[ ${f: -4} == '.dmg' ]]; then
logInfo "Unpacking disk image '${f}'..."
local tmp_dir="/tmp/KeePassXC_${RANDOM}"
2018-01-13 16:10:26 -05:00
mkdir -p ${tmp_dir}/mnt
2021-01-29 18:39:36 -05:00
if ! hdiutil attach -quiet -noautoopen -mountpoint ${tmp_dir}/mnt "${f}"; then
exitError "DMG mount failed!"
fi
2017-12-13 16:38:44 -05:00
cd ${tmp_dir}
2018-01-13 16:10:26 -05:00
cp -a ./mnt ./app
2017-12-13 16:38:44 -05:00
hdiutil detach -quiet ${tmp_dir}/mnt
2021-01-29 18:39:36 -05:00
local app_dir_tmp="./app/KeePassXC.app"
2017-12-13 16:38:44 -05:00
2021-01-29 18:39:36 -05:00
if [ ! -d "$app_dir_tmp" ]; then
2017-12-13 16:38:44 -05:00
cd "${orig_dir}"
exitError "Unpacking failed!"
fi
2021-01-29 18:39:36 -05:00
elif [[ ${f: -4} == '.app' ]]; then
local app_dir_tmp="$f"
else
logWarn "Skipping non-app file '${f}'..."
continue
fi
2017-12-13 16:38:44 -05:00
2021-01-29 18:39:36 -05:00
logInfo "Signing libraries and frameworks..."
2021-01-31 17:31:59 -05:00
if ! find "$app_dir_tmp" \( -name '*.dylib' -o -name '*.so' -o -name '*.framework' \) -print0 | xargs -0 \
2021-01-29 18:39:36 -05:00
xcrun codesign --sign "${key}" --verbose --force --options runtime; then
cd "${orig_dir}"
exitError "Signing failed!"
fi
logInfo "Signing executables..."
if ! find "${app_dir_tmp}/Contents/MacOS" \( -type f -not -name KeePassXC \) -print0 | xargs -0 \
xcrun codesign --sign "${key}" --verbose --force --options runtime; then
cd "${orig_dir}"
exitError "Signing failed!"
fi
# Sign main executable with additional entitlements
if ! xcrun codesign --sign "${key}" --verbose --force --options runtime --entitlements \
"${real_src_dir}/share/macosx/keepassxc.entitlements" "${app_dir_tmp}/Contents/MacOS/KeePassXC"; then
cd "${orig_dir}"
exitError "Signing failed!"
fi
2017-12-13 16:38:44 -05:00
2021-01-29 18:39:36 -05:00
if [[ ${f: -4} == '.dmg' ]]; then
2018-01-13 16:10:26 -05:00
logInfo "Repacking disk image..."
hdiutil create \
-volname "KeePassXC" \
-size $((1000 * ($(du -sk ./app | cut -f1) + 5000))) \
-srcfolder ./app \
-fs HFS+ \
-fsargs "-c c=64,a=16,e=16" \
-format UDBZ \
"${tmp_dir}/$(basename "${f}")"
2019-11-09 18:08:20 -05:00
2017-12-13 16:38:44 -05:00
cd "${orig_dir}"
2018-01-13 16:10:26 -05:00
cp -f "${tmp_dir}/$(basename "${f}")" "${f}"
2017-12-13 16:38:44 -05:00
rm -Rf ${tmp_dir}
fi
2021-01-29 18:39:36 -05:00
logInfo "File '${f}' successfully signed."
2017-12-13 16:38:44 -05:00
done
2022-03-17 18:26:06 -04:00
elif [ -n "$OS_WINDOWS" ]; then
2018-07-08 19:47:35 -04:00
if [[ ! -f "${key}" ]]; then
2021-05-29 12:48:08 -04:00
exitError "Appsign key file was not found! (${key})"
2017-12-13 16:38:44 -05:00
fi
2021-05-29 12:48:08 -04:00
logInfo "Using appsign key ${key}."
IFS=$'\n' read -s -r -p "Key password: " password
2017-12-13 16:38:44 -05:00
echo
for f in "${sign_files[@]}"; do
2019-03-19 18:54:56 -04:00
ext=${f: -4}
if [[ $ext == ".msi" || $ext == ".exe" || $ext == ".dll" ]]; then
2017-11-27 22:46:03 -05:00
# Make sure we can find the signtool
checkSigntoolCommandExists
# osslsigncode does not succeed at signing MSI files at this time...
logInfo "Signing file '${f}' using Microsoft signtool..."
2021-01-31 16:47:35 -05:00
signtool sign -f "${key}" -p "${password}" -d "KeePassXC" -td sha256 \
-fd sha256 -tr "${TIMESTAMP_SERVER}" "${f}"
if [ 0 -ne $? ]; then
2017-11-27 22:46:03 -05:00
exitError "Signing failed!"
fi
2017-12-13 16:38:44 -05:00
else
2017-11-27 22:46:03 -05:00
logInfo "Skipping non-executable file '${f}'..."
2017-12-13 16:38:44 -05:00
fi
done
else
exitError "Unsupported platform for code signing!\n"
fi
logInfo "All done!"
}
2021-01-29 18:39:36 -05:00
# -----------------------------------------------------------------------
# notarize command
# -----------------------------------------------------------------------
notarize() {
local notarize_files=()
local ac_username
local ac_keychain="AC_PASSWORD"
while [ $# -ge 1 ]; do
local arg="$1"
case "$arg" in
-f|--files)
while [ "${2:0:1}" != "-" ] && [ $# -ge 2 ]; do
notarize_files+=("$2")
shift
done ;;
-u|--username)
ac_username="$2"
shift ;;
-c|--keychain)
ac_keychain="$2"
shift ;;
-h|--help)
printUsage "notarize"
exit ;;
*)
logError "Unknown option '$arg'\n"
printUsage "notarize"
exit 1 ;;
esac
shift
done
2022-03-17 18:26:06 -04:00
if [ -z "$OS_MACOS" ]; then
2021-01-29 18:39:36 -05:00
exitError "Notarization is only supported on macOS!"
fi
if [ -z "${notarize_files}" ]; then
logError "Missing arguments, --files is required!\n"
printUsage "notarize"
exit 1
fi
2021-09-29 10:25:52 -04:00
if [ -z "$ac_username" ]; then
2021-01-29 18:39:36 -05:00
logError "Missing arguments, --username is required!"
printUsage "notarize"
exit 1
fi
for f in "${notarize_files[@]}"; do
if [[ ${f: -4} != '.dmg' ]]; then
logWarn "Skipping non-DMG file '${f}'..."
continue
fi
logInfo "Submitting disk image '${f}' for notarization..."
local status
status="$(xcrun altool --notarize-app \
--primary-bundle-id "org.keepassxc.keepassxc" \
--username "${ac_username}" \
--password "@keychain:${ac_keychain}" \
2022-03-17 18:26:06 -04:00
--file "${f}")"
2021-01-29 18:39:36 -05:00
if [ 0 -ne $? ]; then
logError "Submission failed!"
exitError "Error message:\n${status}"
fi
2022-03-17 18:26:06 -04:00
local ticket="$(echo "${status}" | grep -oE '[a-f0-9-]+$')"
2021-01-29 18:39:36 -05:00
logInfo "Submission successful. Ticket ID: ${ticket}."
logInfo "Waiting for notarization to finish (this may take a while)..."
while true; do
echo -n "."
status="$(xcrun altool --notarization-info "${ticket}" \
--username "${ac_username}" \
--password "@keychain:${ac_keychain}" 2> /dev/null)"
2022-03-17 18:26:06 -04:00
if echo "$status" | grep -q "Status Code: 0"; then
2021-01-29 18:39:36 -05:00
logInfo "\nNotarization successful."
break
2022-03-17 18:26:06 -04:00
elif echo "$status" | grep -q "Status Code"; then
2021-01-29 18:39:36 -05:00
logError "\nNotarization failed!"
exitError "Error message:\n${status}"
fi
sleep 5
done
logInfo "Stapling ticket to disk image..."
xcrun stapler staple "${f}"
if [ 0 -ne $? ]; then
exitError "Stapling failed!"
fi
logInfo "Disk image successfully notarized."
done
}
2021-09-28 05:22:15 -04:00
# -----------------------------------------------------------------------
# i18n command
# -----------------------------------------------------------------------
i18n() {
local cmd="$1"
2021-09-29 10:25:52 -04:00
if [ -z "$cmd" ]; then
2021-09-28 05:22:15 -04:00
logError "No subcommand specified.\n"
printUsage i18n
exit 1
elif [ "$cmd" != "tx-push" ] && [ "$cmd" != "tx-pull" ] && [ "$cmd" != "lupdate" ]; then
logError "Unknown subcommand: '${cmd}'\n"
printUsage i18n
exit 1
fi
shift
2021-09-29 10:25:52 -04:00
checkGitRepository
2021-09-28 05:22:15 -04:00
if [ "$cmd" == "lupdate" ]; then
if [ ! -d share/translations ]; then
logError "Command must be called from repository root directory."
exit 1
fi
2021-09-29 10:25:52 -04:00
checkQt5LUpdateExists
2021-09-28 05:22:15 -04:00
logInfo "Updating source translation file..."
LUPDATE=lupdate-qt5
if ! command -v $LUPDATE > /dev/null; then
LUPDATE=lupdate
fi
$LUPDATE -no-ui-lines -disable-heuristic similartext -locations none -no-obsolete src \
-ts share/translations/keepassxc_en.ts $@
return 0
fi
2021-09-29 10:25:52 -04:00
checkTransifexCommandExists
2021-09-28 05:22:15 -04:00
local branch="$(git branch --show-current 2>&1)"
local real_branch="$branch"
if [[ "$branch" =~ ^release/ ]]; then
logInfo "Release branch, setting language resource to master branch."
branch="master"
elif [ "$branch" != "develop" ] && [ "$branch" != "master" ]; then
logError "Must be on master or develop branch!"
exit 1
fi
local resource="keepassxc.share-translations-keepassxc-en-ts--${branch}"
if [ "$cmd" == "tx-push" ]; then
echo -e "This will push the \e[1m'en'\e[0m source file from the current branch to Transifex:\n" >&2
echo -e " \e[1m${real_branch}\e[0m -> \e[1m${resource}\e[0m\n" >&2
echo -n "Continue? [y/N] " >&2
read -r yesno
if [ "$yesno" != "y" ] && [ "$yesno" != "Y" ]; then
logError "Push aborted."
exit 1
fi
logInfo "Pushing source translation file to Transifex..."
tx push -s --use-git-timestamps -r "$resource" $@
elif [ "$cmd" == "tx-pull" ]; then
logInfo "Pulling updated translations from Transifex..."
tx pull -af --minimum-perc=60 --parallel -r "$resource" $@
fi
}
2017-01-28 16:11:05 -05:00
# -----------------------------------------------------------------------
# parse global command line
# -----------------------------------------------------------------------
MODE="$1"
2021-09-29 10:25:52 -04:00
shift || true
if [ -z "$MODE" ]; then
2017-01-28 16:11:05 -05:00
logError "Missing arguments!\n"
printUsage
exit 1
elif [ "help" == "$MODE" ]; then
printUsage "$1"
exit
2018-09-26 16:46:59 -04:00
elif [ "check" == "$MODE" ] || [ "merge" == "$MODE" ] || [ "build" == "$MODE" ] \
2021-01-29 18:39:36 -05:00
|| [ "gpgsign" == "$MODE" ] || [ "appsign" == "$MODE" ]|| [ "notarize" == "$MODE" ] \
2021-09-28 05:22:15 -04:00
|| [ "appimage" == "$MODE" ]|| [ "i18n" == "$MODE" ]; then
2017-12-13 16:38:44 -05:00
${MODE} "$@"
2017-01-28 17:17:48 -05:00
else
printUsage "$MODE"
2017-01-28 16:11:05 -05:00
fi