akkoma/setup.sh

82 lines
2.9 KiB
Bash
Raw Normal View History

2023-03-27 09:39:11 -06:00
#!/bin/bash
export SHELL="/bin/bash"
database() {
mkdir /run/postgresql
mkdir -p $PG_DIR
chown -R postgres:postgres /run/postgresql/
chown -R postgres:postgres /var/lib/postgresql
chown -R postgres:postgres /var/log/postgresql
chmod 0700 $PG_DIR
ls $PG_DIR
su postgres -s $SHELL -lc "$PG_BIN/initdb --auth-host=trust -D $PG_DIR"
cp -f /etc/postgresql.conf $PG_DIR
cp -f /etc/pg_hba.conf $PG_DIR
chown -R postgres:postgres $PG_DIR
su postgres -s $SHELL -lc "$PG_BIN/pg_ctl start -D $PG_DIR"&
#sleep 10
sleep 60
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
echo "create user root with encrypted password 'sql';"| su postgres -s $SHELL -lc psql
echo "ALTER ROLE root SUPERUSER;" | su postgres -s $SHELL -lc psql
echo "CREATE DATABASE pleroma with template = template0 OWNER = root ENCODING = 'UTF8';" | su postgres -s $SHELL -lc psql
echo "CREATE EXTENSION IF NOT EXISTS citext;"| PGPASSWORD=sql psql -U root pleroma
echo "CREATE EXTENSION IF NOT EXISTS pg_trgm;" | PGPASSWORD=sql psql -U root pleroma
echo "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" | PGPASSWORD=sql psql -U root pleroma
}
extract-software(){
cd /opt
ls
unzip akkoma.zip -d /opt/
mv /opt/release /opt/akkoma
chown -R akkoma /opt/akkoma
mkdir -p /var/lib/akkoma/uploads
mkdir -p /var/lib/akkoma/static/static
chown -R akkoma /var/lib/akkoma
chmod -R 777 /var/lib/akkoma
sed -i "s/replaceME/${ENDPOINT}/g" /etc/akkoma/config.exs
}
nginx-ssl(){
sed -i "s/replaceME/${ENDPOINT}/g" /etc/nginx/conf.d/akkoma.conf
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=CO/L=Denver/O=$ENDPOINT/CN=$ENDPOINT" -keyout /etc/ssl/certs/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=CO/L=Denver/O=$BLOAT/CN=$BLOAT" -keyout /etc/ssl/certs/nginx2-selfsigned.key -out /etc/ssl/certs/nginx2-selfsigned.crt
mkdir /var/run/nginx
}
frontends(){
mkdir -p /var/lib/akkoma/static/frontends/tmp
chown -R akkoma /var/lib/akkoma/static/frontends/
FILE=/var/lib/akkoma/static/frontends/pleroma-fe/stable/index.html
if [[ -f "$FILE" ]]; then
echo "$FILE exists."
else
su akkoma -s $SHELL -lc "/opt/akkoma/bin/pleroma_ctl frontend install pleroma-fe --ref stable"
su akkoma -s $SHELL -lc "/opt/akkoma/bin/pleroma_ctl frontend install admin-fe --ref stable"
frontends
fi
}
extract-software
nginx-ssl
database
su akkoma -s $SHELL -lc "/opt/akkoma/bin/pleroma_ctl migrate"
su akkoma -s $SHELL -lc "/opt/akkoma/bin/pleroma start"&
cp -f /tmp/terms-of-service.html /var/lib/akkoma/static/static/
cp -f /tmp/favicon.png /var/lib/akkoma/static/
#Create an Admin User
echo;echo;echo "Sleeping for 30 seconds so Akkoma starts.........."
sleep 60
echo;echo;echo "Create and Admin User:"
cd /opt/akkoma
su akkoma -s $SHELL -lc "echo y | /opt/akkoma/bin/pleroma_ctl user new verita84 verita84@$ENDPOINT --admin"
echo 'nameserver 8.8.8.8' > /etc/resolv.conf
frontends
touch /configured.txt