diff --git a/manifests/script.pp b/manifests/script.pp index 4bc0da4..c5ccce9 100644 --- a/manifests/script.pp +++ b/manifests/script.pp @@ -327,6 +327,13 @@ class sunetdrive::script ( group => 'root', mode => '0700', } + file { '/root/tasks/delete_announcement_with_subject.sh': + ensure => file, + content => template('sunetdrive/script/delete_announcement_with_subject.erb.sh'), + owner => 'root', + group => 'root', + mode => '0700', + } file { '/root/tasks/backupmultinodedb.sh': ensure => file, content => template('sunetdrive/script/backupmultinodedb.erb.sh'), diff --git a/templates/script/delete_announcement_with_subject.erb.sh b/templates/script/delete_announcement_with_subject.erb.sh new file mode 100755 index 0000000..a263dd0 --- /dev/null +++ b/templates/script/delete_announcement_with_subject.erb.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +VALID_ARGS=$(getopt -o s --long subject -- "$@") +# shellcheck disable=SC2181 +if [[ ${?} -ne 0 ]]; then + exit 1; +fi + +usage () { + echo "${0}: -s|--subject " + exit 1 +} + +eval set -- "${VALID_ARGS}" +# shellcheck disable=SC2078 +while [ : ]; do + case "$1" in + -s | --subject) + subject="${2}" + shift 2 + ;; + *) + break + ;; + esac +done + +if [[ -z ${subject} ]]; then + usage +fi +fi + +id=$(/root/tasks/announce.sh --get | xmlstarlet sel -t -i '//subject="'${subject}'"' -m "/ocs/data/element/id" -v .) +if [[ -n ${id} ]]; then + /root/tasks/announce.sh --delete --id "${id}" +fi