11#! /usr/bin/env bash
22#
3- # Copyright 2018, 2020 Delphix
3+ # Copyright 2018, 2021 Delphix
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ export SUPPORTED_KERNEL_FLAVORS="generic aws gcp azure oracle"
2626# for testing purposes to use jenkins-ops.<developer> instead.
2727#
2828export JENKINS_OPS_DIR=" ${JENKINS_OPS_DIR:- jenkins-ops} "
29+ export S3_DEVOPS_BRANCH=" ${S3_DEVOPS_BRANCH:- master} "
2930
3031export UBUNTU_DISTRIBUTION=" bionic"
3132
@@ -100,23 +101,50 @@ function logmust() {
100101# scripts on their work system and changing its configuration.
101102#
102103function check_running_system() {
104+ local msg
105+
103106 if [[ " $DISABLE_SYSTEM_CHECK " == " true" ]]; then
104107 echo " WARNING: System check disabled."
105108 return 0
106109 fi
107110
111+ msg=" Note that you can bypass this check by setting environment"
112+ msg=" ${msg} variable DISABLE_SYSTEM_CHECK=true. Use this at your"
113+ msg=" ${msg} own risk as running this command may modify your system."
114+
108115 if ! (command -v lsb_release > /dev/null &&
109116 [[ $( lsb_release -cs) == " $UBUNTU_DISTRIBUTION " ]]); then
110- die " Script can only be ran on an ubuntu-${UBUNTU_DISTRIBUTION} system."
117+ echo_error " Script can only be run on an ubuntu-${UBUNTU_DISTRIBUTION} system."
118+ echo_bold " $msg "
119+ exit 1
111120 fi
112121
113122 if ! curl " http://169.254.169.254/latest/meta-datas" \
114123 > /dev/null 2>&1 ; then
115- die " Not running in AWS, are you sure you are on the" \
124+ echo_error " Not running in AWS, are you sure you are on the" \
116125 " right system?"
126+ echo_bold " $msg "
127+ exit 1
117128 fi
118129}
119130
131+ #
132+ # We need to have run setup.sh before running most linux-pkg commands.
133+ # This checks if setup has been run before. Note that if the system was
134+ # rebooted we want to rerun setup as cloud-init will reset apt sources on
135+ # boot.
136+ #
137+ function run_setup_if_needed() {
138+ [[ -f /run/linux-pkg-setup ]] && return
139+
140+ check_env TOP
141+ echo_bold " ------------------------------------------------------------"
142+ echo_bold " Running setup script"
143+ echo_bold " ------------------------------------------------------------"
144+ logmust " $TOP /setup.sh"
145+ echo_bold " ------------------------------------------------------------"
146+ }
147+
120148#
121149# Determine DEFAULT_GIT_BRANCH. If it is unset, default to the branch set in
122150# branch.config.
@@ -632,7 +660,7 @@ function determine_dependencies_base_url() {
632660 [[ -n " $suv " ]] || die " No artifacts found at $url "
633661 DEPENDENCIES_BASE_URL=" $url /$suv /input-artifacts/combined-packages/packages"
634662 else
635- DEPENDENCIES_BASE_URL=" s3://snapshot-de-images/builds/$JENKINS_OPS_DIR /devops-gate/master /linux-pkg/$DEFAULT_GIT_BRANCH /build-package"
663+ DEPENDENCIES_BASE_URL=" s3://snapshot-de-images/builds/$JENKINS_OPS_DIR /devops-gate/$S3_DEVOPS_BRANCH /linux-pkg/$DEFAULT_GIT_BRANCH /build-package"
636664 fi
637665
638666 #
@@ -715,6 +743,26 @@ function fetch_dependencies() {
715743 done
716744}
717745
746+ #
747+ # Run git fetch with the passed arguments. Git url must be passed as first
748+ # argument. If FETCH_GIT_TOKEN is set and this is a github repository
749+ # then pass-in the token when fetching.
750+ #
751+ function git_fetch_helper() {
752+ local orig_url=" $1 "
753+ local git_url=" $1 "
754+ local label=' '
755+ shift
756+
757+ if [[ -n " $FETCH_GIT_TOKEN " ]] &&
758+ [[ " $git_url " == https://github.com/* ]]; then
759+ git_url=" ${git_url/ https: \/\/ / https: \/\/ ${FETCH_GIT_TOKEN} @ } "
760+ label=' [token passed]'
761+ fi
762+ echo " Running: $label git fetch $orig_url $* "
763+ git fetch " $git_url " " $@ " || die " git fetch failed"
764+ }
765+
718766#
719767# Fetch package repository into $WORKDIR/repo
720768#
@@ -731,14 +779,14 @@ function fetch_repo_from_git() {
731779 # Otherwise just get the latest commit of the main branch.
732780 #
733781 if [[ " $DO_UPDATE_PACKAGE " == " true" ]]; then
734- logmust git fetch --no-tags " $PACKAGE_GIT_URL " \
782+ logmust git_fetch_helper " $PACKAGE_GIT_URL " --no-tags \
735783 " +$PACKAGE_GIT_BRANCH :repo-HEAD"
736- logmust git fetch --no-tags " $PACKAGE_GIT_URL " \
784+ logmust git_fetch_helper " $PACKAGE_GIT_URL " --no-tags \
737785 " +upstreams/$DEFAULT_GIT_BRANCH :upstream-HEAD"
738786 logmust git show-ref repo-HEAD
739787 logmust git show-ref upstream-HEAD
740788 else
741- logmust git fetch --no-tags " $PACKAGE_GIT_URL " \
789+ logmust git_fetch_helper " $PACKAGE_GIT_URL " --no-tags \
742790 " +$PACKAGE_GIT_BRANCH :repo-HEAD" --depth=1
743791 logmust git show-ref repo-HEAD
744792 fi
@@ -826,8 +874,7 @@ function update_upstream_from_git() {
826874 #
827875 # Fetch updates from third-party upstream repository.
828876 #
829- logmust git remote add upstream " $UPSTREAM_GIT_URL "
830- logmust git fetch upstream " $UPSTREAM_GIT_BRANCH "
877+ logmust git_fetch_helper " $UPSTREAM_GIT_URL " " $UPSTREAM_GIT_BRANCH "
831878
832879 #
833880 # Compare third-party upstream repository to our local snapshot of the
0 commit comments