Skip to content

Instantly share code, notes, and snippets.

@klcodanr
Created August 27, 2022 22:11
Show Gist options
  • Save klcodanr/952d01787890eeb7fd6cda227cc0812f to your computer and use it in GitHub Desktop.
Save klcodanr/952d01787890eeb7fd6cda227cc0812f to your computer and use it in GitHub Desktop.
#!/bin/bash
# The MIT License
#
# Copyright (c) 2022 Dan Klco
#
# Permission is hereby granted, free of charge,
# to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to
# deal in the Software without restriction, including
# without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom
# the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
help() {
echo "./reprocess.sh [host] [file]"
echo "Initiates reprocessing of the paths read from the specified file."
echo " - host the full hostname including the protocol but not the path"
echo " - file a file containing the paths to reprocess, separated by newlines"
}
reprocess() {
RESULT=$(curl -u "${USERNAME}:${PASSWORD}" "${HOST}/bin/asynccommand" -X POST -d profile-select=${PROFILE} -d runPostProcess=true -d operation=PROCESS -d description="Bulk Reprocess" ${REPROCESS_PATHS})
PARSED=$(echo $RESULT | xmllint --xpath '//div[@id="Message"]/text()' -)
echo $PARSED
}
HOST=$1
if [ -z "$HOST" ]; then
echo "ERROR: Host required!"
help
exit 1
fi
FILE=$2
if [ ! -f "$FILE" ]; then
echo "ERROR: File required!"
help
exit 1
fi
PROFILE=${3:-full-process}
read -p 'Username: ' USERNAME
read -sp 'Password: ' PASSWORD
COUNT=0
REPROCESS_PATHS="";
echo ""
echo "Paths:"
while read -r line; do
echo " - ${line}"
ENCODED=$(jq -rn --arg x "${line}" '$x|@uri')
REPROCESS_PATHS="${REPROCESS_PATHS} -d asset=${ENCODED}"
((COUNT=COUNT+1))
done < $FILE
while true; do
read -p "About to reprocess ${COUNT} assets on ${HOST} with user ${USERNAME} and profile ${PROFILE}, proceed? (yes/no) " yn
case $yn in
yes )
reprocess
exit 0;;
no ) echo exiting...;
exit 1;;
* ) echo invalid response;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment