#!/bin/bash toolName="pixelfed" toolTag="v0.10.4" toolDeps="composer jpegoptim php7.3-bcmath" toolPath="/var/www/pixelfed" step_1_info() { echo "Updating apt"; } step_1_alias() { ALIAS="install"; } step_1() { exe apt update } step_2_info() { echo -e "Installing $toolname dependencies: $toolDeps"; } step_2() { exe apt install $toolDeps -y saveReturn $? endReturn exe service php7.3-fpm restart } step_3_info() { echo -e "Get $toolName using git"; } step_3() { exe git clone -b $toolTag https://github.com/pixelfed/pixelfed.git $toolPath cd $toolPath exe chown -R www-data:www-data . # 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 exe composer install --no-ansi --no-interaction --optimize-autoloader saveReturn $? endReturn } step_4_info() { echo "Create mysql database for $toolName"; } step_4() { local mysqlDatabase local mysqlUser local mysqlPass echo "Existing mysql databases:" exe mysql -u root -e 'SHOW DATABASES;' echo -en "Enter database name: " read mysqlDatabase endCheckEmpty mysqlDatabase "database name" exe mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8mb4;' saveReturn $? endReturn echo "Existing mysql user:" exe mysql -u root -e 'SELECT User, Host FROM mysql.user;' echo -en "Enter mysql user name: " read mysqlUser endCheckEmpty mysqlDatabase "user name" echo -en "Enter mysql user password: " read -s mysqlPass endCheckEmpty mysqlPass "password" exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' saveReturn $? endReturn exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' saveReturn $? endReturn exe mysql -u root -e 'FLUSH PRIVILEGES;' } step_5_info() { echo "$toolName configuration"; } step_5() { cd $toolPath exe cp .env.example .env read -p "Edit database settings, hostname, email settings, IMAGE_DRIVER=imagick, etc... (Enter to continue)" exe vi .env exe php artisan key:generate exe php artisan config:cache exe php artisan storage:link exe php artisan migrate --force exe php artisan route:cache } step_6_info() { echo "Create admin user"; } step_6() { cd $toolPath read -p "Create admin user. (Enter to continue)" exe php artisan user:create } step_7_info() { echo "Create pixelfed (horzion) service"; } step_7() { addConf -c "${horizonService}" "${horizonServiceLoc}" saveReturn $? endReturn exe systemctl daemon-reload exe systemctl enable pixelfed.service exe service pixelfed start } horizonServiceLoc="/etc/systemd/system/pixelfed.service" horizonService="\ [Unit] Description=Pixelfeds' 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=/var/www/pixelfed/ ExecStart=/usr/bin/php /var/www/pixelfed/artisan horizon Restart=always Environment= [Install] WantedBy=multi-user.target" step_8_info() { echo "Nginx configuration"; } step_8() { addConf -c "$nginxConfig" "$nginxConfigLoc" exe ln -s "$nginxConfigLoc" "$nginxConfigEnable" exe nginx -t saveReturn $? endReturn 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/php7.3-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() { ALIAS="newenv"; } step_20() { cd $toolPath exe php artisan config:cache exe service pixelfed restart } step_22_info() { echo "Create new user"; } step_22_alias() { ALIAS="createuser"; } step_22() { cd $toolPath exe php artisan user:create } step_24_info() { echo "Upgrade \"${toolPath}\" to supported tag $toolTag"; } step_24_alias() { ALIAS="upgrade"; } step_24() { cd $toolPath exe git pull saveReturn $? endReturn exe git checkout $toolTag saveReturn $? endReturn } step_25_info() { echo "Recommended post update procedure"; } step_25_alias() { ALIAS="postupdate"; } step_25() { cd $toolPath exe composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader exe php artisan config:cache exe php artisan route:cache exe php artisan migrate --force exe php artisan horizon:purge exe php artisan storage:link exe service pixelfed restart } # Sequence Revision VERSION_SEQREV=3 # Workaround when called from different directory # Not needed when path to sequencer is absolut DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" # Path to sequencer . ${DIR}/../sequencer/sequencer.sh