github.com/stevenmatthewt/agent@v3.5.4+incompatible/install.sh (about) 1 #!/bin/bash 2 # 3 # This is the installer for the Buildkite Agent. 4 # 5 # For more information, see: https://github.com/buildkite/agent 6 7 set -e 8 9 COMMAND="bash -c \"\`curl -sL https://raw.githubusercontent.com/buildkite/agent/master/install.sh\`\"" 10 11 echo -e "\033[33m 12 _ _ _ _ _ _ _ _ 13 | | (_) | | | | (_) | | | 14 | |__ _ _ _| | __| | | ___| |_ ___ __ _ __ _ ___ _ __ | |_ 15 | '_ \| | | | | |/ _\` | |/ / | __/ _ \ / _\` |/ _\` |/ _ \ '_ \| __| 16 | |_) | |_| | | | (_| | <| | || __/ | (_| | (_| | __/ | | | |_ 17 |_.__/ \__,_|_|_|\__,_|_|\_\_|\__\___| \__,_|\__, |\___|_| |_|\__| 18 __/ | 19 |___/\033[0m" 20 21 echo -e "Finding latest release..." 22 23 UNAME=$(uname -sm | awk '{print tolower($0)}') 24 25 if [[ ($UNAME == *"mac os x"*) || ($UNAME == *darwin*) ]]; then 26 PLATFORM="darwin" 27 elif [[ ($UNAME == *"freebsd"*) ]]; then 28 PLATFORM="freebsd" 29 else 30 PLATFORM="linux" 31 fi 32 33 if [ -n "$BUILDKITE_INSTALL_ARCH" ]; then 34 ARCH="$BUILDKITE_INSTALL_ARCH" 35 echo "Using explicit arch '$ARCH'" 36 else 37 case $UNAME in 38 *amd64*) ARCH="amd64" ;; 39 *x86_64*) ARCH="amd64" ;; 40 *armv8*) ARCH="arm64" ;; 41 *armv7*) ARCH="armhf" ;; 42 *armv6*) ARCH="armhf" ;; 43 *arm*) ARCH="arm" ;; 44 *) ARCH="386" ;; 45 esac 46 fi 47 48 if [[ "$BETA" == "true" ]]; then 49 RELEASE_INFO_URL="https://buildkite.com/agent/releases/latest?platform=$PLATFORM&arch=$ARCH&prerelease=true" 50 else 51 RELEASE_INFO_URL="https://buildkite.com/agent/releases/latest?platform=$PLATFORM&arch=$ARCH" 52 fi 53 54 if command -v wget >/dev/null; then 55 LATEST_RELEASE=$(wget -qO- "$RELEASE_INFO_URL") 56 else 57 LATEST_RELEASE=$(curl -s "$RELEASE_INFO_URL") 58 fi 59 60 VERSION=$(echo "$LATEST_RELEASE" | awk -F= '/version=/ { print $2 }') 61 DOWNLOAD_FILENAME=$(echo "$LATEST_RELEASE" | awk -F= '/filename=/ { print $2 }') 62 DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | awk -F= '/url=/ { print $2 }') 63 64 function buildkite-download { 65 BUILDKITE_DOWNLOAD_TMP_FILE="/tmp/buildkite-download-$$.txt" 66 67 if command -v wget >/dev/null 68 then 69 wget "$1" -O "$2" 2> $BUILDKITE_DOWNLOAD_TMP_FILE || BUILDKITE_DOWNLOAD_EXIT_STATUS=$? 70 else 71 curl -L -o "$2" "$1" 2> $BUILDKITE_DOWNLOAD_TMP_FILE || BUILDKITE_DOWNLOAD_EXIT_STATUS=$? 72 fi 73 74 if [[ $BUILDKITE_DOWNLOAD_EXIT_STATUS -ne 0 ]]; then 75 echo -e "\033[31mFailed to download file: $1\033[0m\n" 76 77 cat $BUILDKITE_DOWNLOAD_TMP_FILE 78 exit $BUILDKITE_DOWNLOAD_EXIT_STATUS 79 fi 80 } 81 82 echo -e "Installing Version: \033[35mv$VERSION\033[0m" 83 84 # Default the destination folder 85 : ${DESTINATION:="$HOME/.buildkite-agent"} 86 87 # If they have a $HOME/.buildkite folder, rename it to `buildkite-agent` and 88 # symlink back to the old one. Since we changed the name of the folder, we 89 # don't want any scripts that the user has written that may reference 90 # ~/.buildkite to break. 91 if [[ -d "$HOME/.buildkite" && ! -d "$HOME/.buildkite-agent" ]]; then 92 mv "$HOME/.buildkite" "$HOME/.buildkite-agent" 93 ln -s "$HOME/.buildkite-agent" "$HOME/.buildkite" 94 95 echo "" 96 echo "======================= IMPORTANT UPGRADE NOTICE ==========================" 97 echo "" 98 echo "Hey!" 99 echo "" 100 echo "Sorry to be a pain, but we've renamed ~/.buildkite to ~/.buildkite-agent" 101 echo "" 102 echo "I've renamed your .buildkite folder to .buildkite-agent, and created a symlink" 103 echo "from the old location to the new location, just in case you had any scripts that" 104 echo "referenced the previous location." 105 echo "" 106 echo "If you have any questions, feel free to email me at: keith@buildkite.com" 107 echo "" 108 echo "~ Keith" 109 echo "" 110 echo "==========================================================================" 111 echo "" 112 fi 113 114 mkdir -p "$DESTINATION" 115 116 if [[ ! -w "$DESTINATION" ]]; then 117 echo -e "\n\033[31mUnable to write to destination \`$DESTINATION\`\n\nYou can change the destination by running:\n\nDESTINATION=/my/path $COMMAND\033[0m\n" 118 exit 1 119 fi 120 121 echo -e "Destination: \033[35m$DESTINATION\033[0m" 122 123 echo -e "Downloading $DOWNLOAD_URL" 124 125 # Create a temporary folder to download the binary to 126 INSTALL_TMP=/tmp/buildkite-agent-install-$$ 127 mkdir -p $INSTALL_TMP 128 129 # If the file already exists in a folder called releases. This is useful for 130 # local testing of this file. 131 if [[ -e releases/$DOWNLOAD ]]; then 132 echo "Using existing release: releases/$DOWNLOAD_FILENAME" 133 cp releases/"$DOWNLOAD_FILENAME" $INSTALL_TMP 134 else 135 buildkite-download "$DOWNLOAD_URL" "$INSTALL_TMP/$DOWNLOAD_FILENAME" 136 fi 137 138 # Extract the download to a tmp folder inside the $DESTINATION 139 # folder 140 tar -C "$INSTALL_TMP" -zxf "$INSTALL_TMP"/"$DOWNLOAD_FILENAME" 141 142 # Move the buildkite binary into a bin folder 143 mkdir -p "$DESTINATION"/bin 144 mv $INSTALL_TMP/buildkite-agent "$DESTINATION"/bin 145 chmod +x "$DESTINATION"/bin/buildkite-agent 146 147 # Copy the latest config file as dist 148 mv "$INSTALL_TMP"/buildkite-agent.cfg "$DESTINATION"/buildkite-agent.dist.cfg 149 150 # Copy the config file if it doesn't exist 151 if [[ -f $DESTINATION/buildkite-agent.cfg ]]; then 152 echo -e "\n\033[36mIgnoring existing buildkite-agent.cfg (see buildkite-agent.dist.cfg for the latest version)\033[0m" 153 else 154 echo -e "\n\033[36mA default buildkite-agent.cfg has been created for you in $DESTINATION\033[0m" 155 156 cp "$DESTINATION"/buildkite-agent.dist.cfg "$DESTINATION"/buildkite-agent.cfg 157 158 # Set their token for them 159 if [[ -n $TOKEN ]]; then 160 # Need "-i ''" for macOS X and FreeBSD 161 if [[ $(uname) == 'Darwin' ]] || [[ $(uname) == 'FreeBSD' ]]; then 162 sed -i '' "s/token=\"xxx\"/token=\"$TOKEN\"/g" "$DESTINATION"/buildkite-agent.cfg 163 else 164 sed -i "s/token=\"xxx\"/token=\"$TOKEN\"/g" "$DESTINATION"/buildkite-agent.cfg 165 fi 166 else 167 echo -e "\n\033[36mDon't forget to update the config with your agent token! You can find it token on your \"Agents\" page in Buildkite\033[0m" 168 fi 169 fi 170 171 # Copy the hook samples 172 mkdir -p "$DESTINATION"/hooks 173 mv $INSTALL_TMP/hooks/*.sample "$DESTINATION"/hooks 174 175 if [[ -f "$INSTALL_TMP/bootstrap.sh" ]]; then 176 mv "$INSTALL_TMP/bootstrap.sh" "$DESTINATION" 177 chmod +x "$DESTINATION/bootstrap.sh" 178 fi 179 180 echo -e "\n\033[32mSuccessfully installed to $DESTINATION\033[0m 181 182 You can now start the agent! 183 184 $DESTINATION/bin/buildkite-agent start 185 186 For docs, help and support: 187 188 https://buildkite.com/docs/agent/v3 189 190 Happy building! <3 191 "