mirror of
https://github.com/hassio-addons/bashio.git
synced 2025-05-06 20:11:24 +00:00
✨ 🎉 Initial library code
This commit is contained in:
parent
f91b4cbaa9
commit
2346cddca2
26 changed files with 4499 additions and 6 deletions
80
lib/fs.sh
Normal file
80
lib/fs.sh
Normal 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}"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue