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