From 1ceae50833abee718b84e099f7de5126483aa194 Mon Sep 17 00:00:00 2001 From: "Fabio C. Barrionuevo da Luz" Date: Fri, 13 Mar 2015 21:06:58 -0300 Subject: [PATCH 1/4] add requirements file of external dependencies (non-python dependencies), named "requirements.apt" - fix issue #34 --- {{cookiecutter.repo_name}}/requirements.apt | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 {{cookiecutter.repo_name}}/requirements.apt diff --git a/{{cookiecutter.repo_name}}/requirements.apt b/{{cookiecutter.repo_name}}/requirements.apt new file mode 100644 index 00000000..ae26b958 --- /dev/null +++ b/{{cookiecutter.repo_name}}/requirements.apt @@ -0,0 +1,27 @@ +##basic build dependencies of various Django apps for Ubuntu 14.04 +#build-essential metapackage install: make, gcc, g++, +build-essential +#required to translate +gettext +python-dev + +##shared dependencies of: +##Pillow, pylibmc +zlib1g-dev + +##Postgresql and psycopg2 dependencies +libpq-dev + +##Pillow dependencies +libtiff4-dev +libjpeg8-dev +libfreetype6-dev +liblcms1-dev +libwebp-dev + +##pylibmc +libmemcached-dev +libssl-dev + +##django-extensions +graphviz-dev From 164a496a85edbe1c5a67186ee8c9516aec78ba45 Mon Sep 17 00:00:00 2001 From: "Fabio C. Barrionuevo da Luz" Date: Fri, 13 Mar 2015 21:07:25 -0300 Subject: [PATCH 2/4] add shellscript helper to install external dependencies (non-python dependencies) listed on requirements.apt file --- .../install_os_dependencies.sh | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 {{cookiecutter.repo_name}}/install_os_dependencies.sh diff --git a/{{cookiecutter.repo_name}}/install_os_dependencies.sh b/{{cookiecutter.repo_name}}/install_os_dependencies.sh new file mode 100755 index 00000000..35fb1e37 --- /dev/null +++ b/{{cookiecutter.repo_name}}/install_os_dependencies.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [[ $EUID -ne 0 ]]; then + echo -e "\nYou must run this with root privilege" 2>&1 + echo -e "Please do:\n" 2>&1 + echo "sudo ./${0##*/}" 2>&1 + echo -e "\n" 2>&1 + + exit 1 +else + + apt-get update + + # Install the basic compilation dependencies and other required libraries of this project + cat requirements.apt | grep -v "#" | xargs sudo apt-get install -y + + # cleaning downloaded packages from apt-get cache + apt-get clean + +fi From 0fbd6ccd72f4279d61a5b72888612293b378077f Mon Sep 17 00:00:00 2001 From: "Fabio C. Barrionuevo da Luz" Date: Fri, 13 Mar 2015 21:07:42 -0300 Subject: [PATCH 3/4] add shellscript helper to install all python dependencies of the project (local, test, and production dependencies) --- .../install_python_dependencies.sh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 {{cookiecutter.repo_name}}/install_python_dependencies.sh diff --git a/{{cookiecutter.repo_name}}/install_python_dependencies.sh b/{{cookiecutter.repo_name}}/install_python_dependencies.sh new file mode 100755 index 00000000..5d04044a --- /dev/null +++ b/{{cookiecutter.repo_name}}/install_python_dependencies.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +pip --version >/dev/null 2>&1 || { + echo >&2 -e "\npip is required but it's not installed." + echo >&2 -e "You can install it by running the following command:\n" + echo >&2 "wget https://bootstrap.pypa.io/get-pip.py; chmod +x get-pip.py; sudo ./get-pip.py" + echo >&2 -e "\n" + echo >&2 -e "\nFor more information, see pip documentation: https://pip.pypa.io/en/latest/" + exit 1; +} + +virtualenv --version >/dev/null 2>&1 || { + echo >&2 -e "\nvirtualenv is required but it's not installed." + echo >&2 -e "You can install it by running the following command:\n" + echo >&2 "sudo pip install virtualenv" + echo >&2 -e "\n" + echo >&2 -e "\nFor more information, see virtualenv documentation: https://virtualenv.pypa.io/en/latest/" + exit 1; +} + +if [ -z "$VIRTUAL_ENV" ]; then + echo >&2 -e "\nYou need activate a virtualenv first" + echo >&2 -e 'If you do not have a virtualenv created, run the following command to create and automatically activate a new virtualenv named "venv" on current folder:\n' + echo >&2 -e "virtualenv venv" + echo >&2 -e "\nTo leave/disable the currently active virtualenv, run the following command:\n" + echo >&2 "deactivate" + echo >&2 -e "\nTo activate the virtualenv again, run the following command:\n" + echo >&2 "source venv/bin/activate" + echo >&2 -e "\nFor more information, see virtualenv documentation: https://virtualenv.pypa.io/en/latest/" + echo >&2 -e "\n" + exit 1; +else + + pip install -r requirements/local.txt + pip install -r requirements/test.txt + pip install -r requirements.txt +fi + + + From afb9f607e976ef0fc4f8dbfd3242605826158e18 Mon Sep 17 00:00:00 2001 From: "Fabio C. Barrionuevo da Luz" Date: Sat, 11 Apr 2015 12:32:49 -0300 Subject: [PATCH 4/4] refactored install_os_dependencies.sh add .idea on .gitignore --- .gitignore | 3 +- .../install_os_dependencies.sh | 88 ++++++++++++++++--- 2 files changed, 77 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 3f36ae8c..0aae0c9c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.pot *.pyc local_settings.py -repo_name \ No newline at end of file +repo_name +.idea diff --git a/{{cookiecutter.repo_name}}/install_os_dependencies.sh b/{{cookiecutter.repo_name}}/install_os_dependencies.sh index 35fb1e37..477dcafd 100755 --- a/{{cookiecutter.repo_name}}/install_os_dependencies.sh +++ b/{{cookiecutter.repo_name}}/install_os_dependencies.sh @@ -1,20 +1,82 @@ #!/bin/bash -if [[ $EUID -ne 0 ]]; then - echo -e "\nYou must run this with root privilege" 2>&1 - echo -e "Please do:\n" 2>&1 - echo "sudo ./${0##*/}" 2>&1 - echo -e "\n" 2>&1 +OS_REQUIREMENTS_FILENAME="requirements.apt" - exit 1 -else +# Handle call with wrong command +function wrong_command() +{ + echo "${0##*/} - unknown command: '${1}'" + usage_message +} - apt-get update +# Print help / script usage +function usage_message() +{ + echo "usage: ./${0##*/} " + echo "available commands are:" + echo -e "\tlist\t\tPrint a list of all packages defined on ${OS_REQUIREMENTS_FILENAME} file" + echo -e "\thelp\t\tPrint this help" + echo -e "\n\tCommands that require superuser permission:" + echo -e "\tinstall\t\tInstall packages defined on ${OS_REQUIREMENTS_FILENAME} file. Note: This\n\t\t\t does not upgrade the packages already installed for new\n\t\t\t versions, even if new version is available in the repository." + echo -e "\tupgrade\t\tSame that install, but upgrate the already installed packages,\n\t\t\t if new version is available." - # Install the basic compilation dependencies and other required libraries of this project - cat requirements.apt | grep -v "#" | xargs sudo apt-get install -y +} - # cleaning downloaded packages from apt-get cache - apt-get clean +# Read the requirements.apt file, and remove comments and blank lines +function list_packages(){ + cat ${OS_REQUIREMENTS_FILENAME} | grep -v "#" | grep -v "^$"; +} + +function install() +{ + list_packages | xargs apt-get --no-upgrade install -y; +} + +function upgrade() +{ + list_packages | xargs apt-get install -y; +} + + +function install_or_upgrade() +{ + P=${1} + PARAN=${P:-"install"} + + if [[ $EUID -ne 0 ]]; then + echo -e "\nYou must run this with root privilege" 2>&1 + echo -e "Please do:\n" 2>&1 + echo "sudo ./${0##*/} $PARAN" 2>&1 + echo -e "\n" 2>&1 + + exit 1 + else + + apt-get update + + # Install the basic compilation dependencies and other required libraries of this project + if [ "$PARAN" == "install" ]; then + install; + else + upgrade; + fi + + # cleaning downloaded packages from apt-get cache + apt-get clean + + exit 0 + fi + + +} + + +# Handle command argument +case "$1" in + install) install_or_upgrade;; + upgrade) install_or_upgrade "upgrade";; + list) list_packages;; + help) usage_message;; + *) wrong_command $1;; +esac -fi