2015-02-17 03:39:33 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
2015-03-01 23:06:20 +01:00
|
|
|
user=$2
|
|
|
|
is_public=$3
|
2015-02-17 03:39:33 +01:00
|
|
|
|
2015-05-30 09:24:35 +02:00
|
|
|
versionname=$(lsb_release -a | grep Codename | awk -F' ' '{print $2}')
|
|
|
|
|
2015-02-17 03:39:33 +01:00
|
|
|
# Check user parameter
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$user\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
echo "Wrong user"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sudo yunohost app setting diaspora admin_user -v $user
|
|
|
|
|
|
|
|
# Check domain/path availability
|
2015-03-01 23:06:20 +01:00
|
|
|
sudo yunohost app checkurl $domain -a diaspora
|
2015-02-17 03:39:33 +01:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ori_path=$(pwd)
|
|
|
|
final_path=/var/www/diaspora
|
2015-03-01 23:06:20 +01:00
|
|
|
full_url=https://$domain
|
|
|
|
|
|
|
|
sudo yunohost app setting diaspora final_path -v $final_path
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# configure sys apt-get
|
|
|
|
|
|
|
|
cat /etc/apt/sources.list | grep -q backports
|
|
|
|
[ $? != 0 ] && sudo su -c "echo 'deb http://http.debian.net/debian wheezy-backports main' >> /etc/apt/sources.list"
|
|
|
|
|
|
|
|
# get sys deps
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install gawk libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake bison libffi-dev\
|
|
|
|
build-essential libssl-dev libcurl4-openssl-dev libxml2-dev libxslt-dev imagemagick ghostscript git curl libmysqlclient-dev\
|
|
|
|
libmagickwand-dev nodejs-legacy npm -y
|
2015-05-30 09:24:35 +02:00
|
|
|
|
|
|
|
[ "$versionname" == "wheezy" ] && sudo apt-get install -t wheezy-backports redis-server -y
|
|
|
|
[ "$versionname" != "wheezy" ] && sudo apt-get install redis-server -y
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# get source code
|
|
|
|
git clone -b master git://github.com/diaspora/diaspora.git
|
2015-03-01 23:06:20 +01:00
|
|
|
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
tar -cf source.tar.gz diaspora/
|
|
|
|
mv source.tar.gz diaspora/public/source.tar.gz
|
2015-03-01 23:51:00 +01:00
|
|
|
sudo cp -ar diaspora $final_path/../.
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# Generate random password
|
|
|
|
|
|
|
|
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
|
|
|
|
# Use 'diaspora' as database name and user
|
2015-02-17 11:13:33 +01:00
|
|
|
db_user=diaspora
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# Initialize database and store mysql password for upgrade
|
|
|
|
sudo yunohost app initdb $db_user -p $db_pwd -d diaspora_production
|
|
|
|
sudo yunohost app setting diaspora mysqlpwd -v $db_pwd
|
|
|
|
|
|
|
|
# prepare and copy diaspora config file
|
|
|
|
sed -i "s@FULLURLTOCHANGE@$full_url@g" ../conf/diaspora.yml
|
|
|
|
sed -i "s@DBUSERTOCHANGE@$db_user@g" ../conf/database.yml
|
2015-03-01 23:06:20 +01:00
|
|
|
sed -i "s@DBPASSTOCHANGE@$db_pwd@g" ../conf/database.yml
|
2015-02-17 03:39:33 +01:00
|
|
|
sudo cp ../conf/diaspora.yml $final_path/config/
|
|
|
|
sudo cp ../conf/database.yml $final_path/config/
|
|
|
|
|
|
|
|
# install startup script
|
2015-02-17 11:13:33 +01:00
|
|
|
sudo cp ../conf/diaspora_ynh /etc/init.d/diaspora_ynh
|
|
|
|
sudo chmod 754 /etc/init.d/diaspora_ynh
|
|
|
|
sudo update-rc.d diaspora_ynh defaults
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# create and config user
|
2015-03-01 23:06:20 +01:00
|
|
|
sudo adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-login --quiet --home $final_path diaspora
|
2015-02-17 11:55:45 +01:00
|
|
|
sudo chown -R diaspora:diaspora $final_path
|
2015-02-17 03:39:33 +01:00
|
|
|
|
2015-02-18 12:20:25 +01:00
|
|
|
# Config RVM and force get app deps (for debug)
|
2015-03-01 23:06:20 +01:00
|
|
|
sudo su - diaspora -c "curl -sSL https://rvm.io/mpapis.asc | gpg --import - ; curl -L dspr.tk/1t | bash;"
|
|
|
|
#sudo su - diaspora -c "rvm autolibs read-fail ; rvm install 2.0 ; rvm use 2.0.0 --default"
|
|
|
|
|
2015-05-30 23:06:45 +02:00
|
|
|
#add user to sudoers for install
|
|
|
|
DIASPORASUDOERSCONF="diaspora ALL=(ALL:ALL) NOPASSWD: ALL #yunhost_diaspora"
|
|
|
|
sudo cat /etc/sudoers | grep yunhost_diaspora -q
|
|
|
|
if [ $? != 0 ] ; then sudo su -c "echo '$DIASPORASUDOERSCONF' >>/etc/sudoers" ; fi
|
|
|
|
|
2015-03-01 23:06:20 +01:00
|
|
|
sudo su - diaspora -c "rvm install 2.0"
|
|
|
|
|
2015-05-30 23:06:45 +02:00
|
|
|
#rm user from sudoers
|
|
|
|
sudo cat /etc/sudoers | grep yunhost_diaspora -q
|
|
|
|
if [ $? == 0 ] ; then sudo sed -i '/yunhost_diaspora/d' /etc/sudoers ; fi
|
|
|
|
|
2015-05-30 09:24:35 +02:00
|
|
|
#sudo env REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-user-install
|
|
|
|
sudo su - diaspora -c "env REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-user-install"
|
|
|
|
sudo su - diaspora -c "gem install bundler"
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# construct diaspora app
|
2015-03-01 23:06:20 +01:00
|
|
|
sudo su - diaspora -c "RAILS_ENV=production bundle install --without test development"
|
|
|
|
sudo su - diaspora -c "RAILS_ENV=production bundle exec rake db:create db:schema:load"
|
|
|
|
sudo su - diaspora -c "RAILS_ENV=production bundle exec rake assets:precompile"
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
cd $ori_path
|
|
|
|
|
2015-03-01 23:06:20 +01:00
|
|
|
# debug foreman module and start service
|
|
|
|
sudo mv $final_path/.profile $final_path/.profile.bak
|
2015-02-17 11:13:33 +01:00
|
|
|
sudo service diaspora_ynh start
|
2015-02-17 03:39:33 +01:00
|
|
|
|
|
|
|
# config nginx
|
2015-03-01 23:06:20 +01:00
|
|
|
cat /etc/nginx/conf.d/$domain.conf | grep -q "diaspora_server"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
sudo su - -c "cat $ori_path/../conf/nginx_upstream.conf >>/etc/nginx/conf.d/$domain.conf"
|
|
|
|
fi
|
|
|
|
|
2015-02-17 03:39:33 +01:00
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
2015-03-01 23:06:20 +01:00
|
|
|
sed -i "s@ROOTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
2015-02-17 03:39:33 +01:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/diaspora.conf
|
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app setting diaspora skipped_uris -v "/"
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
|
|
|
#protect URIs
|
|
|
|
|
|
|
|
if [ $is_public = "No" ];
|
|
|
|
then
|
|
|
|
sudo yunohost app setting diaspora protected_uris -v "/"
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
fi
|
|
|
|
|