2013-08-22 14:26:38 +00:00
|
|
|
#!/bin/bash
|
|
|
|
LXC=`grep -q lxc /proc/1/environ && echo 'yes' || echo 'no'`
|
2014-10-10 14:16:54 +00:00
|
|
|
if [ -e /etc/os-release ]; then
|
|
|
|
. /etc/os-release
|
|
|
|
else
|
|
|
|
ID=unknown
|
|
|
|
fi
|
|
|
|
UBUNTU_VERSION="$VERSION_ID"
|
2013-08-22 14:26:38 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2014-10-10 14:16:54 +00:00
|
|
|
if [ "$ID" == "debian" ]; then
|
|
|
|
SYSTEMD="yes"
|
|
|
|
echo "deb http://ppa.launchpad.net/j/pandora/ubuntu trusty main" > /etc/apt/sources.list.d/j-pandora.list
|
2014-10-11 10:49:00 +00:00
|
|
|
gpg --keyserver keyserver.ubuntu.com --recv-keys 01975EF3
|
2014-10-10 14:16:54 +00:00
|
|
|
gpg -a --export 01975EF3 | apt-key add -
|
|
|
|
else
|
|
|
|
SYSTEMD="no"
|
|
|
|
if [ "$UBUNTU_VERSION" == "12.04" ]; then
|
|
|
|
EXTRA=python-software-properties
|
|
|
|
else
|
|
|
|
EXTRA=""
|
|
|
|
fi
|
|
|
|
apt-get install -y \
|
|
|
|
update-manager-core \
|
|
|
|
software-properties-common \
|
|
|
|
$EXTRA
|
|
|
|
|
|
|
|
add-apt-repository -y ppa:j/pandora
|
|
|
|
fi
|
2013-08-22 14:26:38 +00:00
|
|
|
apt-get update
|
|
|
|
|
|
|
|
if [ "$LXC" == "no" ]; then
|
|
|
|
apt-get install -y \
|
|
|
|
acpid \
|
|
|
|
ntp
|
|
|
|
fi
|
|
|
|
|
2014-10-10 14:16:54 +00:00
|
|
|
if [ "$UBUNTU_VERSION" == "12.04" ]; then
|
2014-08-10 15:05:23 +00:00
|
|
|
LIBAVCODEC_EXTRA=libavcodec-extra-53
|
|
|
|
else
|
|
|
|
LIBAVCODEC_EXTRA=libavcodec-extra
|
|
|
|
fi
|
|
|
|
|
2013-08-22 14:26:38 +00:00
|
|
|
apt-get install -y \
|
|
|
|
openssh-server \
|
|
|
|
vim \
|
|
|
|
wget \
|
|
|
|
pwgen \
|
|
|
|
nginx \
|
|
|
|
rabbitmq-server \
|
|
|
|
bzr \
|
|
|
|
git \
|
|
|
|
subversion \
|
|
|
|
mercurial \
|
|
|
|
python-setuptools \
|
|
|
|
python-pip \
|
|
|
|
python-virtualenv \
|
|
|
|
python-imaging \
|
|
|
|
python-dev \
|
|
|
|
python-imaging \
|
|
|
|
python-numpy \
|
|
|
|
python-psycopg2 \
|
|
|
|
python-pyinotify \
|
|
|
|
python-simplejson \
|
|
|
|
python-lxml \
|
|
|
|
python-html5lib \
|
|
|
|
python-ox \
|
|
|
|
oxframe \
|
2014-08-10 15:05:23 +00:00
|
|
|
$LIBAVCODEC_EXTRA \
|
2013-08-22 14:26:38 +00:00
|
|
|
libav-tools \
|
|
|
|
ffmpeg2theora \
|
2014-09-25 13:28:08 +00:00
|
|
|
melt \
|
2014-02-13 18:48:47 +00:00
|
|
|
mkvtoolnix \
|
2014-03-08 11:18:36 +00:00
|
|
|
gpac \
|
2013-08-22 14:26:38 +00:00
|
|
|
imagemagick \
|
2014-01-04 12:29:11 +00:00
|
|
|
poppler-utils \
|
2013-08-22 14:26:38 +00:00
|
|
|
ipython \
|
2013-08-29 09:46:32 +00:00
|
|
|
postfix \
|
2013-08-22 14:26:38 +00:00
|
|
|
postgresql \
|
|
|
|
postgresql-contrib
|
2012-10-09 10:44:36 +00:00
|
|
|
|
2014-09-30 14:00:20 +00:00
|
|
|
mkdir -p /home/pandora/.ox/bin
|
|
|
|
wget -O /home/pandora/.ox/bin/ffmpeg https://firefogg.org/bin/ffmpeg.linux
|
|
|
|
wget -O /home/pandora/.ox/bin/ffmpeg2theora https://firefogg.org/bin/ffmpeg2theora.linux
|
|
|
|
chmod +x /home/pandora/.ox/bin/*
|
2014-10-10 14:16:54 +00:00
|
|
|
chown -R pandora.pandora /home/pandora/.ox
|
2014-09-30 14:00:20 +00:00
|
|
|
|
|
|
|
|
2010-12-02 03:32:06 +00:00
|
|
|
sudo -u postgres createuser -S -D -R pandora
|
2011-11-08 17:05:26 +00:00
|
|
|
sudo -u postgres createdb -T template0 --locale=C --encoding=UTF8 -O pandora pandora
|
2012-03-30 14:57:07 +00:00
|
|
|
echo "CREATE EXTENSION pg_trgm;" | sudo -u postgres psql pandora
|
2010-12-02 03:32:06 +00:00
|
|
|
|
|
|
|
#rabbitmq
|
|
|
|
RABBITPWD=$(pwgen -n 16 -1)
|
|
|
|
rabbitmqctl add_user pandora $RABBITPWD
|
|
|
|
rabbitmqctl add_vhost /pandora
|
|
|
|
rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
|
|
|
|
|
|
|
|
#pandora
|
2013-07-03 14:25:57 +00:00
|
|
|
bzr branch http://code.0x2620.org/pandora /srv/pandora
|
|
|
|
bzr branch http://code.0x2620.org/oxjs /srv/pandora/static/oxjs
|
|
|
|
virtualenv --system-site-packages /srv/pandora
|
|
|
|
/srv/pandora/bin/pip install -r /srv/pandora/requirements.txt
|
|
|
|
|
2012-03-23 20:57:43 +00:00
|
|
|
HOST=$(hostname -s)
|
2012-04-20 10:22:32 +00:00
|
|
|
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
|
|
|
|
|
2010-12-02 03:32:06 +00:00
|
|
|
cat > /srv/pandora/pandora/local_settings.py << EOF
|
2011-11-08 17:05:26 +00:00
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'NAME': 'pandora',
|
|
|
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
|
|
|
'USER': 'pandora',
|
|
|
|
'PASSWORD': '',
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 03:32:06 +00:00
|
|
|
BROKER_PASSWORD = "$RABBITPWD"
|
|
|
|
XACCELREDIRECT = True
|
2012-04-20 10:22:32 +00:00
|
|
|
|
|
|
|
DEBUG = False
|
|
|
|
TEMPLATE_DEBUG = DEBUG
|
|
|
|
JSON_DEBUG = False
|
2010-12-02 03:32:06 +00:00
|
|
|
EOF
|
|
|
|
|
2013-02-02 14:23:44 +00:00
|
|
|
MANAGE="sudo -H -u pandora python manage.py"
|
|
|
|
|
2010-12-02 03:32:06 +00:00
|
|
|
cd /srv/pandora/pandora
|
2013-02-02 14:23:44 +00:00
|
|
|
$MANAGE syncdb --noinput
|
|
|
|
$MANAGE migrate
|
2012-06-13 15:59:10 +00:00
|
|
|
echo "DB_GIN_TRGM = True" >> /srv/pandora/pandora/local_settings.py
|
2013-02-02 14:23:44 +00:00
|
|
|
$MANAGE sqlfindindex
|
2013-07-03 17:18:59 +00:00
|
|
|
$MANAGE sync_itemsort
|
2013-02-02 14:23:44 +00:00
|
|
|
echo "UPDATE django_site SET domain = '$HOST.local', name = '$HOST.local' WHERE 1=1;" | $MANAGE dbshell
|
2011-11-08 17:05:26 +00:00
|
|
|
|
2010-12-02 03:32:06 +00:00
|
|
|
mkdir /srv/pandora/data
|
|
|
|
chown -R pandora:pandora /srv/pandora
|
2013-02-02 14:23:44 +00:00
|
|
|
$MANAGE update_static
|
|
|
|
$MANAGE collectstatic -l --noinput
|
2010-12-02 03:32:06 +00:00
|
|
|
|
2014-10-10 14:16:54 +00:00
|
|
|
if [ "$SYSTEMD" == "yes" ]; then
|
|
|
|
cp /srv/pandora/etc/systemd/*.service /lib/systemd/system/
|
2014-10-11 10:49:00 +00:00
|
|
|
cp /srv/pandora/etc/tmpfiles.d/pandora.conf /usr/lib/tmpfiles.d/
|
2014-10-10 14:16:54 +00:00
|
|
|
if [ "$LXC" == "yes" ]; then
|
|
|
|
sed -i s/127.0.0.1/0.0.0.0/g /lib/systemd/system/pandora.service
|
|
|
|
fi
|
2014-10-11 10:49:00 +00:00
|
|
|
systemd-tmpfiles --create /usr/lib/tmpfiles.d/pandora.conf >/dev/null || true
|
2014-10-10 14:16:54 +00:00
|
|
|
for service in pandora pandora-tasks pandora-encoding pandora-cron; do
|
|
|
|
systemctl enable ${service}.service
|
|
|
|
done
|
|
|
|
else
|
|
|
|
cp /srv/pandora/etc/init/* /etc/init/
|
|
|
|
if [ "$LXC" == "yes" ]; then
|
|
|
|
sed -i s/127.0.0.1/0.0.0.0/g /etc/init/pandora.conf
|
|
|
|
fi
|
2014-09-30 12:43:22 +00:00
|
|
|
fi
|
2013-07-03 14:25:57 +00:00
|
|
|
/srv/pandora/ctl start
|
2010-12-02 03:32:06 +00:00
|
|
|
|
2013-02-09 10:42:21 +00:00
|
|
|
#logrotate
|
2013-07-03 14:25:57 +00:00
|
|
|
cp "/srv/pandora/etc/logrotate.d/pandora" "/etc/logrotate.d/pandora"
|
2013-02-09 10:42:21 +00:00
|
|
|
|
2010-12-02 03:32:06 +00:00
|
|
|
#nginx
|
2012-10-30 10:23:36 +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
|
|
|
|
|
2010-12-02 03:32:06 +00:00
|
|
|
service nginx restart
|
|
|
|
|
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
|
|
|
|
|
2013-08-22 14:26:38 +00:00
|
|
|
if [ "$LXC" == "no" ]; then
|
2012-03-30 14:57:07 +00:00
|
|
|
cat > /usr/local/bin/fixtime <<EOF
|
|
|
|
#!/bin/bash
|
|
|
|
while [ 1 ]; do
|
|
|
|
/usr/sbin/ntpdate pool.ntp.org >/dev/null
|
|
|
|
sleep 600
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
chmod +x /usr/local/bin/fixtime
|
2013-08-22 14:26:38 +00:00
|
|
|
fi
|
|
|
|
|
2014-10-10 14:16:54 +00:00
|
|
|
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/\.$//')
|
2012-04-24 09:56:20 +00:00
|
|
|
echo Welcome to pan.do/ra. Connect via one of these URLs:
|
2012-03-30 14:57:07 +00:00
|
|
|
echo
|
2014-10-10 14:16:54 +00:00
|
|
|
if [ -n "\$HOST" ]; then
|
2013-07-11 15:10:17 +00:00
|
|
|
echo " http://\$HOST/"
|
|
|
|
fi
|
2012-03-30 14:57:07 +00:00
|
|
|
for ip in \$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print \$1 }'); 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
|
2012-03-30 14:57:07 +00:00
|
|
|
|
|
|
|
cat > /etc/rc.local << EOF
|
|
|
|
#!/bin/sh -e
|
|
|
|
#vm has one network interface and that might change, make it not persistent
|
|
|
|
rm -f /etc/udev/rules.d/70-persistent-net.rules
|
|
|
|
|
|
|
|
#update issue
|
|
|
|
/usr/local/bin/genissue > /etc/issue
|
|
|
|
EOF
|
2013-08-22 14:26:38 +00:00
|
|
|
|
|
|
|
if [ "$LXC" == "no" ]; then
|
|
|
|
cat >> /etc/rc.local << EOF
|
|
|
|
|
|
|
|
#vm can be suspended, this help to keep the time in sync
|
|
|
|
/usr/local/bin/fixtime &
|
|
|
|
EOF
|
|
|
|
fi
|
2014-10-10 15:54:57 +00:00
|
|
|
|
2012-03-30 14:57:07 +00:00
|
|
|
chmod +x /etc/rc.local
|
2013-07-03 14:25:57 +00:00
|
|
|
|
|
|
|
cat > /home/pandora/.vimrc <<EOF
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
EOF
|
2013-09-03 13:43:32 +00:00
|
|
|
apt-get clean
|