pandora/vm/pandora_install.sh

282 lines
6.9 KiB
Bash
Raw Normal View History

#!/bin/bash
PANDORA=${PANDORA-pandora}
2017-03-16 15:26:39 +00:00
POSTGRES=${POSTGRES-local}
RABBITMQ=${RABBITMQ-local}
NGINX=${NGINX-local}
echo Installing pandora with user: $PANDORA
2015-05-04 08:55:13 +00:00
getent passwd $PANDORA > /dev/null 2>&1 || adduser --disabled-password --gecos "" $PANDORA
LXC=`grep -q lxc /proc/1/environ && echo 'yes' || echo 'no'`
if [ -e /etc/os-release ]; then
. /etc/os-release
fi
2015-02-20 11:28:17 +00:00
if [ -d "/run/systemd/system/" ]; then
SYSTEMD="yes"
else
SYSTEMD="no"
fi
if [ -z "$UBUNTU_CODENAME" ]; then
2017-08-15 11:32:47 +00:00
UBUNTU_CODENAME=zesty
fi
export DEBIAN_FRONTEND=noninteractive
echo "deb http://ppa.launchpad.net/j/pandora/ubuntu ${UBUNTU_CODENAME} main" > /etc/apt/sources.list.d/j-pandora.list
2017-10-24 18:43:30 +00:00
apt-get install -y gnupg
2015-03-14 19:34:54 +00:00
apt-key add - <<EOF
2014-11-18 13:43:51 +00:00
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mI0ESXYhEgEEALl9jDTdmgpApPbjN+7b85dC92HisPUp56ifEkKJOBj0X5HhRqxs
Wjx/zlP4/XJGrHnxJyrdPxjSwAXz7bNdeggkN4JWdusTkr5GOXvggQnng0X7f/rX
oJwoEGtYOCODLPs6PC0qjh5yPzJVeiRsKUOZ7YVNnwNwdfS4D8RZvtCrABEBAAG0
FExhdW5jaHBhZCBQUEEgZm9yIGpeiLYEEwECACAFAkl2IRICGwMGCwkIBwMCBBUC
CAMEFgIDAQIeAQIXgAAKCRAohRM8AZde82FfA/9OB/64/YLaCpizHZ8f6DK3rGgF
e6mX3rFK8yOKGGL06316VhDzfzMiZSauUZ0t+lKHR/KZYeSaFwEoUoblTG/s4IIo
9aBMHWhVXJW6eifKUmTGqEn2/0UxoWQq2C3F6njMkCaP+ALOD5uzaSYGdjqAUAwS
pAAGSEQ4uz6bYSeM4Q==
=SM2a
-----END PGP PUBLIC KEY BLOCK-----
EOF
2016-03-26 21:55:53 +00:00
echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/99languages
2014-11-18 13:43:51 +00:00
2015-05-01 10:45:03 +00:00
apt-get update -qq
if [ "$LXC" == "no" ]; then
apt-get install -y \
acpid \
ntp
fi
2017-03-16 15:26:39 +00:00
EXTRA=""
if [ "$POSTGRES" == "local" ]; then
EXTRA="$EXTRA postgresql postgresql-contrib"
fi
if [ "$RABBITMQ" == "local" ]; then
EXTRA="$EXTRA rabbitmq-server"
fi
if [ "$NGINX" == "local" ]; then
EXTRA="$EXTRA nginx"
fi
apt-get install -y \
2015-05-15 11:42:32 +00:00
sudo \
openssh-server \
2017-11-07 17:54:44 +00:00
iproute2 \
vim \
wget \
pwgen \
git \
2017-02-16 12:49:22 +00:00
python3-setuptools \
python3-pip \
2017-11-02 21:08:17 +00:00
python3-venv \
2017-02-16 12:49:22 +00:00
python3-dev \
python3-pil \
python3-numpy \
python3-psycopg2 \
python3-pyinotify \
python3-simplejson \
python3-lxml \
python3-html5lib \
python3-ox \
oxframe \
ffmpeg \
2014-02-13 18:48:47 +00:00
mkvtoolnix \
2014-03-08 11:18:36 +00:00
gpac \
imagemagick \
poppler-utils \
2016-07-30 00:49:31 +00:00
youtube-dl \
2017-02-16 12:49:22 +00:00
ipython3 \
2013-08-29 09:46:32 +00:00
postfix \
2017-03-16 15:26:39 +00:00
postgresql-client $EXTRA
2012-10-09 10:44:36 +00:00
2017-03-16 15:26:39 +00:00
if [ "$POSTGRES" == "local" ]; then
sudo -u postgres createuser -S -D -R $PANDORA
sudo -u postgres createdb -T template0 --locale=C --encoding=UTF8 -O $PANDORA pandora
echo "CREATE EXTENSION pg_trgm;" | sudo -u postgres psql pandora
fi
#rabbitmq
2017-03-16 15:26:39 +00:00
if [ "$RABBITMQ" == "local" ]; then
RABBITPWD=$(pwgen -n 16 -1)
rabbitmqctl add_user pandora $RABBITPWD
rabbitmqctl add_vhost /pandora
rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
BROKER_URL="amqp://pandora:$RABBITPWD@localhost:5672//pandora"
else
BROKER_URL="$RABBITMQ"
fi
#pandora
git clone https://git.0x2620.org/pandora.git /srv/pandora
cd /srv/pandora
./ctl init
2013-07-03 14:25:57 +00:00
HOST=$(hostname -s)
HOST_CONFIG="/srv/pandora/pandora/config.$HOST.jsonc"
SITE_CONFIG="/srv/pandora/pandora/config.jsonc"
test -e $HOST_CONFIG && cp $HOST_CONFIG $SITE_CONFIG
test -e $SITE_CONFIG || cp /srv/pandora/pandora/config.pandora.jsonc $SITE_CONFIG
2015-03-14 19:34:54 +00:00
cat > /srv/pandora/pandora/local_settings.py <<EOF
DATABASES = {
'default': {
'NAME': 'pandora',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': '$PANDORA',
'PASSWORD': '',
}
}
2017-03-16 15:26:39 +00:00
BROKER_URL = '$BROKER_URL'
XACCELREDIRECT = True
DEBUG = False
TEMPLATE_DEBUG = DEBUG
JSON_DEBUG = False
DB_GIN_TRGM = True
EOF
MANAGE="sudo -H -u $PANDORA /srv/pandora/pandora/manage.py"
2015-03-20 09:28:03 +00:00
mkdir /srv/pandora/data
chown -R $PANDORA:$PANDORA /srv/pandora
2015-03-20 09:28:03 +00:00
2015-05-06 17:00:02 +00:00
echo "Initialize database..."
cd /srv/pandora/pandora
$MANAGE init_db
2015-03-20 08:39:35 +00:00
echo "UPDATE django_site SET domain = '$HOST.local', name = '$HOST.local' WHERE 1=1;" | $MANAGE dbshell
/srv/pandora/ctl install
if [ "$PANDORA" != "pandora" ]; then
sed -i \
2017-03-16 15:26:39 +00:00
-e "s/User=pandora/User=$PANDORA/g" \
-e "s/Group=pandora/Group=$PANDORA/g" \
-e "s/home\/pandora/home\/$PANDORA/g" \
2017-03-16 13:11:15 +00:00
/etc/systemd/system/pandora*.service
2017-03-16 15:26:39 +00:00
sed -i "s/pandora pandora/$PANDORA $PANDORA/g" /etc/tmpfiles.d/pandora.conf
systemctl daemon-reload
fi
if [ "$LXC" == "yes" ]; then
2016-06-09 10:42:00 +00:00
sed -i s/127.0.0.1/0.0.0.0/g /srv/pandora/pandora/gunicorn_config.py
2015-04-29 12:58:11 +00:00
echo "WEBSOCKET_ADDRESS = \"0.0.0.0\"" >> /srv/pandora/pandora/local_settings.py
2014-09-30 12:43:22 +00:00
fi
2013-07-03 14:25:57 +00:00
/srv/pandora/ctl start
2013-02-09 10:42:21 +00:00
#logrotate
#cp "/srv/pandora/etc/logrotate.d/pandora" "/etc/logrotate.d/pandora"
2013-02-09 10:42:21 +00:00
#nginx
2017-03-16 15:26:39 +00:00
if [ "$NGINX" == "local" ]; then
2013-09-15 17:19:09 +00:00
2017-03-16 15:26:39 +00:00
cp "/srv/pandora/etc/nginx/pandora" "/etc/nginx/sites-available/default"
2013-09-15 17:19:09 +00:00
read -r -d '' GZIP <<EOI
gzip_static on;\\
\tgzip_http_version 1.1;\\
\tgzip_vary on;\\
\tgzip_comp_level 6;\\
\tgzip_proxied any;\\
\tgzip_types text/plain text/css application/json text/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;\\
\tgzip_buffers 16 8k;\\
\tgzip_disable "MSIE [1-6]\.(?!.*SV1)";
EOI
sed -i -e "s#gzip_disable \"msie6\";#${GZIP}#g" /etc/nginx/nginx.conf
service nginx restart
2017-03-16 15:26:39 +00:00
fi
2013-08-26 10:39:39 +00:00
if [ "$LXC" == "yes" ]; then
2014-05-06 17:00:57 +00:00
test -e /etc/init/avahi-daemon.conf && sed -i "s/-D/--no-rlimits -D/g" /etc/init/avahi-daemon.conf
2013-08-26 10:39:39 +00:00
fi
if [ "$LXC" == "no" ]; then
2015-05-15 11:42:32 +00:00
if [ "$SYSTEMD" == "yes" ]; then
echo Servers=pool.ntp.org >> /etc/systemd/timesyncd.conf
else
2015-01-19 17:47:46 +00:00
cat > /etc/cron.d/ntp_fixtime <<EOF
# /etc/cron.d/ntp_fixtime: vms can go out of sync, run ntpdate to sync time
*/10 * * * * root /usr/sbin/ntpdate pool.ntp.org >/dev/null
EOF
2015-05-15 11:42:32 +00:00
fi
cat > /usr/local/bin/genissue <<EOF
2014-10-10 15:54:57 +00:00
#!/bin/sh
HOST=\$(ps ax | grep avahi-daemon | grep local | sed "s/.*\[\(.*\)\].*/\1/g" | sed 's/\.$//')
echo Welcome to pan.do/ra. Connect via one of these URLs:
echo
if [ -n "\$HOST" ]; then
echo " http://\$HOST/"
fi
2017-11-07 17:12:47 +00:00
for ip in \$(ip -4 a | grep inet | grep -v peer | grep -v '127.0.0.1' | cut -f1 -d/ | sed s/inet//g | xargs); do
echo " http://\$ip/"
done
echo
EOF
chmod +x /usr/local/bin/genissue
2013-07-03 14:25:57 +00:00
/usr/local/bin/genissue > /etc/issue
2015-03-14 19:34:54 +00:00
cat > /etc/rc.local <<EOF
#!/bin/sh -e
2015-01-19 17:47:46 +00:00
#vm has one network interface and that might change, make sure its not persistent
rm -f /etc/udev/rules.d/70-persistent-net.rules
#update issue
/usr/local/bin/genissue > /etc/issue
EOF
chmod +x /etc/rc.local
2015-03-14 19:34:54 +00:00
fi
2015-01-19 17:47:46 +00:00
apt-get clean
2013-07-03 14:25:57 +00:00
cat > /home/$PANDORA/.vimrc <<EOF
2013-07-03 14:25:57 +00:00
set nocompatible
set encoding=utf-8
set showcmd
set autochdir
set tabstop=4 shiftwidth=4
set expandtab
set si
set sw=4
set sts=4
set backspace=indent,eol,start
set hlsearch
set incsearch
set ignorecase
set smartcase
set modeline
nmap <C-V> "+gP
imap <C-V> <ESC><C-V>i
vmap <C-C> "+y
filetype plugin indent on
syntax on
2014-10-20 15:55:14 +00:00
au BufNewFile,BufRead *.jsonc setf javascript
2013-07-03 14:25:57 +00:00
nmap <C-H> :tabprev<CR>
nmap <C-L> :tabnext<CR>
hi SpellBad ctermbg=0
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode
2015-09-20 16:50:02 +00:00
set lcs=tab:→·,trail:·,nbsp:˽
set list
2017-11-07 22:10:03 +00:00
if has('mouse')
set mouse=
endif
2013-07-03 14:25:57 +00:00
EOF
2017-11-07 22:10:03 +00:00
if [ -e /usr/share/vim/vim80/defaults.vim ]; then
sed -i 's/ set mouse=a/" set mouse=a/g' /usr/share/vim/vim80/defaults.vim
fi