From c67d330eeacdea1dd346cd28cef28b72296ff4e3 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 23 Aug 2015 11:33:13 -0400 Subject: [PATCH] Initial commit, forked from https://git.reticu.li/zot/redmatrix_ynh --- .gitignore | 1 + README.md | 22 +++++++++++++ conf/nginx.conf | 32 ++++++++++++++++++ conf/poller-cron | 2 ++ manifest.json | 47 +++++++++++++++++++++++++++ scripts/addpoller | 2 ++ scripts/install | 77 ++++++++++++++++++++++++++++++++++++++++++++ scripts/remove | 27 ++++++++++++++++ scripts/removepoller | 2 ++ scripts/upgrade | 35 ++++++++++++++++++++ sources | 1 + 11 files changed, 248 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 conf/nginx.conf create mode 100644 conf/poller-cron create mode 100644 manifest.json create mode 100644 scripts/addpoller create mode 100755 scripts/install create mode 100755 scripts/remove create mode 100644 scripts/removepoller create mode 100755 scripts/upgrade create mode 160000 sources diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 00000000..31ad2815 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# YunoHost App for Hubzilla Hub # + +Notes +-------------- + +Before installing, read the [Red Matrix installation instructions](https://github.com/redmatrix/redmatrix/blob/master/install/INSTALL.txt) for important information about + +- SSL certificate validation requirement +- Dedicated domain (must install under web root like **https://red.example.com/** not **https://example.com/red/** ) +- Required packages (these are not yet installed by this YunoHost installer package) + + + +Red Matrix +-------------- + +Current snapshot in *sources*: + +* core: 37d07a7d2a3808169b87c5033ef413ce957bf2ef) +* redmatrix-addons: 8364a6a628be16286a3569f713652a43c87e37e3 + +**Red Matrix will be re-branded as [Hubzilla](https://github.com/redmatrix/hubzilla) as part of a major release coming soon.** \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 00000000..0bea8155 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,32 @@ +location YNH_WWW_PATH { + + # Path to source + alias YNH_WWW_ALIAS/ ; + + # Force https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + + # Example PHP configuration + index index.php index.html; + try_files $uri $uri/ index.php; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + # .htaccess file from Hubzilla converted using http://winginx.com/en/htaccess + location ~ "(^|/)\.git" { return 403; } + location ~ "(^|/)store" { return 403; } + autoindex off; + location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?q=$1; } } + location ~ \.(out|log|gz)$ { deny all; } + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/conf/poller-cron b/conf/poller-cron new file mode 100644 index 00000000..e35a1ab2 --- /dev/null +++ b/conf/poller-cron @@ -0,0 +1,2 @@ +# Run poller periodically to update Hubzilla +*/10 * * * * cd YNH_WWW_PATH; php include/poller.php diff --git a/manifest.json b/manifest.json new file mode 100644 index 00000000..a60d5903 --- /dev/null +++ b/manifest.json @@ -0,0 +1,47 @@ +{ + "name": "Hubzilla", + "id": "hubzilla", + "description": { + "en": "Hubzilla is a decentralized publication platform and social network." + }, + "licence": "CopyLeft", + "developer": { + "name": "Mike Macgirvin", + "email": "", + "url": "https://github.com/redmatrix/hubzilla" + }, + "multi_instance": "false", + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for your Hubzilla hub. Hubzilla must run in the root of this domain." + }, + "example": "hub.example.com" + }, + { + "name": "admin", + "ask": { + "en": "Choose an admin user" + }, + "example": "johndoe" + }, + { + "name": "adminemail", + "ask": { + "en": "Email address for the Hubzilla hub admin" + }, + "example": "johndoe@example.com" + }, + { + "name": "is_public", + "ask": { + "en": "Is it a public application ?" + }, + "choices": ["Yes", "No"], + "default": "Yes" + } + ] + } +} diff --git a/scripts/addpoller b/scripts/addpoller new file mode 100644 index 00000000..c5f314a4 --- /dev/null +++ b/scripts/addpoller @@ -0,0 +1,2 @@ +final_path=$1 +(crontab -l ; echo "*/10 * * * * cd $final_path; php include/poller.php") 2>&1 | grep -v "no crontab" | sort | uniq | crontab - \ No newline at end of file diff --git a/scripts/install b/scripts/install new file mode 100755 index 00000000..948deb91 --- /dev/null +++ b/scripts/install @@ -0,0 +1,77 @@ +#!/bin/bash +app=hubzilla + +# Retrieve arguments +domain=$1 +admin=$2 +adminemail=$3 +is_public=$4 + +path="/" + +# Save app settings +sudo yunohost app setting $app admin -v "$admin" +sudo yunohost app setting $app is_public -v "$is_public" + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a "$app" +if [[ ! $? -eq 0 ]]; then + exit 1 +fi + +# Install dependencies +sudo apt-get install -y -qq php5-cli php5-imagick php5-gd php5-mcrypt + +# Generate random password +db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p') + +# Use 'hubzilla' as database name and user +db_user=$app + +# Initialize database and store mysql password for upgrade +sudo yunohost app initdb $db_user -p $db_pwd +sudo yunohost app setting $app mysqlpwd -v $db_pwd + +# Copy source files +final_path=/var/www/$app +sudo mkdir -p $final_path +sudo rsync -va ../sources/ $final_path/ +sudo mkdir -p "$final_path/store/[data]/smarty3" +sudo chmod -R 777 $final_path/store + +# Import database schema +sudo mysql -u $db_user -p$db_pwd $db_user < $final_path/install/schema_mysql.sql + +# Copy the template install/htconfig.sample.php to .htconfig.php +sudo cp $final_path/install/htconfig.sample.php $final_path/.htconfig.php + +# Use sed to add the database information to .htconfig.php +sudo sed -i "s/your.mysqlhost.com/localhost/g" $final_path/.htconfig.php +sudo sed -i "s/mysqlpassword/$db_pwd/g" $final_path/.htconfig.php +sudo sed -i "s/mysqlusername/$db_user/g" $final_path/.htconfig.php +sudo sed -i "s/mysqldatabasename/$db_user/g" $final_path/.htconfig.php +sudo sed -i "s/myredsite.example/$domain/g" $final_path/.htconfig.php +sudo sed -i "s/[\'admin_email\'] = \'\';/[\'admin_email\'] = \'$adminemail\';/g" $final_path/.htconfig.php +sudo sed -i "s/if the auto install failed, put a unique random string here/$db_pwd$db_pwd$db_pwd/g" $final_path/.htconfig.php + +# Set www-data to owner +sudo chown -R www-data: $final_path + +# Set up poller +sed -i "s@YNH_WWW_PATH@$final_path@g" ../conf/poller-cron +sudo cp ../conf/poller-cron /etc/cron.d/poller-cron + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf +sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf + +# If app is public, add url to SSOWat conf as skipped_uris +if [ "$is_public" = "Yes" ]; +then + sudo yunohost app setting $app skipped_uris -v "/" +fi + +# Restart services +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove new file mode 100755 index 00000000..eaca7799 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,27 @@ +#!/bin/bash +app=hubzilla + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +admin=$(sudo yunohost app setting $app admin) +is_public=$(sudo yunohost app setting $app is_public) + +db_user=$app +db_name=$app +root_pwd=$(sudo cat /etc/yunohost/mysql) +domain=$(sudo yunohost app setting $app domain) + +mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" +# Remove sources +sudo rm -rf /var/www/$app + +# Remove configuration files +sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf + +# Remove poller cron job +sudo rm -f /etc/cron.d/poller-cron + +# Restart services +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/removepoller b/scripts/removepoller new file mode 100644 index 00000000..219b2fc7 --- /dev/null +++ b/scripts/removepoller @@ -0,0 +1,2 @@ +final_path=$1 +(crontab -l ; echo "*/10 * * * * cd $final_path; php include/poller.php") 2>&1 | grep -v "no crontab" | grep -v "include/poller.php" | sort | uniq | crontab - \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100755 index 00000000..abd94112 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,35 @@ +#!/bin/bash +app=hubzilla + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +admin=$(sudo yunohost app setting $app admin) +is_public=$(sudo yunohost app setting $app is_public) + +# Remove trailing "/" for next commands +path=${path%/} + +# Copy source files +final_path=/var/www/$app +sudo mkdir -p $final_path +sudo rsync -va ../sources/ $final_path/ + +# Set www-data to owner +sudo chown -R www-data: $final_path + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf +sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf + +# If app is public, add url to SSOWat conf as skipped_uris +if [ "$is_public" = "Yes" ]; +then + sudo yunohost app setting $app skipped_uris -v "/" +fi + +# Restart services +sudo service nginx reload +sudo yunohost app ssowatconf + diff --git a/sources b/sources new file mode 160000 index 00000000..2a59392b --- /dev/null +++ b/sources @@ -0,0 +1 @@ +Subproject commit 2a59392ba8be974a5deec2e6f15959fde21186ea