From 7ffd6cbef0cc942edcd523d7fb228647d96e6cac Mon Sep 17 00:00:00 2001 From: bvdberg01 <74251551+bvdberg01@users.noreply.github.com> Date: Sun, 24 Nov 2024 17:59:23 +0100 Subject: [PATCH] New script: listmonk LXC (#442) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * New script: listmonk LXC * Fixed issues after PR review * Fixed issues after PR review Co-Authored-By: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * add network.target Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> --------- Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> Co-authored-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> --- ct/listmonk.sh | 96 +++++++++++++++++++++++++++++++++++++ install/listmonk-install.sh | 79 ++++++++++++++++++++++++++++++ json/listmonk.json | 34 +++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 ct/listmonk.sh create mode 100644 install/listmonk-install.sh create mode 100644 json/listmonk.json diff --git a/ct/listmonk.sh b/ct/listmonk.sh new file mode 100644 index 00000000..a44f147c --- /dev/null +++ b/ct/listmonk.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2024 community-scripts ORG +# Author: bvdberg01 +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +function header_info { +clear +cat <<"EOF" + ___ __ __ + / (_)____/ /_____ ___ ____ ____ / /__ + / / / ___/ __/ __ `__ \/ __ \/ __ \/ //_/ + / / (__ ) /_/ / / / / / /_/ / / / / ,< +/_/_/____/\__/_/ /_/ /_/\____/_/ /_/_/|_| + +EOF +} +header_info +echo -e "Loading..." +APP="listmonk" +var_disk="4" +var_cpu="1" +var_ram="512" +var_os="debian" +var_version="12" +variables +color +catch_errors + +function default_settings() { + CT_TYPE="1" + PW="" + CT_ID=$NEXTID + HN=$NSAPP + DISK_SIZE="$var_disk" + CORE_COUNT="$var_cpu" + RAM_SIZE="$var_ram" + BRG="vmbr0" + NET="dhcp" + GATE="" + APT_CACHER="" + APT_CACHER_IP="" + DISABLEIP6="no" + MTU="" + SD="" + NS="" + MAC="" + VLAN="" + SSH="no" + VERB="no" + echo_default +} + +function update_script() { +header_info +check_container_storage +check_container_resources +if [[ ! -f /etc/systemd/system/listmonk.service ]]; then msg_error "No ${APP} Installation Found!"; exit; fi + +RELEASE=$(curl -s https://api.github.com/repos/knadh/listmonk/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + msg_info "Stopping ${APP}" + systemctl stop listmonk + msg_ok "Stopped ${APP}" + + msg_info "Updating ${APP} to v${RELEASE}" + cd /opt + wget -q "https://github.com/knadh/listmonk/releases/download/v${RELEASE}/listmonk_${RELEASE}_linux_amd64.tar.gz" + tar -xzf "listmonk_${RELEASE}_linux_amd64.tar.gz" -C /opt/listmonk + /opt/listmonk/listmonk --upgrade --yes --config /opt/listmonk/config.toml &>/dev/null + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated $APP to v${RELEASE}" + + msg_info "Starting ${APP}" + systemctl start listmonk + msg_ok "Started ${APP}" + + msg_info "Cleaning up" + rm -rf "/opt/listmonk_${RELEASE}_linux_amd64.tar.gz" + msg_ok "Cleaned" + + msg_ok "Updated Successfully" +else + msg_ok "No update required. ${APP} is already at v${RELEASE}" +fi +exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${APP} should be reachable by going to the following URL. + ${BL}http://${IP}:9000${CL} \n" diff --git a/install/listmonk-install.sh b/install/listmonk-install.sh new file mode 100644 index 00000000..09c28933 --- /dev/null +++ b/install/listmonk-install.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2024 community-scripts ORG +# Author: bvdberg01 +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +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 \ + curl \ + sudo \ + mc \ + postgresql +msg_ok "Installed Dependencies" + +msg_info "Setting up PostgreSQL" +DB_NAME=listmonk +DB_USER=listmonk +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | 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 "listmonk-Credentials" +echo -e "listmonk Database User: \e[32m$DB_USER\e[0m" +echo -e "listmonk Database Password: \e[32m$DB_PASS\e[0m" +echo -e "listmonk Database Name: \e[32m$DB_NAME\e[0m" +} >> ~/listmonk.creds +msg_ok "Set up PostgreSQL" + +msg_info "Installing listmonk" +cd /opt +mkdir /opt/listmonk +RELEASE=$(curl -s https://api.github.com/repos/knadh/listmonk/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +wget -q "https://github.com/knadh/listmonk/releases/download/v${RELEASE}/listmonk_${RELEASE}_linux_amd64.tar.gz" +tar -xzf "listmonk_${RELEASE}_linux_amd64.tar.gz" -C /opt/listmonk + +$STD /opt/listmonk/listmonk --new-config --config /opt/listmonk/config.toml +sed -i -e 's/address = "localhost:9000"/address = "0.0.0.0:9000"/' -e 's/^password = ".*"/password = "'"$DB_PASS"'"/' /opt/listmonk/config.toml +$STD /opt/listmonk/listmonk --install --yes --config /opt/listmonk/config.toml + +echo "${RELEASE}" >/opt/${APPLICATION}_version.txt +msg_ok "Installed listmonk" + +msg_info "Creating Service" +cat </etc/systemd/system/listmonk.service +[Unit] +Description=Listmonk Service +Wants=network.target +After=postgresql.service + +[Service] +Type=simple +ExecStart=/opt/listmonk/listmonk --config /opt/listmonk/config.toml +Restart=always +RestartSec=3 +WorkingDirectory=/opt/listmonk + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now listmonk +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +rm -rf "/opt/listmonk_${RELEASE}_linux_amd64.tar.gz" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" \ No newline at end of file diff --git a/json/listmonk.json b/json/listmonk.json new file mode 100644 index 00000000..83fddf04 --- /dev/null +++ b/json/listmonk.json @@ -0,0 +1,34 @@ +{ + "name": "listmonk", + "slug": "listmonk", + "categories": [ + 14 + ], + "date_created": "2024-11-22", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": "9000", + "documentation": "https://listmonk.app/docs/", + "website": "https://listmonk.app/", + "logo": "https://listmonk.app/static/images/logo.svg", + "description": "High performance, self-hosted, newsletter and mailing list manager with a modern dashboard.", + "install_methods": [ + { + "type": "default", + "script": "ct/listmonk.sh", + "resources": { + "cpu": "1", + "ram": "512", + "hdd": "4", + "os": "debian", + "version": "12" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [] +} \ No newline at end of file