🎉 Initial library code

This commit is contained in:
Franck Nijhof 2019-03-14 17:14:31 +01:00
parent f91b4cbaa9
commit 2346cddca2
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
26 changed files with 4499 additions and 6 deletions

80
lib/fs.sh Normal file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env bash
# ==============================================================================
# Community Hass.io Add-ons: Bashio
# Bashio is an bash function library for use with Hass.io add-ons.
#
# It contains a set of commonly used operations and can be used
# to be included in add-on scripts to reduce code duplication across add-ons.
# ==============================================================================
# ------------------------------------------------------------------------------
# Check whether or not a directory exists.
#
# Arguments:
# $1 Path to directory
# ------------------------------------------------------------------------------
function bashio::fs.directory_exists() {
local directory=${1}
bashio::log.trace "${FUNCNAME[0]}:" "$@"
if [[ -d "${directory}" ]]; then
return "${__BASHIO_EXIT_OK}"
fi
return "${__BASHIO_EXIT_NOK}"
}
# ------------------------------------------------------------------------------
# Check whether or not a file exists.
#
# Arguments:
# $1 Path to file
# ------------------------------------------------------------------------------
function bashio::fs.file_exists() {
local file=${1}
bashio::log.trace "${FUNCNAME[0]}:" "$@"
if [[ -f "${file}" ]]; then
return "${__BASHIO_EXIT_OK}"
fi
return "${__BASHIO_EXIT_NOK}"
}
# ------------------------------------------------------------------------------
# Check whether or not a device exists.
#
# Arguments:
# $1 Path to device
# ------------------------------------------------------------------------------
function bashio::fs.device_exists() {
local device=${1}
bashio::log.trace "${FUNCNAME[0]}:" "$@"
if [[ -d "${device}" ]]; then
return "${__BASHIO_EXIT_OK}"
fi
return "${__BASHIO_EXIT_NOK}"
}
# ------------------------------------------------------------------------------
# Check whether or not a socket exists.
#
# Arguments:
# $1 Path to socket
# ------------------------------------------------------------------------------
function bashio::fs.socket_exists() {
local socket=${1}
bashio::log.trace "${FUNCNAME[0]}:" "$@"
if [[ -S "${socket}" ]]; then
return "${__BASHIO_EXIT_OK}"
fi
return "${__BASHIO_EXIT_NOK}"
}