+#
+# Helper functions
+#
+message()
+{
+ if [ -x /bin/plymouth ] && plymouth --ping; then
+ plymouth message --text="$*"
+ else
+ echo "$*" >&2
+ fi
+}
+
+panic2()
+{
+ # Send the panic message to plymouth
+ if [ -x /bin/plymouth ] && plymouth --ping; then
+ plymouth message --text="$*"
+ fi
+ panic "$@"
+ exit 1
+}
+
+unlock()
+{
+ local msg=$1
+ shift
+
+ if [ -x /bin/plymouth ] && plymouth --ping; then
+ msg=$(plymouth ask-for-password --prompt="$msg" | \
+ bcachefs unlock "$@" 2>&1)
+ # If the unlock failed, send any printed messages to plymouth
+ if [ $? -ne 0 ]; then
+ plymouth message --text="Bcachefs: $msg"
+ return 1
+ fi
+ else
+ # If unlock() is called multiple times, don't re-print the prompt message
+ # unless it has changed
+ if [ "$LAST_UNLOCK_MSG" != "$msg" ]; then
+ echo "$msg" >&2
+ LAST_UNLOCK_MSG=$msg
+ fi
+ bcachefs unlock "$@"
+ fi
+}
+