mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge remote-tracking branch 'origin/unstable' into unstable
This commit is contained in:
commit
5427c15c3d
3 changed files with 90 additions and 5 deletions
78
data/apps/helpers.d/package
Normal file
78
data/apps/helpers.d/package
Normal file
|
@ -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 $@
|
||||||
|
}
|
|
@ -1,15 +1,14 @@
|
||||||
# Check if a user exists
|
# Check if a YunoHost user exists
|
||||||
#
|
#
|
||||||
# example: ynh_user_exists 'toto' || exit 1
|
# example: ynh_user_exists 'toto' || exit 1
|
||||||
#
|
#
|
||||||
# usage: ynh_user_exists username
|
# usage: ynh_user_exists username
|
||||||
# | arg: username - the username to check
|
# | arg: username - the username to check
|
||||||
# | ret: retcode - 0 if user exists, 1 otherwise
|
|
||||||
ynh_user_exists() {
|
ynh_user_exists() {
|
||||||
sudo yunohost user list --output-as json | grep -q "\"username\": \"${1}\""
|
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')
|
# example: mail=$(ynh_user_get_info 'toto' 'mail')
|
||||||
#
|
#
|
||||||
|
@ -18,5 +17,13 @@ ynh_user_exists() {
|
||||||
# | arg: key - the key to retrieve
|
# | arg: key - the key to retrieve
|
||||||
# | ret: string - the key's value
|
# | ret: string - the key's value
|
||||||
ynh_user_get_info() {
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -1317,7 +1317,7 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None):
|
||||||
try:
|
try:
|
||||||
action_args = manifest['arguments'][action]
|
action_args = manifest['arguments'][action]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.debug("no arguments found for '%s' in '%s'", action, path)
|
logger.debug("no arguments found for '%s' in manifest", action)
|
||||||
else:
|
else:
|
||||||
for arg in action_args:
|
for arg in action_args:
|
||||||
arg_name = arg['name']
|
arg_name = arg['name']
|
||||||
|
|
Loading…
Add table
Reference in a new issue