diff --git a/.gitignore b/.gitignore index 8e329c3..726c3ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ .*.sw* -config.sh -build/ diff --git a/build.sh b/build.sh deleted file mode 100755 index e551f25..0000000 --- a/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -PLUGINS=$( grep -hv "^#!" plugins-enabled/* ) - -BUILD_FILE=build/changelog -mkdir -p build -[[ -f $BUILD_FILE ]] && rm $BUILD_FILE -cp changelog.sh $BUILD_FILE - -PLUGIN_LINE=$(awk '/%PLUGIN%/ { print NR; exit}' $BUILD_FILE ) -sed -i "${PLUGIN_LINE}r /dev/stdin" $BUILD_FILE <<< "$PLUGINS" - -[[ -f config.sh ]] && { - - CONFIG_LINE=$(awk '/%CONFIG%/ { print NR; exit}' $BUILD_FILE ) - sed -i "${CONFIG_LINE}r config.sh" $BUILD_FILE - -} - -echo "Successfuly built $BUILD_FILE." diff --git a/changelog.sh b/changelog similarity index 62% rename from changelog.sh rename to changelog index de9dc6a..ee7baa0 100755 --- a/changelog.sh +++ b/changelog @@ -1,18 +1,8 @@ #!/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 @@ -29,17 +19,17 @@ change(){ for (( ; ; )); do echo "Select number or x to quit" - for (( i=0; i<${#PLUGIN_CONTENT_MENU[@]}; i++)) ; do - echo "$i) ${PLUGIN_CONTENT_MENU[$i]}" + 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 "${PLUGIN_CONTENT[$REPLY]}" ]] ; then + elif [[ -z "${HOOKS_CONTENT[$REPLY]}" ]] ; then echo "Unknown Key." else - ${PLUGIN_CONTENT[$REPLY]} $TMP + ${HOOKS_CONTENT[$REPLY]} $TMP fi done read -e -i "n" -p "Another section? [yN]:" END @@ -47,7 +37,8 @@ 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 1 + [[ "N" == ${RETURN^^} ]] && return + echo $TMP } hookContentComment(){ @@ -63,7 +54,6 @@ hookOutputFile(){ TMP="$1" cat << HEREDOC >$t - $(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME $( echo -e "$@"|sed 's/^/ /' ) @@ -75,30 +65,29 @@ 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\"" @@ -110,11 +99,9 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n" # parse command change "$ENTRY_FILE" -[[ $? -eq 0 ]] && exit - -for (( i=0; i<${#PLUGIN_OUTPUT_MENU[@]}; i++)) ; do - echo "${PLUGIN_OUTPUT_MENU[$i]}" - ${PLUGIN_OUTPUT[$i]} $ENTRY_FILE +for (( i=0; i<${#HOOKS_OUTPUT_MENU[@]}; i++)) ; do + echo "${HOOKS_OUTPUT_MENU[$i]}" + ${HOOKS_OUTPUT[$i]} $ENTRY_FILE done rm "$ENTRY_FILE" diff --git a/plugins-available/content-hastebin.sh b/hooks-content/hastebin.sh similarity index 51% rename from plugins-available/content-hastebin.sh rename to hooks-content/hastebin.sh index 2b7a238..f1f77d7 100644 --- a/plugins-available/content-hastebin.sh +++ b/hooks-content/hastebin.sh @@ -1,16 +1,16 @@ #!/bin/bash -# 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 ) + +HOOKS_CONTENT+=( hookContentHastebin ) + +HASTEBIN_SERVER=https://paste.interhacker.space + 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 -} +} diff --git a/hooks-output/changelog-server.sh b/hooks-output/changelog-server.sh new file mode 100644 index 0000000..0e37be3 --- /dev/null +++ b/hooks-output/changelog-server.sh @@ -0,0 +1,15 @@ +#!/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 + +} diff --git a/plugins-available/output-changelog-server.sh b/plugins-available/output-changelog-server.sh deleted file mode 100644 index 003c9a3..0000000 --- a/plugins-available/output-changelog-server.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 -} - diff --git a/plugins-enabled/.gitignore b/plugins-enabled/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/plugins-enabled/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*