59 lines
No EOL
2 KiB
Bash
Executable file
59 lines
No EOL
2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# SCRIPT NAME:
|
|
# utils
|
|
#
|
|
# AUTHOR:
|
|
# Severin Kaderli <severin@kaderli.dev>
|
|
#
|
|
# DESCRIPTION:
|
|
# This script provides functions and variables that I use in my other scripts.
|
|
# It is not supposed to be run directly but to be sourced by other scripts.
|
|
#
|
|
# USAGE:
|
|
# Source this script in the needed script.
|
|
#######################################
|
|
# Directory variables
|
|
#######################################
|
|
DIR="$( cd "$(dirname "${BASH_SOURCE[0]}" )" && cd ../../../ && pwd)"
|
|
SYSTEM_DIR="${DIR}/system"
|
|
PACKAGES_DIR="${DIR}/packages"
|
|
|
|
#######################################
|
|
# Bash color code variables
|
|
#######################################
|
|
RESET='\033[0m'
|
|
GREEN='\033[32m'
|
|
RED='\033[31m'
|
|
BLUE='\033[34m'
|
|
YELLOW='\033[33m'
|
|
BOLD="$(tput bold)"
|
|
|
|
#######################################
|
|
# Helper functions
|
|
#######################################
|
|
# Function to print out a log entry together with the current date and time.
|
|
# USAGE: print_time_log SCRIPT MESSAGE
|
|
function print_time_log() {
|
|
echo -e "[$(date "+%F %T")][${1}] ${2}"
|
|
}
|
|
|
|
# Function to print a info message with the current time and to send
|
|
# a notification using notify-send.
|
|
# USAGE: print_notify TITLE MESSAGE
|
|
function print_notify() {
|
|
notify-send "${1}" "${2}"
|
|
echo -e "${YELLOW}[$(date "+%T")] ${1} ${2}${RESET}"
|
|
}
|
|
|
|
# Prints a section title.
|
|
# USAGE: print_section TITLE
|
|
function print_section() {
|
|
echo -e "${YELLOW}${BOLD}┌──────────────────────────────────────────────────────────────────────────────┐"
|
|
echo -e "│ $(printf "%-77s" "${1}")│"
|
|
echo -e "└──────────────────────────────────────────────────────────────────────────────┘${RESET}"
|
|
}
|
|
|
|
function print_log() {
|
|
echo -e " • $1"
|
|
} |