[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
|
||||
|
||||
|
||||
echo ${BASH_SOURCE[@]}
|
||||
APP_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) && pwd )
|
||||
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
|
||||
# %CONFIG% This comment is used to build custom scripts
|
||||
[[ -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
|
||||
msg(){ echo -e "$@"; }
|
||||
panic(){ msg "${@} Exiting."; exit 1;}
|
||||
@ -52,6 +51,15 @@ change(){
|
||||
[[ "N" == ${RETURN^^} ]] && return 1
|
||||
}
|
||||
|
||||
template(){
|
||||
FILE="$1"
|
||||
cat << HEREDOC
|
||||
|
||||
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
|
||||
$( cat "$FILE" |sed 's/^/ /' )
|
||||
HEREDOC
|
||||
}
|
||||
|
||||
hookContentComment(){
|
||||
[[ -z "$1" ]] && echo "Enter a simple comment. Ex: systemctl disable nginx" && return
|
||||
TMP="$1"
|
||||
@ -61,19 +69,12 @@ hookContentComment(){
|
||||
|
||||
hookOutputFile(){
|
||||
[[ -z "$1" ]] && echo "Writing a local changelog entry to $CHANGELOG" && return
|
||||
local t=$(mktemp)
|
||||
TMP="$1"
|
||||
cat << HEREDOC >$t
|
||||
|
||||
|
||||
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
|
||||
|
||||
$( echo -e "$@"|sed 's/^/ /' )
|
||||
HEREDOC
|
||||
|
||||
[[ -f $CHANGELOG ]] && cat /etc/changelog >> $t
|
||||
cat "$t" > $CHANGELOG
|
||||
rm -f "$t"
|
||||
local TMP=$(mktemp)
|
||||
SOURCE="$1"
|
||||
template "$SOURCE" > "$TMP"
|
||||
[[ -f "$CHANGELOG" ]] && cat /etc/changelog >> "$TMP"
|
||||
cat "$TMP" > $CHANGELOG
|
||||
rm -f "$TMP"
|
||||
|
||||
}
|
||||
|
||||
@ -107,7 +108,7 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
|
||||
[[ " <>" == "$CHANGELOG_USERNAME" ]] && panic "srs.ly?"
|
||||
|
||||
# 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
|
||||
change "$ENTRY_FILE"
|
||||
|
Loading…
Reference in New Issue
Block a user