diff --git a/conf/config.json.php b/conf/config.json.php new file mode 100644 index 0000000..69a0604 --- /dev/null +++ b/conf/config.json.php @@ -0,0 +1,60 @@ + diff --git a/conf/datastore.php b/conf/datastore.php new file mode 100644 index 0000000..fa93c7f --- /dev/null +++ b/conf/datastore.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/conf/gen_hash.php b/conf/gen_hash.php new file mode 100644 index 0000000..e69dae1 --- /dev/null +++ b/conf/gen_hash.php @@ -0,0 +1,7 @@ + + diff --git a/conf/ipbans.php b/conf/ipbans.php new file mode 100644 index 0000000..9dadae2 --- /dev/null +++ b/conf/ipbans.php @@ -0,0 +1,10 @@ + + array ( + ), + 'BANS' => + array ( + ), +); +?> \ No newline at end of file diff --git a/conf/lastupdatecheck.txt b/conf/lastupdatecheck.txt new file mode 100644 index 0000000..2c2927f --- /dev/null +++ b/conf/lastupdatecheck.txt @@ -0,0 +1 @@ +0.7.0 */ \ No newline at end of file diff --git a/conf/log.txt b/conf/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/conf/updates.txt b/conf/updates.txt new file mode 100644 index 0000000..fdf0452 --- /dev/null +++ b/conf/updates.txt @@ -0,0 +1 @@ +updateMethodMergeDeprecatedConfigFile;updateMethodRenameDashTags;updateMethodConfigToJson;updateMethodEscapeUnescapedConfig;updateMethodDatastoreIds \ No newline at end of file diff --git a/manifest.json b/manifest.json index 966b507..2ef9d98 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "Shaarli", "id": "shaarli", "packaging_format": 1, + "requirements": { + "yunohost": ">> 2.3.15" + }, "description": { "en": "The personal, minimalist, super-fast, no-database delicious clone", "fr": "Clone de delicious, rapide, simple et sans base de données." @@ -11,7 +14,7 @@ }, "url": "https://github.com/shaarli/Shaarli", "version": "0.8.3", - "multi_instance": "false", + "multi_instance": "true", "arguments": { "install" : [ { @@ -34,7 +37,7 @@ "default": "/shaarli" }, { - "name": "public", + "name": "is_public", "ask": { "en": "Is it a public Shaarli site ?", "fr": "Est-ce un site Shaarli public ?" @@ -68,6 +71,14 @@ "fr": "Administrateur" }, "example": "test" + }, + { + "name": "password", + "type": "password", + "ask": { + "en": "Define password for Shaarli user", + "fr": "Définissez le mot de passe de l'utilisateur Shaarli" + } } ] } diff --git a/scripts/install b/scripts/install index 3253cb3..b88c321 100644 --- a/scripts/install +++ b/scripts/install @@ -1,12 +1,38 @@ #!/bin/bash +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e + +# This is a multi-instance app, meaning it can be installed several times independently +# The id of the app as stated in the manifest is available as $YNH_APP_ID +# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +# The app instance name is available as $YNH_APP_INSTANCE_NAME +# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +# - ynhexample__{N} for the subsequent installations, with N=3,4, ... +# The app instance name is probably what you are interested the most, since this is +# guaranteed to be unique. This is a good unique identifier to define installation path, +# db names, ... +app=$YNH_APP_INSTANCE_NAME + # Retrieve arguments -domain=$1 -path=$2 -is_public=$3 -title=$4 -privatelinkbydefault=$5 -admin=$6 +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN +is_public=$YNH_APP_ARG_IS_PUBLIC +title=$YNH_APP_ARG_TITLE +privatelinkbydefault=$YNH_APP_ARG_PRIVATELINKBYDEFAULT +password=$YNH_APP_ARG_PASSWORD + +# +## Retrieve arguments +#domain=$1 +#path=$2 +#is_public=$3 +#title=$4 +#privatelinkbydefault=$5 +#admin=$6 +# # Load common variables and helpers source ./_common.sh @@ -17,10 +43,10 @@ if [[ ! $? -eq 0 ]]; then echo "Error : the chosen admin user does not exist" exit 1 fi -sudo yunohost app setting shaarli admin -v $admin +sudo yunohost app setting $app admin -v $admin # Check domain/path availability -sudo yunohost app checkurl $domain$path -a shaarli +sudo yunohost app checkurl $domain$path -a $app if [[ ! $? -eq 0 ]]; then exit 1 fi @@ -29,53 +55,81 @@ fi sudo apt-get install php5-cli -y -qq # Copy files to the right place -app_home_path=/home/yunohost.app/shaarli -final_path=/var/www/shaarli +app_home_path=/home/yunohost.app/$app +final_path=/var/www/$app sudo mkdir -p $final_path # Download and extract in /var/www extract_shaarli -sudo mkdir -p $app_home_path/data -sudo mkdir -p $app_home_path/cache -sudo mkdir -p $app_home_path/pagecache -sudo mkdir -p $app_home_path/tmp -sudo mkdir -p $app_home_path/conf -sudo chown -R www-data: $app_home_path +# +#sudo mkdir -p $app_home_path/data +#sudo mkdir -p $app_home_path/cache +#sudo mkdir -p $app_home_path/pagecache +#sudo mkdir -p $app_home_path/tmp +#sudo mkdir -p $app_home_path/conf +#sudo chown -R www-data: $app_home_path +# +# generate the salt salt=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') + +# generate the hash with the password +password_hash=$(php ../conf/gen_hash.php $password $admin $salt) + +# set the proper value for substitution if [ $privatelinkbydefault = "No" ]; then privatelinkbydefault_php=false else privatelinkbydefault_php=true fi -sudo sed -i "s@YNH_SALT@$salt@g" ../conf/init_config.php -sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/init_config.php -sudo sed -i "s@YNH_TITLE@$title@g" ../conf/init_config.php -sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault_php@g" ../conf/init_config.php -sudo sed -i "s@YNH_ADMIN@$admin@g" ../conf/init_config.php +# Prepare the configuration file +sudo sed -i "s@YNH_SALT@$salt@g" ../conf/config.json.php +sudo sed -i "s@YNH_ADMIN@$admin@g" ../conf/config.json.php +sudo sed -i "s@YNH_HASH@$password_hash@g" ../conf/config.json.php +sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/config.json.php +sudo sed -i "s@YNH_TITLE@$title@g" ../conf/config.json.php +sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault_php@g" ../conf/config.json.php -sudo cp ../conf/options.php $app_home_path/data/options.php -sudo cp ../conf/init_config.php $app_home_path/data/config.php -sudo php ../conf/init_config_user.php $(sudo yunohost user list --json | python ../conf/user_list.py) +# +#sudo sed -i "s@YNH_SALT@$salt@g" ../conf/init_config.php +#sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/init_config.php +#sudo sed -i "s@YNH_TITLE@$title@g" ../conf/init_config.php +#sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault_php@g" ../conf/init_config.php +#sudo sed -i "s@YNH_ADMIN@$admin@g" ../conf/init_config.php +# +#sudo cp ../conf/options.php $app_home_path/data/options.php +#sudo cp ../conf/init_config.php $app_home_path/data/config.php +#sudo php ../conf/init_config_user.php $(sudo yunohost user list --json | python ../conf/user_list.py) +# + +# Populate the data directory of the shaarli instance +sudo cp ../conf/config.json.php $final_path/data +sudo cp ../conf/datastore.php $final_path/data +sudo cp ../conf/ipbans.php $final_path/data +sudo cp ../conf/lastupdatecheck.txt $final_path/data +sudo cp ../conf/log.txt $final_path/data +sudo cp ../conf/updates.txt $final_path/data sudo find $final_path -type f | xargs sudo chmod 644 sudo find $final_path -type d | xargs sudo chmod 755 #sudo chown -R root: $final_path -sudo find $app_home_path -type f | xargs sudo chmod 600 -sudo find $app_home_path -type d | xargs sudo chmod 700 -sudo chown -R www-data: $app_home_path +# +#sudo find $app_home_path -type f | xargs sudo chmod 600 +#sudo find $app_home_path -type d | xargs sudo chmod 700 +#sudo chown -R www-data: $app_home_path +# # Modify Nginx configuration file and copy it to Nginx conf directory sudo sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf sudo sed -i "s@YNH_ALIAS@$final_path@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shaarli.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx and regenerate SSOwat conf if [ $is_public = "Yes" ]; then -sudo yunohost app setting shaarli unprotected_uris -v "/" +sudo yunohost app setting $app unprotected_uris -v "/" fi sudo service nginx reload sudo yunohost app ssowatconf