Compare commits
4 Commits
3974567080
...
8890984007
Author | SHA1 | Date | |
---|---|---|---|
|
8890984007 | ||
|
68bd4f90d3 | ||
|
a5cf3456c6 | ||
|
0adaf05483 |
32
changelog.sh
32
changelog.sh
@ -1,15 +1,24 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#Manages an /etc/changelog
|
#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/tty
|
||||||
|
|
||||||
|
# Defining some path variables
|
||||||
APP_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) && pwd )
|
APP_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) && pwd )
|
||||||
APP_NAME=$( basename ${BASH_SOURCE[0]})
|
APP_NAME=$( basename ${BASH_SOURCE[0]})
|
||||||
|
|
||||||
CHANGELOG=/etc/changelog
|
|
||||||
|
|
||||||
|
|
||||||
# %CONFIG% This comment is used to build custom scripts
|
# %CONFIG% This comment is used to build custom scripts
|
||||||
[[ -f "$APP_PATH/config.sh" ]] && source "$APP_PATH/config.sh"
|
[[ -f "$APP_PATH/config.sh" ]] && source "$APP_PATH/config.sh"
|
||||||
|
|
||||||
# Sanity check on changelog file
|
# Sanity check on changelog file
|
||||||
|
[[ -n "$CHANGELOG" ]] && CHANGELOG="/etc/Changelog"
|
||||||
[[ -f "$CHANGELOG" ]] && [[ ! -w "$CHANGELOG" ]] && RUN_SUDO=1
|
[[ -f "$CHANGELOG" ]] && [[ ! -w "$CHANGELOG" ]] && RUN_SUDO=1
|
||||||
[[ ! -f "$CHANGELOG" ]] && ! touch /etc/changelog &>/dev/null && RUN_SUDO=1
|
[[ ! -f "$CHANGELOG" ]] && ! touch /etc/changelog &>/dev/null && RUN_SUDO=1
|
||||||
[[ $RUN_SUDO -eq 1 ]] && {
|
[[ $RUN_SUDO -eq 1 ]] && {
|
||||||
@ -22,6 +31,8 @@ CHANGELOG=/etc/changelog
|
|||||||
msg(){ echo -e "$@"; }
|
msg(){ echo -e "$@"; }
|
||||||
panic(){ msg "${@} Exiting."; exit 1;}
|
panic(){ msg "${@} Exiting."; exit 1;}
|
||||||
ENTRY_FILE=$(mktemp)
|
ENTRY_FILE=$(mktemp)
|
||||||
|
|
||||||
|
# This is the main function
|
||||||
change(){
|
change(){
|
||||||
TMP="$1"
|
TMP="$1"
|
||||||
while true ; do
|
while true ; do
|
||||||
@ -48,9 +59,6 @@ change(){
|
|||||||
read -e -i "n" -p "Another section? [yN]:" END
|
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"
|
|
||||||
read -e -p "OK? [Yn]: " -i y RETURN
|
|
||||||
[[ "N" == ${RETURN^^} ]] && return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template(){
|
template(){
|
||||||
@ -112,11 +120,21 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
|
|||||||
# check changelog exists
|
# check changelog exists
|
||||||
[[ ! -f "$CHANGELOG" ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n" > "$CHANGELOG"
|
[[ ! -f "$CHANGELOG" ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n" > "$CHANGELOG"
|
||||||
|
|
||||||
# parse command
|
# Detect piped content
|
||||||
change "$ENTRY_FILE"
|
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
|
for (( i=0; i<${#PLUGIN_OUTPUT_MENU[@]}; i++)) ; do
|
||||||
echo "${PLUGIN_OUTPUT_MENU[$i]}"
|
echo "${PLUGIN_OUTPUT_MENU[$i]}"
|
||||||
${PLUGIN_OUTPUT[$i]} $ENTRY_FILE
|
${PLUGIN_OUTPUT[$i]} $ENTRY_FILE
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
CHANGELOG=/etc/Changelog
|
||||||
CHANGELOG_SERVER=https://changelog.example.com
|
CHANGELOG_SERVER=https://changelog.example.com
|
||||||
CHANGELOG_AUTH_KEY=your-shared-secret
|
CHANGELOG_AUTH_KEY=your-shared-secret
|
||||||
HASTEBIN_SERVER=https://hastebin.com
|
HASTEBIN_SERVER=https://hastebin.com
|
||||||
|
11
plugins-available/content-command.sh
Normal file
11
plugins-available/content-command.sh
Normal file
@ -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
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Sends the changelog information to a changelog server
|
# Adds a line by sending a file to a hastebin server
|
||||||
# see https://git.interhacker.space/alban/changelog-server
|
# and then print a "/a/file/name https://haste.bin/urlurlurl" line
|
||||||
# Requires an environmental variable to work
|
# Requires an environmental variable to work
|
||||||
# ex: HASTEBIN_SERVER=https://paste.interhacker.space
|
# example HASTEBIN_SERVER=https://paste.interhacker.space
|
||||||
PLUGIN_CONTENT+=( hookContentHastebin )
|
PLUGIN_CONTENT+=( hookContentHastebin )
|
||||||
hookContentHastebin(){
|
hookContentHastebin(){
|
||||||
[[ -z "$1" ]] && echo "Store a file by name in pastebin" && return
|
[[ -z "$1" ]] && echo "Store a file by name in pastebin" && return
|
||||||
[[ -z "$HASTEBIN_SERVER" ]] && echo "Missing HASTEBIN_SERVER variable. Exiting." && return
|
[[ -z "$HASTEBIN_SERVER" ]] && echo "Missing HASTEBIN_SERVER variable. Exiting." && return
|
||||||
TMP="$1"
|
TMP="$1"
|
||||||
read -e -p "File location? " FILE
|
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}'; )
|
URL=$( curl -X POST -s -d "$(cat "$FILE" )" "$HASTEBIN_SERVER/documents" | awk -F '"' '{print "'$HASTEBIN_SERVER'/raw/"$4}'; )
|
||||||
echo "$FILE: $URL" >> $TMP
|
echo "$FILE: $URL" >> $TMP
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user