#!/bin/bash set -e # Retrieve arguments domain=$1 path=$2 is_public=$3 final_path=/var/www/thelounge # Check domain/path availability sudo yunohost app checkurl $domain$path -a thelounge path=${path%/} # Install dependencies sudo apt-get update sudo apt-get install nodejs -y # Create user sudo useradd -d $final_path thelounge\ || 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/lounge.js # Copy files to the right place sudo mkdir -p $final_path/.lounge/users sudo cp ../conf/config.js $final_path/.lounge/ sudo cp ../conf/user.json $final_path/.lounge/users/$user.json sudo cp -a ../sources/* $final_path/ # Set permissions sudo chown -hR thelounge $final_path # Install dependencies sudo su - thelounge -c "cd $final_path && /usr/bin/npm install" # 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/thelounge.conf # Copy systemd service sudo cp ../conf/systemd.service /etc/systemd/system/thelounge.service # Add YunoHost service sudo yunohost service add thelounge -l /var/log/syslog # Make app public if necessary sudo yunohost app setting thelounge is_public -v "$is_public" if [ "$is_public" = "Yes" ]; then sudo yunohost app setting thelounge unprotected_uris -v "/" fi # Reload Nginx, thelounge and regenerate SSOwat conf sudo service nginx reload sudo systemctl enable thelounge sudo systemctl start thelounge || sudo systemctl restart thelounge sudo yunohost app ssowatconf