lxd-selfhosting-scripts/install-gogs.bash

59 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2018-02-11 16:09:27 +01:00
#!/bin/bash
CONTAINER=$1
APPNAME="gogs"
APPURL="wget https://cdn.gogs.io/0.11.4/linux_amd64.tar.gz"
DOMAIN="logerais.com"
TIMEZONE="Europe/Paris"
if [ -z "$CONTAINER" ]; then echo "Missing parameter"; exit 1 ; fi
# Set container timezone
lxc file edit "$CONTAINER/etc/timezone" <<< "${TIMEZONE}"
# Install packages
lxc exec $CONTAINER -- apt update
lxc exec $CONTAINER -- apt install -y curl wget git
lxc exec $CONTAINER -- apt install -y nginx
lxc exec $CONTAINER -- apt install -y postgresql
lxc exec $CONTAINER -- su --login postgres <<< "createuser ${APPNAME}"
lxc exec $CONTAINER -- su --login postgres <<< "createdb --owner=${APPNAME} ${APPNAME}"
lxc exec $CONTAINER -- su --login postgres --shell /usr/bin/psql <<< "ALTER USER \"${APPNAME}\" WITH PASSWORD \'${APPNAME}\';"
lxc exec $CONTAINER -- useradd -m --shell /bin/bash ${APPNAME}
lxc exec $CONTAINER -- usermod --groups sudo --append ${APPNAME}
lxc exec $CONTAINER -- su --login ${APPNAME} --command "wget ${APPURL}"
lxc exec $CONTAINER -- su --login ${APPNAME} --command "tar vxzf linux_amd64.tar.gz"
lxc file edit $CONTAINER/etc/systemd/system/${APPNAME}.service <<EOF
[Unit]
Description=Gogs (Go Git Service)
After=syslog.target
After=network.target
After=postgresql.service
After=nginx.service
[Service]
Type=simple
User=${APPNAME}
Group=${APPNAME}
WorkingDirectory=/home/${APPNAME}/${APPNAME}
ExecStart=/home/${APPNAME}/${APPNAME}/${APPNAME} web
Restart=always
Environment=USER=${APPNAME} HOME=/home/${APPNAME}
[Install]
WantedBy=multi-user.target
EOF
lxc exec $CONTAINER systemctl enable ${APPNAME}
lxc exec $CONTAINER systemctl start ${APPNAME}
# lxc restart $CONTAINER