File bin/lib.sh
Last commit: Tue Nov 26 23:26:36 2024 +0100 Jan Dankert New: Creating a project website
1 #!/bin/bash 2 3 # is $1 a boolean true? 4 is_on() { 5 if [[ "$1" == "true" || "$1" == "1" || "$1" == "on" || "$1" == "enabled" ]]; then 6 return 0; # RC 0 is "true" ;) 7 else 8 return 1 # 1 is != 0, means false ;) 9 fi 10 } 11 12 comma_sep() { 13 echo $1|xargs|sed "s/ /,/g" 14 } 15 16 17 # thx to Stefan Farestam 18 # source: https://stackoverflow.com/questions/5014632/how-can-i-parse-a-yaml-file-from-a-linux-shell-script 19 function parse_yaml { 20 local prefix=$2 21 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') 22 sed -ne "s|^\($s\):|\1|" \ 23 -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ 24 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | 25 awk -F$fs '{ 26 indent = length($1)/2; 27 vname[indent] = $2; 28 for (i in vname) {if (i > indent) {delete vname[i]}} 29 if (length($3) > 0) { 30 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} 31 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3); 32 } 33 }' 34 } 35 36 function notify() { 37 receiver_list=$(comma_sep "$notify_add_receiver_mail $repo_email $USER_EMAIL $LAST_COMMIT_EMAIL") 38 39 if is_on $notify_sendmail; then 40 #echo "Sending mail to $1" 41 printf "To: Jan\nSubject: %s\n\n%s" "Report for $REPO_NAME: $STATUS" "$(cat $TMPFILE)" | sendmail "$receiver_list" 42 if [ $? -ne 0 ]; then 43 cat $TMPFILE 1&2 44 echo "Sending the mail FAILED" 1>&2 45 return 4 46 fi 47 fi 48 49 if ( is_on $notify_smtp && [ -n "$notify_smtp_host" ] ); then 50 curl --silent smtp://${notify_smtp_host} --mail-from "$notify_smtp_from" --mail-rcpt "${notify_add_receiver_mail}" \ 51 --header "Subject: Report for $REPO_NAME: $STATUS" \ 52 --header "X-Repo: $REPO_NAME" \ 53 $receiver_list --upload-file $TMPFILE 2>&1 54 if [ $? -ne 0 ]; then 55 echo "Sending the mail via curl FAILED" 1>&2 56 cat $TMPFILE 1>&2 # Fallback: Std-Out 57 return 4 58 fi 59 fi 60 61 if is_on $notify_stdout; then 62 echo "Output:" 63 cat $TMPFILE 64 fi 65 }
Downloadbin/lib.sh
History Tue, 26 Nov 2024 23:26:36 +0100 Jan Dankert New: Creating a project website Sun, 12 May 2024 19:53:02 +0200 Jan Dankert first edition of DIT, the delivery expert.