1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-04-28 06:30:18 +00:00

WikiJS: Prepare for Using PostgreSQL (#2516)

This commit is contained in:
CanbiZ 2025-02-20 14:03:43 +01:00 committed by GitHub
parent 1a8f5a4007
commit 6d3c442464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@
# License: MIT # License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color color
verb_ip6 verb_ip6
catch_errors catch_errors
@ -14,12 +14,13 @@ network_check
update_os update_os
msg_info "Installing Dependencies" msg_info "Installing Dependencies"
$STD apt-get install -y curl $STD apt-get install -y \
$STD apt-get install -y sudo curl \
$STD apt-get install -y mc sudo \
$STD apt-get install -y git mc \
$STD apt-get install -y ca-certificates git \
$STD apt-get install -y gnupg ca-certificates \
gnupg
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
msg_info "Setting up Node.js Repository" msg_info "Setting up Node.js Repository"
@ -28,36 +29,49 @@ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dea
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >/etc/apt/sources.list.d/nodesource.list echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >/etc/apt/sources.list.d/nodesource.list
msg_ok "Set up Node.js Repository" msg_ok "Set up Node.js Repository"
msg_info "Setting up PostgreSQL Repository"
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
echo "deb https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" >/etc/apt/sources.list.d/pgdg.list
msg_ok "Set up PostgreSQL Repository"
msg_info "Installing Node.js" msg_info "Installing Node.js"
$STD apt-get update $STD apt-get update
$STD apt-get install -y nodejs $STD apt-get install -y nodejs
msg_ok "Installed Node.js" msg_ok "Installed Node.js"
msg_info "Installing Wiki.js" msg_info "Set up PostgreSQL"
mkdir -p /opt/wikijs $STD apt-get install -y postgresql-17
cd /opt/wikijs DB_NAME="wikijs_db"
$STD wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz DB_USER="wikijs_user"
tar xzf wiki-js.tar.gz DB_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)"
rm wiki-js.tar.gz $STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
$STD sudo -u postgres psql -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" $DB_NAME
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';"
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';"
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC';"
{
echo "WikiJS-Credentials"
echo "WikiJS Database User: $DB_USER"
echo "WikiJS Database Password: $DB_PASS"
echo "WikiJS Database Name: $DB_NAME"
} >> ~/wikijs.creds
msg_ok "Set up PostgreSQL"
cat <<EOF >/opt/wikijs/config.yml msg_info "Setup Wiki.js"
bindIP: 0.0.0.0 temp_file=$(mktemp)
port: 3000 RELEASE=$(curl -s https://api.github.com/repos/Requarks/wiki/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
db: wget -q "https://github.com/Requarks/wiki/archive/refs/tags/v${RELEASE}.tar.gz" -O "$temp_file"
type: sqlite tar -xzf "$temp_file"
storage: /opt/wikijs/db.sqlite mv wiki-${RELEASE} /opt/wikijs
logLevel: info mv /opt/wikijs/config.sample.yml /opt/wikijs/config.yml
logFormat: default sed -i -E "s|(host: ).*|\1localhost|; s|(port: ).*|\15432|; s|(user: ).*|\1$DB_USER|; s|(pass: ).*|\1$DB_PASS|; s|(db: ).*|\1$DB_NAME|; s|(ssl: ).*|\1false|" /opt/wikijs/config.yml
dataPath: /opt/wikijs/data echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
bodyParserLimit: 5mb
EOF
$STD npm rebuild sqlite3
msg_ok "Installed Wiki.js" msg_ok "Installed Wiki.js"
msg_info "Creating Service" msg_info "Creating Service"
service_path="/etc/systemd/system/wikijs.service" cat <<EOF >/etc/systemd/system/wikijs.service
[Unit]
echo "[Unit]
Description=Wiki.js Description=Wiki.js
After=network.target After=network.target
@ -70,14 +84,16 @@ Environment=NODE_ENV=production
WorkingDirectory=/opt/wikijs WorkingDirectory=/opt/wikijs
[Install] [Install]
WantedBy=multi-user.target" >$service_path WantedBy=multi-user.target
$STD systemctl enable --now wikijs EOF
systemctl enable --now wikijs
msg_ok "Created Service" msg_ok "Created Service"
motd_ssh motd_ssh
customize customize
msg_info "Cleaning up" msg_info "Cleaning up"
rm -f "$temp_file"
$STD apt-get -y autoremove $STD apt-get -y autoremove
$STD apt-get -y autoclean $STD apt-get -y autoclean
msg_ok "Cleaned" msg_ok "Cleaned"