{pkgs, ...}: '' if [ -t 1 ]; then RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' RESET='\033[0m' BOLD='\033[1m' else RED="" GREEN="" BLUE="" RESET="" fi ## this function is used to change the working directory to the one specified in ## the USER_WORKING_DIR environment variable. this is necessary if you want to edit ## files in the repository. cd_working_dir() { working_dir=$(echo $USER_WORKING_DIR) if [ -z "$working_dir" ]; then echo_fail "USER_WORKING_DIR is not set" echo_hint "Please set the USER_WORKING_DIR environment variable" exit 1 fi if [ ! -d "$working_dir" ]; then echo_fail "USER_WORKING_DIR does not exist" echo_hint "Please set the USER_WORKING_DIR environment variable to a valid directory" exit 1 fi cd $working_dir git_root=$(git rev-parse --show-toplevel) if [ -z "$git_root" ]; then echo_fail "Not a git repository" echo_hint "Please run this script in a git repository" exit 1 fi cd $git_root echo_ok "Changed directory to $working_dir" } is_true() { val="$1" if [ "$val" = 'true' ] || [ "$val" = '1' ]; then return 0 else return 1 fi } echo_header() { ${pkgs.figlet}/bin/figlet -t -f doom -l "$1" } echo_ok() { echo -e "$GREEN✔$RESET $1" } echo_delimiter() { echo " " } echo_section() { echo -e "\n\n$BOLD$1$RESET" } echo_text() { echo -e "$1" } echo_fail() { echo -e "$RED✖ $1$RESET" } echo_hint() { echo -e "$BLUE→ $1$RESET" } echo_step() { echo -e "$BLUE•$RESET $1" } convert_multiline_for_nix() { printf "%s" " }$1" | ${pkgs.gnused}/bin/sed 's/\\/\\\\/g; s/"/\\"/g; s/$/\\n/g' | tr -d '\n' } download_test_images() { echo_step "Downloading docker images" if ! ${pkgs.docker}/bin/docker images | grep atmoz/sftp | grep alpine then echo_step "Downloading atmoz/sftp:alpine" if ! ${pkgs.docker}/bin/docker pull atmoz/sftp:alpine then echo_fail "Failed to download atmoz/sftp:alpine" exit 1 fi fi if ! ${pkgs.docker}/bin/docker images | grep axllent/mailpit then echo_step "Downloading atmoz/sftp:alpine" if ! ${pkgs.docker}/bin/docker pull axllent/mailpit then echo_fail "Failed to download axllent/mailpit" exit 1 fi fi } setup_go_env() { echo_step "Changing directory to ${../..}" cd ${../..} echo_step "Setting GO111MODULE=auto" if ! ${pkgs.go}/bin/go env -w GO111MODULE=auto then echo_fail "Failed to set GO111MODULE=auto" exit 1 fi } if [ -z "$DEBUG_MODE" ]; then DEBUG_MODE='false' fi if [ -n "$CI_JOB_TOKEN" ]; then CI_MODE='true' fi if is_true "$DEBUG_MODE" || is_true "$CI_MODE"; then set -x fi ''