1#!/bin/bash 2# Copyright (c) 2015 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6SCRIPT_DIR=$(dirname $(readlink -f $0)) 7cd ${SCRIPT_DIR}/.. 8 9LOGDIR=logs/stable-version 10OPTIONS=() 11 12# STATUS is part hack, part safety valve. The cron job that invokes 13# this script may be installed and enabled on both a primary and backup 14# server. We skip running on the backup, but really, the backup 15# shouldn't have invoked this script in the first place... 16# 17# If we're not invoked on an autotest server at all, we assume this is 18# for testing, and invoke a dry run instead. 19# 20SERVER_STATUS=$(cli/atest server list $(hostname) 2>&1 | 21 awk '/^Status *:/ { print $NF }') 22if [ "${SERVER_STATUS}" = "primary" ]; then 23 mkdir -p ${LOGDIR} 24 NOTIFY=( 25 chromeos-infra-eng@grotations.appspotmail.com 26 ) 27else 28 if [ -n "${SERVER_STATUS}" ]; then 29 # must be backup 30 exit 0 31 fi 32 OPTIONS=( --dry-run ) 33 NOTIFY=( ${LOGNAME}@google.com ) 34fi 35 36# Redirect onto a log file. For debug purposes, skip redirection if 37# there's a command line argument (we ignore what the argument is), or 38# if there's no log directory. 39# 40TAG=$(date '+%Y-%W') 41if [ $# -eq 0 -a -d ${LOGDIR} ]; then 42 LOGFILE="update-${TAG}.log" 43 exec >>${LOGDIR}/${LOGFILE} 2>&1 44fi 45 46trap 'rm -f ${TMPFILE}' EXIT 47TMPFILE=$(mktemp) 48 49date 50site_utils/assign_stable_images.py "${OPTIONS[@]}" | tee ${TMPFILE} 51echo 52 53# If we have a log directory, clean it up, and send e-mail notification. 54# The log files change name each week, so by throwing out all but the 55# most recent 14 files, we keep about 3 months of history, plus this 56# week's log. 57# 58if [ -d ${LOGDIR} ]; then 59 SUBJECT="Stable version update summary ${TAG}" 60 site_utils/gmail_lib.py -s "${SUBJECT}" "${NOTIFY[@]}" <${TMPFILE} 61 rm -f $(ls -r ${LOGDIR}/update-*.log | sed '1,14 d') 62fi 63