diff --git a/check_process b/check_process new file mode 100644 index 0000000..2f63183 --- /dev/null +++ b/check_process @@ -0,0 +1,32 @@ +;; Test complet + auto_remove=1 + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + language="fr" + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=0 + setup_public=0 + upgrade=0 + backup_restore=0 + multi_instance=0 + incorrect_path=0 + corrupt_source=0 + fail_download_source=0 + port_already_use=0 + final_path_already_use=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + Level 4=1 + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 diff --git a/manifest.json b/manifest.json index 6d5dacd..2c57fe1 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ "fr": "Client web pour CalDAV" }, "url": "http://agendav.org/", - "license": "GPL-3", + "license": "GPL-3.0", "version": "2.0.0", "maintainer": { "name": "julien", @@ -15,7 +15,7 @@ }, "multi_instance": false, "requirements": { - "yunohost": ">= 2.4.0" + "yunohost": ">= 2.7.0" }, "services": [ "nginx", diff --git a/scripts/backup b/scripts/backup index 7b57653..eb67ce2 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,15 +1,19 @@ #!/bin/bash -set -eu +# Source local helpers +source ./_common.sh + +# Source app helpers +source /usr/share/yunohost/helpers + +# Abort script if errors +ynh_abort_if_errors # Set app specific variables app="$YNH_APP_INSTANCE_NAME" dbname=$app dbuser=$app -# Source YunoHost helpers -source /usr/share/yunohost/helpers - # Retrieve app settings domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) diff --git a/scripts/install b/scripts/install index 8a895c2..c90863c 100644 --- a/scripts/install +++ b/scripts/install @@ -1,23 +1,28 @@ #!/bin/bash -set -eu - -# Retrieve arguments -domain=$1 -path=${2%/} -language=$3 - -# Source common variables and helpers +# Source local helpers source ./_common.sh +# Source app helpers +source /usr/share/yunohost/helpers + +# Abort script if errors +ynh_abort_if_errors + +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path=$YNH_APP_ARG_PATH +language=$YNH_APP_ARG_LANGUAGE + # Set app specific variables -app="$YNH_APP_INSTANCE_NAME" +app=$YNH_APP_INSTANCE_NAME dbname=$app dbuser=$app -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || exit 1 +# Check web path availability +ynh_webpath_available "$domain" "$path" +# Register (book) web path +ynh_webpath_register "$app" "$domain" "$path" # Set and store language language=${LANGUAGES[$3]} @@ -33,10 +38,10 @@ DESTDIR="/var/www/${app}" You should safely delete it before installing this app." # Check whether Baïkal or Radicale is installed -if sudo yunohost app list --installed -f baikal | grep -q id ; then +if yunohost app list --installed -f baikal | grep -q id ; then caldav_app="baikal" caldav_baseurl="/cal.php/" -elif sudo yunohost app list --installed -f radicale | grep -q id ; then +elif yunohost app list --installed -f radicale | grep -q id ; then caldav_app="radicale" caldav_baseurl="/" else @@ -76,31 +81,31 @@ sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path" sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path" # Install files and set permissions -sudo mv "$TMPDIR" "$DESTDIR" +mv "$TMPDIR" "$DESTDIR" -sudo useradd -c "$app system account" \ +useradd -c "$app system account" \ -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin \ || ynh_die "Unable to create $app system account" # Protect source code against modifications -sudo find "${DESTDIR}" -type f -exec chown root:root {} \; -exec chmod 644 {} \; -sudo find "${DESTDIR}" -type d -exec chown root:root {} \; -exec chmod 755 {} \; +find "${DESTDIR}" -type f -exec chown root:root {} \; -exec chmod 644 {} \; +find "${DESTDIR}" -type d -exec chown root:root {} \; -exec chmod 755 {} \; # Only agendav user should write here -sudo chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig} -sudo chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig} +chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig} +chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig} # The agendav user should read here, but does not need to write # Other users should not be able to read as it stores passwords. -sudo find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \; -sudo find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \; +find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \; +find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \; # Create log directory -sudo install -m 750 -o $app -g adm -d "$LOGDIR" +install -m 750 -o $app -g adm -d "$LOGDIR" # Initialize database ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" -(cd "$DESTDIR" && sudo sudo -u $app \ +(cd "$DESTDIR" && -u $app \ php agendavcli migrations:migrate --no-interaction) \ || ynh_die "Unable to create AgenDAV tables" @@ -112,7 +117,7 @@ sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf # comment redirection in case of an installation at root [[ -n "$path" ]] || sed -i '$s/^/#/' ../conf/nginx.conf -sudo cp ../conf/nginx.conf "$nginx_conf" +cp ../conf/nginx.conf "$nginx_conf" # Copy and set php-fpm configuration phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" @@ -120,8 +125,8 @@ sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf sed -i "s@{USER}@${app}@g" ../conf/php-fpm.conf sed -i "s@{GROUP}@${app}@g" ../conf/php-fpm.conf -sudo cp ../conf/php-fpm.conf "$phpfpm_conf" +cp ../conf/php-fpm.conf "$phpfpm_conf" # Reload services -sudo service php5-fpm restart -sudo service nginx reload +service php5-fpm restart +service nginx reload diff --git a/scripts/remove b/scripts/remove index 3c22df3..a2e4b3d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,13 +1,16 @@ #!/bin/bash +# Source local helpers +source ./_common.sh + +# Source app helpers +source /usr/share/yunohost/helpers + # Set app specific variables app="$YNH_APP_INSTANCE_NAME" dbname=$app dbuser=$app -# Source YunoHost helpers -source /usr/share/yunohost/helpers - # Drop MySQL database and user ynh_mysql_drop_db "$dbname" || true ynh_mysql_drop_user "$dbuser" || true @@ -16,16 +19,16 @@ ynh_mysql_drop_user "$dbuser" || true domain=$(ynh_app_setting_get "$app" domain) # Delete app directory and configurations -sudo rm -rf "/var/www/${app}" "/var/log/${app}" -sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf" -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +rm -rf "/var/www/${app}" "/var/log/${app}" +rm -f "/etc/php5/fpm/pool.d/${app}.conf" +[[ -n $domain ]] && rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Reload services -sudo service php5-fpm restart || true -sudo service nginx reload || true +service php5-fpm restart || true +service nginx reload || true # Remove the user account # (must be done after php-fpm restart) id "$app" >/dev/null 2>&1 \ - && sudo deluser --quiet --remove-home "$app" >/dev/null \ + && deluser --quiet --remove-home "$app" >/dev/null \ || true diff --git a/scripts/restore b/scripts/restore index 8a8bca2..98befe9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,6 +1,13 @@ #!/bin/bash -set -eu +# Source local helpers +source ./_common.sh + +# Source app helpers +source /usr/share/yunohost/helpers + +# Abort script if errors +ynh_abort_if_errors # Set app specific variables app="$YNH_APP_INSTANCE_NAME" @@ -15,9 +22,8 @@ domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) dbpass=$(ynh_app_setting_get "$app" mysqlpwd) -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || exit 1 +# Check web path availability +ynh_webpath_available "$domain" "$path" # Check destination directory DESTDIR="/var/www/$app" @@ -36,10 +42,10 @@ phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" You should safely delete it before restoring this app." # Check whether Baïkal or Radicale is installed -if sudo yunohost app list --installed -f baikal | grep -q id ; then +if yunohost app list --installed -f baikal | grep -q id ; then caldav_app="baikal" caldav_baseurl="/cal.php/" -elif sudo yunohost app list --installed -f radicale | grep -q id ; then +elif yunohost app list --installed -f radicale | grep -q id ; then caldav_app="radicale" caldav_baseurl="/" else @@ -47,50 +53,50 @@ else fi if ! id -u $app > /dev/null 2>&1 ; then - sudo useradd -c "$app system account" \ + useradd -c "$app system account" \ -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin \ || ynh_die "Unable to create $app system account" fi # Restore the app files and set permissions -sudo cp -a ./sources "$DESTDIR" +cp -a ./sources "$DESTDIR" # Protect source code against modifications -sudo chown -hR root: "$DESTDIR" +chown -hR root: "$DESTDIR" # Only agendav user should write here -sudo chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig} -sudo chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig} +chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig} +chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig} # The agendav user should read here, but does not need to write # Other users should not be able to read as it stores passwords. -sudo find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \; -sudo find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \; +find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \; +find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \; # Clean caches -sudo rm -rf "${DESTDIR}/web/var/cache/"{profiler,twig}/* +rm -rf "${DESTDIR}/web/var/cache/"{profiler,twig}/* # CalDAV config caldav_domain=$(ynh_app_setting_get "$caldav_app" domain) caldav_path=$(ynh_app_setting_get "$caldav_app" path) caldav_url="https://${caldav_domain}${caldav_path%/}" conf_path="${DESTDIR}/web/config/settings.php" -sudo sed -i "s@^\(\$app\['caldav.baseurl'\] = \).*\ +sed -i "s@^\(\$app\['caldav.baseurl'\] = \).*\ @\1'${caldav_url}${caldav_baseurl}';@g" "$conf_path" -sudo sed -i "s@^\(\$app\['caldav.baseurl.public'\] = \).*\ +sed -i "s@^\(\$app\['caldav.baseurl.public'\] = \).*\ @\1'${caldav_domain}';@g" "$conf_path" # Create log directory -sudo install -m 750 -o www-data -g adm -d "/var/log/${app}" +install -m 750 -o www-data -g adm -d "/var/log/${app}" # Create and restore the database ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql # Restore configuration files -sudo cp -a ./nginx.conf "$nginx_conf" -sudo cp -a ./php-fpm.conf "$phpfpm_conf" +cp -a ./nginx.conf "$nginx_conf" +cp -a ./php-fpm.conf "$phpfpm_conf" # Reload services -sudo service php5-fpm restart -sudo service nginx reload +service php5-fpm restart +service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade index 7ab8868..17ce37a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,10 +1,14 @@ #!/bin/bash -set -eu - -# Source common variables and helpers +# Source local helpers source ./_common.sh +# Source app helpers +source /usr/share/yunohost/helpers + +# Abort script if errors +ynh_abort_if_errors + # Set app specific variables app="$YNH_APP_INSTANCE_NAME" dbname=$app @@ -39,10 +43,10 @@ DESTDIR="/var/www/$app" The app is not correctly installed, you should remove it first." # Check whether Baïkal or Radicale is installed -if sudo yunohost app list --installed -f baikal | grep -q id ; then +if yunohost app list --installed -f baikal | grep -q id ; then caldav_app="baikal" caldav_baseurl="/cal.php/" -elif sudo yunohost app list --installed -f radicale | grep -q id ; then +elif yunohost app list --installed -f radicale | grep -q id ; then caldav_app="radicale" caldav_baseurl="/" else @@ -76,32 +80,32 @@ sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path" sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path" # Replace files and set permissions -sudo rm -rf "$DESTDIR" -sudo mv "$TMPDIR" "$DESTDIR" +rm -rf "$DESTDIR" +mv "$TMPDIR" "$DESTDIR" if ! id -u $app > /dev/null 2>&1 ; then - sudo useradd -c "$app system account" \ + useradd -c "$app system account" \ -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin \ || ynh_die "Unable to create $app system account" fi # Protect source code against modifications -sudo find "${DESTDIR}" -type f -exec chown root:root {} \; -exec chmod 644 {} \; -sudo find "${DESTDIR}" -type d -exec chown root:root {} \; -exec chmod 755 {} \; +find "${DESTDIR}" -type f -exec chown root:root {} \; -exec chmod 644 {} \; +find "${DESTDIR}" -type d -exec chown root:root {} \; -exec chmod 755 {} \; # Only agendav user should write here -sudo chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig} -sudo chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig} +chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig} +chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig} # The agendav user should read here, but does not need to write # Other users should not be able to read as it stores passwords. -sudo find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \; -sudo find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \; +find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \; +find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \; # Create log directory -sudo install -m 750 -o $app -g adm -d "$LOGDIR" +install -m 750 -o $app -g adm -d "$LOGDIR" # Run database migrations -(cd "$DESTDIR" && sudo sudo -u $app \ +(cd "$DESTDIR" && -u $app \ php agendavcli migrations:migrate --no-interaction) \ || ynh_die "Unable to run AgenDAV database migration" @@ -113,7 +117,7 @@ sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf # comment redirection in case of an installation at root [[ -n "$path" ]] || sed -i '$s/^/#/' ../conf/nginx.conf -sudo cp ../conf/nginx.conf "$nginx_conf" +cp ../conf/nginx.conf "$nginx_conf" # Copy and set php-fpm configuration phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" @@ -121,8 +125,8 @@ sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf sed -i "s@{USER}@${app}@g" ../conf/php-fpm.conf sed -i "s@{GROUP}@${app}@g" ../conf/php-fpm.conf -sudo cp ../conf/php-fpm.conf "$phpfpm_conf" +cp ../conf/php-fpm.conf "$phpfpm_conf" # Reload services -sudo service php5-fpm restart || true -sudo service nginx reload || true +service php5-fpm restart || true +service nginx reload || true