#!/bin/bash set -e # Retrieve arguments domain=$1 path=$2 is_public=$3 final_path=/var/www/shout # Ensure that it is installed on Debian Jessie VERSION=$(sed 's/\..*//' /etc/debian_version) if [[ "$VERSION" == '7' ]]; then echo "You need at least Debian 8 (Jessie) to run this app" && exit 1 fi # Check domain/path availability sudo yunohost app checkurl $domain$path -a shout path=${path%/} # Install dependencies sudo apt-get update sudo apt-get install nodejs-legacy npm -y # Create user sudo useradd -d $final_path shout \ || echo "User already created" # Modify the random username user=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') sed -i "s@USERTOCHANGE@$user@g" ../conf/user.json sed -i "s@PATHTOCHANGE@$path/@g" ../conf/config.js # HACK: Change the socket.io path in the sources sed -i "s@PATHTOCHANGE@$path@g" ../sources/client/js/shout.js # Copy files to the right place sudo mkdir -p $final_path/.shout/users sudo cp ../conf/config.js $final_path/.shout/ sudo cp ../conf/user.json $final_path/.shout/users/$user.json sudo cp -a ../sources/* $final_path/ # Set permissions sudo chown -hR shout $final_path # Install dependencies sudo su -c "cd $final_path && /usr/bin/npm install --production" shout # Modify Nginx configuration file and copy it to Nginx conf directory if [[ "$path" == "" ]]; then sed -i "s@LOCATIONTOCHANGE@/@g" ../conf/nginx.conf else sed -i "s@LOCATIONTOCHANGE@$path@g" ../conf/nginx.conf fi sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shout.conf # Copy systemd service sudo cp ../conf/systemd.service /etc/systemd/system/shout.service # Add YunoHost service sudo yunohost service add shout -l /var/log/syslog # Make app public if necessary sudo yunohost app setting shout is_public -v "$is_public" if [ "$is_public" = "Yes" ]; then sudo yunohost app setting shout unprotected_uris -v "/" fi # Reload Nginx, shout and regenerate SSOwat conf sudo service nginx reload sudo systemctl enable shout sudo systemctl start shout || sudo systemctl restart shout sudo yunohost app ssowatconf