Last active
August 29, 2024 18:10
-
-
Save espeon/dffcea222330db8edadbb3501f497d62 to your computer and use it in GitHub Desktop.
Little ffmpeg update script
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 | |
| # Variables | |
| BASE_URL="https://johnvansickle.com/ffmpeg/builds" | |
| # 'git' or 'release' | |
| FF_VERSION="git" | |
| # See John's website for supported arches: https://johnvansickle.com/ffmpeg/ | |
| FF_ARCH='amd64' | |
| DOWNLOAD_DIR="$HOME/ffmpeg" | |
| FFMPEG_ARCHIVE="ffmpeg-$FF_VERSION-$FF_ARCH-static.tar.xz" | |
| FFMPEG_URL="$BASE_URL/$FFMPEG_ARCHIVE" | |
| README_URL="https://johnvansickle.com/ffmpeg/$FF_VERSION-readme.txt" | |
| CONFIG_DIR="$HOME/.config/ffmpeg-updater" | |
| COMMIT_FILE="$CONFIG_DIR/last_commit.txt" | |
| # Create necessary directories | |
| mkdir -p "$DOWNLOAD_DIR" | |
| mkdir -p "$CONFIG_DIR" | |
| # Fetch the current commit hash from the website | |
| echo "Fetching the current commit hash..." | |
| CURRENT_COMMIT_HASH=$(curl -s "$README_URL" | grep -oP '(?<=version: )\w+') | |
| if [ -z "$CURRENT_COMMIT_HASH" ]; then | |
| echo "Failed to fetch the commit hash." | |
| exit 1 | |
| fi | |
| # Read the saved commit hash from the last update | |
| if [ -f "$COMMIT_FILE" ]; then | |
| SAVED_COMMIT_HASH=$(cat "$COMMIT_FILE") | |
| else | |
| SAVED_COMMIT_HASH="" | |
| fi | |
| # Compare the current and saved commit hashes | |
| if [ "$CURRENT_COMMIT_HASH" == "$SAVED_COMMIT_HASH" ]; then | |
| echo "FFmpeg is up to date. No need to download." | |
| exit 0 | |
| else | |
| echo "New FFmpeg version detected. Updating..." | |
| fi | |
| # Download the latest FFmpeg | |
| echo "Downloading FFmpeg..." | |
| curl -L -o "$DOWNLOAD_DIR/$FFMPEG_ARCHIVE" "$FFMPEG_URL" | |
| # Extract the archive | |
| echo "Extracting FFmpeg..." | |
| tar -xJf "$DOWNLOAD_DIR/$FFMPEG_ARCHIVE" -C "$DOWNLOAD_DIR" | |
| # Determine the extracted directory name | |
| EXTRACTED_DIR=$(find "$DOWNLOAD_DIR" -type d -name "ffmpeg-$FF_VERSION-*-$FF_ARCH-static") | |
| # Move FFmpeg binaries to /usr/local/bin | |
| if [ -d "$EXTRACTED_DIR" ]; then | |
| echo "Updating FFmpeg binaries..." | |
| sudo mv "$EXTRACTED_DIR/ffmpeg" /usr/local/bin/ | |
| sudo mv "$EXTRACTED_DIR/ffprobe" /usr/local/bin/ | |
| else | |
| echo "Extraction failed or directory not found." | |
| exit 1 | |
| fi | |
| # Save the current commit hash for future checks | |
| echo "$CURRENT_COMMIT_HASH" > "$COMMIT_FILE" | |
| echo "Saved the current commit hash." | |
| # Clean up | |
| echo "Cleaning up..." | |
| rm -rf "$DOWNLOAD_DIR/$FFMPEG_ARCHIVE" "$EXTRACTED_DIR" "$DOWNLOAD_DIR" | |
| echo "FFmpeg update complete! Version: $CURRENT_COMMIT_HASH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment