github.com/google/cadvisor@v0.49.1/build/assets.sh (about) 1 #!/bin/bash 2 3 # Copyright 2015 Google Inc. All rights reserved. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -e 18 19 GIT_ROOT=$(dirname "${BASH_SOURCE}")/.. 20 21 ASSETS_INPUT_DIRS="$GIT_ROOT/cmd/internal/pages/assets/js/... $GIT_ROOT/cmd/internal/pages/assets/styles/..." 22 ASSETS_OUTPUT_PATH="$GIT_ROOT/cmd/internal/pages/static/assets.go" 23 ASSETS_PACKAGE="static" 24 25 TEMPLATES_INPUT_DIRS="$GIT_ROOT/cmd/internal/pages/assets/html/..." 26 TEMPLATES_OUTPUT_PATH="$GIT_ROOT/cmd/internal/pages/templates.go" 27 TEMPLATES_PACKAGE="pages" 28 29 FORCE="${FORCE:-}" # Force assets to be rebuilt if FORCE=true 30 31 # Install while in a temp dir to avoid polluting go.mod/go.sum 32 pushd "${TMPDIR:-/tmp}" > /dev/null 33 go install github.com/kevinburke/go-bindata/go-bindata@v3.24.0 34 popd > /dev/null 35 36 build_asset () { 37 local package=$1 38 local output_path=$2 39 local input_dirs=${@:3} 40 local tmp_output=$(mktemp) 41 local year="$(git log -1 --date=format:'%Y' --format=%cd -- ${output_path})" 42 43 go-bindata -nometadata -o $output_path -pkg $package $input_dirs 44 cat build/boilerplate/boilerplate.go.txt | sed "s/YEAR/$year/" > "${tmp_output}" 45 echo -e "// generated by build/assets.sh; DO NOT EDIT\n" >> "${tmp_output}" 46 cat "${output_path}" >> "${tmp_output}" 47 gofmt -w -s "${tmp_output}" 48 mv "${tmp_output}" "${output_path}" 49 } 50 51 for f in $GIT_ROOT/cmd/internal/pages/assets/js/* $GIT_ROOT/cmd/internal/pages/assets/styles/*; do 52 if [ "$FORCE" == "true" ] || [ "$f" -nt $ASSETS_OUTPUT_PATH -o ! -e $ASSETS_OUTPUT_PATH ]; then 53 build_asset "$ASSETS_PACKAGE" "$ASSETS_OUTPUT_PATH" "$ASSETS_INPUT_DIRS" 54 break; 55 fi 56 done 57 58 for f in $GIT_ROOT/cmd/internal/pages/assets/html/*; do 59 if [ "$FORCE" == "true" ] || [ "$f" -nt $TEMPLATES_OUTPUT_PATH -o ! -e $TEMPLATES_OUTPUT_PATH ]; then 60 build_asset "$TEMPLATES_PACKAGE" "$TEMPLATES_OUTPUT_PATH" "$TEMPLATES_INPUT_DIRS" 61 break; 62 fi 63 done 64 65 exit 0