2024-02-20 15:23:09 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-04-04 18:09:39 +08:00
|
|
|
# SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2024-02-26 22:20:17 +08:00
|
|
|
set -euo pipefail
|
2024-02-20 15:23:09 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
2024-03-18 22:24:40 +08:00
|
|
|
CONF_DIR=$SCRIPT_DIR/onlyoffice-conf
|
|
|
|
BUILDS_DIR=$CONF_DIR/onlyoffice-builds.git
|
2024-02-22 16:23:20 +08:00
|
|
|
OO_DIR=$SCRIPT_DIR/www/common/onlyoffice/dist
|
2024-03-18 22:24:40 +08:00
|
|
|
PROPS_FILE="$CONF_DIR"/onlyoffice.properties
|
2024-03-06 16:48:49 +08:00
|
|
|
|
2024-03-18 17:17:06 +08:00
|
|
|
declare -A PROPS
|
2024-02-20 15:23:09 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
main() {
|
|
|
|
mkdir -p "$CONF_DIR"
|
2024-03-18 22:24:40 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
load_props
|
2024-03-18 22:24:40 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
parse_arguments "$@"
|
2024-02-22 16:23:20 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
ask_for_license
|
2024-03-06 16:48:49 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
# Remeber the 1st version that is installed. This will help us install only
|
|
|
|
# needed OnlyOffice versions in a later version of this script.
|
|
|
|
set_prop oldest_needed_version v1
|
2024-03-18 22:24:40 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
mkdir -p "$OO_DIR"
|
|
|
|
install_version v1 4f370beb
|
|
|
|
install_version v2b d9da72fd
|
|
|
|
install_version v4 6ebc6938
|
|
|
|
install_version v5 88a356f0
|
|
|
|
install_version v6 abd8a309
|
|
|
|
install_version v7 ba82142f
|
|
|
|
install_x2t v7.3+1 ab0c05b0e4c81071acea83f0c6a8e75f5870c360ec4abc4af09105dd9b52264af9711ec0b7020e87095193ac9b6e20305e446f2321a541f743626a598e5318c1
|
2024-02-20 15:23:09 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
rm -rf "$BUILDS_DIR"
|
|
|
|
if command -v rdfind &>/dev/null; then
|
|
|
|
rdfind -makehardlinks true -makeresultsfile false $OO_DIR/v*
|
|
|
|
fi
|
2024-02-20 15:23:09 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
load_props() {
|
|
|
|
if [ -e "$PROPS_FILE" ]; then
|
|
|
|
while IFS='=' read -r key value; do
|
|
|
|
PROPS["$key"]="$value"
|
|
|
|
done <"$PROPS_FILE"
|
|
|
|
fi
|
2024-03-06 16:48:49 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
set_prop() {
|
|
|
|
PROPS["$1"]="$2"
|
2024-03-06 16:48:49 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
for i in "${!PROPS[@]}"; do
|
|
|
|
echo "$i=${PROPS[$i]}"
|
|
|
|
done >"$PROPS_FILE"
|
2024-03-06 16:48:49 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
parse_arguments() {
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
-h | --help)
|
|
|
|
show_help
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-a | --accept-license)
|
|
|
|
ACCEPT_LICENSE="1"
|
|
|
|
shift
|
|
|
|
;;
|
2024-07-02 07:38:51 +08:00
|
|
|
-t | --trust-repository)
|
|
|
|
TRUST_REPOSITORY="1"
|
|
|
|
shift
|
|
|
|
;;
|
2024-05-24 15:39:39 +08:00
|
|
|
*)
|
|
|
|
show_help
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2024-02-20 15:23:09 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
ask_for_license() {
|
|
|
|
if [ ${ACCEPT_LICENSE+x} ] || [ "${PROPS[agree_license]:-no}" == yes ]; then
|
|
|
|
return
|
|
|
|
fi
|
2024-03-06 16:48:49 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
ensure_command_available curl
|
2024-03-18 17:17:06 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
(
|
|
|
|
echo -e "Please review the license of OnlyOffice:\n\n"
|
|
|
|
curl https://raw.githubusercontent.com/ONLYOFFICE/web-apps/master/LICENSE.txt 2>/dev/null
|
|
|
|
) | less
|
2024-03-18 17:17:06 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
read -rp "Do you accept the license? (Y/N): " confirm &&
|
|
|
|
[[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
|
2024-03-18 17:17:06 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
set_prop "agree_license" yes
|
2024-03-06 16:48:49 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
show_help() {
|
|
|
|
cat <<EOF
|
2024-02-20 15:23:09 +08:00
|
|
|
install-onlyoffice installs or upgrades OnlyOffice.
|
|
|
|
|
2024-03-18 17:17:06 +08:00
|
|
|
NOTE: When you have rdfind installed, it will be used to save ~650MB of disk
|
|
|
|
space.
|
|
|
|
|
2024-02-20 15:23:09 +08:00
|
|
|
OPTIONS:
|
|
|
|
-h, --help
|
|
|
|
Show this help.
|
|
|
|
|
2024-03-18 17:17:06 +08:00
|
|
|
-a, --accept-license
|
|
|
|
Accept the license of OnlyOffice and do not ask when running this
|
|
|
|
script. Read and accept this before using this option:
|
|
|
|
https://github.com/ONLYOFFICE/web-apps/blob/master/LICENSE.txt
|
2024-07-02 07:38:51 +08:00
|
|
|
|
|
|
|
-t, --trust-repository
|
|
|
|
Automatically configure the cloned onlyoffice-builds repository
|
|
|
|
as a safe.directory.
|
|
|
|
https://git-scm.com/docs/git-config/#Documentation/git-config.txt-safedirectory
|
|
|
|
|
2024-02-20 15:23:09 +08:00
|
|
|
EOF
|
2024-05-24 15:39:39 +08:00
|
|
|
exit 1
|
2024-02-20 15:23:09 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
ensure_oo_is_downloaded() {
|
2024-07-02 07:38:51 +08:00
|
|
|
ensure_command_available git
|
2024-03-18 17:17:06 +08:00
|
|
|
|
2024-03-18 22:24:40 +08:00
|
|
|
if ! [ -d "$BUILDS_DIR" ]; then
|
2024-03-19 18:28:27 +08:00
|
|
|
echo "Downloading OnlyOffice..."
|
2024-03-18 22:24:40 +08:00
|
|
|
git clone --bare https://github.com/cryptpad/onlyoffice-builds.git "$BUILDS_DIR"
|
2024-02-20 15:23:09 +08:00
|
|
|
fi
|
2024-07-02 07:38:51 +08:00
|
|
|
if [ ${TRUST_REPOSITORY+x} ] || [ "${PROPS[trust_repository]:-no}" == yes ]; then
|
|
|
|
git config --global --add safe.directory /cryptpad/onlyoffice-conf/onlyoffice-builds.git
|
|
|
|
fi
|
2024-02-20 15:23:09 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
install_version() {
|
|
|
|
local DIR=$1
|
|
|
|
local COMMIT=$2
|
|
|
|
local FULL_DIR=$OO_DIR/$DIR
|
|
|
|
local LAST_DIR
|
|
|
|
LAST_DIR=$(pwd)
|
2024-02-22 18:01:58 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
if [ ! -e "$FULL_DIR"/.commit ] || [ "$(cat "$FULL_DIR"/.commit)" != "$COMMIT" ]; then
|
|
|
|
ensure_oo_is_downloaded
|
2024-03-18 22:24:40 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
rm -rf "$FULL_DIR"
|
2024-03-18 22:24:40 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
cd "$BUILDS_DIR"
|
|
|
|
git worktree add "$FULL_DIR" "$COMMIT"
|
2024-02-26 22:20:17 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
cd "$LAST_DIR"
|
2024-02-26 22:20:17 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
echo "$COMMIT" >"$FULL_DIR"/.commit
|
2024-02-26 22:20:17 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
echo "$DIR updated"
|
|
|
|
else
|
|
|
|
echo "$DIR was up to date"
|
|
|
|
fi
|
2024-02-20 15:23:09 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
if [ ${CLEAR+x} ]; then
|
|
|
|
rm -f "$FULL_DIR"/.git
|
|
|
|
fi
|
2024-02-20 15:23:09 +08:00
|
|
|
}
|
2024-02-26 22:20:17 +08:00
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
install_x2t() {
|
|
|
|
ensure_command_available curl
|
|
|
|
ensure_command_available sha512sum
|
|
|
|
ensure_command_available unzip
|
|
|
|
|
|
|
|
local VERSION=$1
|
|
|
|
local HASH=$2
|
|
|
|
local LAST_DIR
|
|
|
|
LAST_DIR=$(pwd)
|
|
|
|
local X2T_DIR=$OO_DIR/x2t
|
|
|
|
|
|
|
|
if [ ! -e "$X2T_DIR"/.version ] || [ "$(cat "$X2T_DIR"/.version)" != "$VERSION" ]; then
|
|
|
|
rm -rf "$X2T_DIR"
|
|
|
|
mkdir -p "$X2T_DIR"
|
|
|
|
|
|
|
|
cd "$X2T_DIR"
|
|
|
|
|
|
|
|
curl "https://github.com/cryptpad/onlyoffice-x2t-wasm/releases/download/$VERSION/x2t.zip" --location --output x2t.zip
|
|
|
|
# curl "https://github.com/cryptpad/onlyoffice-x2t-wasm/releases/download/v7.3%2B1/x2t.zip" --location --output x2t.zip
|
|
|
|
echo "$HASH x2t.zip" >x2t.zip.sha512
|
|
|
|
if ! sha512sum --check x2t.zip.sha512; then
|
|
|
|
echo "x2t.zip does not match expected checksum"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
unzip x2t.zip
|
|
|
|
rm x2t.zip*
|
|
|
|
|
|
|
|
echo "$VERSION" >"$X2T_DIR"/.version
|
|
|
|
|
|
|
|
echo "x2t updated"
|
|
|
|
else
|
|
|
|
echo "x2t was up to date"
|
|
|
|
fi
|
2024-02-20 15:23:09 +08:00
|
|
|
}
|
|
|
|
|
2024-05-24 15:39:39 +08:00
|
|
|
ensure_command_available() {
|
|
|
|
if ! command -v "$1" &>/dev/null; then
|
|
|
|
echo "$1 needs to be installed to run this script"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-03-18 17:17:06 +08:00
|
|
|
}
|
|
|
|
|
2024-02-20 15:23:09 +08:00
|
|
|
main "$@"
|