Skip to content

Commit bf1966f

Browse files
authored
Alpine-PostgreSQL (#3751)
1 parent 3504cda commit bf1966f

File tree

3 files changed

+162
-37
lines changed

3 files changed

+162
-37
lines changed

ct/alpine-postgresql.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: MickLesk (CanbiZ)
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://postgresql.org/
7+
8+
APP="Alpine-PostgreSQL"
9+
var_tags="${var_tags:-alpine;database}"
10+
var_cpu="${var_cpu:-1}"
11+
var_ram="${var_ram:-256}"
12+
var_disk="${var_disk:-1}"
13+
var_os="${var_os:-alpine}"
14+
var_version="${var_version:-3.21}"
15+
var_unprivileged="${var_unprivileged:-1}"
16+
17+
header_info "$APP"
18+
variables
19+
color
20+
catch_errors
21+
22+
function update_script() {
23+
msg_info "Updating Alpine Packages"
24+
$STD apk update
25+
$STD apk upgrade
26+
msg_ok "Updated Alpine Packages"
27+
28+
msg_info "Updating PostgreSQL"
29+
$STD apk upgrade postgresql postgresql-contrib
30+
msg_ok "Updated PostgreSQL"
31+
32+
msg_info "Restarting PostgreSQL"
33+
$STD rc-service postgresql restart
34+
msg_ok "Restarted PostgreSQL"
35+
36+
exit 0
37+
}
38+
39+
start
40+
build_container
41+
description
42+
43+
msg_ok "Completed Successfully!\n"
44+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
45+
echo -e "${INFO}${YW} Access it using the following IP:${CL}"
46+
echo -e "${TAB}${GATEWAY}${BGN}${IP}:5432${CL}"
Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
11
{
2-
"name": "PostgreSQL",
3-
"slug": "postgresql",
4-
"categories": [
5-
8
6-
],
7-
"date_created": "2024-05-02",
8-
"type": "ct",
9-
"updateable": false,
10-
"privileged": false,
11-
"interface_port": 5432,
12-
"documentation": null,
13-
"website": "https://www.postgresql.org/",
14-
"logo": "https://raw.githubusercontent.com/loganmarchione/homelab-svg-assets/main/assets/postgresql.svg",
15-
"description": "PostgreSQL (often referred to as Postgres) is an open-source relational database management system that is known for its extensibility and strict adherence to SQL standards. It is a free and powerful database solution, suitable for a wide range of applications, from small projects to large enterprise systems. PostgreSQL is widely used for its reliability, feature-richness, and robustness.",
16-
"install_methods": [
17-
{
18-
"type": "default",
19-
"script": "ct/postgresql.sh",
20-
"resources": {
21-
"cpu": 1,
22-
"ram": 1024,
23-
"hdd": 4,
24-
"os": "debian",
25-
"version": "12"
26-
}
27-
}
28-
],
29-
"default_credentials": {
30-
"username": null,
31-
"password": null
2+
"name": "PostgreSQL",
3+
"slug": "postgresql",
4+
"categories": [8],
5+
"date_created": "2024-05-02",
6+
"type": "ct",
7+
"updateable": false,
8+
"privileged": false,
9+
"interface_port": 5432,
10+
"documentation": null,
11+
"website": "https://www.postgresql.org/",
12+
"logo": "https://raw.githubusercontent.com/loganmarchione/homelab-svg-assets/main/assets/postgresql.svg",
13+
"description": "PostgreSQL (often referred to as Postgres) is an open-source relational database management system that is known for its extensibility and strict adherence to SQL standards. It is a free and powerful database solution, suitable for a wide range of applications, from small projects to large enterprise systems. PostgreSQL is widely used for its reliability, feature-richness, and robustness.",
14+
"install_methods": [
15+
{
16+
"type": "default",
17+
"script": "ct/postgresql.sh",
18+
"resources": {
19+
"cpu": 1,
20+
"ram": 1024,
21+
"hdd": 4,
22+
"os": "debian",
23+
"version": "12"
24+
}
3225
},
33-
"notes": [
34-
{
35-
"text": "Set a password after installation for postgres user by running `echo \"ALTER USER postgres with encrypted password 'your_password';\" | sudo -u postgres psql`",
36-
"type": "info"
37-
}
38-
]
39-
}
26+
{
27+
"type": "alpine",
28+
"script": "ct/alpine-postgresql.sh",
29+
"resources": {
30+
"cpu": 1,
31+
"ram": 256,
32+
"hdd": 1,
33+
"os": "alpine",
34+
"version": "3.21"
35+
}
36+
}
37+
],
38+
"default_credentials": {
39+
"username": null,
40+
"password": null
41+
},
42+
"notes": [
43+
{
44+
"text": "Set a password after installation for postgres user by running `echo \"ALTER USER postgres with encrypted password 'your_password';\" | sudo -u postgres psql`",
45+
"type": "info"
46+
}
47+
]
48+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: MickLesk (CanbiZ)
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://www.postgresql.org/
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 PostgreSQL"
17+
$STD apk add --no-cache postgresql16 postgresql16-contrib postgresql16-openrc sudo
18+
msg_ok "Installed PostgreSQL"
19+
20+
msg_info "Enabling PostgreSQL Service"
21+
$STD rc-update add postgresql default
22+
msg_ok "Enabled PostgreSQL Service"
23+
24+
msg_info "Starting PostgreSQL"
25+
$STD rc-service postgresql start
26+
msg_ok "Started PostgreSQL"
27+
28+
msg_info "Configuring PostgreSQL for External Access"
29+
conf_file="/etc/postgresql16/postgresql.conf"
30+
hba_file="/etc/postgresql16/pg_hba.conf"
31+
sed -i 's/^#listen_addresses =.*/listen_addresses = '\''*'\''/' "$conf_file"
32+
sed -i '/^host\s\+all\s\+all\s\+127.0.0.1\/32\s\+md5/ s/.*/host all all 0.0.0.0\/0 md5/' "$hba_file"
33+
$STD rc-service postgresql restart
34+
msg_ok "Configured and Restarted PostgreSQL"
35+
36+
read -r -p "Would you like to install Adminer with lighttpd? <y/N>: " prompt
37+
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
38+
msg_info "Installing Adminer and dependencies"
39+
$STD apk add --no-cache \
40+
lighttpd \
41+
lighttpd-openrc \
42+
php83 \
43+
php83-cgi \
44+
php83-common \
45+
php83-curl \
46+
php83-gd \
47+
php83-mbstring \
48+
php83-pdo \
49+
php83-pgsql \
50+
php83-openssl \
51+
php83-zip \
52+
php83-session \
53+
jq
54+
55+
sed -i 's|# *include "mod_fastcgi.conf"|include "mod_fastcgi.conf"|' /etc/lighttpd/lighttpd.conf
56+
mkdir -p /var/www/localhost/htdocs
57+
ADMINER_VERSION=$(curl -fsSL https://api.github.com/repos/vrana/adminer/releases/latest | jq -r '.tag_name' | sed 's/^v//')
58+
curl -fsSL "https://github.com/vrana/adminer/releases/download/v${ADMINER_VERSION}/adminer-${ADMINER_VERSION}.php" -o /var/www/localhost/htdocs/adminer.php
59+
chown lighttpd:lighttpd /var/www/localhost/htdocs/adminer.php
60+
chmod 755 /var/www/localhost/htdocs/adminer.php
61+
msg_ok "Adminer Installed"
62+
63+
msg_info "Starting Lighttpd"
64+
$STD rc-update add lighttpd default
65+
$STD rc-service lighttpd restart
66+
msg_ok "Lighttpd Started"
67+
fi
68+
69+
motd_ssh
70+
customize

0 commit comments

Comments
 (0)