diff --git a/changelog.sh b/changelog.sh index 83cb9e7..fa37754 100755 --- a/changelog.sh +++ b/changelog.sh @@ -1,24 +1,15 @@ #!/bin/bash #Manages an /etc/changelog -# Immediately attempt to read from named pipe -# And store the piped content if provided -[[ -p /proc/self/fd/0 ]] && export STDIN=$( cat ) -# And then force the input to be from terminal -exec 0/dev/null && RUN_SUDO=1 [[ $RUN_SUDO -eq 1 ]] && { @@ -31,8 +22,6 @@ APP_NAME=$( basename ${BASH_SOURCE[0]}) msg(){ echo -e "$@"; } panic(){ msg "${@} Exiting."; exit 1;} ENTRY_FILE=$(mktemp) - -# This is the main function change(){ TMP="$1" while true ; do @@ -59,6 +48,9 @@ change(){ read -e -i "n" -p "Another section? [yN]:" END [[ "${END^^}" == "N" ]] && break 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 } template(){ @@ -120,21 +112,11 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n" # check changelog exists [[ ! -f "$CHANGELOG" ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n" > "$CHANGELOG" -# Detect piped content -if [[ -n "$STDIN" ]] ; then - echo -e "$STDIN" > $ENTRY_FILE +# parse command +change "$ENTRY_FILE" -#OR enter interactive mode -else - change "$ENTRY_FILE" -fi +[[ $? -eq 0 ]] && exit -# confirm the output -echo -e "\nHere is the content you are about to add:\n\n$(cat $ENTRY_FILE)\n" -read -e -p "OK? [Yn]: " -i y RETURN -[[ "N" == ${RETURN^^} ]] && exit 1 - -# Send data to outputs for (( i=0; i<${#PLUGIN_OUTPUT_MENU[@]}; i++)) ; do echo "${PLUGIN_OUTPUT_MENU[$i]}" ${PLUGIN_OUTPUT[$i]} $ENTRY_FILE diff --git a/config.sample.sh b/config.sample.sh index c7935c6..3995eeb 100644 --- a/config.sample.sh +++ b/config.sample.sh @@ -1,4 +1,3 @@ -CHANGELOG=/etc/Changelog CHANGELOG_SERVER=https://changelog.example.com CHANGELOG_AUTH_KEY=your-shared-secret HASTEBIN_SERVER=https://hastebin.com diff --git a/plugins-available/content-command.sh b/plugins-available/content-command.sh deleted file mode 100644 index e7a9a27..0000000 --- a/plugins-available/content-command.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# Add a content line by decorating the input with triple backticks ``` -PLUGIN_CONTENT+=( hookContentCmd ) -hookContentCmd(){ - [[ -z "$1" ]] && echo "Add a shell command line" && return - TMP="$1" - read -e -p "Command line? " CMD - [[ -z "$CMD" ]] && panic "Not a valid content" && return - echo "\`\`\`$CMD\`\`\`" >> $TMP -} - diff --git a/plugins-available/content-hastebin.sh b/plugins-available/content-hastebin.sh index aa1d03b..2b7a238 100644 --- a/plugins-available/content-hastebin.sh +++ b/plugins-available/content-hastebin.sh @@ -1,15 +1,15 @@ #!/bin/bash -# Adds a line by sending a file to a hastebin server -# and then print a "/a/file/name https://haste.bin/urlurlurl" line +# Sends the changelog information to a changelog server +# see https://git.interhacker.space/alban/changelog-server # Requires an environmental variable to work -# example HASTEBIN_SERVER=https://paste.interhacker.space +# 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" && return + [[ ! -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 }