Skip to content

Instantly share code, notes, and snippets.

@jslay88
Last active March 28, 2024 16:36
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jslay88/bf654c23eaaaed443bb8e8b41d02b2a9 to your computer and use it in GitHub Desktop.
Save jslay88/bf654c23eaaaed443bb8e8b41d02b2a9 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" # credit @teefax
fi
cp -Rfp "$tempdir/lens/dist/$arch/OpenLens.app" "$HOME/Applications/"
rm -Rf "$tempdir"
print_alias_message
}
install_posix() {
echo "Installing OpenLens (Posix)..."
cd "$tempdir"
sudo dpkg -i "$(ls -Art $tempdir/lens/dist/*.deb | tail -n 1)"
rm -Rf "$tempdir"
print_alias_message
}
install_windows() {
echo "Installing OpenLens (Windows)..."
"$(/bin/ls -Art $tempdir/lens/dist/OpenLens*.exe | tail -n 1)"
rm -Rf "$tempdir"
print_alias_message
}
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"
if [ -z "$1" ]; then
echo "Checking GitHub API for latests tag..."
OPENLENS_VERSION=$(curl -s https://api.github.com/repos/lensapp/lens/releases/latest | sed -En 's/ "tag_name": "(.+)",/\1/p')
else
if [[ "$1" == v* ]]; then
OPENLENS_VERSION="$1"
else
OPENLENS_VERSION="v$1"
fi
echo "Using supplied tag $OPENLENS_VERSION"
fi
if [ -z $OPENLENS_VERSION ]; then
echo "Failed to get valid version tag. Aborting!"
exit 1
fi
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"
}
print_alias_message() {
if [ "$(type -t install_openlens)" != 'alias' ]; then
printf "It is recommended to add an alias to your shell profile to run this script again.\n"
printf "alias install_openlens=\"curl -o- https://gist.githubusercontent.com/jslay88/bf654c23eaaaed443bb8e8b41d02b2a9/raw/install_openlens.sh | bash\"\n\n"
fi
}
if [[ "$(uname)" == "Linux" ]]; then
install_deps_posix
install_nvm
build_openlens "$1"
install_posix
elif [[ "$(uname)" == "Darwin" ]]; then
install_deps_darwin
install_nvm
build_openlens "$1"
install_darwin
else
install_deps_windows
install_nvm
build_openlens "$1"
install_windows
fi
echo "Done!"
@brentjohnson
Copy link

The build part works for Apple Silicon, but the install fails because the binary ends up in lens/dist/mac-arm64.

@jslay88
Copy link
Author

jslay88 commented Aug 9, 2022 via email

@jslay88
Copy link
Author

jslay88 commented Aug 9, 2022

See https://gist.github.com/teefax/0c054ad8af0597c189b81737ad61ccf4/revisions#diff-4aee302d2437f003b4159c29f932f4be96a5dc21705b9f087df2a0f075abcb07 for the changes needed to build on Apple Silicon

Thanks for taking care of this while I’m occupied. I have updated mine to incorporate your changes and gave credit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment