[fix] fixes critical bugs due to hazardous rewriting
This commit is contained in:
parent
895cab87b4
commit
06a6aded5a
45
changelog.sh
45
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;}
|
||||||
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user