Skip to content

Instantly share code, notes, and snippets.

View XIIIVI's full-sized avatar

Fabrice TX XIIIVI

View GitHub Profile
#
# test_succeeded
# - param1: the message to display
#
test_succeeded() {
local MESSAGE=${1}
echo -e "${TEST_RESULT_OK} ${MESSAGE}"
PASSED_TEST_COUNT=$((PASSED_TEST_COUNT + 1))
#
# check_bash_syntax
# - param1: shell to check
#
check_bash_syntax() {
local SCRIPT=${1}
TEST_COUNT=$((TEST_COUNT + 1))
STATUS=$(shellcheck ${SCRIPT} | grep problems | wc -l)
#
# check_if_users_belong_to_docker_group
# - param 1: list of users
# - param 2: targetted group
#
# WARNING: this function uses the global variable FILE_ETC_GROUP
#
check_if_users_belong_to_group() {
local USER_LIST=("$@") # Rebuild the array with rest of arguments
local TARGETTED_GROUP="${2}"
#
# display_file_content
# - param1: the file whose content will be displayed
#
display_file_content() {
local FILE_TO_CAT=${1}
echo -e "${YELLOW}__________________________________ ${FILE_TO_CAT} (Start) __________________________________${RESET_COLOR}"
cat ${FILE_TO_CAT}
#
# install_required_softwares
#
install_required_softwares() {
echo -e "${YELLOW}Installing the required software${RESET_COLOR}"
# Install the required packages if needed
if ! [ -x "$(command -v kpartx)" ]; then
echo -e "${YELLOW}Installing kpartx${RESET_COLOR}"
eval $CMD_APT_GET_INSTALL kpartx
...
# Parses the parameters
while (( "$#" )); do
case "${1}" in
--enable-wifi)
ENABLE_WIFI="true"
shift # past argument
;;
-h|--help)
...
# Parses the parameters
while (( "$#" )); do
case "${1}" in
# Handle flags
--flag1)
FLAG1="true"
shift # past argument
;;
...
#
# banner
# - param1: the text to display
#
banner() {
local MESSAGE=${1}
echo -e "${GREEN}"
...
# Define the APT commands
CMD_APT_GET_UPDATE="DEBIAN_FRONTEND=noninteractive apt-get -qq -o Dpkg::Use-Pty=0 update"
CMD_APT_GET_INSTALL="DEBIAN_FRONTEND=noninteractive apt-get -qq -o Dpkg::Use-Pty=0 install"
CMD_APT_GET_AUTOREMOVE="DEBIAN_FRONTEND=noninteractive apt-get -qq -o Dpkg::Use-Pty=0 --purge autoremove"
CMD_APT_GET_CLEAN="DEBIAN_FRONTEND=noninteractive apt-get -qq -o Dpkg::Use-Pty=0 clean"
#
...
#
# display_help
#
display_help() {
echo "Usage: ${0}.sh --param1 <This is the first parameter>"
echo " --param2 <This is the second parameter>"
echo " --flag1"
echo " [--flag2|flag3 (Default)]"