From 4e7ec2952fb83e3dfbf5a97f4d17225626295bca Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 29 Mar 2019 05:56:59 +0100 Subject: [PATCH] Fix install and removal --- README.md | 12 ++++ check_process | 3 +- conf/.env | 53 ++++++++++----- conf/app.src | 4 +- conf/nginx.conf | 45 ++++++------- conf/php-fpm.conf | 2 +- manifest.json | 10 --- scripts/_common.sh | 6 +- scripts/_pgsql.sh | 160 --------------------------------------------- scripts/install | 32 +++++---- scripts/remove | 28 ++++---- 11 files changed, 117 insertions(+), 238 deletions(-) delete mode 100644 scripts/_pgsql.sh diff --git a/README.md b/README.md index 4dd1c54b..a94130a9 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,18 @@ Don't hesitate to give a hand if you wish, I assume only the nginx file needs im ![](https://camo.githubusercontent.com/c1c2e74057dcff57e103fcbb3239840802fcf752/68747470733a2f2f706978656c6665642e6e7963332e63646e2e6469676974616c6f6365616e7370616365732e636f6d2f6d656469612f53637265656e25323053686f74253230323031392d30322d30352532306174253230362e33342e3539253230504d2e706e67) +## Configuration + +### Administrator + +After being first registered, you need to execute the folloing command to promote first registered as admin + +**Run:** + + $ (cd /var/www/pixelfed && php artisan user:admin 1) + +and respond yes to the question ` Add admin privileges to this user?` + ## Documentation * Official documentation: https://docs.pixelfed.org/master/ diff --git a/check_process b/check_process index 2402e30b..901667fe 100644 --- a/check_process +++ b/check_process @@ -1,11 +1,10 @@ ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) - path="/path" (PATH) is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 - setup_sub_dir=1 + setup_sub_dir=0 setup_root=1 setup_nourl=0 setup_private=0 diff --git a/conf/.env b/conf/.env index 7a01e595..ccd91fe0 100644 --- a/conf/.env +++ b/conf/.env @@ -1,10 +1,13 @@ APP_NAME=__APP__ -APP_ENV=local +APP_ENV=production APP_KEY= APP_DEBUG=true -APP_URL=http://__DOMAIN____PATH__ +APP_URL=https://__DOMAIN__ -LOG_CHANNEL=stackouille +ADMIN_DOMAIN="__DOMAIN__" +APP_DOMAIN="__DOMAIN__" + +LOG_CHANNEL=stack DB_CONNECTION=pgsql DB_HOST=127.0.0.1 @@ -14,36 +17,56 @@ DB_USERNAME=__DB_USER__ DB_PASSWORD=__DB_PWD__ BROADCAST_DRIVER=log -CACHE_DRIVER=file -SESSION_DRIVER=file +CACHE_DRIVER=redis +SESSION_DRIVER=redis SESSION_LIFETIME=120 -QUEUE_DRIVER=sync +QUEUE_DRIVER=redis REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_DRIVER=smtp -MAIL_HOST=smtp.mailtrap.io -MAIL_PORT=2525 +MAIL_HOST=localhost +MAIL_PORT=25 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS="pixelfed@__DOMAIN__" +MAIL_FROM_NAME="Pixelfed" + +SESSION_DOMAIN="${APP_DOMAIN}" +SESSION_SECURE_COOKIE=true +API_BASE="/api/1/" +API_SEARCH="/api/search" + +OPEN_REGISTRATION=true +RECAPTCHA_ENABLED=false +ENFORCE_EMAIL_VERIFICATION=true PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 -SESSION_DOMAIN=".pixelfed.dev" -SESSION_SECURE_COOKIE=true -API_BASE="/api/1/" -API_SEARCH="/api/search" - -OPEN_REGISTRATION=true +MAX_PHOTO_SIZE=15000 +MAX_CAPTION_LENGTH=150 +MAX_ALBUM_LENGTH=4 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" MIX_APP_URL="${APP_URL}" MIX_API_BASE="${API_BASE}" -MIX_API_SEARCH="${API_SEARCH}" \ No newline at end of file +MIX_API_SEARCH="${API_SEARCH}" + +ACTIVITYPUB_INBOX=false +ACTIVITYPUB_SHAREDINBOX=false +HORIZON_DARKMODE=true + +# Set these both "true" to enable federation. +# You might need to also run: +# php artisan cache:clear +# php artisan optimize:clear +# php artisan optimize +ACTIVITY_PUB=false +REMOTE_FOLLOW=false diff --git a/conf/app.src b/conf/app.src index 597d9510..30825423 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/pixelfed/pixelfed/archive/12857575550a0c86a11ce1445835dcede4d37150.tar.gz -SOURCE_SUM=9228d2d0154c998f584e168ffff4a76205c3212e6c282203add136c371d931bd +SOURCE_URL=https://github.com/pixelfed/pixelfed/archive/ac53aea28884f0c49c110ac6d87a7b40e92171c9.tar.gz +SOURCE_SUM=ca6156026eb1bb8d8995d247a895b88078e93f1127b75af07058d74f57830846 OURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index a7d741cf..67b55d0a 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,36 +1,33 @@ location __PATH__ { - # Path to source - alias __FINALPATH__/public/ ; + # Path to source + alias __FINALPATH__/public/ ; + try_files $uri $uri/ @pixelfed; - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } + # Force usage of https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } index index.php; - # Common parameter to increase upload size limit in conjuction with dedicated php-fpm file - #client_max_body_size 50M; + # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file + #client_max_body_size 50M; - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php/php7.2-fpm-__NAME__.sock; - # If you don't use a dedicated fpm config for your app, - # use a general fpm pool. - # This is to be used INSTEAD of line above - # Don't forget to adjust scripts install/upgrade/remove/backup accordingly - # - #fastcgi_pass unix:/var/run/php5-fpm.sock; - - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } +location @pixelfed { + rewrite /(.*)$ /index.php?/$1 last; +} diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 4a93f0cf..6d45f960 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -33,7 +33,7 @@ group = __USER__ ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php7.2-fpm-__NAMETOCHANGE__.sock ; Set listen(2) backlog. ; Default Value: 511 (-1 on FreeBSD and OpenBSD) diff --git a/manifest.json b/manifest.json index 9d4282f7..c681704a 100644 --- a/manifest.json +++ b/manifest.json @@ -31,16 +31,6 @@ }, "example": "domain.org" }, - { - "name": "path", - "type": "path", - "ask": { - "en": "Choose a path for Pixelfed", - "fr": "Choisissez un chemin pour Pixelfed" - }, - "example": "/pixelfed", - "default": "/pixelfed" - }, { "name": "is_public", "type": "boolean", diff --git a/scripts/_common.sh b/scripts/_common.sh index a044f494..84ec0517 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,11 @@ #================================================= # dependencies used by the app -pkg_dependencies="php7.2-mbstring postgresql redis-server" +pkg_dependencies="php7.2-pgsql php7.2-mbstring php7.2-bcmath php7.2-simplexml php7.2-curl postgresql redis-server \ +php7.2-intl php7.2-exif \ +libfreetype6 libjpeg62-turbo libpng16-16 libxpm4 libvpx4 libwebp6 libmagickwand-6.q16-3 \ +php7.2-imagick imagick \ +pngquant jpegoptim gifsicle" #================================================= # PERSONAL HELPERS diff --git a/scripts/_pgsql.sh b/scripts/_pgsql.sh deleted file mode 100644 index 10314a2b..00000000 --- a/scripts/_pgsql.sh +++ /dev/null @@ -1,160 +0,0 @@ -#!/bin/bash - -#================================================= -# -# POSTGRES HELPERS -# -# Point of contact : Jean-Baptiste Holcroft -#================================================= - -# Create a master password and set up global settings -# Please always call this script in install and restore scripts -# -# usage: ynh_psql_test_if_first_run - -ynh_psql_test_if_first_run() { - if [ -f /etc/yunohost/psql ]; - then - echo "PostgreSQL is already installed, no need to create master password" - else - pgsql=$(ynh_string_random) - pg_hba="" - echo "$pgsql" >> /etc/yunohost/psql - - if [ -e /etc/postgresql/9.4/ ] - then - pg_hba=/etc/postgresql/9.4/main/pg_hba.conf - elif [ -e /etc/postgresql/9.6/ ] - then - pg_hba=/etc/postgresql/9.6/main/pg_hba.conf - else - ynh_die "postgresql shoud be 9.4 or 9.6" - fi - - systemctl start postgresql - sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$pgsql'" postgres - - # force all user to connect to local database using passwords - # https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF - # Note: we can't use peer since YunoHost create users with nologin - # See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user - sed -i '/local\s*all\s*all\s*peer/i \ - local all all password' "$pg_hba" - systemctl enable postgresql - systemctl reload postgresql - fi -} - -# Open a connection as a user -# -# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" -# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql -# -# usage: ynh_psql_connect_as user pwd [db] -# | arg: user - the user name to connect as -# | arg: pwd - the user password -# | arg: db - the database to connect to -ynh_psql_connect_as() { - local user="$1" - local pwd="$2" - local db="$3" - sudo --login --user=postgres PGUSER="$user" PGPASSWORD="$pwd" psql "$db" -} - -# # Execute a command as root user -# -# usage: ynh_psql_execute_as_root sql [db] -# | arg: sql - the SQL command to execute -# | arg: db - the database to connect to -ynh_psql_execute_as_root () { - local sql="$1" - sudo --login --user=postgres psql <<< "$sql" -} - -# Execute a command from a file as root user -# -# usage: ynh_psql_execute_file_as_root file [db] -# | arg: file - the file containing SQL commands -# | arg: db - the database to connect to -ynh_psql_execute_file_as_root() { - local file="$1" - local db="$2" - sudo --login --user=postgres psql "$db" < "$file" -} - -# Create a database, an user and its password. Then store the password in the app's config -# -# After executing this helper, the password of the created database will be available in $db_pwd -# It will also be stored as "psqlpwd" into the app settings. -# -# usage: ynh_psql_setup_db user name [pwd] -# | arg: user - Owner of the database -# | arg: name - Name of the database -# | arg: pwd - Password of the database. If not given, a password will be generated -ynh_psql_setup_db () { - local db_user="$1" - local db_name="$2" - local new_db_pwd=$(ynh_string_random) # Generate a random password - # If $3 is not given, use new_db_pwd instead for db_pwd. - local db_pwd="${3:-$new_db_pwd}" - ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database - ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config -} - -# Create a database and grant privilegies to a user -# -# usage: ynh_psql_create_db db [user [pwd]] -# | arg: db - the database name to create -# | arg: user - the user to grant privilegies -# | arg: pwd - the user password -ynh_psql_create_db() { - local db="$1" - local user="$2" - local pwd="$3" - ynh_psql_create_user "$user" "$pwd" - sudo --login --user=postgres createdb --owner="$user" "$db" -} - -# Drop a database -# -# usage: ynh_psql_drop_db db -# | arg: db - the database name to drop -# | arg: user - the user to drop -ynh_psql_remove_db() { - local db="$1" - local user="$2" - sudo --login --user=postgres dropdb "$db" - ynh_psql_drop_user "$user" -} - -# Dump a database -# -# example: ynh_psql_dump_db 'roundcube' > ./dump.sql -# -# usage: ynh_psql_dump_db db -# | arg: db - the database name to dump -# | ret: the psqldump output -ynh_psql_dump_db() { - local db="$1" - sudo --login --user=postgres pg_dump "$db" -} - - -# Create a user -# -# usage: ynh_psql_create_user user pwd [host] -# | arg: user - the user name to create -ynh_psql_create_user() { - local user="$1" - local pwd="$2" - sudo --login --user=postgres psql -c"CREATE USER $user WITH PASSWORD '$pwd'" postgres -} - -# Drop a user -# -# usage: ynh_psql_drop_user user -# | arg: user - the user name to drop -ynh_psql_drop_user() { - local user="$1" - sudo --login --user=postgres dropuser "$user" -} \ No newline at end of file diff --git a/scripts/install b/scripts/install index f622f8a2..e302dd76 100644 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source _pgsql.sh source ynh_install_php source ynh_add_secure_repos__2 source ynh_composer @@ -25,7 +24,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH +path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME @@ -56,7 +55,7 @@ ynh_app_setting_set $app is_public $is_public #================================================= ynh_print_info "Installing dependencies..." -ynh_install_php --phpversion=7.2 +ynh_install_php --phpversion="7.2" ynh_install_app_dependencies $pkg_dependencies @@ -67,13 +66,13 @@ ynh_print_info "Creating a PostgreSQL database..." ynh_psql_test_if_first_run -db_name=$(ynh_sanitize_dbid "$app") +db_name=$(ynh_sanitize_dbid $app) db_user=$db_name db_pwd=$(ynh_string_random) -ynh_app_setting_set "$app" db_name "$db_name" +ynh_app_setting_set $app db_name $db_name # Initialize database and store postgres password for upgrade -ynh_psql_setup_db "$db_name" "$db_user" +ynh_psql_setup_db $db_user $db_name $db_pwd systemctl reload postgresql @@ -104,9 +103,14 @@ ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +ynh_print_info "Configuring php-fpm..." # Create a dedicated php-fpm config -ynh_add_fpm_config --phpversion=7.2 +ynh_add_fpm_config --phpversion="7.2" + +#Ugly move waiting 'ynh_add_fpm_config --phpversion='' released +mv /etc/php/7.0/fpm/pool.d/$app.conf /etc/php/7.2/fpm/pool.d/$app.conf +systemctl reload php7.2-fpm #================================================= # INSTALL PHP DEPENDENCIES @@ -140,15 +144,19 @@ ynh_replace_string "__DB_PWD__" "$db_pwd" "$config" ynh_store_file_checksum "$config" #================================================= -# GENERATE KEY AND CLEAR CACHE +# DEPLOYMENT #================================================= -# generate key and clear cache -( - cd "$final_path" +pushd $final_path php7.2 artisan -n key:generate --force php7.2 artisan config:clear -) + php7.2 artisan config:cache + php7.2 artisan route:cache + php7.2 artisan storage:link + php7.2 artisan migrate --force + php7.2 artisan update + php7.2 artisan horizon:purge +popd #================================================= # GENERIC FINALIZATION diff --git a/scripts/remove b/scripts/remove index 2a7a9287..5a119775 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,7 +7,6 @@ #================================================= source _common.sh -source _pgsql.sh source ynh_install_php source ynh_add_secure_repos__2 source /usr/share/yunohost/helpers @@ -31,8 +30,23 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= ynh_print_info "Removing the PostgreSQL database" +ynh_psql_execute_as_root "\connect $db_name +SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';" + # Remove a database if it exists, along with the associated user -ynh_psql_remove_db "$db_name" "$app" +ynh_psql_remove_db $db_user $db_name + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= +ynh_print_info "Removing php-fpm configuration" + +#Ugly move waiting 'ynh_add_fpm_config --phpversion='' released +mv /etc/php/7.2/fpm/pool.d/$app.conf /etc/php/7.0/fpm/pool.d/$app.conf +systemctl reload php7.2-fpm + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config #================================================= # REMOVE DEPENDENCIES @@ -40,8 +54,8 @@ ynh_psql_remove_db "$db_name" "$app" ynh_print_info "Removing dependencies" # Remove metapackage and its dependencies -ynh_remove_app_dependencies ynh_remove_php +ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR @@ -59,14 +73,6 @@ ynh_print_info "Removing nginx web server configuration" # Remove the dedicated nginx config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_print_info "Removing php-fpm configuration" - -# Remove the dedicated php-fpm config -ynh_remove_fpm_config - #================================================= # GENERIC FINALIZATION #=================================================