From caba74438ecf234d9dcf12ccd2abf23b8948678e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Apr 2019 09:57:28 -0400 Subject: [PATCH 1/3] [libcalamares] Improve XDG handling - When environment is empty, use default values from spec - Search in application-named subdirs first (but keep previous behavior of also searching directly in the named dirs) - Don't consider empty XDG_* elements - Settings XDG_DATA_DIRS=":" would yield an empty list of extra directories to check; don't bother setting haveExtraDirs for that. --- src/libcalamares/utils/CalamaresUtils.cpp | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 3ab758522..4a8b1f528 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -99,21 +99,32 @@ setAppDataDir( const QDir& dir ) /* Split $ENV{@p name} on :, append to @p l, making sure each ends in / */ static void -mungeEnvironment( QStringList& l, const char *name ) +mungeEnvironment( QStringList& l, const char* name, const char* defaultDirs ) { - for ( auto s : QString( qgetenv( name ) ).split(':') ) + static const QString calamaresSubdir = QStringLiteral( "calamares/" ); + + QStringList dirs = QString( qgetenv( name ) ).split( ':' ); + if ( dirs.isEmpty() ) + dirs = QString( defaultDirs ).split( ':' ); + + for ( auto s : dirs ) + { + if ( s.isEmpty() ) + continue; if ( s.endsWith( '/' ) ) - l << s; + l << ( s + calamaresSubdir ) << s; else - l << ( s + '/' ); + l << ( s + '/' + calamaresSubdir ) << ( s + '/' ); + } } void setXdgDirs() { - s_haveExtraDirs = true; - mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS" ); - mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS" ); + mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS", "/etc/xdg" ); + mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" ); + + s_haveExtraDirs = !( s_extraConfigDirs.isEmpty() && s_extraDataDirs.isEmpty() ); } QStringList From 14f8262f2d497148431cb2a13e44cc8eee884a4d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Apr 2019 10:17:42 -0400 Subject: [PATCH 2/3] CI: Fix Copyright - yes, that's also me, but not the right address for Calamares --- ci/AppImage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/AppImage.sh b/ci/AppImage.sh index da5e41766..5adafbcd4 100644 --- a/ci/AppImage.sh +++ b/ci/AppImage.sh @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: BSD-2-Clause # -# Copyright 2019 Adriaan de Groot +# Copyright 2019 Adriaan de Groot # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions From c9421ca32c689ba3d5463634dea7c9b604ca71e5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Apr 2019 09:59:56 -0400 Subject: [PATCH 3/3] CI: follow XDG spec more closely in AppImage script - Misplaced $D - Set XDG_*_DIRS without the /calamares/ trailer - Don't overwrite XDG_*, but append for AppImage, avoid unnecessary : - Explain XDG_* tweaks in the AppImage documentation at the top. --- ci/AppImage.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ci/AppImage.sh b/ci/AppImage.sh index 5adafbcd4..1bb067b1e 100644 --- a/ci/AppImage.sh +++ b/ci/AppImage.sh @@ -56,7 +56,11 @@ # The build process for AppImage proceeds in a directory build-AppImage # that is created in the current directory. # -# TODO: Conda / Python support doesn't work yet. +# The resulting AppImage has XDG_* enabled, and appends the in-image +# directories to the current environment. You can set XDG_* in the +# current environment to use other configurations and data, e.g. the +# data in the current live environment. Or leave it unset, to try +# Calamares with only the configuration contained in the AppImage. # ### END USAGE @@ -207,10 +211,13 @@ mv "$IMAGE_DIR/usr/bin/calamares" "$IMAGE_DIR/usr/bin/calamares.bin" cat > "$IMAGE_DIR/usr/bin/calamares" <<"EOF" #! /bin/sh # -# Calamares proxy-script -export XDG_DATA_DIRS="$APPDIR/usr/share/calamares:" -export XDG_CONFIG_DIRS="$APPDIR/etc/calamares:$D/usr/share:" -export PYTHONPATH=$APPDIR/usr/lib: +# Calamares proxy-script. Runs Calamares with XDG support enabled, +# and in-image XDG dirs set up so that compiled-in configuration can be used. +test -n "${XDG_DATA_DIRS}" && XDG_DATA_DIRS="${XDG_DATA_DIRS}:" +test -n "${XDG_CONFIG_DIRS}" $$ XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS}:" +export XDG_DATA_DIRS="${XDG_DATA_DIRS}${APPDIR}/usr/share/" +export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS}${APPDIR}/etc/:${APPDIR}/usr/share/" +export PYTHONPATH="${APPDIR}/usr/lib:" cd "$APPDIR" exec "$APPDIR"/usr/bin/calamares.bin -X "$@" EOF