2015-08-23 17:57:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#debug commands
|
|
|
|
#exec > >(tee /tmp/debug-install.log)
|
|
|
|
#exec 2>&1
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
app_domain=$1
|
|
|
|
app_path=$2
|
2015-09-05 17:52:58 +02:00
|
|
|
app_public=$3
|
|
|
|
app_method=$4
|
|
|
|
app_port=$5
|
|
|
|
app_fork=$6
|
|
|
|
app_opts=$7
|
|
|
|
app_host=$8
|
2015-08-23 17:57:27 +02:00
|
|
|
|
2015-09-05 17:52:58 +02:00
|
|
|
# Basic variable declaration
|
|
|
|
BASEDIR="$(dirname "$(pwd)")"
|
|
|
|
|
|
|
|
# Common variable declaration
|
2015-08-23 17:57:27 +02:00
|
|
|
app_id=headphones
|
|
|
|
app_user=headphones
|
2015-09-05 17:52:58 +02:00
|
|
|
app_local_host="127.0.0.1"
|
|
|
|
app_python_bin="/usr/bin/python"
|
|
|
|
## Destinations definitions
|
|
|
|
app_install_dir="/opt/yunohost/${app_id}"
|
|
|
|
app_data_dir="/home/yunohost.app/${app_id}"
|
|
|
|
app_logs_dir="/var/log/${app_id}"
|
|
|
|
app_config_file="${app_data_dir}/config.ini"
|
|
|
|
app_pid_file="/var/run/${app_id}/${app_id}.pid"
|
|
|
|
## Sources definitions
|
|
|
|
app_src_conf="$BASEDIR/conf/${app_id}.conf"
|
|
|
|
app_src_dfts="$BASEDIR/conf/${app_id}.defaults"
|
|
|
|
app_src_init="$BASEDIR/conf/${app_id}.init"
|
|
|
|
app_src_nginx_conf="$BASEDIR/conf/nginx.conf"
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $app_domain$app_path -a $app_id
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Make install if localhost installation
|
2015-09-05 17:52:58 +02:00
|
|
|
if [[ $app_method == "LOCAL"* ]]; then
|
|
|
|
|
|
|
|
# Check port availability
|
|
|
|
sudo yunohost app checkport $app_port
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
# Make directories
|
|
|
|
sudo mkdir -p $app_logs_dir
|
|
|
|
sudo mkdir -p $app_data_dir
|
|
|
|
sudo mkdir -p $app_install_dir
|
|
|
|
|
2015-09-05 17:52:58 +02:00
|
|
|
# Install latest version of app using the fork
|
2015-08-23 17:57:27 +02:00
|
|
|
sudo apt-get install -y git-core
|
|
|
|
sudo git clone $app_fork $app_install_dir
|
|
|
|
|
|
|
|
# Install dependencies (using virtualenv)
|
|
|
|
if [[ $(python --version 2>&1) != Python\ 2* ]]; then
|
|
|
|
app_python_bin=$app_install_dir/bin/python
|
|
|
|
sudo apt-get install -y python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python
|
|
|
|
sudo virtualenv $app_install_dir
|
|
|
|
sudo bash -c "source $app_install_dir/bin/activate && pip install cheetah"
|
|
|
|
fi
|
|
|
|
|
2015-09-05 17:52:58 +02:00
|
|
|
# Create app user
|
|
|
|
id -u $app_user &>/dev/null || sudo useradd --home-dir $app_data_dir --shell /bin/false $app_user
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
# Configure daemon
|
2015-09-05 17:52:58 +02:00
|
|
|
sudo sed -i "s@USERTOCHANGE@$app_user@g" $app_src_dfts
|
|
|
|
sudo sed -i "s@APPDIRTOCHANGE@$app_install_dir@g" $app_src_dfts
|
|
|
|
sudo sed -i "s@DATADIRTOCHANGE@$app_data_dir@g" $app_src_dfts
|
|
|
|
sudo sed -i "s@PIDFILETOCHANGE@$app_pid_file@g" $app_src_dfts
|
|
|
|
sudo sed -i "s@PYTBINTOCHANGE@$app_python_bin@g" $app_src_dfts
|
|
|
|
sudo sed -i "s@OPTSTOCHANGE@$app_config_file@g" $app_src_dfts
|
|
|
|
sudo sed -i "s@PORTTOCHANGE@$app_port@g" $app_src_dfts
|
|
|
|
sudo cp -a $app_src_dfts /etc/default/$app_id
|
|
|
|
sudo cp -a $app_src_init /etc/init.d/$app_id
|
2015-08-23 17:57:27 +02:00
|
|
|
|
2015-09-05 17:52:58 +02:00
|
|
|
# Configure app
|
|
|
|
sudo sed -i "s@PATHTOCHANGE@$app_path@g" $app_src_conf
|
|
|
|
sudo sed -i "s@PORTTOCHANGE@$app_port@g" $app_src_conf
|
|
|
|
sudo sed -i "s@APPDIRTOCHANGE@$app_install_dir@g" $app_src_conf
|
|
|
|
sudo sed -i "s@LOGSDIRTOCHANGE@$app_logs_dir@g" $app_src_conf
|
|
|
|
sudo cp -a $app_src_conf $app_config_file
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
# Configure specifics options
|
|
|
|
case "$app_opts" in
|
|
|
|
*"Transmission"*)
|
|
|
|
ref_file=$(sudo sed -n -e '/^CONFIG_DIR/ s/.*\= *//p' $(find /etc/default -name '*transmission*') | sed 's/["* ]//g')/settings.json
|
|
|
|
ref_field=(download-dir rpc-bind-address rpc-port rpc-url rpc-username rpc-password)
|
|
|
|
for i in ${ref_field[*]}; do ref_value+=$(sudo sed -n -e "/$i/ s/.*\: *//p" $ref_file | sed 's/["*,]//g'); done
|
|
|
|
ref_value=($ref_value)
|
2015-09-05 17:52:58 +02:00
|
|
|
sudo sed -i "s@download_torrent_dir =.*@download_torrent_dir = ${ref_value[0]}@g" $app_src_conf
|
|
|
|
sudo sed -i "s@transmission_host =.*@transmission_host = http://${ref_value[1]}:${ref_value[2]}${ref_value[3]}@g" $app_src_conf
|
|
|
|
sudo sed -i "s@transmission_username =.*@transmission_username = ${ref_value[4]}@g" $app_src_conf
|
|
|
|
sudo sed -i "s@transmission_password =.*@transmission_password = ${ref_value[5]}@g" $app_src_conf
|
|
|
|
sudo sed -i "s@torrent_downloader =.*@torrent_downloader = 1@g" $app_src_conf
|
|
|
|
sudo sed -i "s@keep_torrent_files =.*@keep_torrent_files = 1@g" $app_src_conf
|
|
|
|
sudo sed -i "s@prefer_torrents =.*@prefer_torrents = 1@g" $app_src_conf
|
|
|
|
sudo cp -a $app_src_conf $app_config_file
|
2015-08-23 17:57:27 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Set rights
|
|
|
|
sudo chown -R $app_user $app_install_dir
|
|
|
|
sudo chown -R $app_user $app_data_dir
|
|
|
|
sudo chown -R $app_user $app_logs_dir
|
|
|
|
sudo chmod +x /etc/init.d/$app_id
|
|
|
|
sudo chmod +x -R $app_install_dir
|
|
|
|
sudo chmod +x -R $app_data_dir
|
|
|
|
sudo chmod +x -R $app_logs_dir
|
|
|
|
|
|
|
|
# Add service to YunoHost's monitoring
|
2015-09-05 17:52:58 +02:00
|
|
|
sudo yunohost service add $app_id --log $app_logs_dir --status "ps aux | grep $app_id | grep -v grep"
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
# Start daemon at boot
|
|
|
|
sudo update-rc.d $app_id defaults
|
|
|
|
|
2015-09-05 17:52:58 +02:00
|
|
|
# Start service
|
|
|
|
sudo service $app_id start
|
|
|
|
|
|
|
|
# Set proxy host variable
|
|
|
|
app_host="http://${app_local_host}:${app_port}${app_path%/}"
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Remove trailing "/" for next commands
|
|
|
|
app_path=${app_path%/}
|
|
|
|
|
|
|
|
# Configure Nginx
|
2015-09-05 17:52:58 +02:00
|
|
|
sudo sed -i "s@PATHTOCHANGE@$app_path@g" $app_src_nginx_conf
|
|
|
|
sudo sed -i "s@HOSTTOCHANGE@$app_host@g" $app_src_nginx_conf
|
|
|
|
sudo cp $app_src_nginx_conf /etc/nginx/conf.d/$app_domain.d/$app_id.conf
|
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
|
|
|
if [[ $app_public == "Yes" ]]; then
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
|
|
|
sudo yunohost app setting $app_id unprotected_uris -v "/"
|
|
|
|
fi
|
2015-08-23 17:57:27 +02:00
|
|
|
|
2015-09-05 17:52:58 +02:00
|
|
|
# Save app settings
|
|
|
|
sudo yunohost app setting $app_id public -v "$app_public"
|
|
|
|
sudo yunohost app setting $app_id method -v "$app_method"
|
|
|
|
sudo yunohost app setting $app_id host -v "$app_host"
|
2015-08-23 17:57:27 +02:00
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|