add rust function & linkwarden 24.04

This commit is contained in:
CanbiZ 2025-05-27 10:33:04 +02:00
parent 1216d2f27c
commit 42402c54dc
3 changed files with 257 additions and 0 deletions

84
ct/linkwarden.sh Normal file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://linkwarden.app/
APP="Linkwarden"
var_tags="${var_tags:-bookmark}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-4096}"
var_disk="${var_disk:-12}"
var_os="${var_os:-ubuntu}"
var_version="${var_version:-24.04}"
header_info "$APP"
variables
color
catch_errors
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 -fsSL 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
NODE_VERSION="22" NODE_MODULE="yarn@latest" install_node_and_modules
msg_info "Stopping ${APP}"
systemctl stop linkwarden
msg_ok "Stopped ${APP}"
msg_info "Updating Rust"
$STD apt-get install -y build-essential
$STD curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
echo 'export PATH=/usr/local/cargo/bin:$PATH' >>/etc/profile
source /etc/profile
$STD cargo install monolith
msg_ok "Updated Rust"
msg_info "Updating ${APP} to ${RELEASE}"
cd /opt
mv /opt/linkwarden/.env /opt/.env
rm -rf /opt/linkwarden
RELEASE=$(curl -fsSL https://api.github.com/repos/linkwarden/linkwarden/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
curl -fsSL "https://github.com/linkwarden/linkwarden/archive/refs/tags/${RELEASE}.zip" -o ${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
cp /opt/.env /opt/linkwarden/.env
$STD yarn prisma:generate
$STD yarn web:build
$STD yarn prisma:deploy
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
msg_ok "Cleaned"
msg_ok "Updated Successfully"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}."
fi
exit
}
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}"

View File

@ -0,0 +1,129 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# Co-Author: MickLesk (Canbiz)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://linkwarden.app/
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing Dependencies"
$STD apt-get install -y \
make \
git \
build-essential
msg_ok "Installed Dependencies"
NODE_VERSION="22" NODE_MODULE="yarn@latest" install_node_and_modules
PG_VERSION="15" install_postgresql
RUST_CRATES="monolith" install_rust_and_crates
# msg_info "Installing Rust"
# curl -fsSL https://sh.rustup.rs -o rustup-init.sh
# $STD bash rustup-init.sh -y --profile minimal
# echo 'export PATH="$HOME/.cargo/bin:$PATH"' >>~/.bashrc
# export PATH="$HOME/.cargo/bin:$PATH"
# rm rustup-init.sh
# $STD cargo install monolith
# msg_ok "Installed Rust"
msg_info "Setting up PostgreSQL DB"
DB_NAME=linkwardendb
DB_USER=linkwarden
DB_PASS="$(openssl rand -base64 18 | tr -d '/' | cut -c1-13)"
SECRET_KEY="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)"
$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 "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 "${TAB3}Would you like to add Adminer? <y/N> " prompt
# if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
# msg_info "Installing Adminer"
# $STD apt install -y adminer
# $STD a2enconf adminer
# systemctl reload apache2
# IP=$(hostname -I | awk '{print $1}')
# echo "" >>~/linkwarden.creds
# echo -e "Adminer Interface: \e[32m$IP/adminer/\e[0m" >>~/linkwarden.creds
# echo -e "Adminer System: \e[32mPostgreSQL\e[0m" >>~/linkwarden.creds
# echo -e "Adminer Server: \e[32mlocalhost:5432\e[0m" >>~/linkwarden.creds
# 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 -fsSL https://api.github.com/repos/linkwarden/linkwarden/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
curl -fsSL "https://github.com/linkwarden/linkwarden/archive/refs/tags/${RELEASE}.zip" -o ${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
IP=$(hostname -I | awk '{print $1}')
env_path="/opt/linkwarden/.env"
echo "
NEXTAUTH_SECRET=${SECRET_KEY}
NEXTAUTH_URL=http://${IP}:3000
DATABASE_URL=postgresql://${DB_USER}:${DB_PASS}@localhost:5432/${DB_NAME}
" >$env_path
$STD yarn prisma:generate
$STD yarn web:build
$STD yarn prisma:deploy
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
msg_ok "Installed Linkwarden"
msg_info "Creating Service"
cat <<EOF >/etc/systemd/system/linkwarden.service
[Unit]
Description=Linkwarden Service
After=network.target
[Service]
Type=exec
Environment=PATH=$PATH
WorkingDirectory=/opt/linkwarden
ExecStart=/usr/bin/yarn concurrently:start
[Install]
WantedBy=multi-user.target
EOF
systemctl enable -q --now linkwarden
msg_ok "Created Service"
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"

View File

@ -1191,3 +1191,47 @@ setup_rbenv_stack() {
rm -rf "$TMP_DIR"
msg_ok "rbenv stack ready (Ruby $RUBY_VERSION)"
}
install_rust_and_crates() {
local RUST_TOOLCHAIN="${RUST_TOOLCHAIN:-stable}"
local RUST_CRATES="${RUST_CRATES:-}"
# Install rustup if not available
if ! command -v rustup &>/dev/null; then
msg_info "Installing rustup"
curl -fsSL https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN"
export PATH="$HOME/.cargo/bin:$PATH"
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >>"$HOME/.profile"
msg_ok "Installed rustup with $RUST_TOOLCHAIN"
else
msg_ok "rustup already installed"
rustup install "$RUST_TOOLCHAIN"
fi
rustup default "$RUST_TOOLCHAIN"
rustup update
# install crates
if [[ -n "$RUST_CRATES" ]]; then
IFS=',' read -ra CRATES <<<"$RUST_CRATES"
for crate in "${CRATES[@]}"; do
local NAME VER
if [[ "$crate" == *"@"* ]]; then
NAME="${crate%@*}"
VER="${crate##*@}"
else
NAME="$crate"
VER=""
fi
if cargo install --list | grep -q "^$NAME "; then
msg_info "Crate $NAME already installed, updating"
cargo install "$NAME" ${VER:+--version "$VER"} --force
else
msg_info "Installing crate $NAME ${VER:+($VER)}"
cargo install "$NAME" ${VER:+--version "$VER"}
fi
done
msg_ok "All requested Rust crates processed"
fi
}