| | 1 | These two scripts are used to update the Debian packages on the servers and to record the updates in `/root/Changelog`. |
| | 2 | |
| | 3 | == a-up == |
| | 4 | |
| | 5 | {{{ |
| | 6 | #!/usr/bin/env bash |
| | 7 | |
| | 8 | # This script runs "aptitude full-upgrade" and updates the Changelog |
| | 9 | |
| | 10 | # location of the logchange script, we assume it has been |
| | 11 | # installed int he same directory as this script is in |
| | 12 | #DIR="/usr/local/bin" |
| | 13 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| | 14 | LOGCHANGE="$DIR/logchange" |
| | 15 | |
| | 16 | # check that the script is being run by root |
| | 17 | if [[ "$(id -u)" != "0" ]] ; then |
| | 18 | echo "You must run '$0' as root or via sudo" |
| | 19 | exit 1 |
| | 20 | fi |
| | 21 | |
| | 22 | # check that the logchange script is installed |
| | 23 | if [[ ! -f "${LOGCHANGE}" ]] ; then |
| | 24 | echo "You need to install the '${LOGCHANGE}' script before you can run $0" |
| | 25 | exit 2 |
| | 26 | fi |
| | 27 | |
| | 28 | # For Ubuntu Touch |
| | 29 | UBUNTU_TOUCH=$( uname -a | grep 'ubuntu-phablet' ) |
| | 30 | if [[ "${UBUNTU_TOUCH}" ]]; then |
| | 31 | echo "Ubuntu touch so skipping kernel update" |
| | 32 | export FLASH_KERNEL_SKIP="true" |
| | 33 | fi |
| | 34 | |
| | 35 | # check that packages are installed and if not then install, this depends on the |
| | 36 | # package name matching the binary in /usr/bin, this check is done first because |
| | 37 | # it's faster |
| | 38 | DEPENDENCIES="apt-show-versions aptitude" |
| | 39 | for d in ${DEPENDENCIES}; do |
| | 40 | if [[ ! -f "/usr/bin/${d}" ]] ; then |
| | 41 | DEP_CHECK=$(dpkg -s ${d} 2>&1 | grep "Status: install ok installed") |
| | 42 | if [[ ! "${DEP_CHECK}" ]]; then |
| | 43 | echo "Installing '${d}'" |
| | 44 | apt-get install ${d} |
| | 45 | fi |
| | 46 | fi |
| | 47 | done |
| | 48 | |
| | 49 | # get updates |
| | 50 | apt-get -qq update |
| | 51 | # get a list of updates |
| | 52 | UPDATES=$(apt-show-versions -b -u | xargs) |
| | 53 | # if we have updates then install them and write the list of updates to the |
| | 54 | # Changelog |
| | 55 | if [[ "${UPDATES}" ]]; then |
| | 56 | echo "About to upgrade '${UPDATES}'" |
| | 57 | ${LOGCHANGE} "${UPDATES} : updated" |
| | 58 | aptitude full-upgrade |
| | 59 | # Delete dowloaded packages to free up space |
| | 60 | if [[ "${UBUNTU_TOUCH}" ]]; then |
| | 61 | apt-get clean |
| | 62 | else |
| | 63 | aptitude autoclean |
| | 64 | echo "If ownCloud has been updated run the following commands:" |
| | 65 | echo "su - owncloud -s /bin/bash" |
| | 66 | echo "php console.php upgrade" |
| | 67 | fi |
| | 68 | exit 0 |
| | 69 | else |
| | 70 | echo "No updates today" |
| | 71 | exit 0 |
| | 72 | fi |
| | 73 | }}} |
| | 74 | |
| | 75 | == logchange == |
| | 76 | |
| | 77 | {{{ |
| | 78 | #!/usr/bin/env bash |
| | 79 | |
| | 80 | # This is a script to update the /root/Changelog |
| | 81 | |
| | 82 | # File name of the Changelog |
| | 83 | CHANGELOG_NAME="Changelog" |
| | 84 | |
| | 85 | DATESTAMP="$(date +%Y-%m-%d)" |
| | 86 | TIMESTAMP="$(date +%Y-%m-%d-%H-%M-%S)" |
| | 87 | |
| | 88 | # check that the script is being run by root |
| | 89 | if [[ "$(id -u)" != "0" ]] ; then |
| | 90 | echo "You must run $0 as root or via sudo" |
| | 91 | exit 2 |
| | 92 | fi |
| | 93 | |
| | 94 | # check that $HOME is set |
| | 95 | if [[ ${HOME} ]]; then |
| | 96 | CHANGELOG_DIR="${HOME}" |
| | 97 | CHANGELOG="${CHANGELOG_DIR}/${CHANGELOG_NAME}" |
| | 98 | BACKUP_DIR="${CHANGELOG_DIR}/.${CHANGELOG_NAME}" |
| | 99 | CHANGELOG_BACKUP="${BACKUP_DIR}/${CHANGELOG_NAME}.${TIMESTAMP}" |
| | 100 | else |
| | 101 | echo "You are homeless?" |
| | 102 | exit 1 |
| | 103 | fi |
| | 104 | |
| | 105 | # get a username and if we can't use root |
| | 106 | if [[ ${SUDO_USER} ]]; then |
| | 107 | CHANGELOG_EDITOR="${SUDO_USER}" |
| | 108 | elif [[ ${USER} ]]; then |
| | 109 | CHANGELOG_EDITOR="${USER}" |
| | 110 | else |
| | 111 | CHANGELOG_EDITOR="root" |
| | 112 | fi |
| | 113 | |
| | 114 | # check for some changes on standard input |
| | 115 | if [[ $1 ]]; then |
| | 116 | CHANGES="$1" |
| | 117 | elif [[ ! "$1" ]]; then |
| | 118 | echo "Type the changes you would like recorded then [ENTER]:" |
| | 119 | read changes |
| | 120 | CHANGES=${changes} |
| | 121 | fi |
| | 122 | |
| | 123 | # create the backup directory if it doesn't exist |
| | 124 | if [[ ! -d "${BACKUP_DIR}" ]] ; then |
| | 125 | mkdir ${BACKUP_DIR} |
| | 126 | fi |
| | 127 | |
| | 128 | # backup the CHANGELOG if it exists |
| | 129 | if [[ -f "${CHANGELOG}" ]] ; then |
| | 130 | cp -a ${CHANGELOG} ${CHANGELOG_BACKUP} |
| | 131 | fi |
| | 132 | |
| | 133 | # write the date and user to the CHANGELOG |
| | 134 | echo -e "${DATESTAMP}\t${CHANGELOG_EDITOR}" > ${CHANGELOG} |
| | 135 | |
| | 136 | # write what we have done, taken from standard in |
| | 137 | echo -e "\t*\t${CHANGES}" >> ${CHANGELOG} |
| | 138 | |
| | 139 | # write a blank line |
| | 140 | echo >> ${CHANGELOG} |
| | 141 | |
| | 142 | # write the backup back to the $CHANGELOG |
| | 143 | if [[ -f "${CHANGELOG_BACKUP}" ]] ; then |
| | 144 | cat ${CHANGELOG_BACKUP} >> ${CHANGELOG} |
| | 145 | fi |
| | 146 | |
| | 147 | # gz the backup if it exists |
| | 148 | if [[ -f "${CHANGELOG_BACKUP}" ]] ; then |
| | 149 | gzip ${CHANGELOG_BACKUP} |
| | 150 | fi |
| | 151 | |
| | 152 | exit 0 |
| | 153 | }}} |