#! /bin/sh set -e set -u function install_composer() { php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php --install-dir=bin --filename=composer php -r "unlink('composer-setup.php');" } function install() { install_composer mkdir /tmp/cypht-temp cd /tmp/cypht-temp wget https://github.com/jasonmunro/cypht/archive/master.zip unzip master.zip cd cypht-master && composer install && cd .. cp cypht-master/hm3.sample.ini cypht-master/hm3.ini find cypht-master -type d -print | xargs chmod 755 find cypht-master -type f -print | xargs chmod 644 mv cypht-master/* $1 cd $1 rm -rf /tmp/cypht-temp } function config_user_gen() { php ./scripts/config_gen.php php ./scripts/create_account.php admin admin } function run_auth_sqlite() { echo "CREATE TABLE hm_user_session (hm_id varchar(180), data longblob, date timestamp, primary key (hm_id));" \ | sqlite3 /mnt/test.db || true echo "CREATE TABLE hm_user (username varchar(250), hash varchar(250), primary key (username));" \ | sqlite3 /mnt/test.db || true echo "CREATE TABLE hm_user_settings(username varchar(250), settings longblob, primary key (username));" \ | sqlite3 /mnt/test.db || true } function run_auth_pgsql() { echo '127.0.0.1 localhost' >> /etc/hosts mkdir -p /run/postgresql chmod -R 777 /run/postgresql if [ ! -d /mnt/postgresql/data ]; then sudo -u postgres bash -c ' mkdir -p /mnt/postgresql/data && chmod 0700 /mnt/postgresql/data && initdb /mnt/postgresql/data && echo "host all all 0.0.0.0/8 md5" >> /mnt/postgresql/data/pg_hba.conf && echo "listen_addresses='"'"'*'"'"'" >> /mnt/postgresql/data/postgresql.conf && pg_ctl -D /mnt/postgresql/data start && psql postgresql://localhost:5432 \ --command "CREATE DATABASE test WITH ENCODING UTF8 TEMPLATE=template0;" && psql postgresql://localhost:5432/test \ --command "CREATE USER bel WITH SUPERUSER PASSWORD '"'"'pwd'"'"';" && psql postgresql://bel:pwd@localhost:5432/test \ --command "GRANT ALL PRIVILEGES ON DATABASE test TO bel;" && psql postgresql://bel:pwd@localhost:5432/test \ --command "CREATE TABLE hm_user_session (hm_id varchar(250) primary key not null, data text, date timestamp);" && psql postgresql://bel:pwd@localhost:5432/test \ --command "CREATE TABLE hm_user (username varchar(255) primary key not null, hash varchar(255));" && psql postgresql://bel:pwd@localhost:5432/test \ --command "CREATE TABLE hm_user_settings (username varchar(250) primary key not null, settings text);" ' else sudo -u postgres bash -c 'pg_ctl -D /mnt/postgresql/data start' fi } DESTINATION="/mnt/cypht" if [ ! -d $DESTINATION ]; then mkdir -p $DESTINATION install $DESTINATION fi cd $DESTINATION run_auth_pgsql #run_auth_sqlite config_user_gen mkdir -p /var/lib/hm3 mkdir -p /var/lib/hm3/attachments mkdir -p /var/lib/hm3/users mkdir -p /var/lib/hm3/app_data ln -s /mnt/cypht/site /var/www/html/mail php -S 0.0.0.0:8080 & /mnt/proxy "$@" exit $?