Skip to content

Instantly share code, notes, and snippets.

@teefax
Forked from jslay88/install_openlens.sh
Last active August 9, 2022 16:00
Show Gist options
  • Save teefax/0c054ad8af0597c189b81737ad61ccf4 to your computer and use it in GitHub Desktop.
Save teefax/0c054ad8af0597c189b81737ad61ccf4 to your computer and use it in GitHub Desktop.
Build and Install OpenLens
#!/bin/bash
install_deps_windows() {
echo "Installing Build Dependencies (Windows)..."
choco install -y make visualstudio2019buildtools visualstudio2019-workload-vctools
}
install_deps_darwin() {
echo "Installing Build Dependencies (Darwin)..."
xcode-select --install
if ! hash make 2>/dev/null; then
if ! hash brew 2>/dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
echo "Installing make via Homebrew..."
brew install make
fi
}
install_deps_posix() {
echo "Installing Build Dependencies (Posix)..."
sudo apt-get install -y make g++ curl
}
install_darwin() {
echo "Killing OpenLens (if open)..."
killall OpenLens
echo "Installing OpenLens (Darwin)..."
rm -Rf "$HOME/Applications/OpenLens.app"
arch="mac"
if [[ "$(uname -m)" == "arm64" ]]; then
arch="mac-arm64"
fi
cp -Rfp "$tempdir/lens/dist/$arch/OpenLens.app" "$HOME/Applications/"
rm -Rf "$tempdir"
}
install_posix() {
echo "Installing OpenLens (Posix)..."
cd "$tempdir"
sudo dpkg -i "$(ls -Art $tempdir/lens/dist/*.deb | tail -n 1)"
rm -Rf "$tempdir"
}
install_windows() {
echo "Installing OpenLens (Windows)..."
"$(/bin/ls -Art $tempdir/lens/dist/OpenLens*.exe | tail -n 1)"
rm -Rf "$tempdir"
}
install_nvm() {
if [ -z "$NVM_DIR" ]; then
echo "Installing NVM..."
NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | sed -En 's/ "tag_name": "(.+)",/\1/p')
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh | bash
NVM_DIR="$HOME/.nvm"
fi
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
}
build_openlens() {
tempdir=$(mktemp -d)
cd "$tempdir"
OPENLENS_VERSION=$(curl -s https://api.github.com/repos/lensapp/lens/releases/latest | sed -En 's/ "tag_name": "(.+)",/\1/p')
curl -L https://github.com/lensapp/lens/archive/refs/tags/$OPENLENS_VERSION.tar.gz | tar xvz
mv lens-* lens
cd lens
NVM_CURRENT=$(nvm current)
nvm install 16
nvm use 16
npm install -g yarn
make build
nvm use "$NVM_CURRENT"
}
if [[ "$(uname)" == "Linux" ]]; then
install_deps_posix
install_nvm
build_openlens
install_posix
elif [[ "$(uname)" == "Darwin" ]]; then
install_deps_darwin
install_nvm
build_openlens
install_darwin
else
install_deps_windows
install_nvm
build_openlens
install_windows
fi
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment