#!/bin/bash # # SCRIPT NAME: # utils.sh # # AUTHOR: # Severin Kaderli # # 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' ####################################### # Helper functions ####################################### # Function to display fancy headers # USAGE: print_header TITLE function print_header() { echo -e "\n${GREEN}########################################" echo -e "# ${1}" echo -e "########################################${RESET}" } # Creates the given directory in the home directory # USAGE: create_directory DIRECTORY function create_directory() { echo -e "- Creating directory ${YELLOW}${HOME}/${1}${RESET}" mkdir -p "${HOME}/${1}" } # Creates a symlink of the given file from the home directory to here. # USAGE: create_link FILE function create_link() { echo -e "- Linking ${YELLOW}${HOME}/${1}${RESET} -> ${YELLOW}${SYSTEM_DIR}/${1}${RESET}" rm -rf "${HOME:?}/$1" ln -fs "${SYSTEM_DIR}/${1}" "${HOME}/${1}" } # Function to set owner and permission of a file # USAGE: set_permission OWNER PERMISSION FILE function set_permission() { echo -e "- Changing permission of ${YELLOW}${3}${RESET} to ${YELLOW}${1}${RESET}" sudo chown -R "${1}" "${3}" echo -e "- Changing permission of ${YELLOW}${3}${RESET} to ${YELLOW}${2}${RESET}" sudo chmod -R "${2}" "${3}" } # Function to enable a service # USAGE: enable_service SERVICE function enable_service() { echo -e "- Enabling service ${YELLOW}${1}${RESET}" sudo systemctl enable "${1}" }