2014-08-26 00:49:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-12-07 23:24:59 +01:00
|
|
|
app="ethercalc"
|
|
|
|
name="ether"
|
|
|
|
name+="calc"
|
|
|
|
instance_number=$(echo $app | sed 's/[^0-9]//g')
|
2014-08-26 00:49:46 +02:00
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
|
|
|
is_public=$3
|
2014-09-08 00:23:35 +02:00
|
|
|
port=$((instance_number+8000))
|
2014-08-26 00:49:46 +02:00
|
|
|
|
|
|
|
# Check domain/path availability
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
2014-08-26 00:49:46 +02:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-12-07 23:11:39 +01:00
|
|
|
echo "Register configuration..."
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo yunohost app setting $app is_public -v $is_public
|
|
|
|
sudo yunohost app setting $app port -v $port
|
2014-08-26 00:49:46 +02:00
|
|
|
|
|
|
|
# Remove trailing "/" for next commands
|
|
|
|
path=${path%/}
|
|
|
|
|
2014-12-07 23:11:39 +01:00
|
|
|
echo "Install dependencies..."
|
|
|
|
sudo apt-get update
|
2014-08-26 00:49:46 +02:00
|
|
|
sudo apt-get install nodejs-legacy npm redis-server -y
|
|
|
|
|
2014-12-07 23:11:39 +01:00
|
|
|
echo "Installing EtherCalc with NPM..."
|
2014-12-07 23:24:59 +01:00
|
|
|
final_path=/var/www/$app
|
2014-12-07 23:11:39 +01:00
|
|
|
sudo mkdir -p $final_path
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo useradd -d $final_path $app
|
|
|
|
su --shell /bin/bash --command "cd $final_path/ && npm install --production $name" $app
|
2014-12-07 23:11:39 +01:00
|
|
|
|
|
|
|
echo "Cleaning up install tree..."
|
|
|
|
sudo rm -rf $final_path/.npm
|
|
|
|
find $final_path -type d | grep "test$" | xargs sudo rm -rf
|
|
|
|
find $final_path -type d | grep "tests$" | xargs sudo rm -rf
|
|
|
|
|
2014-12-07 23:24:59 +01:00
|
|
|
echo "Setting up permissions"
|
|
|
|
sudo chown -R ghostblog: $final_path
|
|
|
|
|
2014-12-07 23:11:39 +01:00
|
|
|
echo "Setting up init script..."
|
2014-12-07 23:24:59 +01:00
|
|
|
logfile=/var/log/$name/$app.log
|
|
|
|
sed -i "s@YUNOPORT@$port@g" ../conf/$name
|
|
|
|
sed -i "s@YUNOLOG@$app@g" ../conf/$name
|
|
|
|
sed -i "s@YUNOPATH@$path@g" ../conf/$name
|
|
|
|
sudo cp ../conf/$name /etc/init.d/$app
|
|
|
|
sudo chmod +x /etc/init.d/$app
|
|
|
|
sudo update-rc.d $app defaults
|
|
|
|
if [ ! -d "/var/log/$name/" ]; then
|
|
|
|
sudo mkdir /var/log/$name/
|
2014-09-08 00:23:35 +02:00
|
|
|
fi
|
2014-12-07 23:11:39 +01:00
|
|
|
sudo touch $logfile
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo chown $app $logfile
|
|
|
|
sudo service $app stop
|
|
|
|
sudo service $app start
|
|
|
|
sudo yunohost service add $app -l $logfile
|
2014-08-26 00:49:46 +02:00
|
|
|
|
2014-12-07 23:11:39 +01:00
|
|
|
echo "Setting up logrotate configuration..."
|
|
|
|
sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/logrotate
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/$app
|
2014-12-07 23:11:39 +01:00
|
|
|
|
|
|
|
echo "Nginx configuration ..."
|
2014-08-26 00:49:46 +02:00
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf*
|
|
|
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf*
|
2014-09-08 00:23:35 +02:00
|
|
|
sed -i "s@YUNOPORT@$port@g" ../conf/nginx.conf*
|
2014-12-07 23:24:59 +01:00
|
|
|
sed -i "s@YUNOAPP@$app@g" ../conf/nginx.conf*
|
2014-08-26 00:49:46 +02:00
|
|
|
if [ "$path" = "" ];
|
|
|
|
then
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo cp ../conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/$app.conf
|
2014-08-26 00:49:46 +02:00
|
|
|
else
|
2014-12-07 23:24:59 +01:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2014-08-26 00:49:46 +02:00
|
|
|
fi
|
|
|
|
|
2014-12-07 23:11:39 +01:00
|
|
|
echo "Reloading Nginx..."
|
2014-08-26 00:49:46 +02:00
|
|
|
sudo service nginx reload
|
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
2014-09-22 23:42:08 +02:00
|
|
|
sudo yunohost app setting ethercalc skipped_uris -v "/"
|
2014-08-26 00:49:46 +02:00
|
|
|
fi
|
|
|
|
sudo yunohost app ssowatconf
|