mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
* [enh] Use a csv to list file to backup * [enh] Use csv python module * [wip] Backup refactoring * [wip] Backup class refactoring * [enh] Add archivemount dependencies * [wip] Restore refactoring * [fix] Some error in this refactoring * [fix] Missing backup key translation * [fix] Bad YNH_CWD in hook backup * [fix] App backup part was broken * [fix] Restore operation was broken * [fix] No compressed backup * [fix] Don't commit backup path into csv if app backup fail * [fix] Default backup collect_dir should be in tmp subdir * [enh] Simplify a copy code * [enh] Build backup info from properties * [enh] Improve comments presentation * Adding first tests for backup/restore * Adding more backup/restore app test scenario * [enh] Separate BackupMethods in distinct class * Adding test of restoring a wordpress archive from 2.4 * [fix] Be able to delete backup link too * [fix] Bad internationalization key * [fix] Edge case with empty mysql pwd restore * [fix] Unset var in restore * [fix] Edge case with empty mysql pwd restore * Adding test for backup crash handling * Cleaning tests + checking tmp dir is empty * [fix] Missing tmp in backup path * [fix] Error on reading backup csv * Adding test of failed restore * Adding tests when not enough space available * Simplifying tests using markers * [fix] ynh backup/restore helpers with only one arg * [fix] Unmount subdir with python * [enh] Improve backup size management * [fix] None object in backup * [enh] Remove dead code * [fix] Missing locales * [enh] Adapat test about needed space * [fix] Pass some test * [enh] Remove dead code * [enh] Pass all test * [enh] Adding test that backups contains what's expected * Fix typo in tests * [fix] Bad documentation * [enh] Add comment * [enh] Use len in place of implicit {} == False * [enh] Add comment * [enh] Add comment * [enh] Refactoring on _collect_app_files * Adding skeleton for remaining tests to write * [enh] Use a csv to list file to backup * [enh] Use csv python module * [wip] Backup refactoring * [wip] Backup class refactoring * [enh] Add archivemount dependencies * [wip] Restore refactoring * [fix] Some error in this refactoring * [fix] Missing backup key translation * [fix] Bad YNH_CWD in hook backup * [fix] App backup part was broken * [fix] Restore operation was broken * [fix] No compressed backup * [fix] Don't commit backup path into csv if app backup fail * [fix] Default backup collect_dir should be in tmp subdir * [enh] Simplify a copy code * [enh] Build backup info from properties * [enh] Improve comments presentation * Adding first tests for backup/restore * Adding more backup/restore app test scenario * [enh] Separate BackupMethods in distinct class * Adding test of restoring a wordpress archive from 2.4 * [fix] Be able to delete backup link too * [fix] Bad internationalization key * [fix] Edge case with empty mysql pwd restore * [fix] Unset var in restore * [fix] Edge case with empty mysql pwd restore * Adding test for backup crash handling * Cleaning tests + checking tmp dir is empty * [fix] Missing tmp in backup path * [fix] Error on reading backup csv * Adding test of failed restore * Adding tests when not enough space available * Simplifying tests using markers * [fix] ynh backup/restore helpers with only one arg * [fix] Unmount subdir with python * [enh] Improve backup size management * [fix] None object in backup * [enh] Remove dead code * [fix] Missing locales * [enh] Adapat test about needed space * [fix] Pass some test * [enh] Remove dead code * [enh] Pass all test * [enh] Adding test that backups contains what's expected * Fix typo in tests * [fix] Bad documentation * Adding skeleton for remaining tests to write * [enh] Add comment * [enh] Use len in place of implicit {} == False * [enh] Add comment * [enh] Add comment * [enh] Refactoring on _collect_app_files * [fix] Replay e1a507 deleted by rebase * [fix] ynh_restore helper * Renaming 'hooks' terminology to 'system' where it makes sense * Propagating new --system/--ignore-system to actionmap * Adding more tests + clarifying some functions and messages * Factorize out the definition and validation of backup/restore targets * Add missing key * Use list comprehension instead of dirty loops * [enh] Add docstring in BackupManager * [enh] Add docstring on BackupMethod(s) * [fix] Remove deadcode * [fix] Remove debug message * [enh] Add comments on RestoreManager * [enh] Add comments on backup constants * Adding a proper report/result for each backup target * Skipping tests not implemented yet * Fixing little mistake from merging * [fix] Support different fs or archivemount error * [enh] Backup helpers readability * [fix] Copy backup method * [fix] Deprecated warning always displayed * [enh] Retrieve info.json file inside tar.gz * Trying to reorganize methods with sections for readability * [enh] Support archivemount failure * [fix] Missing env var for system part restore helpers * Clarifying disk usage / free space computation * [enh] Refactoring around backup set_targets() * Clarifying structure of backup_create and backup_restore * Move RestoreManager between BackupManager and BackupMethods * [fix] Missing locales * [fix] System part restore if archivemount failure * [enh] Extract all conf instead of specific code * [fix] Other output directory (compressed archive) * [enh] Add test for uncompressed backup * [fix] Compressed backup in an existing output directory * [fix] Return size for retro-compatibility * [fix] Mountpoint check aborting script when called with -eu * [fix] Avoid failure test with set -eu * [fix] locale strings missing/bad arguments * Check free space before mount * [fix] ynh_restore_helpers with existing archive path * Adding skeletons for moar tests * Fixing some weird bug in _get_archive_path * Adding a regen-conf at the end of system restore * Adding tests of system restore from 2.4 * Have a class dedicated to target management * Cleaning tests * Misc formatting * More meaningful variable names inside app restore * [fix] can't call source ../settings/scripts/_common.sh in app backup * [fix] ynh_install_app_dependencies is not compatible with readonly mount * [fix] Remove temporary file
149 lines
5 KiB
Text
149 lines
5 KiB
Text
# Check either a package is installed or not
|
|
#
|
|
# example: ynh_package_is_installed 'yunohost' && echo "ok"
|
|
#
|
|
# usage: ynh_package_is_installed name
|
|
# | arg: name - the package name to check
|
|
ynh_package_is_installed() {
|
|
dpkg-query -W -f '${Status}' "$1" 2>/dev/null \
|
|
| grep -c "ok installed" &>/dev/null
|
|
}
|
|
|
|
# Get the version of an installed package
|
|
#
|
|
# example: version=$(ynh_package_version 'yunohost')
|
|
#
|
|
# usage: ynh_package_version name
|
|
# | arg: name - the package name to get version
|
|
# | ret: the version or an empty string
|
|
ynh_package_version() {
|
|
if ynh_package_is_installed "$1"; then
|
|
dpkg-query -W -f '${Version}' "$1" 2>/dev/null
|
|
else
|
|
echo ''
|
|
fi
|
|
}
|
|
|
|
# APT wrapper for non-interactive operation
|
|
#
|
|
# usage: ynh_apt update
|
|
ynh_apt() {
|
|
DEBIAN_FRONTEND=noninteractive sudo apt-get -y -qq $@
|
|
}
|
|
|
|
# Update package index files
|
|
#
|
|
# usage: ynh_package_update
|
|
ynh_package_update() {
|
|
ynh_apt update
|
|
}
|
|
|
|
# Install package(s)
|
|
#
|
|
# usage: ynh_package_install name [name [...]]
|
|
# | arg: name - the package name to install
|
|
ynh_package_install() {
|
|
ynh_apt --no-remove -o Dpkg::Options::=--force-confdef \
|
|
-o Dpkg::Options::=--force-confold install $@
|
|
}
|
|
|
|
# Remove package(s)
|
|
#
|
|
# usage: ynh_package_remove name [name [...]]
|
|
# | arg: name - the package name to remove
|
|
ynh_package_remove() {
|
|
ynh_apt remove $@
|
|
}
|
|
|
|
# Remove package(s) and their uneeded dependencies
|
|
#
|
|
# usage: ynh_package_autoremove name [name [...]]
|
|
# | arg: name - the package name to remove
|
|
ynh_package_autoremove() {
|
|
ynh_apt autoremove $@
|
|
}
|
|
|
|
# Build and install a package from an equivs control file
|
|
#
|
|
# example: generate an empty control file with `equivs-control`, adjust its
|
|
# content and use helper to build and install the package:
|
|
# ynh_package_install_from_equivs /path/to/controlfile
|
|
#
|
|
# usage: ynh_package_install_from_equivs controlfile
|
|
# | arg: controlfile - path of the equivs control file
|
|
ynh_package_install_from_equivs () {
|
|
controlfile=$1
|
|
|
|
# Check if the equivs package is installed. Or install it.
|
|
ynh_package_is_installed 'equivs' \
|
|
|| ynh_package_install equivs
|
|
|
|
# retrieve package information
|
|
pkgname=$(grep '^Package: ' $controlfile | cut -d' ' -f 2) # Retrieve the name of the debian package
|
|
pkgversion=$(grep '^Version: ' $controlfile | cut -d' ' -f 2) # And its version number
|
|
[[ -z "$pkgname" || -z "$pkgversion" ]] \
|
|
&& echo "Invalid control file" && exit 1 # Check if this 2 variables aren't empty.
|
|
|
|
# Update packages cache
|
|
ynh_package_update
|
|
|
|
# Build and install the package
|
|
TMPDIR=$(mktemp -d)
|
|
# Note that the cd executes into a sub shell
|
|
# Create a fake deb package with equivs-build and the given control file
|
|
# Install the fake package without its dependencies with dpkg
|
|
# Install missing dependencies with ynh_package_install
|
|
(cp "$controlfile" "${TMPDIR}/control" && cd "$TMPDIR" \
|
|
&& equivs-build ./control 1>/dev/null \
|
|
&& sudo dpkg --force-depends \
|
|
-i "./${pkgname}_${pkgversion}_all.deb" 2>&1 \
|
|
&& ynh_package_install -f)
|
|
[[ -n "$TMPDIR" ]] && rm -rf $TMPDIR # Remove the temp dir.
|
|
|
|
# check if the package is actually installed
|
|
ynh_package_is_installed "$pkgname"
|
|
}
|
|
|
|
# Define and install dependencies with a equivs control file
|
|
# This helper can/should only be called once per app
|
|
#
|
|
# usage: ynh_install_app_dependencies dep [dep [...]]
|
|
# | arg: dep - the package name to install in dependence
|
|
ynh_install_app_dependencies () {
|
|
dependencies=$@
|
|
manifest_path="../manifest.json"
|
|
if [ ! -e "$manifest_path" ]; then
|
|
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
|
fi
|
|
version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file.
|
|
dep_app=${app//_/-} # Replace all '_' by '-'
|
|
|
|
if ynh_package_is_installed "${dep_app}-ynh-deps"; then
|
|
echo "A package named ${dep_app}-ynh-deps is already installed" >&2
|
|
else
|
|
cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
|
Section: misc
|
|
Priority: optional
|
|
Package: ${dep_app}-ynh-deps
|
|
Version: ${version}
|
|
Depends: ${dependencies// /, }
|
|
Architecture: all
|
|
Description: Fake package for ${app} (YunoHost app) dependencies
|
|
This meta-package is only responsible of installing its dependencies.
|
|
EOF
|
|
ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \
|
|
|| ynh_die "Unable to install dependencies" # Install the fake package and its dependencies
|
|
rm /tmp/${dep_app}-ynh-deps.control
|
|
ynh_app_setting_set $app apt_dependencies $dependencies
|
|
fi
|
|
}
|
|
|
|
# Remove fake package and its dependencies
|
|
#
|
|
# Dependencies will removed only if no other package need them.
|
|
#
|
|
# usage: ynh_remove_app_dependencies
|
|
ynh_remove_app_dependencies () {
|
|
dep_app=${app//_/-} # Replace all '_' by '-'
|
|
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
|
|
}
|