1+ #! /usr/bin/env bash
2+
3+ # Copyright (c) 2021-2024 tteck
4+ # Author: tteck (tteckster)
5+ # Co-Author: remz1337
6+ # License: MIT
7+ # https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
8+
9+ source /dev/stdin <<< " $FUNCTIONS_FILE_PATH"
10+ color
11+ verb_ip6
12+ catch_errors
13+ setting_up_container
14+ network_check
15+ update_os
16+
17+ msg_info " Installing Dependencies (Patience)"
18+ $STD apt-get install -y {curl,sudo,mc}
19+ $STD apt-get install -y gpg pkg-config libffi-dev
20+ $STD apt-get install -y --no-install-recommends build-essential libpq-dev libkrb5-dev
21+ $STD apt-get install -y libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev pkg-config libffi-dev zlib1g-dev libxmlsec1 libxmlsec1-dev libxmlsec1-openssl libmaxminddb0
22+ msg_ok " Installed Dependencies"
23+
24+ msg_info " Installing yq"
25+ YQ_LATEST=" $( wget -qO- " https://api.github.com/repos/mikefarah/yq/releases/latest" | grep -Po ' "tag_name": "\K.*?(?=")' ) "
26+ $STD wget " https://github.com/mikefarah/yq/releases/download/${YQ_LATEST} /yq_linux_amd64" -qO /usr/bin/yq
27+ chmod +x /usr/bin/yq
28+ msg_ok " Installed yq"
29+
30+ msg_info " Installing Python 3.12"
31+ wget -q https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz -O Python.tgz
32+ tar -zxf Python.tgz
33+ cd Python-3.12.1
34+ $STD ./configure --enable-optimizations
35+ $STD make altinstall
36+ $STD cd -
37+ $STD rm -rf Python-3.12.1
38+ $STD rm -rf Python.tgz
39+ $STD update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1
40+ msg_ok " Installed Python 3.12"
41+
42+ NODE_VER=" 22"
43+ msg_info " Installing Node.js ${NODE_VER} "
44+ mkdir -p /etc/apt/keyrings
45+ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
46+ echo " deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VER} .x nodistro main" > /etc/apt/sources.list.d/nodesource.list
47+ $STD apt-get update
48+ $STD apt-get install -y nodejs
49+ msg_ok " Installed Node.js ${NODE_VER} "
50+
51+ msg_info " Building Authentik website"
52+ RELEASE=$( curl -s https://api.github.com/repos/goauthentik/authentik/releases/latest | grep " tarball_url" | awk ' {print substr($2, 2, length($2)-3)}' )
53+ mkdir -p /opt/authentik
54+ $STD wget -qO authentik.tar.gz " ${RELEASE} "
55+ tar -xzf authentik.tar.gz -C /opt/authentik --strip-components 1 --overwrite
56+ rm -rf authentik.tar.gz
57+ cd /opt/authentik/website
58+ $STD npm install
59+ $STD npm run build-bundled
60+ cd /opt/authentik/web
61+ $STD npm install
62+ $STD npm run build
63+ echo " ${RELEASE} " > /opt/${APPLICATION} _version.txt
64+ msg_ok " Built Authentik website"
65+
66+ msg_info " Installing Golang"
67+ cd ~
68+ set +o pipefail
69+ GO_RELEASE=$( curl -s https://go.dev/dl/ | grep -o -m 1 " go.*\linux-amd64.tar.gz" )
70+ $STD wget -q https://golang.org/dl/${GO_RELEASE}
71+ tar -xzf ${GO_RELEASE} -C /usr/local
72+ $STD ln -s /usr/local/go/bin/go /usr/bin/go
73+ rm -rf go/
74+ rm -rf ${GO_RELEASE}
75+ set -o pipefail
76+ msg_ok " Installed Golang"
77+
78+ msg_info " Building Go Proxy"
79+ cd /opt/authentik
80+ $STD go mod download
81+ $STD go build -o /go/authentik ./cmd/server
82+ $STD go build -o /opt/authentik/authentik-server /opt/authentik/cmd/server/
83+ msg_ok " Built Go Proxy"
84+
85+ msg_info " Installing GeoIP"
86+ cd ~
87+ GEOIP_RELEASE=$( curl -s https://api.github.com/repos/maxmind/geoipupdate/releases/latest | grep " tag_name" | awk ' {print substr($2, 3, length($2)-4) }' )
88+ $STD wget -qO geoipupdate.deb https://github.com/maxmind/geoipupdate/releases/download/v${GEOIP_RELEASE} /geoipupdate_${GEOIP_RELEASE} _linux_amd64.deb
89+ $STD dpkg -i geoipupdate.deb
90+ rm geoipupdate.deb
91+ cat << EOF >/etc/GeoIP.conf
92+ #GEOIPUPDATE_EDITION_IDS="GeoLite2-City GeoLite2-ASN"
93+ #GEOIPUPDATE_VERBOSE="1"
94+ #GEOIPUPDATE_ACCOUNT_ID_FILE="/run/secrets/GEOIPUPDATE_ACCOUNT_ID"
95+ #GEOIPUPDATE_LICENSE_KEY_FILE="/run/secrets/GEOIPUPDATE_LICENSE_KEY"
96+ EOF
97+ msg_ok " Installed GeoIP"
98+
99+ msg_info " Installing Python Dependencies"
100+ cd /opt/authentik
101+ $STD apt install -y python3-pip
102+ $STD apt install -y git
103+ $STD pip3 install --upgrade pip
104+ $STD pip3 install poetry poetry-plugin-export
105+ $STD ln -s /usr/local/bin/poetry /usr/bin/poetry
106+ $STD poetry install --only=main --no-ansi --no-interaction --no-root
107+ $STD poetry export --without-hashes --without-urls -f requirements.txt --output requirements.txt
108+ $STD pip install --no-cache-dir -r requirements.txt
109+ $STD pip install .
110+ msg_ok " Installed Python Dependencies"
111+
112+ msg_info " Installing Redis"
113+ $STD apt install -y redis-server
114+ systemctl enable -q --now redis-server
115+ msg_ok " Installed Redis"
116+
117+ msg_info " Installing PostgreSQL"
118+ $STD apt install -y postgresql postgresql-contrib
119+ DB_NAME=" authentik"
120+ DB_USER=" authentik"
121+ DB_PASS=" $( openssl rand -base64 18 | cut -c1-13) "
122+ $STD sudo -u postgres psql -c " CREATE DATABASE $DB_NAME ;"
123+ $STD sudo -u postgres psql -c " CREATE USER $DB_USER WITH PASSWORD '$DB_PASS ';"
124+ $STD sudo -u postgres psql -c " GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER ;"
125+ $STD sudo -u postgres psql -c " ALTER DATABASE $DB_NAME OWNER TO $DB_USER ;"
126+ $STD sudo -u postgres psql -c " ALTER USER $DB_USER WITH SUPERUSER;"
127+ msg_ok " Installed PostgreSQL"
128+
129+ msg_info " Installing Authentik"
130+ mkdir -p /etc/authentik
131+ cp /opt/authentik/authentik/lib/default.yml /opt/authentik/authentik/lib/default.yml.BAK
132+ mv /opt/authentik/authentik/lib/default.yml /etc/authentik/config.yml
133+ $STD yq -i " .secret_key = \" $( openssl rand -hex 32) \" " /etc/authentik/config.yml
134+ $STD yq -i " .postgresql.password = \" ${DB_PASS} \" " /etc/authentik/config.yml
135+ $STD yq -i " .geoip = \" /opt/authentik/tests/GeoLite2-City-Test.mmdb\" " /etc/authentik/config.yml
136+ cp -r /opt/authentik/authentik/blueprints /opt/authentik/blueprints
137+ $STD yq -i " .blueprints_dir = \" /opt/authentik/blueprints\" " /etc/authentik/config.yml
138+ $STD apt install -y python-is-python3
139+ $STD ln -s /usr/local/bin/gunicorn /usr/bin/gunicorn
140+ $STD ln -s /usr/local/bin/celery /usr/bin/celery
141+ cd /opt/authentik
142+ $STD bash /opt/authentik/lifecycle/ak migrate
143+ msg_ok " Installed Authentik"
144+
145+ msg_info " Configuring Services"
146+ cat << EOF >/etc/systemd/system/authentik-server.service
147+ [Unit]
148+ Description = Authentik Server
149+ [Service]
150+ ExecStart=/opt/authentik/authentik-server
151+ WorkingDirectory=/opt/authentik/
152+ #User=authentik
153+ #Group=authentik
154+ Restart=always
155+ RestartSec=5
156+ [Install]
157+ WantedBy=multi-user.target
158+ EOF
159+ systemctl enable -q --now authentik-server
160+ sleep 2
161+ cat << EOF >/etc/systemd/system/authentik-worker.service
162+ [Unit]
163+ Description = Authentik Worker
164+ [Service]
165+ Environment=DJANGO_SETTINGS_MODULE="authentik.root.settings"
166+ ExecStart=celery -A authentik.root.celery worker -Ofair --max-tasks-per-child=1 --autoscale 3,1 -E -B -s /tmp/celerybeat-schedule -Q authentik,authentik_scheduled,authentik_events
167+ WorkingDirectory=/opt/authentik/authentik
168+ #User=authentik
169+ #Group=authentik
170+ Restart=always
171+ RestartSec=5
172+ [Install]
173+ WantedBy=multi-user.target
174+ EOF
175+ systemctl enable -q --now authentik-worker
176+ sleep 5
177+ msg_ok " Configured Services"
178+
179+ motd_ssh
180+ customize
181+
182+ msg_info " Cleaning up"
183+ $STD apt-get -y autoremove
184+ $STD apt-get -y autoclean
185+ msg_ok " Cleaned"
0 commit comments