| 1 | These scripts were written to enable the quick and easy updating of packages and the Changelog. |
| 2 | |
| 3 | The following two scripts, {{{a-up}}} and {{{logchanges}}}, they are installed on PenguinServer and can be used to do system updates and record the updates in /root/Changelog. The contents of the Changelog is then emailed to root by [https://labs.riseup.net/code/projects/metche metche] so that the people working on the server know what updates have been applied. |
| 4 | |
| 5 | == a-up == |
| 6 | |
| 7 | {{{ |
| 8 | #!/bin/bash |
| 9 | |
| 10 | # This script runs "aptitude full-upgrade" and updates the Changelog |
| 11 | |
| 12 | # location of the logchange script |
| 13 | LOGCHANGE="/usr/local/bin/logchange" |
| 14 | |
| 15 | # check that the logchange script is installed |
| 16 | if [[ ! -f $LOGCHANGE ]] ; then |
| 17 | echo "You need to install the $LOGCHANGE script before you can run $0" |
| 18 | exit |
| 19 | fi |
| 20 | |
| 21 | # check that apt-show-versions in installed and if it isn't then install it |
| 22 | if [[ ! -f "/usr/bin/apt-show-versions" ]] ; then |
| 23 | echo "Installing apt-show-versions, please wait a while after it's installed" |
| 24 | logchange "apt-show-versions : installed" |
| 25 | aptitude install apt-show-versions |
| 26 | exit |
| 27 | fi |
| 28 | |
| 29 | # get updates |
| 30 | apt-get -qq update |
| 31 | # get a list of updates |
| 32 | UPDATES=$(apt-show-versions -b -u | xargs) |
| 33 | # if we have updates then install them and write the list of updates to the |
| 34 | # Changelog |
| 35 | if [[ $UPDATES ]]; then |
| 36 | echo "About to upgrade $UPDATES" |
| 37 | logchange "$UPDATES : updated" |
| 38 | aptitude full-upgrade |
| 39 | exit |
| 40 | else |
| 41 | echo "No updates today" |
| 42 | exit |
| 43 | fi |
| 44 | |
| 45 | }}} |
| 46 | |
| 47 | == logchange == |
| 48 | |
| 49 | {{{ |
| 50 | #!/bin/bash |
| 51 | |
| 52 | # This is a script to update the Changelog |
| 53 | |
| 54 | # File name of the Changelog |
| 55 | CHANGELOG_NAME="Changelog" |
| 56 | |
| 57 | DATESTAMP=$(date +%Y-%m-%d) |
| 58 | TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S) |
| 59 | |
| 60 | # check that $HOME is set |
| 61 | if [[ $HOME ]]; then |
| 62 | CHANGELOG_DIR=$HOME |
| 63 | CHANGELOG=$CHANGELOG_DIR/$CHANGELOG_NAME |
| 64 | BACKUP_DIR=$CHANGELOG_DIR/.$CHANGELOG_NAME |
| 65 | CHANGELOG_BACKUP=$BACKUP_DIR/$CHANGELOG_NAME.$TIMESTAMP |
| 66 | else |
| 67 | echo "You are homeless?" |
| 68 | exit |
| 69 | fi |
| 70 | |
| 71 | # get a username and if we can't use root |
| 72 | if [[ $SUDO_USER ]]; then |
| 73 | CHANGELOG_EDITOR=$SUDO_USER |
| 74 | elif [[ $USER ]]; then |
| 75 | CHANGELOG_EDITOR=$USER |
| 76 | else |
| 77 | CHANGELOG_EDITOR=root |
| 78 | fi |
| 79 | |
| 80 | # check for some changes on standard input |
| 81 | if [[ $1 ]]; then |
| 82 | CHANGES=$1 |
| 83 | elif [[ ! $1 ]]; then |
| 84 | echo "Type the changes you would like recorded then [ENTER]:" |
| 85 | read changes |
| 86 | CHANGES=$changes |
| 87 | fi |
| 88 | |
| 89 | # create the backup directory if it doesn't exist |
| 90 | if [[ ! -d "${BACKUP_DIR}" ]] ; then |
| 91 | mkdir $BACKUP_DIR |
| 92 | fi |
| 93 | |
| 94 | # backup the CHANGELOG if it exists |
| 95 | if [[ -f "${CHANGELOG}" ]] ; then |
| 96 | cp -a $CHANGELOG $CHANGELOG_BACKUP |
| 97 | fi |
| 98 | |
| 99 | # write the date and user to the CHANGELOG |
| 100 | echo -e "$DATESTAMP\t$CHANGELOG_EDITOR" > $CHANGELOG |
| 101 | |
| 102 | # write what we have done, taken from standard in |
| 103 | echo -e "\t*\t$CHANGES" >> $CHANGELOG |
| 104 | |
| 105 | # write a blank line |
| 106 | echo >> $CHANGELOG |
| 107 | |
| 108 | # write the backup back to the $CHANGELOG |
| 109 | if [[ -f "${CHANGELOG_BACKUP}" ]] ; then |
| 110 | cat $CHANGELOG_BACKUP >> $CHANGELOG |
| 111 | fi |
| 112 | }}} |