pixelfed - use configurable php version and install composer locally

This commit is contained in:
2022-11-27 18:23:35 +01:00
parent 849c911954
commit 661f2ff550
2 changed files with 102 additions and 88 deletions

View File

@@ -2,92 +2,100 @@
toolName="pixelfed"
toolTag="dev"
toolDeps="composer jpegoptim php7.3-bcmath php-imagick"
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: $toolDeps"; }
step_2_info() { echo -e "Installing $toolName dependencies"; }
step_2() {
exe apt install $toolDeps -y
exe apt install "${toolPhpDeps[@]/#/${sq_phpName}-}" $toolDeps ${sq_aptOpt}
endReturn -o $? "Installing deps for $toolName failed"
exe service php7.3-fpm restart
exe service ${sq_phpName}-fpm restart
endReturn -o $? "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 . # change user/group to http user and http group
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
exe composer install --no-ansi --no-interaction --optimize-autoloader
}
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 -o $? "Composer install error"
}
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: "
exe read mysqlDatabase
endCheckEmpty mysqlDatabase "database name"
exe mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8mb4;'
endReturn -o $? "Creating database failed"
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"'"';'
endReturn -o $? "Creating database user \"${mysqlUser}\" failed";
exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';'
endReturn -o $? "Granting privileges for user \"${mysqlUser}\" failed";
exe mysql -u root -e 'FLUSH PRIVILEGES;'
step_5_info() { echo "Create mysql database for $toolName"; }
step_5() {
exe ${seq_origin:?}/mysql.sh createdb -c utf8mb4
}
step_5_info() { echo "$toolName configuration"; }
step_5() {
exe cd $toolPath
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 php artisan key:generate
exe php artisan config:cache
exe php artisan storage:link
exe php artisan migrate --force
exe php artisan route:cache
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 php artisan passport:install
exe ${sq_phpName:?} artisan passport:install
}
step_6_info() { echo "Create admin user"; }
step_6() {
exe cd $toolPath
exe read -p "Create admin user. (Enter to continue)"
exe php artisan user:create
}
step_7_info() { echo "Create pixelfed (horzion) service"; }
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 -o $? "Failed to add horizon service"
exe systemctl daemon-reload
@@ -117,25 +125,28 @@ RestartSec=2s
Type=simple
User=www-data
Group=www-data
WorkingDirectory=${toolPath}/
ExecStart=/usr/bin/php ${toolPath}/artisan horizon
WorkingDirectory=${toolPath:?}/
ExecStart=/usr/bin/php ${toolPath:?}/artisan horizon
Restart=always
Environment=
[Install]
WantedBy=multi-user.target"
step_8_info() { echo "Create scheduler cron job"; }
step_8_alias() { echo "scheduler"; }
step_8() {
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"
}
schedulerCron="/etc/cron.d/pixelfedScheduler"
schedulerCmd="* * * * * cd ${toolPath} && php artisan schedule:run >>/dev/null 2>&1"
step_9_info() { echo "Nginx configuration"; }
step_9() {
addConf -c "$nginxConfig" "$nginxConfigLoc"
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 -o $? "Nginx configuration check error"
@@ -146,7 +157,7 @@ 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;
server unix:/var/run/php/${sq_phpName:?}-fpm.sock;
}
map \$http_x_forwarded_proto \$proxy_https {
@@ -199,16 +210,16 @@ location ~ /\\.(?!well-known).* {
step_20_info() { echo "Reload configuration (.env)"; }
step_20_alias() { echo "newenv"; }
step_20() {
exe cd $toolPath
exe php artisan config:cache
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 php artisan user:create
exe cd ${toolPath:?}
exe ${sq_phpName:?} artisan user:create
}
step_24_info() { echo "Checkout to dev branch. Losing local changes!"; }
@@ -224,7 +235,7 @@ step_24() {
;;
esac
fi
exe cd $toolPath
exe cd ${toolPath:?}
exe git fetch --all
exe git reset --hard origin/dev
exe git pull origin dev
@@ -234,7 +245,7 @@ step_24() {
step_100_info() { echo "Upgrade \"${toolPath}\" to supported tag $toolTag"; }
step_100_alias() { echo "upgrade"; }
step_100() {
exe cd $toolPath
exe cd ${toolPath:?}
exe git pull origin $toolTag
endReturn -o $? "git pull failed"
exe git checkout $toolTag
@@ -244,17 +255,17 @@ step_100() {
step_101_info() { echo "Recommended post update procedure"; }
step_101_alias() { echo "postupdate"; }
step_101() {
exe cd $toolPath
exe composer install
exe php artisan config:cache
exe php artisan route:cache
exe php artisan view:cache
exe php artisan cache:clear
exe php artisan migrate --force
exe php artisan horizon:purge
exe php artisan horizon:publish
exe php artisan storage:link
exe php artisan instance:actor
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"
}
@@ -263,10 +274,10 @@ step_101() {
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 php artisan package:discover
exe php artisan horizon:install
exe php artisan route:cache
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"
}