Created
March 6, 2024 00:22
-
-
Save karubits/7088f5d54c5ae8ec007eaab40c299ac2 to your computer and use it in GitHub Desktop.
A simple bash scrpit for install lazy docker as a direct binary from github
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 | |
# Function to check if lazydocker is installed | |
is_lazydocker_installed() { | |
if command -v lazydocker &> /dev/null; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Function to get the currently installed version of lazydocker | |
get_installed_version() { | |
lazydocker --version | grep -oP 'Version: \K.*' | |
} | |
# Check if lazydocker is already installed | |
if is_lazydocker_installed; then | |
installed_version=$(get_installed_version) | |
latest_version=$(curl -s https://api.github.com/repos/jesseduffield/lazydocker/releases/latest | jq -r '.tag_name' | sed 's/v//') | |
if [ "$installed_version" = "$latest_version" ]; then | |
echo "β¨ Lazydocker is already installed and up to date! β¨" | |
echo "Installed Version: $installed_version" | |
exit 0 | |
else | |
echo "π Updating lazydocker to the latest version $latest_version... π" | |
fi | |
else | |
echo "π Installing lazydocker... π" | |
fi | |
# Check if jq is installed, if not, install it | |
if ! command -v jq &> /dev/null; then | |
echo "Installing jq..." | |
apt-get update | |
apt-get install -y jq | |
if [ $? -ne 0 ]; then | |
echo "Error: Unable to install jq. Exiting." | |
exit 1 | |
fi | |
fi | |
# Check for the latest version of lazydocker on GitHub | |
latest_version=$(curl -s https://api.github.com/repos/jesseduffield/lazydocker/releases/latest | jq -r '.tag_name') | |
if [ -z "$latest_version" ]; then | |
echo "Error: Unable to fetch the latest version of lazydocker from GitHub." | |
exit 1 | |
fi | |
# Remove the "v" from the version | |
latest_version=${latest_version#v} | |
# Download it to /tmp/ | |
download_url="https://github.com/jesseduffield/lazydocker/releases/download/v${latest_version}/lazydocker_${latest_version}_Linux_x86_64.tar.gz" | |
curl -L -o "/tmp/lazydocker.tar.gz" "$download_url" | |
if [ $? -ne 0 ]; then | |
echo "Error: Unable to download lazydocker from $download_url." | |
exit 1 | |
fi | |
# Extract it in the /tmp/ directory | |
tar -C /tmp/ -xzf "/tmp/lazydocker.tar.gz" || { | |
echo "Error: Unable to extract lazydocker archive." | |
rm "/tmp/lazydocker.tar.gz" | |
exit 1 | |
} | |
# Move the binary lazydocker to /usr/bin/local | |
mv "/tmp/lazydocker" "/usr/local/bin/" || { | |
echo "Error: Unable to move lazydocker binary to /usr/local/bin/." | |
rm "/tmp/lazydocker.tar.gz" | |
exit 1 | |
} | |
# Make it executable | |
chmod +x "/usr/local/bin/lazydocker" || { | |
echo "Error: Unable to make lazydocker executable." | |
rm "/tmp/lazydocker.tar.gz" | |
exit 1 | |
} | |
# Clean up temporary files | |
rm "/tmp/lazydocker.tar.gz" | |
echo "Lazydocker installed successfully!" | |
lazydocker --version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment