diff --git a/scripts/install b/scripts/install index 71bf15e..3fb51e6 100755 --- a/scripts/install +++ b/scripts/install @@ -1,18 +1,23 @@ #!/bin/bash +# Exit on command errors and treat unset variables as an error +set -eu + # Retrieve arguments -domain=$1 -is_public=$2 +domain=$YUNOHOST_APP_ARG_DOMAIN +is_public=$YUNOHOST_APP_ARG_IS_PUBLIC + +# Save app settings + +ynh_app_setting_set "$app" is_public "$is_public" # Source YunoHost helpers . /usr/share/yunohost/helpers # Check domain/path availability -sudo yunohost app checkurl $domain -a diaspora -if [[ ! $? -eq 0 ]] -then - exit 1 -fi +sudo yunohost app checkurl $domain -a "$app" \ + || ynh_die "Domain not available: ${domain}${path_url}" + ori_path=$(pwd) final_path=/var/www/diaspora @@ -28,7 +33,7 @@ sudo apt-get install -y -- \ libmagickwand-dev nodejs-legacy npm redis-server # Get source code -git clone -b master git://github.com/diaspora/diaspora.git +git clone -b master https://github.com/diaspora/diaspora echo $(pwd) @@ -37,15 +42,21 @@ tar -cf source.tar.gz diaspora/ mv source.tar.gz diaspora/public/source.tar.gz sudo cp -ar diaspora $final_path/../. -# 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') +### 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. -# Use 'diaspora' as database name and user -db_user=diaspora +# 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" -# Initialize database and store mysql password for upgrade -sudo yunohost app setting diaspora mysqlpwd -v "$db_pwd" -ynh_mysql_create_db diaspora_production "$db_user" "$db_pwd" +# Load initial SQL into the new database + ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \ +# < "../sources/sql/mysql.init.sql" +### MySQL end ### # prepare and copy diaspora config file sed -i "s@FULLURLTOCHANGE@$full_url@g" ../conf/diaspora.yml