[enh] adds hooks contents

This commit is contained in:
root 2020-05-15 09:46:56 +00:00
parent 375bf66c2c
commit 031aad7aa3
2 changed files with 56 additions and 4 deletions

View File

@ -3,6 +3,7 @@
CHANGELOG=/etc/changelog CHANGELOG=/etc/changelog
# functions # functions
msg(){ echo -e "$@"; } msg(){ echo -e "$@"; }
@ -25,10 +26,25 @@ change(){
while true ; do while true ; do
echo -e "\nType the nature of the change.\nExample: > mysql: do not start on boot\n" echo -e "\nType the nature of the change.\nExample: > mysql: do not start on boot\n"
read -e -p "> " SUB read -e -p "> " SUB
echo -e "\nType the comments, how you did that.\nExample: > echo 'manual' | sudo tee -a /etc/init/mysql.override\n" echo -e "* $SUB" >> $TMP
read -e -p "> " EXP echo -e "\nTime for some details."
echo -e "* $SUB\n$EXP\n" >> $TMP
read -e -i "n" -p "More? [yN]:" END for (( ; ; )); do
echo "Select number or x to quit"
for (( i=0; i<${#HOOKS_CONTENT_MENU[@]}; i++)) ; do
echo "$i) ${HOOKS_CONTENT_MENU[$i]}"
done
echo "x) No more details."
read -e -n 1 -p "Your choice? :" REPLY
if [[ "x" == ${REPLY,,} ]]; then
break
elif [[ -z "${HOOKS_CONTENT[$REPLY]}" ]] ; then
echo "Unknown Key."
else
${HOOKS_CONTENT[$REPLY]} $TMP
fi
done
read -e -i "n" -p "Another section? [yN]:" END
[[ "${END^^}" == "N" ]] && break [[ "${END^^}" == "N" ]] && break
done done
echo -e "\nHere is the content you are about to add.\n\n$(cat $TMP)\n" echo -e "\nHere is the content you are about to add.\n\n$(cat $TMP)\n"
@ -38,7 +54,27 @@ change(){
rm $TMP rm $TMP
} }
hookContentComment(){
[[ -z "$1" ]] && echo "Enter a simple comment. Ex: systemctl disable nginx" && return
TMP="$1"
read -e -p "Your comment: " CONTENT
echo "$CONTENT" >> $TMP
}
# Exec # Exec
# Build the hook content menu
HOOKS_CONTENT+=("hookContentComment")
declare -a HOOKS_CONTENT_MENU
[[ -n "hooks-content/*" ]] && source hooks-content/*
for (( i = 0; i < ${#HOOKS_CONTENT[@]} ; i++ )); do
TXT=$( ${HOOKS_CONTENT[$i]} )
HOOKS_CONTENT_MENU+=("$( ${HOOKS_CONTENT[$i]} )")
done
echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n" echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
# set environment variables # set environment variables
[[ -z "$CHANGELOG_USERNAME" ]] && read -e -p "Your name? " NAME&& read -e -p "Your email? " EMAIL && CHANGELOG_USERNAME="${NAME^} <$EMAIL>" && echo "export CHANGELOG_USERNAME=\"$CHANGELOG_USERNAME\"" [[ -z "$CHANGELOG_USERNAME" ]] && read -e -p "Your name? " NAME&& read -e -p "Your email? " EMAIL && CHANGELOG_USERNAME="${NAME^} <$EMAIL>" && echo "export CHANGELOG_USERNAME=\"$CHANGELOG_USERNAME\""

16
hooks-content/hastebin.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
HOOKS_CONTENT+=( hookContentHastebin )
HASTEBIN_SERVER=https://paste.interhacker.space
hookContentHastebin(){
[[ -z "$1" ]] && echo "Store a file by name in pastebin" && return
TMP="$1"
read -e -p "File location? " FILE
[[ ! -f $FILE ]] && panic "Not a valid file" && exit
URL=$( curl -X POST -s -d "$(cat "$FILE" )" "$HASTEBIN_SERVER/documents" | awk -F '"' '{print "'$HASTEBIN_SERVER'/raw/"$4}'; )
echo "$FILE: $URL" >> $TMP
}