From 915080e8d4c56c0609e5c4484e27a6cb51a2a0d3 Mon Sep 17 00:00:00 2001 From: luccioman Date: Sat, 5 Jan 2019 19:30:52 +0100 Subject: [PATCH] Added Snap package configuration to choose to version data or not By default when the Snap package is installed, YaCy data is stored in a versioned user folder, allowing to revert to previous data after a package refresh for example. But it can consumes much disk space, so it is now possible to tell YaCy snap not to version its data, with the Snap configuration setting "data.versioned=false". --- addon/snap/snapPasswd.sh | 16 +++++++++++++ addon/snap/snapStartYACY.sh | 45 +++++++++++++++++++++++++++++++++++++ snap/hooks/configure | 6 +++++ snap/snapcraft.yaml | 6 ++--- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100755 addon/snap/snapPasswd.sh create mode 100755 addon/snap/snapStartYACY.sh create mode 100755 snap/hooks/configure diff --git a/addon/snap/snapPasswd.sh b/addon/snap/snapPasswd.sh new file mode 100755 index 000000000..5449d5f0c --- /dev/null +++ b/addon/snap/snapPasswd.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# Wrapper script for Snap package specific instructions before calling the bin/passwd.sh script + +# Check the snap configuration to properly fill the YACY_DATA_PATH environment variable +DATA_VERSIONED="$(snapctl get data.versioned)" +if [ "$DATA_VERSIONED" = "false" ]; then + # YaCy data is in the Snap common (non versioned) user data + YACY_DATA_PATH="$SNAP_USER_COMMON/DATA" +else + # Defaults : YaCy data is in the Snap versioned user data + YACY_DATA_PATH="$SNAP_USER_DATA/DATA" +fi +export YACY_DATA_PATH + +sh "$SNAP/yacy/bin/passwd.sh" \ No newline at end of file diff --git a/addon/snap/snapStartYACY.sh b/addon/snap/snapStartYACY.sh new file mode 100755 index 000000000..2d6cf44e1 --- /dev/null +++ b/addon/snap/snapStartYACY.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env sh + +# Wrapper script for Snap package specific instructions before calling the startYACY.sh script + +# Check the snap configuration to properly fill the YACY_DATA_PATH environment variable +echo "*******************************************************************************" +DATA_VERSIONED="$(snapctl get data.versioned)" +if [ "$DATA_VERSIONED" = "false" ]; then + # YaCy data is in the Snap common (non versioned) user data + YACY_PARENT_DATA_PATH="$SNAP_USER_COMMON" + + if [ ! -d "$YACY_PARENT_DATA_PATH/DATA" ] && [ -d "$SNAP_USER_DATA/DATA" ]; then + if [ -f "$SNAP_USER_DATA/DATA/yacy.running" ]; then + echo "**** Warning : can not move YaCy snap data from versioned to non versioned folder as YaCy appears to be already running." + else + (mv "$SNAP_USER_DATA/DATA" "$YACY_PARENT_DATA_PATH" && \ + echo "*** YaCy snap data moved from versioned to non versioned snap data." ) \ + || echo "**** Warning : could not move YaCy snap data from versioned to non versioned folder." + fi + fi + + echo "** YaCy snap is using non versioned data at $YACY_PARENT_DATA_PATH/DATA" + echo "** You can configure it to use snap versioned data with the following command :" + echo "** sudo snap set $SNAP_NAME data.versioned=true" +else + # Defaults : YaCy data is in the Snap versioned user data + YACY_PARENT_DATA_PATH="$SNAP_USER_DATA" + + if [ ! -d "$YACY_PARENT_DATA_PATH/DATA" ] && [ -d "$SNAP_USER_COMMON/DATA" ]; then + if [ -f "$SNAP_USER_COMMON/DATA/yacy.running" ]; then + echo "**** Warning : can not move YaCy snap data from non versioned to versioned folder as YaCy appears to be already running." + else + (mv "$SNAP_USER_COMMON/DATA" "$YACY_PARENT_DATA_PATH" && \ + echo "*** YaCy snap data moved from non versioned to versioned snap data." ) \ + || echo "**** Warning : could not move YaCy snap data from non versioned to versioned folder." + fi + fi + + echo "** YaCy snap is using versioned data at $YACY_PARENT_DATA_PATH/DATA" + echo "** To reduce disk usage, you can configure it to use snap non versioned data with the following command :" + echo "** sudo snap set $SNAP_NAME data.versioned=false" +fi +export YACY_PARENT_DATA_PATH + +sh "$SNAP/yacy/startYACY.sh" -f -s "$YACY_PARENT_DATA_PATH" \ No newline at end of file diff --git a/snap/hooks/configure b/snap/hooks/configure new file mode 100755 index 000000000..fe52ee561 --- /dev/null +++ b/snap/hooks/configure @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +# Snap configuration hook script +# Even if empty, its presence is required to enable the Snap specific "data.versioned" configuration key + +echo "Configuring yacy-search" \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 18629309b..ab5c042a4 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -19,7 +19,7 @@ apps: # needed to run wkhtmltopdf from YaCy within the Snap for Snapshots generation # with wkhtmltopdf 0.12.2.4 included with Ubuntu 16.04 LTS (recommended minimum system to build Snaps in 2018) QT_QPA_PLATFORM_PLUGIN_PATH: "$SNAP/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" - command: sh "$SNAP/yacy/startYACY.sh" -f -s "$SNAP_USER_DATA" + command: sh "$SNAP/yacy/addon/snap/snapStartYACY.sh" # Interfaces authorizations requirements # network-bind - to allow acting as an HTTP server and client # desktop - to launch the default desktop navigator when starting (with xdg-open command) - not strictly necessary @@ -29,9 +29,7 @@ apps: # x11 - needed by wkhtmltopdf to generate Snapshots using WebKit engine - not necessary when Snapshots feature is not used plugs: [network-bind, desktop, home, x11] passwd: # set the YaCy administrator password - environment: - YACY_DATA_PATH: "$SNAP_USER_DATA/DATA" - command: sh "$SNAP/yacy/bin/passwd.sh" + command: sh "$SNAP/yacy/addon/snap/snapPasswd.sh" # Interfaces authorizations requirements # network - to allow requesting the ConfigAccounts_p HTTP API when the server is running plugs: [network]