2014-05-08 16:59:35 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -u
|
2015-04-29 13:17:21 +00:00
|
|
|
|
set -e
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
|
|
bold=$(tput bold)
|
|
|
|
|
normal=$(tput sgr0)
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 13:17:21 +00:00
|
|
|
|
PYTHON_BIN='python3'
|
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
|
function help () {
|
|
|
|
|
if [[ $# -gt 1 ]]; then
|
|
|
|
|
CMD="print_${2}_help"
|
|
|
|
|
$CMD
|
|
|
|
|
else
|
|
|
|
|
print_help
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function print_help () {
|
|
|
|
|
cat <<- EOF
|
|
|
|
|
|
|
|
|
|
${bold}NAME${normal}
|
|
|
|
|
${bold}orchestra-admin${normal} - Orchetsra administration script
|
|
|
|
|
|
|
|
|
|
${bold}OPTIONS${normal}
|
|
|
|
|
${bold}install_requirements${normal}
|
|
|
|
|
Installs Orchestra requirements using apt-get and pip
|
|
|
|
|
|
|
|
|
|
${bold}install_postfix${normal}
|
|
|
|
|
Installs postfix packages including dovecot, amavis, spamassassin and clamav
|
|
|
|
|
|
|
|
|
|
${bold}uninstall_postfix${normal}
|
|
|
|
|
Uninstall postfix packages including dovecot, amavis, spamassassin and clamav
|
|
|
|
|
|
|
|
|
|
${bold}install_certificate${normal}
|
|
|
|
|
Installs a valid all-purpose self signed certificate that is valid for the next ten years
|
|
|
|
|
|
|
|
|
|
${bold}uninstall_certificate${normal}
|
|
|
|
|
Uninstall certificate
|
|
|
|
|
|
|
|
|
|
${bold}startproject${normal}
|
|
|
|
|
Creates a new Django-orchestra instance
|
|
|
|
|
|
|
|
|
|
${bold}help${normal}
|
|
|
|
|
Displays this help text or related help page as argument
|
|
|
|
|
for example:
|
|
|
|
|
${bold}orchestra-admin help startproject${normal}
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
# in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
show () {
|
|
|
|
|
echo " ${bold}\$ ${@}${normal}"
|
|
|
|
|
}
|
|
|
|
|
export -f show
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
run () {
|
|
|
|
|
show "${@}"
|
|
|
|
|
"${@}"
|
|
|
|
|
}
|
|
|
|
|
export -f run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_root () {
|
|
|
|
|
[ $(whoami) != 'root' ] && { echo -e "\nErr. This should be run as root\n" >&2; exit 1; }
|
|
|
|
|
}
|
|
|
|
|
export -f check_root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_orchestra_dir () {
|
2015-04-29 13:17:21 +00:00
|
|
|
|
if ! $(echo "import orchestra" | $PYTHON_BIN 2> /dev/null); then
|
|
|
|
|
echo -e "\norchestra not installed.\n" >&2
|
2014-05-08 16:59:35 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2015-04-29 13:17:21 +00:00
|
|
|
|
PATH=$(echo "import orchestra, os; print(os.path.dirname(os.path.realpath(orchestra.__file__)))" | $PYTHON_BIN)
|
2014-05-08 16:59:35 +00:00
|
|
|
|
echo $PATH
|
|
|
|
|
}
|
|
|
|
|
export -f get_orchestra_dir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function print_install_requirements_help () {
|
2014-09-24 20:09:41 +00:00
|
|
|
|
cat <<- EOF
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
|
|
${bold}NAME${normal}
|
|
|
|
|
${bold}orchetsra-admin install_requirements${normal} - Installs all Orchestra requirements using apt-get and pip
|
|
|
|
|
|
|
|
|
|
${bold}OPTIONS${normal}
|
|
|
|
|
${bold}-t, --testing${normal}
|
|
|
|
|
Install Orchestra normal requirements plus those needed for running functional tests
|
|
|
|
|
|
|
|
|
|
${bold}-h, --help${normal}
|
|
|
|
|
Displays this help text
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function install_requirements () {
|
|
|
|
|
opts=$(getopt -o h,t -l help,testing -- "$@") || exit 1
|
|
|
|
|
set -- $opts
|
|
|
|
|
testing=false
|
|
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
case $1 in
|
|
|
|
|
-h|--help) print_deploy_help; exit 0 ;;
|
|
|
|
|
-t|--testing) testing=true; shift ;;
|
|
|
|
|
(--) shift; break;;
|
|
|
|
|
(-*) echo "$0: Err. - unrecognized option $1" 1>&2; exit 1;;
|
|
|
|
|
(*) break;;
|
|
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
unset OPTIND
|
|
|
|
|
unset opt
|
|
|
|
|
|
2015-04-29 13:17:21 +00:00
|
|
|
|
check_root || true
|
|
|
|
|
ORCHESTRA_PATH=$(get_orchestra_dir) || true
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
2015-05-03 17:44:46 +00:00
|
|
|
|
# TODO reduce this list to 0
|
|
|
|
|
# include /usr/sbin/named-checkzone
|
|
|
|
|
# wkhtmltopdf -> reportlab
|
|
|
|
|
# remove rabbit, postgres
|
|
|
|
|
# uwsgi –py-autoreload for devel
|
2015-04-03 10:14:45 +00:00
|
|
|
|
APT="python3 \
|
|
|
|
|
python3-pip \
|
|
|
|
|
python3-psycopg2 \
|
2015-04-29 13:17:21 +00:00
|
|
|
|
python3-lxml \
|
2015-04-03 10:14:45 +00:00
|
|
|
|
python3-dev \
|
2014-05-08 16:59:35 +00:00
|
|
|
|
bind9utils \
|
2015-04-03 10:14:45 +00:00
|
|
|
|
python3-cracklib \
|
2014-10-04 14:19:29 +00:00
|
|
|
|
libz-dev \
|
2014-08-29 12:45:27 +00:00
|
|
|
|
wkhtmltopdf \
|
2014-10-17 10:04:47 +00:00
|
|
|
|
xvfb \
|
2015-03-29 16:10:07 +00:00
|
|
|
|
ca-certificates \
|
|
|
|
|
gettext"
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
2015-05-03 17:44:46 +00:00
|
|
|
|
# TODO remove celery deps, django 1.8.1, glic3rinu fork, celery email
|
2015-05-03 20:08:32 +00:00
|
|
|
|
PIP="django==1.8.1 \
|
2014-07-18 15:32:27 +00:00
|
|
|
|
django-celery-email==1.0.4 \
|
2015-04-05 22:34:47 +00:00
|
|
|
|
https://github.com/glic3rinu/django-fluent-dashboard/archive/master.zip \
|
2014-05-08 16:59:35 +00:00
|
|
|
|
https://bitbucket.org/izi/django-admin-tools/get/a0abfffd76a0.zip \
|
|
|
|
|
IPy==0.81 \
|
2015-04-02 16:14:55 +00:00
|
|
|
|
django-extensions==1.5.2 \
|
2014-05-08 16:59:35 +00:00
|
|
|
|
django-transaction-signals==1.0.0 \
|
2014-10-17 10:04:47 +00:00
|
|
|
|
django-celery==3.1.16 \
|
|
|
|
|
celery==3.1.16 \
|
2014-10-04 14:19:29 +00:00
|
|
|
|
kombu==3.0.23 \
|
|
|
|
|
billiard==3.3.0.18 \
|
2014-05-08 16:59:35 +00:00
|
|
|
|
Markdown==2.4 \
|
2015-04-23 14:34:04 +00:00
|
|
|
|
djangorestframework==3.1.1 \
|
2014-10-04 13:23:04 +00:00
|
|
|
|
paramiko==1.15.1 \
|
2014-10-04 14:19:29 +00:00
|
|
|
|
ecdsa==0.11 \
|
2014-05-08 16:59:35 +00:00
|
|
|
|
Pygments==1.6 \
|
2015-04-23 14:34:04 +00:00
|
|
|
|
django-filter==0.9.2 \
|
2015-05-03 20:13:27 +00:00
|
|
|
|
https://github.com/glic3rinu/passlib/archive/master.zip \
|
2014-07-29 14:37:25 +00:00
|
|
|
|
jsonfield==0.9.22 \
|
2015-04-29 13:17:21 +00:00
|
|
|
|
python-dateutil==2.4.2 \
|
2014-10-17 10:04:47 +00:00
|
|
|
|
django-iban==0.3.0 \
|
2014-10-30 16:34:02 +00:00
|
|
|
|
requests \
|
|
|
|
|
phonenumbers \
|
|
|
|
|
django-countries \
|
2015-03-29 16:10:07 +00:00
|
|
|
|
django-localflavor \
|
|
|
|
|
pip==6.0.8"
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
|
|
if $testing; then
|
|
|
|
|
APT="${APT} \
|
2014-10-04 21:29:05 +00:00
|
|
|
|
iceweasel \
|
2015-04-29 13:17:21 +00:00
|
|
|
|
dnsutils"
|
2014-05-08 16:59:35 +00:00
|
|
|
|
PIP="${PIP} \
|
|
|
|
|
selenium \
|
2014-09-24 20:09:41 +00:00
|
|
|
|
xvfbwrapper \
|
2014-10-03 14:02:11 +00:00
|
|
|
|
freezegun \
|
2014-10-03 17:37:36 +00:00
|
|
|
|
coverage \
|
2015-04-04 17:44:07 +00:00
|
|
|
|
flake8 \
|
2015-04-03 13:03:08 +00:00
|
|
|
|
django-debug-toolbar==1.3.0 \
|
|
|
|
|
https://github.com/django-nose/django-nose/archive/master.zip \
|
2014-10-16 15:25:38 +00:00
|
|
|
|
sqlparse \
|
2014-11-21 17:18:59 +00:00
|
|
|
|
pyinotify \
|
2015-04-29 13:17:21 +00:00
|
|
|
|
PyMySQL"
|
2014-05-08 16:59:35 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Make sure locales are in place before installing postgres
|
|
|
|
|
if [[ $({ perl --help > /dev/null; } 2>&1|grep 'locale failed') ]]; then
|
|
|
|
|
run sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen
|
|
|
|
|
run locale-gen
|
|
|
|
|
update-locale LANG=en_US.UTF-8
|
|
|
|
|
fi
|
|
|
|
|
|
2014-10-17 10:04:47 +00:00
|
|
|
|
run apt-get update
|
|
|
|
|
run apt-get install -y $APT
|
|
|
|
|
|
|
|
|
|
# Install ca certificates before executing pip install
|
2014-10-04 21:29:05 +00:00
|
|
|
|
if [[ ! -e /usr/local/share/ca-certificates/cacert.org ]]; then
|
|
|
|
|
mkdir -p /usr/local/share/ca-certificates/cacert.org
|
|
|
|
|
wget -P /usr/local/share/ca-certificates/cacert.org \
|
|
|
|
|
http://www.cacert.org/certs/root.crt \
|
|
|
|
|
http://www.cacert.org/certs/class3.crt
|
|
|
|
|
update-ca-certificates
|
|
|
|
|
fi
|
2014-10-16 17:14:21 +00:00
|
|
|
|
|
2015-04-03 10:14:45 +00:00
|
|
|
|
run pip3 install $PIP
|
2014-10-16 17:14:21 +00:00
|
|
|
|
|
2014-10-04 21:29:05 +00:00
|
|
|
|
# Patch passlib
|
2015-05-03 20:13:27 +00:00
|
|
|
|
# IMPORT="from django.contrib.auth.hashers import mask_hash, _"
|
|
|
|
|
# COLLECTIONS="from collections import OrderedDict"
|
|
|
|
|
# PASSLIB_PATH=$(python3 -c "from passlib.ext.django import utils; print(utils.__file__)")
|
|
|
|
|
# sed -i "s/${IMPORT}, SortedDict/${IMPORT}\n ${COLLECTIONS}/" $PASSLIB_PATH
|
|
|
|
|
# sed -i "s/SortedDict/OrderedDict/g" $PASSLIB_PATH
|
2014-05-08 16:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
export -f install_requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print_startproject_help () {
|
|
|
|
|
cat <<- EOF
|
|
|
|
|
|
|
|
|
|
${bold}NAME${normal}
|
|
|
|
|
${bold}orchestra-admin startproject${normal} - Create a new Django-Orchestra instance
|
|
|
|
|
|
|
|
|
|
${bold}SYNOPSIS${normal}
|
|
|
|
|
Options: [ -h ]
|
|
|
|
|
|
|
|
|
|
${bold}OPTIONS${normal}
|
|
|
|
|
${bold}-h, --help${normal}
|
|
|
|
|
This help message
|
|
|
|
|
|
|
|
|
|
${bold}EXAMPLES${normal}
|
|
|
|
|
orchestra-admin startproject controlpanel
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function startproject () {
|
|
|
|
|
local PROJECT_NAME="$2"; shift
|
|
|
|
|
|
|
|
|
|
opts=$(getopt -o h -l help -- "$@") || exit 1
|
|
|
|
|
set -- $opts
|
|
|
|
|
|
|
|
|
|
set -- $opts
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
case $1 in
|
|
|
|
|
-h|--help) print_startproject_help; exit 0 ;;
|
|
|
|
|
(--) shift; break;;
|
|
|
|
|
(-*) echo "$0: Err. - unrecognized option $1" 1>&2; exit 1;;
|
|
|
|
|
(*) break;;
|
|
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
unset OPTIND
|
|
|
|
|
unset opt
|
|
|
|
|
|
|
|
|
|
[ $(whoami) == 'root' ] && { echo -e "\nYou don't want to run this as root\n" >&2; exit 1; }
|
|
|
|
|
ORCHESTRA_PATH=$(get_orchestra_dir) || { echo "Error getting orchestra dir"; exit 1; }
|
|
|
|
|
if [[ ! -e $PROJECT_NAME/manage.py ]]; then
|
|
|
|
|
run django-admin.py startproject $PROJECT_NAME --template="${ORCHESTRA_PATH}/conf/project_template"
|
|
|
|
|
# This is a workaround for this issue https://github.com/pypa/pip/issues/317
|
|
|
|
|
run chmod +x $PROJECT_NAME/manage.py
|
|
|
|
|
# End of workaround ###
|
|
|
|
|
else
|
|
|
|
|
echo "Not cloning: $PROJECT_NAME already exists."
|
|
|
|
|
fi
|
|
|
|
|
# Install bash autocompletition for django commands
|
|
|
|
|
if [[ ! $(grep 'source $HOME/.django_bash_completion.sh' ~/.bashrc &> /dev/null) ]]; then
|
|
|
|
|
# run wget https://raw.github.com/django/django/master/extras/django_bash_completion \
|
|
|
|
|
# --no-check-certificate -O ~/.django_bash_completion.sh
|
|
|
|
|
cp ${ORCHESTRA_PATH}/bin/django_bash_completion.sh ~/.django_bash_completion.sh
|
|
|
|
|
echo 'source $HOME/.django_bash_completion.sh' >> ~/.bashrc
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
export -f startproject
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ $# -lt 1 ] && print_help
|
|
|
|
|
$1 "${@}"
|