1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/diaspora_ynh.git synced 2024-09-03 18:26:13 +02:00
diaspora_ynh/scripts/install

152 lines
5 KiB
Text
Raw Normal View History

2015-02-17 03:39:33 +01:00
#!/bin/bash
2017-06-09 13:06:41 +02:00
# Exit on command errors and treat unset variables as an error
set -eu
2017-06-09 15:45:50 +02:00
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2017-06-09 16:36:14 +02:00
# App variable
app=$YNH_APP_INSTANCE_NAME
2017-06-09 14:50:09 +02:00
2015-02-17 03:39:33 +01:00
# Retrieve arguments
2017-06-09 16:09:19 +02:00
domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_DOMAIN
2017-06-09 13:06:41 +02:00
2017-06-09 13:13:58 +02:00
# Save app settings
2017-06-09 13:06:41 +02:00
2017-06-09 16:11:46 +02:00
ynh_app_setting_set $app is_public $is_public
2017-06-09 16:17:52 +02:00
ynh_app_setting_set $app domain $domain
2015-02-17 03:39:33 +01:00
# Check domain/path availability
2017-06-09 13:06:41 +02:00
sudo yunohost app checkurl $domain -a "$app" \
|| ynh_die "Domain not available: ${domain}${path_url}"
2015-02-17 03:39:33 +01:00
ori_path=$(pwd)
final_path=/var/www/diaspora
full_url=https://$domain
sudo yunohost app setting diaspora final_path -v $final_path
2015-02-17 03:39:33 +01:00
2015-06-25 23:42:02 +02:00
# Get sys deps
2017-06-09 16:17:52 +02:00
sudo curl -sL https://deb.nodesource.com/setup_7.x | sudo bash -
sudo apt-get install -yy -qq nodejs
2015-02-17 03:39:33 +01:00
sudo apt-get update
2015-06-25 23:42:02 +02:00
sudo apt-get install -y -- \
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 \
2017-06-09 16:17:52 +02:00
libmagickwand-dev redis-server
2015-02-17 03:39:33 +01:00
2015-06-25 23:42:02 +02:00
# Get source code
2017-06-09 13:06:41 +02:00
git clone -b master https://github.com/diaspora/diaspora
echo $(pwd)
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
2017-06-09 17:13:14 +02:00
### MySQL ###
# If your app use a MySQL database you can use these lines to bootstrap
# a database, an associated user and save the password in app settings.
# # Generate MySQL password and create database
dbuser=$app
dbname=$app
dbpass=$(ynh_string_random 12)
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# # Load initial SQL into the new database
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
2017-06-09 18:58:26 +02:00
< "../sources/sql/mysql.init.sql"
2017-06-09 17:13:14 +02:00
### MySQL end ###
2017-06-09 16:17:52 +02:00
2015-02-17 03:39:33 +01:00
# 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
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/
2015-06-25 23:42:02 +02:00
# Install startup script
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
2015-06-25 23:42:02 +02:00
# Create and config user
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
2017-02-08 23:06:06 +01:00
# Config RVM and force get app deps (for debug) and add hack for installation
2015-06-09 23:39:13 +02:00
sudo su - diaspora -c "curl --retry 5 -sSL https://rvm.io/mpapis.asc | gpg --import - ; curl --retry 5 -L dspr.tk/1t | bash;"
2017-02-08 23:06:06 +01:00
sudo su - diaspora -c "curl --retry 5 -sSL https://s.diaspora.software/1t | sed 's# bash # sed \"s/noexec/noexechack/g\" | bash #g' | bash ;"
2015-06-25 23:42:02 +02:00
# Add user to sudoers for install
2015-05-30 23:06:45 +02:00
DIASPORASUDOERSCONF="diaspora ALL=(ALL:ALL) NOPASSWD: ALL #yunhost_diaspora"
sudo cat /etc/sudoers | grep yunhost_diaspora -q
2015-06-25 23:42:02 +02:00
if [ $? != 0 ]
then
sudo su -c "echo '$DIASPORASUDOERSCONF' >> /etc/sudoers"
fi
2015-05-30 23:06:45 +02:00
2017-02-08 21:02:56 +01:00
sudo su - diaspora -c "rvm install 2.3"
2015-06-09 16:39:25 +02:00
sudo su - diaspora -c "env REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-user-install"
2015-06-10 19:58:41 +02:00
sudo su - diaspora -c "x=1; RET=1; while [ \$x -le 5 ] && [ \"\$RET\" != 0 ] ; do gem install bundler ; RET=\$? ; x=\$(( \$x + 1 )) ; done"
2015-06-25 23:42:02 +02:00
# Remove user from sudoers
2015-05-30 23:06:45 +02:00
sudo cat /etc/sudoers | grep yunhost_diaspora -q
2015-06-25 23:42:02 +02:00
if [ $? == 0 ]
then
sudo sed -i '/yunhost_diaspora/d' /etc/sudoers
fi
2015-05-30 23:06:45 +02:00
2015-02-17 03:39:33 +01:00
# construct diaspora app
2017-02-08 21:02:56 +01:00
#sudo su - diaspora -c "RAILS_ENV=production bundle install --without test development --with mysql --retry 10"
#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"
sudo su - diaspora -c "RAILS_ENV=production bin/bundle install --jobs $(nproc) --deployment --without test development --with mysql --retry 10"
sudo su - diaspora -c "RAILS_ENV=production bin/rake db:create db:schema:load"
sudo su - diaspora -c "RAILS_ENV=production bin/rake assets:precompile"
2015-02-17 03:39:33 +01:00
cd $ori_path
2015-06-25 23:42:02 +02:00
# Debug foreman module and start service
sudo mv $final_path/.profile $final_path/.profile.bak
sudo service diaspora_ynh start
2015-02-17 03:39:33 +01:00
2015-06-25 23:42:02 +02:00
# Install home page
2015-05-31 13:01:01 +02:00
sudo cp ../conf/_show.html.haml $final_path/app/views/home/_show.html.haml
2015-05-31 11:35:04 +02:00
2015-02-17 03:39:33 +01:00
# config nginx
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
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
2015-06-25 23:42:02 +02:00
# Protect URIs
if [ $is_public = "no" -o $is_public = "NO" -o $is_public = "No" ]
2015-02-17 03:39:33 +01:00
then
sudo yunohost app setting diaspora protected_uris -v "/"
sudo yunohost app ssowatconf
fi