1+ #! /usr/bin/env bash
2+
3+ # Copyright (c) 2021-2024 community-scripts ORG
4+ # Author: bvdberg01
5+ # License: MIT
6+ # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
7+
8+ source /dev/stdin <<< " $FUNCTIONS_FILE_PATH"
9+ color
10+ verb_ip6
11+ catch_errors
12+ setting_up_container
13+ network_check
14+ update_os
15+
16+ msg_info " Installing Dependencies"
17+ $STD apt-get install -y \
18+ curl \
19+ sudo \
20+ mc \
21+ postgresql
22+ msg_ok " Installed Dependencies"
23+
24+ msg_info " Setting up PostgreSQL"
25+ DB_NAME=listmonk
26+ DB_USER=listmonk
27+ DB_PASS=$( openssl rand -base64 18 | tr -dc ' a-zA-Z0-9' | cut -c1-13)
28+ $STD sudo -u postgres psql -c " CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS ';"
29+ $STD sudo -u postgres psql -c " CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;"
30+ {
31+ echo " listmonk-Credentials"
32+ echo -e " listmonk Database User: \e[32m$DB_USER \e[0m"
33+ echo -e " listmonk Database Password: \e[32m$DB_PASS \e[0m"
34+ echo -e " listmonk Database Name: \e[32m$DB_NAME \e[0m"
35+ } >> ~ /listmonk.creds
36+ msg_ok " Set up PostgreSQL"
37+
38+ msg_info " Installing listmonk"
39+ cd /opt
40+ mkdir /opt/listmonk
41+ RELEASE=$( curl -s https://api.github.com/repos/knadh/listmonk/releases/latest | grep " tag_name" | awk ' {print substr($2, 3, length($2)-4) }' )
42+ wget -q " https://github.com/knadh/listmonk/releases/download/v${RELEASE} /listmonk_${RELEASE} _linux_amd64.tar.gz"
43+ tar -xzf " listmonk_${RELEASE} _linux_amd64.tar.gz" -C /opt/listmonk
44+
45+ $STD /opt/listmonk/listmonk --new-config --config /opt/listmonk/config.toml
46+ sed -i -e ' s/address = "localhost:9000"/address = "0.0.0.0:9000"/' -e ' s/^password = ".*"/password = "' " $DB_PASS " ' "/' /opt/listmonk/config.toml
47+ $STD /opt/listmonk/listmonk --install --yes --config /opt/listmonk/config.toml
48+
49+ echo " ${RELEASE} " > /opt/${APPLICATION} _version.txt
50+ msg_ok " Installed listmonk"
51+
52+ msg_info " Creating Service"
53+ cat << EOF >/etc/systemd/system/listmonk.service
54+ [Unit]
55+ Description=Listmonk Service
56+ Wants=network.target
57+ After=postgresql.service
58+
59+ [Service]
60+ Type=simple
61+ ExecStart=/opt/listmonk/listmonk --config /opt/listmonk/config.toml
62+ Restart=always
63+ RestartSec=3
64+ WorkingDirectory=/opt/listmonk
65+
66+ [Install]
67+ WantedBy=multi-user.target
68+ EOF
69+ systemctl enable -q --now listmonk
70+ msg_ok " Created Service"
71+
72+ motd_ssh
73+ customize
74+
75+ msg_info " Cleaning up"
76+ rm -rf " /opt/listmonk_${RELEASE} _linux_amd64.tar.gz"
77+ $STD apt-get -y autoremove
78+ $STD apt-get -y autoclean
79+ msg_ok " Cleaned"
0 commit comments