Skip to content

Instantly share code, notes, and snippets.

@karubits
Created March 6, 2024 00:22
Show Gist options
  • Save karubits/7088f5d54c5ae8ec007eaab40c299ac2 to your computer and use it in GitHub Desktop.
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
#!/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