| #!/bin/bash |
| # Copyright 2023 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # This script is intended to be run in the SDK |
| |
| # This script stitches together all the procedures necessary to upgrade osconfig. |
| # Upgrading osconfig (along with a few other golang packages) involves a few long |
| # running procedures so having a script like this should help with some of the toil |
| # until we find a better long term solution. |
| |
| set -o errexit |
| set -o nounset |
| set -o pipefail |
| |
| VERSION=$1 |
| NEW_EBUILD="google-osconfig-agent-$VERSION" |
| |
| if [[ -z $VERSION ]]; then |
| echo "You need to pass a version to this script" |
| echo "Example: ./upgrade-osconfig-script.sh 20230504.00" |
| exit 1 |
| fi |
| |
| cd /mnt/host/source/src/overlays/project-lakitu/app-admin/google-osconfig-agent/ || exit 1 |
| |
| # Get the latest ebuild |
| LATEST_OSCONFIG_EBUILD=$(find . -name "*.ebuild" -type f | sort -r | head -n 1) |
| |
| # Remove symlinks |
| find . -type l -name "*ebuild" -exec rm {} \; |
| |
| # Rename latest ebuild to desired version |
| mv "$LATEST_OSCONFIG_EBUILD" "temp" |
| |
| # Remove all ebuild files |
| find . -name "*.ebuild" -type f -exec rm {} \; |
| |
| mv "temp" "$NEW_EBUILD.ebuild" |
| |
| # Create symlink revision file |
| ln -s "$NEW_EBUILD.ebuild" "$NEW_EBUILD-r1.ebuild" |
| |
| # Get modules |
| curl "https://raw.githubusercontent.com/GoogleCloudPlatform/osconfig/$VERSION/go.sum" -o _GO.SUM |
| cut -d' ' -f-2 _GO.SUM | awk '{print "\t\""$0"\""}' > _EGO_SUM |
| |
| # Insert modules into EGO_SUM list |
| # Delete existing EGO_SUM |
| sed -i '/EGO_SUM=/,/)/{//!d}' "$NEW_EBUILD.ebuild" |
| # Insert new EGO_SUM |
| while read i; do |
| sed -i -e '/EGO_SUM=/a\' -e " $i" "$NEW_EBUILD.ebuild" |
| done <_EGO_SUM |
| |
| # Prepare upload to GCS BUCKET |
| git diff | grep "^+" | grep -v "^+++" > _NEWMODS |
| sed 's/"//g' -i _NEWMODS # Removes quotation marks. |
| |
| # Generates the modules’ URIs relative to the Go proxy server URI. |
| awk '{print $2"/@v/"$3".zip"}' _NEWMODS | sed 's/\/go.mod.zip$/.mod/g' > _MOD_REL_URIS |
| mkdir _DOWNLOADS |
| |
| # Creates a script file _DOWNLOAD.sh, that downloads the module files from the Go proxy server into _DOWNLOADS directory. |
| cat _MOD_REL_URIS | while read line; do echo curl https://proxy.golang.org/$line -o _DOWNLOADS/`echo $line | sed 's/\//%2F/g'` ; done > _DOWNLOAD.sh |
| sh _DOWNLOAD.sh |
| pushd _DOWNLOADS |
| # Uploads the modules files into Chrome OS local mirror. |
| for f in *; do |
| gsutil ls "gs://chromeos-mirror/gentoo/distfiles/${f}" || gsutil ls "gs://chromeos-localmirror/distfiles/${f}" || gsutil cp -n -a public-read "${f}" gs://chromeos-localmirror/distfiles/ ; |
| done |
| popd |
| |
| wget https://github.com/GoogleCloudPlatform/osconfig/archive/$VERSION.tar.gz |
| gsutil cp -n -a public-read $VERSION.tar.gz gs://chromeos-localmirror/distfiles/google-osconfig-agent-$VERSION.tar.gz |
| rm -Rf _GO.SUM _EGO_SUM _NEWMODS _MOD_REL_URIS _DOWNLOAD.sh _DOWNLOADS $VERSION.tar.gz |
| |
| # Generate manifest |
| ebuild-lakitu $(equery-lakitu w app-admin/google-osconfig-agent) manifest |
| |
| cat <<EOF > /tmp/cmsg |
| app-admin/google-osconfig-agent: Update google-osconfig-agent to $VERSION |
| |
| BUG=b/TODO |
| TEST=presubmit |
| RELEASE_NOTE=Updated app-admin/google-osconfig-agent to $VERSION. |
| |
| cos-patch: lts-refresh |
| EOF |
| |
| git add . |
| git commit -F /tmp/cmsg |
| rm /tmp/cmsg |
| |
| echo "Commit created with message" |
| git --no-pager show -s --format=%B HEAD |
| echo "Update the bug in the commit message and push it to complete the upgrade." |