53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
|
#!/bin/bash
|
||
|
#Manages an /etc/changelog
|
||
|
|
||
|
CHANGELOG=/etc/changelog
|
||
|
|
||
|
# functions
|
||
|
|
||
|
msg(){ echo -e "$@"; }
|
||
|
panic(){ msg "${@} Exiting."; exit 1;}
|
||
|
template(){
|
||
|
t=$(mktemp)
|
||
|
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"
|
||
|
}
|
||
|
|
||
|
change(){
|
||
|
local TMP=$(mktemp)
|
||
|
while true ; do
|
||
|
echo -e "\nType the nature of the change.\nExample: > mysql: do not start on boot\n"
|
||
|
read -e -p "> " SUB
|
||
|
echo -e "\nType the comments, how you did that.\nExample: > echo 'manual' | sudo tee -a /etc/init/mysql.override\n"
|
||
|
read -e -p "> " EXP
|
||
|
echo -e "* $SUB\n$EXP\n" >> $TMP
|
||
|
read -e -i "n" -p "More? [yN]:" END
|
||
|
[[ "${END^^}" == "N" ]] && break
|
||
|
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
|
||
|
template "$(cat $TMP)"
|
||
|
rm $TMP
|
||
|
}
|
||
|
|
||
|
# Exec
|
||
|
echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
|
||
|
# set environment variables
|
||
|
[[ -z "$CHANGELOG_USERNAME" ]] && read -e -p "Your name? " NAME&& read -e -p "Your email? " EMAIL && CHANGELOG_USERNAME="${NAME^} <$EMAIL>" && echo "export CHANGELOG_USERNAME=\"$CHANGELOG_USERNAME\""
|
||
|
[[ " <>" == "$CHANGELOG_USERNAME" ]] && panic "srs.ly?"
|
||
|
|
||
|
# check changelog exists
|
||
|
[[ ! -f $CHANGELOG ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n"
|
||
|
|
||
|
# parse command
|
||
|
change
|
||
|
|