Skip to content

Commit

Permalink
groundwork to support multi-arch
Browse files Browse the repository at this point in the history
  • Loading branch information
pirafrank committed May 16, 2021
1 parent 94c067e commit 13d99f3
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 118 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ COPY install_dotfiles.zsh \
setups/setup_docker_cli.zsh \
setups/setup_fzf.sh \
setups/setup_zprezto.zsh \
setups/setup_env.sh \
setups/setup_utils.sh \
workspaces/setup_nvm.zsh \
workspaces/setup_pyenv.zsh \
Expand Down
117 changes: 35 additions & 82 deletions setups/setup_cloud_clients.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,126 +3,79 @@
# this script installs various cloud tools
# it can also be used to update them to their latest version.


### variables ###

folder="${HOME}/bin2"

echo "
Running as : $(whoami)
Home folder: $HOME
Install dir: $folder
"

# creating target dir if it doesn't exist
# it should've been created in prev script
if [ -d $folder ]; then
mkdir -p $folder
fi
### script body ###

# init environment
source setup_env.sh
setArchAndPlatform
welcome
createDir "$folder"
cd $folder

# packer
echo "Installing packer..."
if [ -f packer ]; then rm -f packer; fi
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
printf "\n\nInstalling packer...\n"
latest_version=$(curl -sL https://releases.hashicorp.com/packer \
| grep href | grep packer | head -n1 | cut -d'/' -f3)
url="https://releases.hashicorp.com/packer/${latest_version}/packer_${latest_version}_${platform}_amd64.zip"
curl -o packer.zip -L $url
unzip packer.zip
rm -f packer.zip
chmod +x packer
url="https://releases.hashicorp.com/packer/${latest_version}/packer_${latest_version}_${PLATFORM}_${ARCH_ALT}.zip"
downloadAndInstall $url packer

# scaleway
echo "Installing scaleway client..."
if [ -f scw ]; then rm -f scw; fi
printf "\n\nInstalling scaleway client...\n"
url=$(curl -sL https://api.github.com/repos/scaleway/scaleway-cli/releases/latest \
| grep http | grep -i "$(uname -s)" | grep -i "$(uname -m)" | cut -d':' -f 2,3 | cut -d'"' -f2)
if [ -z "$url" ]; then
echo "Unsupported OS. Skipping scw installation..."
else
curl -o ./scw -L $url
chmod +x scw
fi
| grep http | grep -i "${PLATFORM}" | grep -i "${ARCH}" | cut -d':' -f 2,3 | cut -d'"' -f2)
downloadAndInstall $url scw

# hetzner
echo "Installing hetzner client..."
printf "\n\nInstalling hetzner client...\n"
if [ -f hcloud ]; then rm -f hcloud; fi
if [ $(uname -s) = 'Darwin' ]; then
url=$(curl -sL https://api.github.com/repos/hetznercloud/cli/releases/latest \
| grep http | grep -i macos | grep amd64 | grep 'zip' | cut -d':' -f 2,3 | cut -d'"' -f2)
| grep http | grep -i macos | grep ${ARCH_ALT} | grep 'zip' | cut -d':' -f 2,3 | cut -d'"' -f2)
else
url=$(curl -sL https://api.github.com/repos/hetznercloud/cli/releases/latest \
| grep http | grep -i "$(uname -s)" | grep amd64 | grep 'tar.gz' | cut -d':' -f 2,3 | cut -d'"' -f2)
| grep http | grep -i "${PLATFORM}" | grep ${ARCH_ALT} | grep 'tar.gz' | cut -d':' -f 2,3 | cut -d'"' -f2)
fi
if [ -z "$url" ]; then
echo "Unsupported OS. Skipping hcloud installation..."
else
curl -o hcloud-bin.tar.gz -L $url
tar -xzf hcloud-bin.tar.gz
rm -f hcloud-bin.tar.gz
chmod +x hcloud
fi


downloadAndInstall $url hcloud

# kubectl
if [ -f kubectl ]; then rm -f kubectl; fi
ARCH="$(uname -s | tr '[:upper:]' '[:lower:]')"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${ARCH}/amd64/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${ARCH}/amd64/kubectl.sha256"

printf "\n\nInstalling kubectl...\n"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${ARCH}/${ARCH_ALT}/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${ARCH}/${ARCH_ALT}/kubectl.sha256"
if [ $(uname -s) = 'Darwin' ]; then alias sha256sum='shasum -a 256'; fi

if [ "$(<kubectl.sha256)" = "$(sha256sum kubectl | awk '{print $1}')" ]; then
chmod +x kubectl
rm -f kubectl.sha256
fi


# helm
printf "\n\nInstalling helm...\n"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
HELM_INSTALL_DIR="$HOME/bin2" bash ./get_helm.sh --no-sudo
rm -f get_helm.sh


# kubectx + kubens
echo "Installing kubectx..."
if [ -f kubectx ]; then rm -f kubectx; fi
printf "\n\nInstalling kubectx...\n"
url=$(curl -sL https://api.github.com/repos/ahmetb/kubectx/releases/latest \
| grep http | grep -i "$(uname -s)" | grep -i "$(uname -m)" | cut -d':' -f 2,3 \
| grep http | grep -i "$PLATFORM" | grep -i "$ARCH" | cut -d':' -f 2,3 \
| cut -d'"' -f2 | grep -i kubectx_)
if [ -z "$url" ]; then
echo "Unsupported OS. Skipping kubectx installation..."
else
curl -o ./kubectx.tar.gz -L $url
tar -xzf kubectx.tar.gz
chmod +x kubectx
rm -f kubectx.tar.gz
rm -f LICENSE
fi
downloadAndInstall $url kubectx
rm -f LICENSE

echo "Installing kubens..."
if [ -f kubens ]; then rm -f kubens; fi
printf "\n\nInstalling kubens...\n"
url=$(curl -sL https://api.github.com/repos/ahmetb/kubectx/releases/latest \
| grep http | grep -i "$(uname -s)" | grep -i "$(uname -m)" | cut -d':' -f 2,3 \
| grep http | grep -i "$PLATFORM" | grep -i "$ARCH" | cut -d':' -f 2,3 \
| cut -d'"' -f2 | grep -i kubens)
if [ -z "$url" ]; then
echo "Unsupported OS. Skipping kubens installation..."
else
curl -o ./kubens.tar.gz -L $url
tar -xzf kubens.tar.gz
chmod +x kubens
rm -f kubens.tar.gz
rm -f LICENSE
fi

downloadAndInstall $url kubens
rm -f LICENSE

# stern
echo "Installing stern..."
if [ -f stern ]; then rm -f stern; fi
printf "\n\nInstalling stern...\n"
url=$(curl -sL https://api.github.com/repos/wercker/stern/releases/latest \
| grep http | grep -i "$(uname -s)" | cut -d':' -f 2,3 | cut -d'"' -f2)
if [ -z "$url" ]; then
echo "Unsupported OS. Skipping stern installation..."
else
curl -o ./stern -L $url
chmod +x stern
fi
| grep http | grep -i "$PLATFORM" | cut -d':' -f 2,3 | cut -d'"' -f2)
downloadAndInstall $url stern
67 changes: 67 additions & 0 deletions setups/setup_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

### variables ###

folder="${HOME}/bin2"


### functions ###

function del {
if [ -f "$1" ]; then rm -f "$1"; fi
}

function setArchAndPlatform {
PLATFORM="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH_ALT="armv5";;
armv6*) ARCH_ALT="armv6";;
armv7*) ARCH_ALT="arm";;
aarch64) ARCH_ALT="arm64";;
x86) ARCH_ALT="386";;
x86_64) ARCH_ALT="amd64";;
i686) ARCH_ALT="386";;
i386) ARCH_ALT="386";;
esac
}

function downloadAndInstall {
url="$1"
name="$2"
if [ ! -z $url ]; then
del $name
if [ ! -z $(echo $url | grep 'tar.gz') ]; then
# it's tar.gzipped
curl -L $url | tar xz
elif [ ! -z $(echo $url | grep 'zip') ]; then
# it's zipped
curl -o "$name.zip" -L $url
unzip "$name.zip"
rm -f "$name.zip"
else
# not compressed
curl -o ./$name -L $url
fi
chmod +x $name
else
echo "Unsupported OS. Skipping $name installation..."
fi
}

function welcome {
echo "
Running as : $(whoami)
Home folder: $HOME
Install dir: $folder
Platform : $PLATFORM
Arch : $ARCH (aka ${ARCH_ALT})
"
}

function createDir {
folder="$1"
# creating target dir if it doesn't exist
# it should've been created in prev script
if [ -d $folder ]; then mkdir -p $folder; fi
}
58 changes: 22 additions & 36 deletions setups/setup_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,48 @@
# this script installs various utils.
# it can also be used to update them to their latest version.

folder="${HOME}/bin2"

function del {
if [ -f "$1" ]; then rm -f "$1"; fi
}
### variables ###

echo "
Running as : $(whoami)
Home folder: $HOME
Install dir: $folder
"
folder="${HOME}/bin2"

# creating target dir if it doesn't exist
# it should've been created in prev script
if [ -d $folder ]; then
mkdir -p $folder
fi
cd $folder

### script body ###

platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch=$(arch)
# init environment
source setup_env.sh
setArchAndPlatform
welcome
createDir "$folder"
cd $folder

# yq
echo "Installing yq..."
printf "Installing yq...\n"
# ...v2
del yq2
url="https://github.com/mikefarah/yq/releases/download/2.3.0/yq_${platform}_amd64"
curl -o ./yq2 -L $url
chmod +x yq2
url="https://github.com/mikefarah/yq/releases/download/2.3.0/yq_${PLATFORM}_${ARCH_ALT}"
downloadAndInstall $url yq2
# ...latest
del yq
url=$(curl -sL https://api.github.com/repos/mikefarah/yq/releases/latest \
| grep http | grep -i "$platform" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep -E '*(amd64)$')
curl -o ./yq -L $url
chmod +x yq
| grep http | grep -i "$PLATFORM" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep -E "*($ARCH_ALT)$")
downloadAndInstall $url yq

# dive - to inspect docker images layers
echo "Installing dive..."
del dive
printf "\n\nInstalling dive...\n"
url=$(curl -sL https://api.github.com/repos/wagoodman/dive/releases/latest \
| grep http | grep -i "$platform" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep 'tar.gz')
curl -L $url | tar xz
chmod +x dive
| grep http | grep -i "$PLATFORM" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep 'tar.gz' | grep $ARCH_ALT)
downloadAndInstall $url dive

# lazygit
del lazygit
printf "\n\nInstalling lazygit...\n"
url=$(curl -sL https://api.github.com/repos/jesseduffield/lazygit/releases/latest \
| grep http | grep -i "$platform" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep 'tar.gz' | grep $arch)
curl -L $url | tar xz
chmod +x lazygit
| grep http | grep -i "$PLATFORM" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep 'tar.gz' | grep $ARCH)
downloadAndInstall $url lazygit

# ipinfo cli
printf "\n\nInstalling ipinfo cli...\n"
del ipinfo
url=$(curl -sL https://api.github.com/repos/ipinfo/cli/releases/latest \
| grep http | grep -i "$platform" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep 'tar.gz' | grep 'amd64')
| grep http | grep -i "$PLATFORM" | cut -d':' -f 2,3 | cut -d'"' -f2 | grep 'tar.gz' | grep $ARCH_ALT)
curl -L $url | tar xz
mv ipinfo*amd64 ipinfo
chmod +x ipinfo

0 comments on commit 13d99f3

Please sign in to comment.