Compare commits

..

1 Commits

Author SHA1 Message Date
Slaviša Arežina 9e559c0b3a Update Docmost configuration and service start messages 2026-07-09 18:47:54 +02:00
2 changed files with 22 additions and 42 deletions
+3 -3
View File
@@ -39,9 +39,7 @@ function update_script() {
create_backup /opt/docmost/.env \
/opt/docmost/data
fetch_and_deploy_gh_release "docmost" "docmost/docmost" "tarball"
restore_backup
# Fix: Docmost EE (audit logs etc.) lives in a git submodule that is NOT
@@ -54,9 +52,11 @@ function update_script() {
sed -i '/^@Module({$/i @Global()' /opt/docmost/apps/server/src/core/core.module.ts
fi
msg_insfo "Configuring Docmost"
cd /opt/docmost
$STD pnpm install --force
$STD pnpm build
msg_ok "Updated ${APP}"
msg_ok "Configured Docmost"
msg_info "Starting Service"
systemctl start docmost
+19 -39
View File
@@ -36,10 +36,6 @@
#
# ==============================================================================
# Guard against double-sourcing (core.func uses the same pattern)
[[ -n "${_TOOLS_FUNC_LOADED:-}" ]] && return 0
_TOOLS_FUNC_LOADED=1
# ------------------------------------------------------------------------------
# Debug helper - outputs to stderr when TOOLS_DEBUG is enabled
# Usage: debug_log "message"
@@ -95,17 +91,16 @@ curl_with_retry() {
while [[ $attempt -le $retries ]]; do
debug_log "curl attempt $attempt/$retries: $url"
# Build curl command as array to avoid command injection via extra_opts
local -a curl_args=(curl -fsSL --connect-timeout "$connect_timeout" --max-time "$timeout")
[[ -n "$extra_opts" ]] && read -ra _extra <<<"$extra_opts" && curl_args+=("${_extra[@]}")
local curl_cmd="curl -fsSL --connect-timeout $connect_timeout --max-time $timeout"
[[ -n "$extra_opts" ]] && curl_cmd="$curl_cmd $extra_opts"
if [[ "$output" == "-" ]]; then
if "${curl_args[@]}" "$url"; then
if $curl_cmd "$url"; then
success=true
break
fi
else
if "${curl_args[@]}" -o "$output" "$url"; then
if $curl_cmd -o "$output" "$url"; then
success=true
break
fi
@@ -158,16 +153,15 @@ curl_api_with_retry() {
while [[ $attempt -le $retries ]]; do
debug_log "curl API attempt $attempt/$retries: $url"
# Build curl command as array to avoid command injection via extra_opts
local -a curl_args=(curl -fsSL --connect-timeout "$connect_timeout" --max-time "$timeout" -w '%{http_code}')
[[ -n "$extra_opts" ]] && read -ra _extra <<<"$extra_opts" && curl_args+=("${_extra[@]}")
local curl_cmd="curl -fsSL --connect-timeout $connect_timeout --max-time $timeout -w '%{http_code}'"
[[ -n "$extra_opts" ]] && curl_cmd="$curl_cmd $extra_opts"
if [[ -n "$body_file" ]]; then
http_code=$("${curl_args[@]}" -o "$body_file" "$url" 2>/dev/null) || true
http_code=$($curl_cmd -o "$body_file" "$url" 2>/dev/null) || true
else
# Capture body and http_code separately
local tmp_body="/tmp/curl_api_body_$$"
http_code=$("${curl_args[@]}" -o "$tmp_body" "$url" 2>/dev/null) || true
http_code=$($curl_cmd -o "$tmp_body" "$url" 2>/dev/null) || true
if [[ -f "$tmp_body" ]]; then
cat "$tmp_body"
rm -f "$tmp_body"
@@ -310,10 +304,7 @@ edit_yaml_config() {
return 1
fi
# Escape sed metacharacters in value (| and &) to prevent injection
local escaped_value="${value//|/\\|}"
escaped_value="${escaped_value//&/\\&}"
sed -i "s|^\([[:space:]]*${key}[[:space:]]*:\).*|\1 ${escaped_value}|" "$file"
sed -i "s|^\([[:space:]]*${key}[[:space:]]*:\).*|\1 ${value}|" "$file"
}
# ------------------------------------------------------------------------------
@@ -1696,6 +1687,10 @@ is_ubuntu() {
[[ "$(get_os_info id)" == "ubuntu" ]]
}
is_alpine() {
[[ "$(get_os_info id)" == "alpine" ]]
}
# ------------------------------------------------------------------------------
# Get Debian/Ubuntu major version
# ------------------------------------------------------------------------------
@@ -2459,10 +2454,8 @@ start_timer() {
end_timer() {
local start_time="$1"
local label="${2:-Operation}"
local end_time
end_time=$(date +%s)
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo "${label} took ${duration}s"
}
# ------------------------------------------------------------------------------
@@ -6753,16 +6746,9 @@ setup_mariadb_db() {
msg_info "Setting up MariaDB Database"
# Use --defaults-extra-file to pass credentials safely and escape identifiers
# to prevent SQL injection via DB name / user / password
local _db_escaped _user_escaped _pass_escaped
_db_escaped="${MARIADB_DB_NAME//\'/\'\'}"
_user_escaped="${MARIADB_DB_USER//\'/\'\'}"
_pass_escaped="${MARIADB_DB_PASS//\'/\'\'}"
$STD mariadb -u root -e "CREATE DATABASE \`$_db_escaped\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
$STD mariadb -u root -e "CREATE USER '$_user_escaped'@'localhost' IDENTIFIED BY '$_pass_escaped';"
$STD mariadb -u root -e "GRANT ALL ON \`$_db_escaped\`.* TO '$_user_escaped'@'localhost';"
$STD mariadb -u root -e "CREATE DATABASE \`$MARIADB_DB_NAME\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
$STD mariadb -u root -e "CREATE USER '$MARIADB_DB_USER'@'localhost' IDENTIFIED BY '$MARIADB_DB_PASS';"
$STD mariadb -u root -e "GRANT ALL ON \`$MARIADB_DB_NAME\`.* TO '$MARIADB_DB_USER'@'localhost';"
# Optional extra grants
if [[ -n "${MARIADB_DB_EXTRA_GRANTS:-}" ]]; then
@@ -8392,14 +8378,8 @@ setup_postgresql_db() {
fi
msg_info "Setting up PostgreSQL Database"
# Escape single quotes in identifiers to prevent SQL injection
local _pg_user_escaped _pg_pass_escaped _pg_db_escaped
_pg_user_escaped="${PG_DB_USER//\'/\'\'}"
_pg_pass_escaped="${PG_DB_PASS//\'/\'\'}"
_pg_db_escaped="${PG_DB_NAME//\'/\'\'}"
$STD sudo -u postgres psql -c "CREATE ROLE $_pg_user_escaped WITH LOGIN PASSWORD '$_pg_pass_escaped';"
$STD sudo -u postgres psql -c "CREATE DATABASE $_pg_db_escaped WITH OWNER $_pg_user_escaped ENCODING 'UTF8' TEMPLATE template0;"
$STD sudo -u postgres psql -c "CREATE ROLE $PG_DB_USER WITH LOGIN PASSWORD '$PG_DB_PASS';"
$STD sudo -u postgres psql -c "CREATE DATABASE $PG_DB_NAME WITH OWNER $PG_DB_USER ENCODING 'UTF8' TEMPLATE template0;"
# Configure pg_cron database BEFORE creating the extension (must be set before pg_cron loads)
if [[ -n "${PG_DB_EXTENSIONS:-}" ]] && [[ ",${PG_DB_EXTENSIONS//[[:space:]]/}," == *",pg_cron,"* ]]; then