-
-
Save shakahl/21c0fac0c4748b7fe32b4ac73c01083c to your computer and use it in GitHub Desktop.
Build and Install OpenLens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment