Skip to content

Commit

Permalink
Linkwarden - Harmonize Script, Add Monolith & Bugfixing (#306)
Browse files Browse the repository at this point in the history
* Update linkwarden.sh

Add new StorageCheck
Harmonize Update Script
Increase Ressources
Correct check of version

* Update linkwarden-install.sh

Harmonize Script
Switch from Git to Release
Add Monolith
Add Cargo

* Tweak

* Update linkwarden.json
  • Loading branch information
MickLesk authored Nov 18, 2024
1 parent b9e8454 commit fb07064
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
28 changes: 19 additions & 9 deletions ct/linkwarden.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EOF
header_info
echo -e "Loading..."
APP="Linkwarden"
var_disk="8"
var_disk="12"
var_cpu="2"
var_ram="2048"
var_os="ubuntu"
Expand Down Expand Up @@ -54,29 +54,39 @@ function default_settings() {

function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /opt/linkwarden ]]; then msg_error "No ${APP} Installation Found!"; exit; fi

RELEASE=$(curl -s https://api.github.com/repos/linkwarden/linkwarden/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
msg_info "Stopping ${APP}"
systemctl stop linkwarden
msg_ok "Stopped ${APP}"

msg_info "Updating ${APP} to ${RELEASE}"
cd /opt
mv /opt/linkwarden /opt/linkwarden_bak
RELEASE=$(curl -s https://api.github.com/repos/linkwarden/linkwarden/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
wget -q "https://github.com/linkwarden/linkwarden/archive/refs/tags/${RELEASE}.zip"
unzip -q ${RELEASE}.zip
mv linkwarden-${RELEASE:1} /opt/linkwarden
cd /opt/linkwarden
git pull
yarn
npx playwright install-deps
yarn playwright install
yarn prisma generate
yarn build
yarn prisma migrate deploy
yarn &>/dev/null
npx playwright install-deps &>/dev/null
yarn playwright install &>/dev/null
cp /opt/linkwarden_bak/.env /opt/linkwarden/.env
yarn build &>/dev/null
yarn prisma migrate deploy &>/dev/null
echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated ${APP} to ${RELEASE}"

msg_info "Starting ${APP}"
systemctl start linkwarden
msg_ok "Started ${APP}"
msg_info "Cleaning up"
rm -rf /opt/${RELEASE}.zip
rm -rf /opt/linkwarden_bak
msg_ok "Cleaned"
msg_ok "Updated Successfully"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}."
Expand Down
56 changes: 39 additions & 17 deletions install/linkwarden-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Copyright (c) 2021-2024 tteck
# Author: tteck (tteckster)
# Co-Author: MickLesk (Canbiz)
# License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE

Expand All @@ -14,12 +15,13 @@ network_check
update_os

msg_info "Installing Dependencies"
$STD apt-get install -y curl
$STD apt-get install -y sudo
$STD apt-get install -y mc
$STD apt-get install -y git
$STD apt-get install -y gpg
$STD apt-get install -y postgresql
$STD apt-get install -y \
curl \
sudo \
mc \
make \
postgresql \
cargo
msg_ok "Installed Dependencies"

msg_info "Setting up Node.js Repository"
Expand All @@ -34,22 +36,28 @@ $STD apt-get install -y nodejs
$STD npm install -g yarn
msg_ok "Installed Node.js/Yarn"

msg_info "Clone Linkwarden Repository"
$STD git clone https://github.com/linkwarden/linkwarden.git /opt/linkwarden
cd /opt/linkwarden
msg_ok "Cloned Linkwarden Repository"
msg_info "Installing Monolith"
$STD cargo install monolith
echo 'export PATH=~/.cargo/bin:$PATH' >>~/.bashrc
export PATH=~/.cargo/bin:$PATH
msg_ok "Installed Monolith"

msg_info "Setting up PostgreSQL DB"
DB_NAME=linkwardendb
DB_USER=linkwarden
DB_PASS="$(openssl rand -base64 18 | tr -d '/' | cut -c1-13)"
$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 TEMPLATE template0;"

echo "" >>~/linkwarden.creds
echo -e "Linkwarden Database User: \e[32m$DB_USER\e[0m" >>~/linkwarden.creds
echo -e "Linkwarden Database Password: \e[32m$DB_PASS\e[0m" >>~/linkwarden.creds
echo -e "Linkwarden Database Name: \e[32m$DB_NAME\e[0m" >>~/linkwarden.creds
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
$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 "Linkwarden-Credentials"
echo "Linkwarden Database User: $DB_USER"
echo "Linkwarden Database Password: $DB_PASS"
echo "Linkwarden Database Name: $DB_NAME"
echo "Linkwarden Secret: $SECRET_KEY"
} >> ~/linkwarden.creds
msg_ok "Set up PostgreSQL DB"

read -r -p "Would you like to add Adminer? <y/N> " prompt
Expand All @@ -66,12 +74,24 @@ if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
echo -e "Adminer Username: \e[32m$DB_USER\e[0m" >>~/linkwarden.creds
echo -e "Adminer Password: \e[32m$DB_PASS\e[0m" >>~/linkwarden.creds
echo -e "Adminer Database: \e[32m$DB_NAME\e[0m" >>~/linkwarden.creds
{
echo ""
echo "Adminer-Credentials"
echo "Adminer WebUI: $IP/adminer/"
echo "Adminer Database User: $DB_USER"
echo "Adminer Database Password: $DB_PASS"
echo "Adminer Database Name: $DB_NAME"
} >> ~/linkwarden.creds
msg_ok "Installed Adminer"
fi

msg_info "Installing Linkwarden (Patience)"
cd /opt
RELEASE=$(curl -s https://api.github.com/repos/linkwarden/linkwarden/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
wget -q "https://github.com/linkwarden/linkwarden/archive/refs/tags/${RELEASE}.zip"
unzip -q ${RELEASE}.zip
mv linkwarden-${RELEASE:1} /opt/linkwarden
cd /opt/linkwarden
$STD yarn
$STD npx playwright install-deps
$STD yarn playwright install
Expand All @@ -85,6 +105,7 @@ DATABASE_URL=postgresql://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}
" >$env_path
$STD yarn build
$STD yarn prisma migrate deploy
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
msg_ok "Installed Linkwarden"

msg_info "Creating Service"
Expand All @@ -108,6 +129,7 @@ motd_ssh
customize

msg_info "Cleaning up"
rm -rf /opt/${RELEASE}.zip
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"
10 changes: 5 additions & 5 deletions json/linkwarden.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"updateable": false,
"privileged": false,
"interface_port": "3000",
"documentation": null,
"documentation": "https://docs.linkwarden.app/",
"website": "https://linkwarden.app/",
"logo": "https://raw.githubusercontent.com/linkwarden/linkwarden/main/assets/logo.png",
"description": "Linkwarden is a fully self-hostable, open-source collaborative bookmark manager to collect, organize and archive webpages.",
Expand All @@ -20,7 +20,7 @@
"resources": {
"cpu": "2",
"ram": "2048",
"hdd": "8",
"hdd": "12",
"os": "ubuntu",
"version": "22.04"
}
Expand All @@ -32,8 +32,8 @@
},
"notes": [
{
"text": "Show Database/Adminer Credentials: `cat linkwarden.creds`",
"type": "warning"
"text": "Linkwarden > 2.8.2 needs Monolith, More info: `https://github.com/community-scripts/ProxmoxVE/discussions/305`",
"type": "info"
}
]
}
}

0 comments on commit fb07064

Please sign in to comment.