| #!/bin/sh |
| |
| # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Check uber shopfloor server, fetch and parse board config. |
| # |
| # Channel image URLs and checksums are sent out through stdout for shell |
| # to eval. The format: |
| # |
| # SRC_{CHANNEL}_URL=http://shopfloor_server:port/pathto/gzimage |
| # SRC_{CHANNEL}_CHECKSUM=plain_image_binarysha1_base64 |
| # |
| # For memento updater compatibility, images should be generated by script |
| # make_factory_package.sh. |
| # |
| # Example: |
| # SHOPFLOOR="http://SF_SERVER:SF_PORT" |
| # BOARD="testboard" |
| # result=$(ping_shopfloor) |
| # rc="$?" |
| # if [ "$rc" = "0" ]; then |
| # eval "$result" |
| # fi |
| # if [ "$SHOPFLOOR_INSTALL" = "1" ]; then |
| # do_install |
| # ... |
| # |
| |
| sf_log() { |
| if [ -z "$(command -v "log")" ]; then |
| echo "$(date) $*" >&2 |
| else |
| log "$*" |
| fi |
| } |
| |
| ping_shopfloor() { |
| local channel_hash="" |
| local channel_file="" |
| local channel_name="" |
| local config_file="default.conf" |
| local line="" |
| local resource_url="" |
| local wget_output="" |
| local wget_rc="0" |
| local channels="" |
| local cleanup_files="" |
| |
| # Get config file name from BOARD |
| if [ -n "$BOARD" ]; then |
| config_file="${BOARD}.conf" |
| fi |
| |
| # Get resource URL from SHOPFLOOR or OMAHA |
| if [ -n "$SHOPFLOOR" ]; then |
| resource_url="$SHOPFLOOR/res" |
| elif [ -n "$OMAHA" ]; then |
| resource_url="${OMAHA%/update}/res" |
| else |
| sf_log "ping_shopfloor: SHOPFLOOR and OMAHA not found." |
| return 1 |
| fi |
| |
| # Ping shopfloor by fetching the config file |
| wget_output="$(mktemp "/tmp/conf_XXXXXXXX")" |
| cleanup_files="$wget_output" |
| wget -O $wget_output "$resource_url/$config_file" 2>/dev/null || |
| wget_rc="$?" |
| |
| if [ "$wget_rc" != "0" ]; then |
| sf_log "ping_shopfloor: could not fetch $resource_url/$config_file" |
| [ -f "$cleanup_files" ] && rm $cleanup_files |
| return 1 |
| fi |
| |
| # Fix shell read line without \n |
| echo >>"$wget_output" |
| |
| # Parse channels and skip comments in a subprocess |
| channels="$(mktemp "/tmp/sf_XXXXXXXX")" |
| cleanup_files="$cleanup_files $channels" |
| while IFS= read line; do |
| # Remove leading whitespaces |
| line=$(echo $line | sed -e 's/^[ \t]*//') |
| # Skip comment and empty lines |
| [ -n "$(echo $line | grep -E '^#')" -o -z "$line" ] && continue |
| # Split channel, file, and hash |
| channel_name=$(echo $line | cut -d':' -f1) |
| channel_file=$(echo $line | cut -d':' -f2) |
| channel_hash=$(echo $line | cut -d':' -f3) |
| if [ -z "$channel_name" -o -z "$channel_file" -o -z "$channel_hash" ]; then |
| sf_log "ping_shopfloor: not a channel $resource_url/$config_file ($line)" |
| [ -n "$cleanup_files" ] && rm $cleanup_files |
| return 1 |
| fi |
| echo "SRC_${channel_name}_URL=$resource_url/$channel_file" >> "$channels" |
| echo "SRC_${channel_name}_CHECKSUM=$channel_hash" >> "$channels" |
| done <"$wget_output" |
| |
| if [ "$?" != "0" ]; then |
| [ -n "$cleanup_files" ] && rm $cleanup_files |
| return 1 |
| fi |
| |
| cat "$channels" |
| echo "SHOPFLOOR_INSTALL=1" |
| |
| [ -n "$cleanup_files" ] && rm $cleanup_files |
| return 0 |
| } |
| |