[fix] Bit of renaming things

This commit is contained in:
alban 2020-05-18 01:10:06 +02:00
parent e77830a144
commit d296e615e9
6 changed files with 71 additions and 52 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
.*.sw*
config.sh
build/

View File

@ -1,8 +1,18 @@
#!/bin/bash
#Manages an /etc/changelog
# %CONFIG% This comment is used to build custom scripts
CHANGELOG=/etc/changelog
[[ -w /etc/changelog ]] || {
echo -e "\nYou cannot write to $CHANGELOG... This doesn't look serious!\n"
read -e -i y -n 1 -p "Run as sudo [Yn]? : "
[[ "Y" == ${REPLY^} ]] && sudo -E $0
exit 0
}
# functions
@ -19,17 +29,17 @@ change(){
for (( ; ; )); do
echo "Select number or x to quit"
for (( i=0; i<${#HOOKS_CONTENT_MENU[@]}; i++)) ; do
echo "$i) ${HOOKS_CONTENT_MENU[$i]}"
for (( i=0; i<${#PLUGIN_CONTENT_MENU[@]}; i++)) ; do
echo "$i) ${PLUGIN_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
elif [[ -z "${PLUGIN_CONTENT[$REPLY]}" ]] ; then
echo "Unknown Key."
else
${HOOKS_CONTENT[$REPLY]} $TMP
${PLUGIN_CONTENT[$REPLY]} $TMP
fi
done
read -e -i "n" -p "Another section? [yN]:" END
@ -37,8 +47,7 @@ change(){
done
echo -e "\nHere is the content you are about to add.\n\n$(cat $TMP)\n"
read -e -p "OK? [Yn]: " -i y RETURN
[[ "N" == ${RETURN^^} ]] && return
echo $TMP
[[ "N" == ${RETURN^^} ]] && return 1
}
hookContentComment(){
@ -54,6 +63,7 @@ hookOutputFile(){
TMP="$1"
cat << HEREDOC >$t
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
$( echo -e "$@"|sed 's/^/ /' )
@ -65,29 +75,30 @@ HEREDOC
}
# Build the hook content menu
PLUGIN_CONTENT+=("hookContentComment")
declare -a PLUGIN_CONTENT_MENU
# Build the hook content menu
PLUGIN_OUTPUT+=("hookOutputFile")
declare -a PLUGIN_OUTPUT_MENU
# %PLUGIN% This comment is used to build custom scripts
[[ -d "plugins-enabled" ]] && [[ -n "plugins-enabled/*" ]] && source plugins-enabled/*
for (( i = 0; i < ${#PLUGIN_OUTPUT[@]} ; i++ )); do
TXT=$( ${PLUGIN_OUTPUT[$i]} )
PLUGIN_OUTPUT_MENU+=("$( ${PLUGIN_OUTPUT[$i]} )")
done
for (( i = 0; i < ${#PLUGIN_CONTENT[@]} ; i++ )); do
TXT=$( ${PLUGIN_CONTENT[$i]} )
PLUGIN_CONTENT_MENU+=("$( ${PLUGIN_CONTENT[$i]} )")
done
# 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
# Build the hook content menu
HOOKS_OUTPUT+=("hookOutputFile")
declare -a HOOKS_OUTPUT_MENU
[[ -n "hooks-output/*" ]] && source hooks-output/*
for (( i = 0; i < ${#HOOKS_OUTPUT[@]} ; i++ )); do
TXT=$( ${HOOKS_OUTPUT[$i]} )
HOOKS_OUTPUT_MENU+=("$( ${HOOKS_OUTPUT[$i]} )")
done
echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
# 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\""
@ -99,9 +110,11 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
# parse command
change "$ENTRY_FILE"
for (( i=0; i<${#HOOKS_OUTPUT_MENU[@]}; i++)) ; do
echo "${HOOKS_OUTPUT_MENU[$i]}"
${HOOKS_OUTPUT[$i]} $ENTRY_FILE
[[ $? -eq 0 ]] && exit
for (( i=0; i<${#PLUGIN_OUTPUT_MENU[@]}; i++)) ; do
echo "${PLUGIN_OUTPUT_MENU[$i]}"
${PLUGIN_OUTPUT[$i]} $ENTRY_FILE
done
rm "$ENTRY_FILE"

View File

@ -1,15 +0,0 @@
#!/bin/bash
HOOKS_OUTPUT+=( hookOutputChangelogServer )
CHANGELOG_SERVER=http://localhost:3000
hookOutputChangelogServer(){
[[ -z "$1" ]] && echo "Sending changelog to remote server" && return
CONTENT=$(jq -aRs . $1|tr '"' '\"')
PAYLOAD="{\"author\":\"$CHANGELOG_USERNAME\",\"server\":\"$(hostname -f)\",\"content\":${CONTENT}}"
URL=$( curl -X POST -H "Content-Type: application/json" -s -d "${PAYLOAD}" "$CHANGELOG_SERVER/changelog/_doc"; )
echo "$FILE: $URL" >> $TMP
}

View File

@ -1,16 +1,16 @@
#!/bin/bash
HOOKS_CONTENT+=( hookContentHastebin )
HASTEBIN_SERVER=https://paste.interhacker.space
# Sends the changelog information to a changelog server
# see https://git.interhacker.space/alban/changelog-server
# Requires an environmental variable to work
# ex: HASTEBIN_SERVER=https://paste.interhacker.space
PLUGIN_CONTENT+=( hookContentHastebin )
hookContentHastebin(){
[[ -z "$1" ]] && echo "Store a file by name in pastebin" && return
[[ -z "$HASTEBIN_SERVER" ]] && echo "Missing HASTEBIN_SERVER variable. Exiting." && 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
}

View File

@ -0,0 +1,18 @@
#!/bin/bash
# Sends the changelog information to a changelog server
# see https://git.interhacker.space/alban/changelog-server
# Requires environmental variables to work
# CHANGELOG_SERVER
# CHANGELOG_AUTH_KEY
PLUGIN_OUTPUT+=( hookOutputChangelogServer )
hookOutputChangelogServer(){
[[ -z "$1" ]] && echo "Sending changelog to remote server" && return
[[ -z "$CHANGELOG_SERVER" ]] && echo "Missing CHANGELOG_SERVER variable. Exiting." && return
[[ -z "$CHANGELOG_AUTH_KEY" ]] && echo "Missing CHANGELOG_AUTH_KEY variable. Exiting." && return
CONTENT=$(jq -aRs . $1|tr '"' '\"')
PAYLOAD="{\"author\":\"$CHANGELOG_USERNAME\",\"server\":\"$(hostname -f)\",\"content\":${CONTENT}}"
URL=$( curl -X POST -H "AuthorizationToken: $CHANGELOG_AUTH_KEY" -H "Content-Type: application/json" -s -d "${PAYLOAD}" "$CHANGELOG_SERVER/changelog/_doc"; )
[[ 0 -ne $? ]] && echo "Failed to upload the changelog..." && return
echo "$FILE: $URL" >> $TMP
}

1
plugins-enabled/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*