django-orchestra-test/orchestra/bin/orchestra-admin

247 lines
6.6 KiB
Plaintext
Raw Permalink Normal View History

2014-05-08 16:59:35 +00:00
#!/bin/bash
set -u
set -e
2014-05-08 16:59:35 +00:00
bold=$(tput -T ${TERM:-xterm} bold)
normal=$(tput -T ${TERM:-xterm} sgr0)
2014-05-08 16:59:35 +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 () {
2015-10-02 09:31:32 +00:00
cat <<- EOF
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}NAME${normal}
${bold}orchestra-admin${normal} - Orchetsra administration script
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}OPTIONS${normal}
${bold}install_requirements${normal}
Installs Orchestra requirements using apt-get and pip
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}startproject${normal}
Creates a new Django-orchestra instance
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}help${normal}
Displays this help text or related help page as argument
for example:
${bold}orchestra-admin help startproject${normal}
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
EOF
}
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 () {
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
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
2021-03-30 12:19:17 +00:00
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
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}OPTIONS${normal}
${bold}-t, --testing${normal}
Install Orchestra normal requirements plus those needed for running functional tests
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}-h, --help${normal}
Displays this help text
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
EOF
}
function install_requirements () {
opts=$(getopt -o h,t -l help,testing -- "$@") || exit 1
set -- $opts
testing=false
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
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
2021-03-30 12:19:17 +00:00
check_root || true
ORCHESTRA_PATH=$(get_orchestra_dir) || true
2021-03-30 12:19:17 +00:00
2015-10-03 11:12:51 +00:00
# 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
2021-03-30 12:19:17 +00:00
2015-05-05 20:11:03 +00:00
# lxml: libxml2-dev, libxslt1-dev, zlib1g-dev
2015-10-03 10:37:43 +00:00
APT="bind9utils \
ca-certificates \
gettext \
libcrack2-dev \
2015-05-04 12:57:41 +00:00
libxml2-dev \
libxslt1-dev \
2015-10-03 10:37:43 +00:00
python3 \
python3-pip \
python3-dev \
ssh-client \
wget \
2014-10-17 10:04:47 +00:00
xvfb \
2015-10-03 10:37:43 +00:00
zlib1g-dev"
2015-10-03 11:12:51 +00:00
if $testing; then
APT="${APT} \
git \
iceweasel \
dnsutils"
2015-10-03 19:16:50 +00:00
fi
2021-03-30 12:19:17 +00:00
2015-10-03 11:12:51 +00:00
run apt-get update
run apt-get install -y $APT
2021-03-30 12:19:17 +00:00
2015-10-03 11:12:51 +00:00
# Install ca certificates before executing pip install
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
2021-03-30 12:19:17 +00:00
2015-05-15 14:19:24 +00:00
# cracklib and lxml are excluded on the requirements.txt because they need unconvinient system dependencies
2015-10-03 10:37:43 +00:00
PIP="$(wget http://git.io/orchestra-requirements.txt -O - | tr '\n' ' ') \
2015-05-04 14:19:58 +00:00
cracklib \
lxml==3.3.5"
2014-05-08 16:59:35 +00:00
if $testing; then
PIP="${PIP} \
selenium \
2014-09-24 20:09:41 +00:00
xvfbwrapper \
2021-03-30 12:19:17 +00:00
freezegun==0.3.14 \
coverage \
2015-04-04 17:44:07 +00:00
flake8 \
2015-04-03 13:03:08 +00:00
django-debug-toolbar==1.3.0 \
2016-10-11 10:01:56 +00:00
django-nose==1.4.4 \
2014-10-16 15:25:38 +00:00
sqlparse \
2014-11-21 17:18:59 +00:00
pyinotify \
PyMySQL"
2014-05-08 16:59:35 +00:00
fi
2021-03-30 12:19:17 +00:00
2015-10-03 11:12:51 +00:00
run pip3 install $PIP
2021-03-30 12:19:17 +00:00
2015-05-15 14:19:24 +00:00
# Install a more recent version of wkhtmltopdf (0.12.2) (PDF page number support)
2015-10-03 11:12:51 +00:00
wkhtmltox_version=$(dpkg --list | grep wkhtmltox | awk {'print $3'})
2015-10-03 19:16:50 +00:00
minor=$(echo -e "$wkhtmltox_version\n0.12.2.1" | sort -V | head -n 1)
if [[ ! $wkhtmltox_version ]] || [[ $wkhtmltox_version != 0.12.2.1 && $minor == ${wkhtmltox_version} ]]; then
2015-10-01 20:14:32 +00:00
wkhtmltox=$(mktemp)
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb -O ${wkhtmltox}
2015-10-01 20:14:32 +00:00
dpkg -i ${wkhtmltox} || { echo "Installing missing dependencies for wkhtmltox..." && apt-get -f -y install; }
fi
2014-05-08 16:59:35 +00:00
}
export -f install_requirements
print_startproject_help () {
cat <<- EOF
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}NAME${normal}
${bold}orchestra-admin startproject${normal} - Create a new Django-Orchestra instance
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}SYNOPSIS${normal}
Options: [ -h ]
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}OPTIONS${normal}
${bold}-h, --help${normal}
This help message
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
${bold}EXAMPLES${normal}
orchestra-admin startproject controlpanel
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
EOF
}
function startproject () {
local PROJECT_NAME="$2"; shift
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
opts=$(getopt -o h -l help -- "$@") || exit 1
set -- $opts
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
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
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
unset OPTIND
unset opt
2021-03-30 12:19:17 +00:00
2014-05-08 16:59:35 +00:00
[ $(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
2015-10-03 19:16:50 +00:00
[ $# -lt 1 ] && { print_help; exit 1; }
2014-05-08 16:59:35 +00:00
$1 "${@}"