Skip to content

Instantly share code, notes, and snippets.

@thenets
Created March 29, 2017 14:24
Show Gist options
  • Save thenets/ccacaf8a13e5d4a15390a9b26e7c40aa to your computer and use it in GitHub Desktop.
Save thenets/ccacaf8a13e5d4a15390a9b26e7c40aa to your computer and use it in GitHub Desktop.
clear
echo "# ======================================================== #"
echo "# == Easy CKAN installation for Ubuntu 16.04 == #"
echo "# #"
echo "# Special thanks to: #"
echo "# Alerson Luz (GitHub: alersonluz) #"
echo "# Adrien GRIMAL #"
echo "# ======================================================== #"
su -c "sleep 3"
# Get parameters from user
# ==============================================
echo ""
echo "# ======================================================== #"
echo "# == 1. Set main config variables == #"
echo "# ======================================================== #"
echo ""
# No arguments sent. Interactive input.
if [ -z "$1" ] || [ -z "$2" ]; then
echo "# 1.1. Set site URL"
echo "| You site URL must be like http://localhost"
echo -n "| Type the domain: http://"
read v_siteurl
echo ""
echo "# 1.2. Set Password PostgreSQL (database)"
echo "| Enter a password to be used on installation process. "
echo -n "| Type a password: "
read v_password
# Set from arguments
else
v_siteurl=$1
v_password=$2
fi
# Preparations
# ==============================================
echo ""
echo "# ======================================================== #"
echo "# == 2. Update Ubuntu packages == #"
echo "# ======================================================== #"
su -c "sleep 2"
cd /tmp
apt-get update
# Main dependences
# ==============================================
echo "# ======================================================== #"
echo "# == 3. Install CKAN dependences from 'apt-get' == #"
echo "# ======================================================== #"
su -c "sleep 2"
apt-get install -y python-dev postgresql libpq-dev python-pip python-virtualenv git-core openjdk-8-jdk sudo
mkdir /usr/java
ln -s /usr/lib/jvm/java-8-openjdk-amd64 /usr/java/default
# HARD FIX POSTGRES
service postgresql restart
su postgres -c "psql -c \"update pg_database set datallowconn = TRUE where datname = 'template0';\""
su postgres -c "psql -d template0 -c \"update pg_database set datistemplate = FALSE where datname = 'template1';\""
su postgres -c "psql -d template0 -c \"drop database template1;\""
su postgres -c "psql -d template0 -c \"create database template1 with template = template0 encoding = 'UTF8';\""
su postgres -c "psql -d template0 -c \"update pg_database set datistemplate = TRUE where datname = 'template1';\""
su postgres -c "psql -d template1 -c \"update pg_database set datallowconn = FALSE where datname = 'template0';\""
# HARD FIX POSTGRES
# Setup a PostgreSQL database
# ==============================================
#echo "| Insert the SAME password two more times..."
#: $(su postgres -c "createuser -S -D -R -P ckan_default")
su postgres -c "psql --command \"CREATE USER ckan_default WITH PASSWORD '"$v_password"';\""
su postgres -c "createdb -O ckan_default ckan_default -E utf-8"
# Setup CKAN
# ==============================================
echo ""
echo ""
echo "# ======================================================== #"
echo "# == 4. Setup CKAN == #"
echo "# ======================================================== #"
su -c "sleep 2"
# Create user
echo "# 4.1. Creating CKAN user..."
useradd -m -s /sbin/nologin -d /usr/lib/ckan -c "CKAN User" ckan
sudo usermod -a -G staff ckan
chmod 775 -R /usr/local/lib/python2.7
chmod 755 /usr/lib/ckan
chown ckan.33 -R /usr/lib/ckan
# Python Virtual Environment
echo "# 4.2. Creating Python Virtual Environment..."
su -c "sleep 2"
apt-get install -y python-paste
su -s /bin/bash - ckan -c "mkdir -p /usr/lib/ckan/default"
su -s /bin/bash - ckan -c "virtualenv --no-site-packages /usr/lib/ckan/default"
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && pip install --upgrade pip" # HARD FIX
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && pip install setuptools==20.4" # HARD FIX for CKAN 2.6.0
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && pip install html5lib==0.999" # HARD FIX
# Installing CKAN and dependences
echo "# 4.3. Installing CKAN and dependences..."
apt-get install -y libmemcached-dev zlib1g-dev # FIX for CKAN 2.6.0
su -c "sleep 2"
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && pip install -e 'git+https://github.com/ckan/[email protected]#egg=ckan'"
sed -i "s/bleach==1.4.2/bleach==1.4.3/g" /usr/lib/ckan/default/src/ckan/requirements.txt # HOT FIX
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && pip install -r /usr/lib/ckan/default/src/ckan/pip-requirements-docs.txt"
# Create main CKAN config files
echo "# 4.4. Creating main configuration file at /etc/ckan/default/development.ini ..."
su -c "sleep 2"
mkdir -p /etc/ckan/default
chown -R ckan.ckan /etc/ckan
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && paster make-config ckan /etc/ckan/default/development.ini"
sed -i "s/ckan.site_url =/ckan.site_url = http:\/\/$v_siteurl/g" /etc/ckan/default/development.ini
sed -i "s/ckan_default:pass@localhost/ckan_default:$v_password@localhost/g" /etc/ckan/default/development.ini
sed -i "s/#solr_url/solr_url/g" /etc/ckan/default/development.ini
sed -i "s/127.0.0.1:8983/127.0.0.1:8080/g" /etc/ckan/default/development.ini
chown ckan.33 -R /etc/ckan/default
# Setup a storage path
echo "# 4.5 Setting a storage path for upload support..."
su -c "sleep 2"
mkdir -p /var/lib/ckan
chown -R ckan.33 /var/lib/ckan
sed -i 's/#ckan.storage_path/ckan.storage_path/g' /etc/ckan/default/development.ini
# Install Solr
# ==============================================
echo ""
echo ""
echo "# ======================================================== #"
echo "# == 5. Install Apache Solr == #"
echo "# ======================================================== #"
su -c "sleep 2"
echo "# 5.1. Installing from 'apt-get'..."
apt-get -y install solr-tomcat
mv /etc/solr/conf/schema.xml /etc/solr/conf/schema.xml.bak
cp /usr/lib/ckan/default/src/ckan/ckan/config/solr/schema.xml /etc/solr/conf/schema.xml
# Restarting services
echo "# 5.2. Restarting Solr..."
service tomcat7 restart
# Last configurations
# ==============================================
echo ""
echo ""
echo "# ======================================================== #"
echo "# == 6. Finishing == #"
echo "# ======================================================== #"
su -c "sleep 2"
# HARD FIX POSTGRES
service postgresql restart
su postgres -c "psql -c \"update pg_database set datallowconn = TRUE where datname = 'template0';\""
su postgres -c "psql -d template0 -c \"update pg_database set datistemplate = FALSE where datname = 'template1';\""
su postgres -c "psql -d template0 -c \"drop database template1;\""
su postgres -c "psql -d template0 -c \"create database template1 with template = template0 encoding = 'UTF8';\""
su postgres -c "psql -d template0 -c \"update pg_database set datistemplate = TRUE where datname = 'template1';\""
su postgres -c "psql -d template1 -c \"update pg_database set datallowconn = FALSE where datname = 'template0';\""
service postgresql restart
# HARD FIX POSTGRES
echo "# 6.1. Initilize CKAN database..."
service tomcat7 restart
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && cd /usr/lib/ckan/default/src/ckan && paster db init -c /etc/ckan/default/development.ini"
echo "# 6.2. Set 'who.ini'..."
ln -s /usr/lib/ckan/default/src/ckan/who.ini /etc/ckan/default/who.ini
echo "# 6.3. Enable Tomcat6 and PostgreSQL on startup..."
sudo update-rc.d postgresql enable
sudo update-rc.d tomcat7 enable
# Create a admin account
# ==============================================
clear
echo "# ======================================================== #"
echo "# == 7. CKAN Account == #"
echo "# ======================================================== #"
su -c "sleep 2"
echo "# 7.1 Creating a Admin account..."
echo "| Your account name will be 'admin'."
echo "| Type the admin password:"
su -s /bin/bash - ckan -c ". /usr/lib/ckan/default/bin/activate && cd /usr/lib/ckan/default/src/ckan && paster sysadmin add admin -c /etc/ckan/default/development.ini"
# PLUGINS
#
# Just if installation doesn't have args
# ==============================================
if [ -z "$1" ] || [ -z "$2" ]; then
echo ""
echo ""
echo "# ======================================================== #"
echo "# == Plugins (optional) == #"
echo "# ======================================================== #"
su -c "sleep 2"
# PLUGIN Harvest Installer
echo "# PLUGIN Harvest"
echo -n "# You want to install? [y/N]: "
read plugin_harvest
if [[ $plugin_harvest == "y" ]]
then
su -c "easyckan plugin install harvest"
fi
# PLUGIN DataStore Installer
echo "# PLUGIN DataStore"
echo -n "# You want to install? [y/N]: "
read plugin_datastore
if [[ $plugin_datastore == "y" ]]
then
su -c "easyckan plugin install datastore"
fi
echo ""
fi
su -c "sleep 2"
echo ""
echo "# ======================================================== #"
echo "# == CKAN installation complete! == #"
echo "# ======================================================== #"
echo "|"
echo "# Press [Enter] to continue..."
read success
@oliverkarst
Copy link

oliverkarst commented Mar 31, 2017

Hi @luiz Felipe F M Costa,

really interesting work!! super!!

After trying the documentation for source installation in the Docs with errors this script was my next try. I am not that much expirienced in ckan or python, I just want to evaluate the new version of ckan for the company i am working for, because they now use a ckan setup from source, done by an external employee.

So what I did was to setup a VM with ubuntu 16.04.02.
Copy your script over and run it in the terminal.

  1. chmod +x on_your_script_copied_to_vm
  2. Step: switch to root via sudo su
  3. ./ckan_ubuntu16.04_installer.sh

For the Plugins (optinal) I got errors:
PLUGIN Harvest
You want to install? [y/N]: y
bash: easyckan: command not found
PLUGIN DataStore
You want to install? [y/N]: y
bash: easyckan: command not found`

At the end the CKAN installation was complete. In all the output not other errors where shown, all seemed to be completed successfully inclusive database updates, etc.

I opened the browser and entered http://localhost. In development.ini the ckan.site_url is set to http://localhost

but could the message "Unable to connect"

Any idea what could be wrong?

Thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment