Skip to content

Commit b3087af

Browse files
committed
Place the PHP version into a variable (#2307)
Also - trims a few trailing whitespace characters - gitignores VS code workspace
1 parent e419b62 commit b3087af

File tree

12 files changed

+28
-14
lines changed

12 files changed

+28
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ tools/__pycache__/
55
externals/
66
.env
77
.vagrant
8-
api/docs/api-docs.html
8+
api/docs/api-docs.html
9+
*.code-workspace

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
Next
5+
----
6+
7+
* Place PHP version into a global variable
8+
49
Version 64 (September 2, 2023)
510
------------------------------
611

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ This is a challenge faced by everyone who runs their own mail server, with or wi
7979
Contributing and Development
8080
----------------------------
8181

82-
Mail-in-a-Box is an open source project. Your contributions and pull requests are welcome. See [CONTRIBUTING](CONTRIBUTING.md) to get started.
82+
Mail-in-a-Box is an open source project. Your contributions and pull requests are welcome. See [CONTRIBUTING](CONTRIBUTING.md) to get started.
8383

8484

8585
The Acknowledgements

conf/nginx-top.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
## your own --- please do not ask for help from us.
88

99
upstream php-fpm {
10-
server unix:/var/run/php/php8.0-fpm.sock;
10+
server unix:/var/run/php/php{{phpver}}-fpm.sock;
1111
}
1212

management/backup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import rtyaml
1313
from exclusiveprocess import Lock
1414

15-
from utils import load_environment, shell, wait_for_service
15+
from utils import load_environment, shell, wait_for_service, get_php_version
1616

1717
def backup_status(env):
1818
# If backups are dissbled, return no status.
@@ -262,6 +262,7 @@ def get_target_type(config):
262262

263263
def perform_backup(full_backup):
264264
env = load_environment()
265+
php_fpm = f"php{get_php_version()}-fpm"
265266

266267
# Create an global exclusive lock so that the backup script
267268
# cannot be run more than one.
@@ -297,7 +298,7 @@ def service_command(service, command, quit=None):
297298
if quit:
298299
sys.exit(code)
299300

300-
service_command("php8.0-fpm", "stop", quit=True)
301+
service_command(php_fpm, "stop", quit=True)
301302
service_command("postfix", "stop", quit=True)
302303
service_command("dovecot", "stop", quit=True)
303304
service_command("postgrey", "stop", quit=True)
@@ -334,7 +335,7 @@ def service_command(service, command, quit=None):
334335
service_command("postgrey", "start", quit=False)
335336
service_command("dovecot", "start", quit=False)
336337
service_command("postfix", "start", quit=False)
337-
service_command("php8.0-fpm", "start", quit=False)
338+
service_command(php_fpm, "start", quit=False)
338339

339340
# Remove old backups. This deletes all backup data no longer needed
340341
# from more than 3 days ago.

management/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def wait_for_service(port, public, env, timeout):
178178
return False
179179
time.sleep(min(timeout/4, 1))
180180

181+
def get_php_version():
182+
# Gets the version of PHP installed in the system.
183+
return shell("check_output", ["/usr/bin/php", "-v"])[4:7]
184+
181185
if __name__ == "__main__":
182186
from web_update import get_web_domains
183187
env = load_environment()

management/web_update.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mailconfig import get_mail_domains
88
from dns_update import get_custom_dns_config, get_dns_zones
99
from ssl_certificates import get_ssl_certificates, get_domain_ssl_files, check_certificate
10-
from utils import shell, safe_domain_name, sort_domains
10+
from utils import shell, safe_domain_name, sort_domains, get_php_version
1111

1212
def get_web_domains(env, include_www_redirects=True, include_auto=True, exclude_dns_elsewhere=True):
1313
# What domains should we serve HTTP(S) for?
@@ -83,6 +83,7 @@ def read_conf(conf_fn):
8383

8484
# Build an nginx configuration file.
8585
nginx_conf = read_conf("nginx-top.conf")
86+
nginx_conf = re.sub("{{phpver}}", get_php_version(), nginx_conf)
8687

8788
# Load the templates.
8889
template0 = read_conf("nginx.conf")

setup/functions.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# -o pipefail: don't ignore errors in the non-last command in a pipeline
55
set -euo pipefail
66

7+
# This global variable pinpoints the PHP version for the whole MiaB app
8+
# Upgrade it only with care and tests. Nextcloud versions depend on it.
79
PHP_VER=8.0
810

911
function hide_output {

setup/web.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ chmod a+r /var/lib/mailinabox/mozilla-autoconfig.xml
124124

125125
# Create a generic mta-sts.txt file which is exposed via the
126126
# nginx configuration at /.well-known/mta-sts.txt
127-
# more documentation is available on:
127+
# more documentation is available on:
128128
# https://www.uriports.com/blog/mta-sts-explained/
129129
# default mode is "enforce". In /etc/mailinabox.conf change
130130
# "MTA_STS_MODE=testing" which means "Messages will be delivered

setup/zpush.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ if [ $needs_update == 1 ]; then
4141
mv /tmp/z-push/*/src /usr/local/lib/z-push
4242
rm -rf /tmp/z-push.zip /tmp/z-push
4343

44-
# Create admin and top scripts with PHP_VER
44+
# Create admin and top scripts with PHP_VER
4545
rm -f /usr/sbin/z-push-{admin,top}
4646
echo '#!/bin/bash' > /usr/sbin/z-push-admin
4747
echo php$PHP_VER /usr/local/lib/z-push/z-push-admin.php '"$@"' >> /usr/sbin/z-push-admin
4848
chmod 755 /usr/sbin/z-push-admin
4949
echo '#!/bin/bash' > /usr/sbin/z-push-top
5050
echo php$PHP_VER /usr/local/lib/z-push/z-push-top.php '"$@"' >> /usr/sbin/z-push-top
5151
chmod 755 /usr/sbin/z-push-top
52-
52+
5353
echo $VERSION > /usr/local/lib/z-push/version
5454
fi
5555

tools/owncloud-restore.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ ! -f $1/config.php ]; then
2626
fi
2727

2828
echo "Restoring backup from $1"
29-
service php8.0-fpm stop
29+
service php$PHP_VER-fpm stop
3030

3131
# remove the current ownCloud/Nextcloud installation
3232
rm -rf /usr/local/lib/owncloud/
@@ -45,5 +45,5 @@ chown www-data:www-data $STORAGE_ROOT/owncloud/config.php
4545

4646
sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ maintenance:mode --off
4747

48-
service php8.0-fpm start
48+
service php$PHP_VER-fpm start
4949
echo "Done"

tools/owncloud-unlockadmin.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
source /etc/mailinabox.conf # load global vars
1010

1111
ADMIN=$(./mail.py user admins | head -n 1)
12-
test -z "$1" || ADMIN=$1
12+
test -z "$1" || ADMIN=$1
1313

1414
echo I am going to unlock admin features for $ADMIN.
1515
echo You can provide another user to unlock as the first argument of this script.
1616
echo
1717
echo WARNING: you could break mail-in-a-box when fiddling around with Nextcloud\'s admin interface
1818
echo If in doubt, press CTRL-C to cancel.
19-
echo
19+
echo
2020
echo Press enter to continue.
2121
read
2222

0 commit comments

Comments
 (0)