Changes between Initial Version and Version 1 of AptitudeUpdateScript


Ignore:
Timestamp:
01/11/13 13:03:13 (4 years ago)
Author:
chris
Comment:

Page created

Legend:

Unmodified
Added
Removed
Modified
  • AptitudeUpdateScript

    v1 v1  
     1These scripts were written to enable the quick and easy updating of packages and the Changelog. 
     2 
     3The 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 
     13LOGCHANGE="/usr/local/bin/logchange" 
     14 
     15# check that the logchange script is installed 
     16if [[ ! -f $LOGCHANGE ]] ; then 
     17  echo "You need to install the $LOGCHANGE script before you can run $0" 
     18  exit 
     19fi 
     20 
     21# check that apt-show-versions in installed and if it isn't then install it 
     22if [[ ! -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 
     27fi 
     28 
     29# get updates 
     30apt-get -qq update 
     31# get a list of updates 
     32UPDATES=$(apt-show-versions -b -u | xargs) 
     33# if we have updates then install them and write the list of updates to the  
     34# Changelog 
     35if [[ $UPDATES ]]; then 
     36  echo "About to upgrade $UPDATES" 
     37  logchange "$UPDATES : updated" 
     38  aptitude full-upgrade 
     39  exit 
     40else 
     41  echo "No updates today" 
     42  exit 
     43fi 
     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 
     55CHANGELOG_NAME="Changelog" 
     56 
     57DATESTAMP=$(date +%Y-%m-%d) 
     58TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S) 
     59 
     60# check that $HOME is set 
     61if [[ $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 
     66else 
     67  echo "You are homeless?" 
     68  exit 
     69fi 
     70 
     71# get a username and if we can't use root 
     72if [[ $SUDO_USER ]]; then 
     73  CHANGELOG_EDITOR=$SUDO_USER 
     74elif [[ $USER ]]; then 
     75  CHANGELOG_EDITOR=$USER 
     76else 
     77  CHANGELOG_EDITOR=root 
     78fi 
     79 
     80# check for some changes on standard input 
     81if [[ $1 ]]; then 
     82  CHANGES=$1 
     83elif [[ ! $1 ]]; then 
     84  echo "Type the changes you would like recorded then [ENTER]:" 
     85  read changes 
     86  CHANGES=$changes 
     87fi 
     88 
     89# create the backup directory if it doesn't exist  
     90if [[ ! -d "${BACKUP_DIR}" ]] ; then 
     91  mkdir $BACKUP_DIR 
     92fi 
     93 
     94# backup the CHANGELOG if it exists 
     95if [[ -f "${CHANGELOG}" ]] ; then 
     96  cp -a $CHANGELOG $CHANGELOG_BACKUP 
     97fi 
     98 
     99# write the date and user to the CHANGELOG  
     100echo -e "$DATESTAMP\t$CHANGELOG_EDITOR" > $CHANGELOG 
     101 
     102# write what we have done, taken from standard in 
     103echo -e "\t*\t$CHANGES" >> $CHANGELOG 
     104 
     105# write a blank line  
     106echo >> $CHANGELOG 
     107 
     108# write the backup back to the $CHANGELOG 
     109if [[ -f "${CHANGELOG_BACKUP}" ]] ; then 
     110  cat $CHANGELOG_BACKUP >> $CHANGELOG 
     111fi 
     112}}}