From 3246dc44dd6f843c5ee700ff0bda4fd9dc357fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 2 Jan 2016 13:33:25 +0100 Subject: [PATCH 1/3] [fix] Correct debug message when no arguments found in the manifest --- src/yunohost/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index f43dd60be..4fb54d9a5 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1317,7 +1317,7 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None): try: action_args = manifest['arguments'][action] except KeyError: - logger.debug("no arguments found for '%s' in '%s'", action, path) + logger.debug("no arguments found for '%s' in manifest", action) else: for arg in action_args: arg_name = arg['name'] From bd64a0c661b8a1715d8b52defb3465e6e9888b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 3 Jan 2016 17:20:32 +0100 Subject: [PATCH 2/3] [enh] Add a helper to check if a user exists on the system --- data/apps/helpers.d/user | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/data/apps/helpers.d/user b/data/apps/helpers.d/user index fc58d0027..bfd044070 100644 --- a/data/apps/helpers.d/user +++ b/data/apps/helpers.d/user @@ -1,15 +1,14 @@ -# Check if a user exists +# Check if a YunoHost user exists # # example: ynh_user_exists 'toto' || exit 1 # # usage: ynh_user_exists username # | arg: username - the username to check -# | ret: retcode - 0 if user exists, 1 otherwise ynh_user_exists() { sudo yunohost user list --output-as json | grep -q "\"username\": \"${1}\"" } -# Retrieve a user information +# Retrieve a YunoHost user information # # example: mail=$(ynh_user_get_info 'toto' 'mail') # @@ -18,5 +17,13 @@ ynh_user_exists() { # | arg: key - the key to retrieve # | ret: string - the key's value ynh_user_get_info() { - sudo yunohost user info "${1}" --output-as plain | ynh_get_plain_key "${2}" + sudo yunohost user info "$1" --output-as plain | ynh_get_plain_key "$2" +} + +# Check if a user exists on the system +# +# usage: ynh_system_user_exists username +# | arg: username - the username to check +ynh_system_user_exists() { + getent passwd "$1" &>/dev/null } From 2ce7c4b8df2a987d312937b2e302b03a9c3de37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 3 Jan 2016 17:31:18 +0100 Subject: [PATCH 3/3] [enh] Provide bash helpers for packages manipulation (wip #97) --- data/apps/helpers.d/package | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 data/apps/helpers.d/package diff --git a/data/apps/helpers.d/package b/data/apps/helpers.d/package new file mode 100644 index 000000000..266b40e05 --- /dev/null +++ b/data/apps/helpers.d/package @@ -0,0 +1,78 @@ +# 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 +} + +# Install package(s) +# +# usage: ynh_package_install name [name [...]] +# | arg: name - the package name to install +ynh_package_install() { + sudo apt-get -y -qq install $@ +} + +# 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() { + ynh_package_is_installed 'equivs' \ + || ynh_package_install equivs + + # retrieve package information + pkgname=$(grep '^Package: ' $1 | cut -d' ' -f 2) + pkgversion=$(grep '^Version: ' $1 | cut -d' ' -f 2) + [[ -z "$pkgname" || -z "$pkgversion" ]] \ + && echo "Invalid control file" && exit 1 + controlfile=$(readlink -f "$1") + + # build and install the package + TMPDIR=$(ynh_mkdir_tmp) + (cd $TMPDIR \ + && equivs-build "$controlfile" 1>/dev/null \ + && sudo dpkg --force-depends \ + -i "./${pkgname}_${pkgversion}_all.deb" 2>&1 \ + && sudo apt-get -f -y -qq install) \ + && ([[ -n "$TMPDIR" ]] && rm -rf $TMPDIR) +} + +# Remove package(s) +# +# usage: ynh_package_remove name [name [...]] +# | arg: name - the package name to remove +ynh_package_remove() { + sudo apt-get -y -qq remove $@ +} + +# Remove package(s) and their uneeded dependencies +# +# usage: ynh_package_autoremove name [name [...]] +# | arg: name - the package name to remove +ynh_package_autoremove() { + sudo apt-get -y -qq autoremove $@ +}