1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/headphones_ynh.git synced 2024-09-03 19:26:02 +02:00
headphones_ynh/scripts/install
Snipees 9026d270c8 📦 init
import files
2015-08-23 17:57:27 +02:00

135 lines
4.6 KiB
Bash

#!/bin/bash
#debug commands
#exec > >(tee /tmp/debug-install.log)
#exec 2>&1
# Retrieve arguments
app_domain=$1
app_path=$2
app_host=$3
app_port=$4
app_fork=$5
app_opts=$6
# Set variables
app_id=headphones
app_user=headphones
app_install_dir=/opt/yunohost/$app_id
app_data_dir=/home/yunohost.app/$app_id
app_logs_dir=/var/log/$app_id
app_pid_file=/var/run/$app_id/$app_id.pid
app_config_file=$app_data_dir/config.ini
app_init_file=$app_install_dir/init-scripts/init.ubuntu
app_python_bin=/usr/bin/python
# Check domain/path availability
sudo yunohost app checkurl $app_domain$app_path -a $app_id
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Check port availability
sudo yunohost app checkport $app_port
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Make install if localhost installation
if [[ $app_host == "127.0.0.1" ]]; then
# Make directories
sudo mkdir -p $app_logs_dir
sudo mkdir -p $app_data_dir
sudo mkdir -p $app_install_dir
# Install the latest version of App using the fork
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
# Create App user
id -u $app_user &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app_user
# Configure daemon
sudo sed -i "s@USERTOCHANGE@$app_user@g" ../conf/$app_id
sudo sed -i "s@APPDIRTOCHANGE@$app_install_dir@g" ../conf/$app_id
sudo sed -i "s@DATADIRTOCHANGE@$app_data_dir@g" ../conf/$app_id
sudo sed -i "s@PIDFILETOCHANGE@$app_pid_file@g" ../conf/$app_id
sudo sed -i "s@PYTBINTOCHANGE@$app_python_bin@g" ../conf/$app_id
sudo sed -i "s@OPTSTOCHANGE@$app_config_file@g" ../conf/$app_id
sudo sed -i "s@PORTTOCHANGE@$app_port@g" ../conf/$app_id
sudo cp -a ../conf/$app_id /etc/default/$app_id
sudo cp -a $app_init_file /etc/init.d/$app_id
# Configure App
sudo sed -i "s@PATHTOCHANGE@$app_path@g" ../conf/config.ini
sudo sed -i "s@PORTTOCHANGE@$app_port@g" ../conf/config.ini
sudo sed -i "s@APPDIRTOCHANGE@$app_install_dir@g" ../conf/config.ini
sudo sed -i "s@LOGSDIRTOCHANGE@$app_logs_dir@g" ../conf/config.ini
sudo cp -a ../conf/config.ini $app_config_file
# 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)
sudo sed -i "s@download_torrent_dir =.*@download_torrent_dir = ${ref_value[0]}@g" ../conf/config.ini
sudo sed -i "s@transmission_host =.*@transmission_host = http://${ref_value[1]}:${ref_value[2]}${ref_value[3]}@g" ../conf/config.ini
sudo sed -i "s@transmission_username =.*@transmission_username = ${ref_value[4]}@g" ../conf/config.ini
sudo sed -i "s@transmission_password =.*@transmission_password = ${ref_value[5]}@g" ../conf/config.ini
sudo sed -i "s@torrent_downloader =.*@torrent_downloader = 1@g" ../conf/config.ini
sudo sed -i "s@keep_torrent_files =.*@keep_torrent_files = 1@g" ../conf/config.ini
sudo sed -i "s@prefer_torrents =.*@prefer_torrents = 1@g" ../conf/config.ini
sudo cp -a ../conf/config.ini $app_config_file
;;
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
sudo yunohost service add $app_id --log $app_logs_dir/ --status "ps aux | grep $app_id | grep -v grep"
# Start daemon at boot
sudo update-rc.d $app_id defaults
# Reload daemon
sudo service $app_id restart
fi
# Remove trailing "/" for next commands
app_path=${app_path%/}
# Configure Nginx
sudo sed -i "s@IPTOCHANGE@$app_host@g" ../conf/nginx.conf
sudo sed -i "s@PORTTOCHANGE@$app_port@g" ../conf/nginx.conf
sudo sed -i "s@PATHTOCHANGE@$app_path@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$app_domain.d/$app_id.conf
# Store used IP for upgrades
sudo yunohost app setting $app_id host -v $app_host
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
echo $?
sudo yunohost app ssowatconf