#!/bin/bash toolName="pixelfed" toolTag="dev" toolPhpDeps=(bcmath ctype curl exif gd iconv intl mbstring redis tokenizer xml zip) toolDeps="jpegoptim php-imagick" toolPath="/var/www/pixelfed" sq_aptOpt= sq_config=0 sq_phpName=php sq_PoolConfig= seq_config() { if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then sq_config=1 else # End if no configuration file exists dry || return 1 fi ## Apt cmdline option to suppress user interaction interactive || sq_aptOpt="-y" ## Disable error checks if external scripts are used ## e.g. error on unbound variables #disableErrorCheck sq_phpName="php${sc_phpVersion:?}" sq_PoolConfig="/etc/php/${sc_phpVersion:?}/fpm/pool.d/www.conf" ## Return of non zero value will abort the sequence return 0 } step_1_info() { echo "Updating apt"; } step_1_alias() { echo "install"; } step_1() { exe apt update } step_2_info() { echo -e "Installing $toolName dependencies"; } step_2() { exe apt install "${toolPhpDeps[@]/#/${sq_phpName}-}" $toolDeps ${sq_aptOpt} endReturn "Installing deps for $toolName failed" exe service ${sq_phpName}-fpm restart endReturn "Problems starting $toolName" } step_3_info() { echo -e "Get $toolName using git"; } step_3() { exe git clone -b $toolTag https://github.com/pixelfed/pixelfed.git "${toolPath:?}" exe cd "${toolPath:?}" exe chown -R www-data:www-data "${toolPath:?}" # change user/group to http user and http group exe find . -type d -exec chmod 755 {} \; # set all directories to rwx by user/group exe find . -type f -exec chmod 644 {} \; # set all files to rw by user/group } step_4_info() { echo "Install composer and ${toolName} dependencies"; } step_4() { exe cd "${toolPath:?}" exe ${seq_origin:?}/composer.sh -qq install exe sudo -u www-data ${sq_phpName:?} composer.phar install --no-ansi --no-interaction --optimize-autoloader endReturn "Composer install error" } step_5_info() { echo "Create mysql database for $toolName"; } step_5() { exe ${seq_origin:?}/mysql.sh createdb -c utf8mb4 } step_6_info() { echo "$toolName configuration"; } step_6() { exe cd "${toolPath:?}" exe cp .env.example .env exe read -p "Edit database settings, hostname, email settings, IMAGE_DRIVER=imagick, etc... (Enter to continue)" exe vi .env exe ${sq_phpName:?} artisan key:generate exe ${sq_phpName:?} artisan config:cache exe ${sq_phpName:?} artisan storage:link exe ${sq_phpName:?} artisan migrate --force exe ${sq_phpName:?} artisan route:cache # Needed for using oauth (app like pixeldroid) # https://github.com/pixelfed/pixelfed/issues/2654 exe ${sq_phpName:?} artisan passport:install } step_7_info() { echo "Create admin user"; } step_7() { exe cd "${toolPath:?}" exe read -p "Create admin user. (Enter to continue)" exe ${sq_phpName:?} artisan user:create } step_8_info() { echo "Create pixelfed (horzion) service"; } step_8() { addConf -c "${horizonService}" "${horizonServiceLoc}" endReturn "Failed to add horizon service" exe systemctl daemon-reload exe systemctl enable pixelfed.service exe service pixelfed start } horizonServiceLoc="/etc/systemd/system/pixelfed.service" horizonService="\ [Unit] Description=${toolName}s' Horizon After=syslog.target After=network.target #Requires=mysql.service Requires=mariadb.service #Requires=postgresql.service #Requires=memcached.service #Requires=redis.service [Service] # Modify these two values and uncomment them if you have # repos with lots of files and get an HTTP error 500 because # of that ### #LimitMEMLOCK=infinity #LimitNOFILE=65535 RestartSec=2s Type=simple User=www-data Group=www-data WorkingDirectory=${toolPath:?}/ ExecStart=/usr/bin/php ${toolPath:?}/artisan horizon Restart=always Environment= [Install] WantedBy=multi-user.target" step_9_info() { echo "Create scheduler cron job"; } step_9_alias() { echo "scheduler"; } step_9() { local schedulerCron="/etc/cron.d/pixelfedScheduler" local schedulerCmd="* * * * * cd $(escpath ${toolPath}) && ${sq_phpName:?} artisan schedule:run >>/dev/null 2>&1" addConf -s "$schedulerCmd" "$schedulerCron" } step_10_info() { echo "Nginx configuration"; } step_10() { lNginxConfig="$(eval echo "${nginxConfig}")" addConf -c "$lNginxConfig" "$nginxConfigLoc" exe ln -s "$nginxConfigLoc" "$nginxConfigEnable" exe nginx -t endReturn "Nginx configuration check error" exe service nginx restart } nginxConfigLoc="/etc/nginx/sites-available/pixelfed" nginxConfigEnable="/etc/nginx/sites-enabled/pixelfed" nginxConfig="\ upstream php-handler-pixel { server unix:/var/run/php/${sq_phpName:?}-fpm.sock; } map \$http_x_forwarded_proto \$proxy_https { default ''; https 'on'; } server { listen 80; listen [::]:80; add_header X-Frame-Options \"SAMEORIGIN\"; add_header X-XSS-Protection \"1; mode=block\"; add_header X-Content-Type-Options \"nosniff\"; # Path to the root of your installation root ${toolPath}/public; index index.html index.htm index.php; charset utf-8; client_max_body_size 64M; location / { try_files \$uri \$uri/ /index.php?\$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \\.php$ { try_files \$uri =404; fastcgi_split_path_info ^(.+\\.php)(/.+)$; fastcgi_pass php-handler-pixel; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME \$request_filename; fastcgi_param PATH_INFO \$fastcgi_path_info; # fix preview problem fastcgi_param REQUEST_SCHEME \$http_x_forwarded-proto; fastcgi_param HTTPS \$proxy_https if_not_empty; } location ~ /\\.(?!well-known).* { deny all; } }" step_20_info() { echo "Reload configuration (.env)"; } step_20_alias() { echo "newenv"; } step_20() { exe cd ${toolPath:?} exe sudo -u www-data ${sq_phpName:?} artisan config:cache exe service pixelfed restart } step_22_info() { echo "Create new user"; } step_22_alias() { echo "createuser"; } step_22() { exe cd ${toolPath:?} exe ${sq_phpName:?} artisan user:create } step_24_info() { echo "Checkout to dev branch. Losing local changes!"; } step_24_alias() { echo "forcedev"; } step_24() { exe read -p "Are you sure: y/[n]? " answer if ! dry ; then case $answer in [yY]) ;; *) return 1 ;; esac fi exe cd ${toolPath:?} exe git fetch --all exe git reset --hard origin/dev exe git pull origin dev exe git checkout dev } step_100_info() { echo "Upgrade \"${toolPath}\" to supported tag $toolTag"; } step_100_alias() { echo "upgrade"; } step_100() { exe cd ${toolPath:?} exe git pull origin $toolTag endReturn "git pull failed" exe git checkout $toolTag endReturn "git checkout failed" } step_101_info() { echo "Recommended post update procedure"; } step_101_alias() { echo "postupdate"; } step_101() { exe cd ${toolPath:?} exe sudo -u www-data ${sq_phpName:?} composer.phar install exe sudo -u www-data ${sq_phpName:?} artisan config:cache exe sudo -u www-data ${sq_phpName:?} artisan route:cache exe sudo -u www-data ${sq_phpName:?} artisan view:cache exe sudo -u www-data ${sq_phpName:?} artisan cache:clear exe sudo -u www-data ${sq_phpName:?} artisan migrate --force exe sudo -u www-data ${sq_phpName:?} artisan horizon:purge exe sudo -u www-data ${sq_phpName:?} artisan horizon:publish exe sudo -u www-data ${sq_phpName:?} artisan storage:link exe sudo -u www-data ${sq_phpName:?} artisan instance:actor echo -n " [I] Restarting pixelfed horzion service..." exe service pixelfed restart && echo "ok" } # Src: https://docs.pixelfed.org/running-pixelfed/troubleshooting.html step_102_info() { echo "Fix if horizon services is running but not showing the administration interface"; } step_102_alias() { echo "fixhorizon"; } step_102() { exe cd ${toolPath:?} exe sudo -u www-data ${sq_phpName:?} artisan package:discover exe sudo -u www-data ${sq_phpName:?} artisan horizon:install exe sudo -u www-data ${sq_phpName:?} artisan route:cache echo -n " [I] Restarting pixelfed horzion service..." exe service pixelfed restart && echo "ok" } # Sequence Revision readonly sqr_minVersion=16 # Path to sequencer . sequencer.sh