From 0adaf05483dd196e0090cfe7145d0317f41213d6 Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 3 Jun 2020 20:52:22 +0200 Subject: [PATCH 1/4] [enh] It should be able to read from piped content --- changelog.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/changelog.sh b/changelog.sh index fa37754..7a3a554 100755 --- a/changelog.sh +++ b/changelog.sh @@ -4,7 +4,9 @@ APP_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) && pwd ) APP_NAME=$( basename ${BASH_SOURCE[0]}) - +STDIN=$( cat ) +ls -lh /proc/self/fd +exec 0 "$CHANGELOG" -# parse command -change "$ENTRY_FILE" +# Detect piped content +if [[ -n "$STDIN" ]] ; then + echo -e "$STDIN" > $ENTRY_FILE -[[ $? -eq 0 ]] && exit +#OR enter interactive mode +else + change "$ENTRY_FILE" +fi +# 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 From a5cf3456c68b5ce9d92a1f661e35b57ae42eadb8 Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 3 Jun 2020 21:50:40 +0200 Subject: [PATCH 2/4] [fix] Changelog location should be configurable and piped content work with self call of sudo --- changelog.sh | 15 +++++++++++---- config.sample.sh | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/changelog.sh b/changelog.sh index 7a3a554..83cb9e7 100755 --- a/changelog.sh +++ b/changelog.sh @@ -1,17 +1,24 @@ #!/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 ]] && { diff --git a/config.sample.sh b/config.sample.sh index 3995eeb..c7935c6 100644 --- a/config.sample.sh +++ b/config.sample.sh @@ -1,3 +1,4 @@ +CHANGELOG=/etc/Changelog CHANGELOG_SERVER=https://changelog.example.com CHANGELOG_AUTH_KEY=your-shared-secret HASTEBIN_SERVER=https://hastebin.com From 68bd4f90d32ca07f68c65dc1f2a415a710cef4e0 Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 3 Jun 2020 21:51:15 +0200 Subject: [PATCH 3/4] [enh] There should be a command plugin --- plugins-available/content-command.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 plugins-available/content-command.sh diff --git a/plugins-available/content-command.sh b/plugins-available/content-command.sh new file mode 100644 index 0000000..e7a9a27 --- /dev/null +++ b/plugins-available/content-command.sh @@ -0,0 +1,11 @@ +#!/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 +} + From 8890984007de8b10e6ee8ff8fffe537b3d670c03 Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 3 Jun 2020 21:51:32 +0200 Subject: [PATCH 4/4] [fix] content hastebin should work --- plugins-available/content-hastebin.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins-available/content-hastebin.sh b/plugins-available/content-hastebin.sh index 2b7a238..aa1d03b 100644 --- a/plugins-available/content-hastebin.sh +++ b/plugins-available/content-hastebin.sh @@ -1,15 +1,15 @@ #!/bin/bash -# Sends the changelog information to a changelog server -# see https://git.interhacker.space/alban/changelog-server +# Adds a line by sending a file to a hastebin server +# and then print a "/a/file/name https://haste.bin/urlurlurl" line # Requires an environmental variable to work -# ex: HASTEBIN_SERVER=https://paste.interhacker.space +# example 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 + [[ ! -f $FILE ]] && panic "Not a valid file" && return URL=$( curl -X POST -s -d "$(cat "$FILE" )" "$HASTEBIN_SERVER/documents" | awk -F '"' '{print "'$HASTEBIN_SERVER'/raw/"$4}'; ) echo "$FILE: $URL" >> $TMP }