Skip to content

Commit

Permalink
Merge pull request #154 from masnax/content-interface-ceph
Browse files Browse the repository at this point in the history
snapcraft/hooks: Share common functions among hooks
  • Loading branch information
tomponline authored Sep 21, 2023
2 parents 440402d + 04a0e66 commit fa19eb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 80 deletions.
42 changes: 6 additions & 36 deletions snapcraft/hooks/configure
Original file line number Diff line number Diff line change
@@ -1,46 +1,16 @@
#!/bin/sh -eu
#!/bin/sh

set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi

# Utility functions
get_bool() {
value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]')

# See if it's true
for yes in "true" "1" "yes" "on"; do
if [ "${value}" = "${yes}" ]; then
echo "true"
return
fi
done

# See if it's false
for no in "false" "0" "no" "off"; do
if [ "${value}" = "${no}" ]; then
echo "false"
return
fi
done

# Invalid value (or not set)
return
}

verify_int () {
value="${1:-}"

# Verify if the value is a positive integer
if echo "${value}" | grep -Eq '^[0-9]+$'; then
echo "${value}"
return
fi
SNAP_CURRENT="$(realpath "${SNAP}/..")/current"
export "${SNAP_CURRENT}"

# Invalid value (or not set)
return
}
. "${SNAP_CURRENT}/snap/hooks/common"

# Don't fail if the mount namespace isn't properly setup yet
if [ ! -e /run/snapd-snap.socket ]; then
Expand Down
26 changes: 4 additions & 22 deletions snapcraft/hooks/connect-plug-ceph-conf
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
#!/bin/sh

# Utility functions
get_bool() {
value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]')
set -eu

# See if it's true
for yes in "true" "1" "yes" "on"; do
if [ "${value}" = "${yes}" ]; then
echo "true"
return
fi
done
SNAP_CURRENT="$(realpath "${SNAP}/..")/current"
export "${SNAP_CURRENT}"

# See if it's false
for no in "false" "0" "no" "off"; do
if [ "${value}" = "${no}" ]; then
echo "false"
return
fi
done

# Invalid value (or not set)
return
}
. "${SNAP_CURRENT}/snap/hooks/common"

ceph_builtin=$(get_bool "$(snapctl get ceph.builtin)")

if ! [ "${ceph_builtin:-"false"}" = "true" ]; then
ln -snf ${SNAP_DATA}/microceph/conf/ /etc/ceph
fi
26 changes: 4 additions & 22 deletions snapcraft/hooks/disconnect-plug-ceph-conf
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
#!/bin/sh

# Utility functions
get_bool() {
value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]')
set -eu

# See if it's true
for yes in "true" "1" "yes" "on"; do
if [ "${value}" = "${yes}" ]; then
echo "true"
return
fi
done
SNAP_CURRENT="$(realpath "${SNAP}/..")/current"
export "${SNAP_CURRENT}"

# See if it's false
for no in "false" "0" "no" "off"; do
if [ "${value}" = "${no}" ]; then
echo "false"
return
fi
done

# Invalid value (or not set)
return
}
. "${SNAP_CURRENT}/snap/hooks/common"

ceph_builtin=$(get_bool "$(snapctl get ceph.builtin)")

if [ "${ceph_builtin:-"false"}" = "true" ]; then
mkdir -p "${SNAP_COMMON}/ceph"
ln -snf "${SNAP_COMMON}/ceph" /etc/ceph
Expand Down

0 comments on commit fa19eb0

Please sign in to comment.