#!/bin/bash -ex

HOSTNAME=salam
 
# set hostname
echo "$HOSTNAME" > /etc/hostname
sed -i "s|127.0.1.1 \(.*\)|127.0.1.1 $HOSTNAME|" /etc/hosts
 
# start mysql daemon
/etc/init.d/mysql start

install()
{
    apt-get update
    DEBIAN_FRONTEND=noninteractive apt-get -y \
        -o DPkg::Options::=--force-confdef \
        -o DPkg::Options::=--force-confold \
        install $@
}

install php5-cli php5-gd dnsutils wmi-client

# setup salam
ln -s /usr/local/salam/salam.conf /etc/apache2/conf.d/salam.conf
 
# configure cron
crontab -l > temp
cat /usr/local/salam/salam.cron >> temp
crontab temp
 
# set file permissions
chmod +x /usr/local/salam/salam_run
chmod +x /usr/local/salam/plugins/*
chmod 777 /usr/local/salam/library/settings.php
chmod 777 /usr/local/salam/frontend/admin/.htpasswd
chmod 777 /usr/local/salam/frontend
chmod 777 /usr/local/salam/frontend/install.php
 
# setup mysql database
mysql -uroot --execute "CREATE DATABASE salam"
mysql -uroot --database=salam < /usr/local/salam/salam.sql
 
# stop mysql daemon
/etc/init.d/mysql stop
