[init]
This commit is contained in:
commit
375bf66c2c
36
README.md
Normal file
36
README.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# changelog : manage changes on a server
|
||||||
|
|
||||||
|
Based on the Masters Book of Serious Sysadmin's Best Practices Chapter, this script aims at unifying and simplifying the management of changelog files on a server.
|
||||||
|
|
||||||
|
## Crash course
|
||||||
|
|
||||||
|
```
|
||||||
|
wget https://this.repo.srs.ly/alban/changelog/bla/bla/raw/changelog
|
||||||
|
chmod +x changelog
|
||||||
|
sudo ./changelog
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will ask for your name if no `CHANGELOG_USERNAME` environment variable is found.
|
||||||
|
|
||||||
|
Then it will ask for a first change informations:
|
||||||
|
|
||||||
|
* The nature of the change: which software / domain did you change? Why?
|
||||||
|
* Some comments: How did you do it? What was happening? Is it fixed?
|
||||||
|
|
||||||
|
**Limitations**
|
||||||
|
|
||||||
|
* Please note that to enter multiline comments, you have for now to escape newline characters using the `\\\\n` sequence. Ugly.
|
||||||
|
|
||||||
|
* By default, it will attempt to create and edit `/etc/changelog`. You better be running it as root, by default.
|
||||||
|
|
||||||
|
|
||||||
|
# Possible improvements
|
||||||
|
|
||||||
|
* Enable a sudo requirement / ways to restart oneself as a root user
|
||||||
|
* Enable simple multiline comments
|
||||||
|
* Provide a way to attach files
|
||||||
|
* Provide a way (plugins?) to report each change to a central server
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
52
changelog
Executable file
52
changelog
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#!/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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user