[fix] fixes critical bugs due to hazardous rewriting
This commit is contained in:
parent
895cab87b4
commit
06a6aded5a
75
changelog.sh
75
changelog.sh
@ -2,21 +2,20 @@
|
|||||||
#Manages an /etc/changelog
|
#Manages an /etc/changelog
|
||||||
|
|
||||||
|
|
||||||
echo ${BASH_SOURCE[@]}
|
|
||||||
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]})
|
||||||
|
|
||||||
[[ -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 "$APP_PATH/$APP_NAME" && exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CHANGELOG=/etc/changelog
|
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
|
||||||
|
[[ -f "$CHANGELOG" ]] && [[ ! -w "$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 "$APP_PATH/$APP_NAME" && exit 0
|
||||||
|
}
|
||||||
|
|
||||||
# functions
|
# functions
|
||||||
msg(){ echo -e "$@"; }
|
msg(){ echo -e "$@"; }
|
||||||
panic(){ msg "${@} Exiting."; exit 1;}
|
panic(){ msg "${@} Exiting."; exit 1;}
|
||||||
@ -30,19 +29,19 @@ change(){
|
|||||||
echo -e "\nTime for some details."
|
echo -e "\nTime for some details."
|
||||||
|
|
||||||
for (( ; ; )); do
|
for (( ; ; )); do
|
||||||
echo "Select number or x to quit"
|
echo "Select number or x to quit"
|
||||||
for (( i=0; i<${#PLUGIN_CONTENT_MENU[@]}; i++)) ; do
|
for (( i=0; i<${#PLUGIN_CONTENT_MENU[@]}; i++)) ; do
|
||||||
echo "$i) ${PLUGIN_CONTENT_MENU[$i]}"
|
echo "$i) ${PLUGIN_CONTENT_MENU[$i]}"
|
||||||
done
|
done
|
||||||
echo "x) No more details."
|
echo "x) No more details."
|
||||||
read -e -n 1 -p "Your choice? :" REPLY
|
read -e -n 1 -p "Your choice? :" REPLY
|
||||||
if [[ "x" == ${REPLY,,} ]]; then
|
if [[ "x" == ${REPLY,,} ]]; then
|
||||||
break
|
break
|
||||||
elif [[ -z "${PLUGIN_CONTENT[$REPLY]}" ]] ; then
|
elif [[ -z "${PLUGIN_CONTENT[$REPLY]}" ]] ; then
|
||||||
echo "Unknown Key."
|
echo "Unknown Key."
|
||||||
else
|
else
|
||||||
${PLUGIN_CONTENT[$REPLY]} $TMP
|
${PLUGIN_CONTENT[$REPLY]} $TMP
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
read -e -i "n" -p "Another section? [yN]:" END
|
read -e -i "n" -p "Another section? [yN]:" END
|
||||||
[[ "${END^^}" == "N" ]] && break
|
[[ "${END^^}" == "N" ]] && break
|
||||||
@ -52,6 +51,15 @@ change(){
|
|||||||
[[ "N" == ${RETURN^^} ]] && return 1
|
[[ "N" == ${RETURN^^} ]] && return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template(){
|
||||||
|
FILE="$1"
|
||||||
|
cat << HEREDOC
|
||||||
|
|
||||||
|
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
|
||||||
|
$( cat "$FILE" |sed 's/^/ /' )
|
||||||
|
HEREDOC
|
||||||
|
}
|
||||||
|
|
||||||
hookContentComment(){
|
hookContentComment(){
|
||||||
[[ -z "$1" ]] && echo "Enter a simple comment. Ex: systemctl disable nginx" && return
|
[[ -z "$1" ]] && echo "Enter a simple comment. Ex: systemctl disable nginx" && return
|
||||||
TMP="$1"
|
TMP="$1"
|
||||||
@ -61,19 +69,12 @@ hookContentComment(){
|
|||||||
|
|
||||||
hookOutputFile(){
|
hookOutputFile(){
|
||||||
[[ -z "$1" ]] && echo "Writing a local changelog entry to $CHANGELOG" && return
|
[[ -z "$1" ]] && echo "Writing a local changelog entry to $CHANGELOG" && return
|
||||||
local t=$(mktemp)
|
local TMP=$(mktemp)
|
||||||
TMP="$1"
|
SOURCE="$1"
|
||||||
cat << HEREDOC >$t
|
template "$SOURCE" > "$TMP"
|
||||||
|
[[ -f "$CHANGELOG" ]] && cat /etc/changelog >> "$TMP"
|
||||||
|
cat "$TMP" > $CHANGELOG
|
||||||
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
|
rm -f "$TMP"
|
||||||
|
|
||||||
$( echo -e "$@"|sed 's/^/ /' )
|
|
||||||
HEREDOC
|
|
||||||
|
|
||||||
[[ -f $CHANGELOG ]] && cat /etc/changelog >> $t
|
|
||||||
cat "$t" > $CHANGELOG
|
|
||||||
rm -f "$t"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
|
|||||||
[[ " <>" == "$CHANGELOG_USERNAME" ]] && panic "srs.ly?"
|
[[ " <>" == "$CHANGELOG_USERNAME" ]] && panic "srs.ly?"
|
||||||
|
|
||||||
# check changelog exists
|
# check changelog exists
|
||||||
[[ ! -f $CHANGELOG ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n"
|
[[ ! -f "$CHANGELOG" ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n" > "$CHANGELOG"
|
||||||
|
|
||||||
# parse command
|
# parse command
|
||||||
change "$ENTRY_FILE"
|
change "$ENTRY_FILE"
|
||||||
@ -115,8 +116,8 @@ change "$ENTRY_FILE"
|
|||||||
[[ $? -eq 0 ]] && exit
|
[[ $? -eq 0 ]] && exit
|
||||||
|
|
||||||
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
|
||||||
done
|
done
|
||||||
|
|
||||||
rm "$ENTRY_FILE"
|
rm "$ENTRY_FILE"
|
||||||
|
Loading…
Reference in New Issue
Block a user