Created
March 7, 2020 06:26
-
-
Save hongkongkiwi/3d9937d92ff0dda209a72e23643607f0 to your computer and use it in GitHub Desktop.
Updates mergerfs to the latest version
This file contains 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
#!/usr/bin/env bash | |
# Read a single char from /dev/tty, prompting with "$*" | |
# Note: pressing enter will return a null string. Perhaps a version terminated with X and then remove it in caller? | |
# See https://unix.stackexchange.com/a/367880/143394 for dealing with multi-byte, etc. | |
function get_keypress { | |
local REPLY IFS= | |
>/dev/tty printf '%s' "$*" | |
[[ $ZSH_VERSION ]] && read -rk1 # Use -u0 to read from STDIN | |
# See https://unix.stackexchange.com/q/383197/143394 regarding '\n' -> '' | |
[[ $BASH_VERSION ]] && </dev/tty read -rn1 | |
printf '%s' "$REPLY" | |
} | |
# Get a y/n from the user, return yes=0, no=1 enter=$2 | |
# Prompt using $1. | |
# If set, return $2 on pressing enter, useful for cancel or defualting | |
function get_yes_keypress { | |
local prompt="${1:-Are you sure [y/n]? }" | |
local enter_return=$2 | |
local REPLY | |
# [[ ! $prompt ]] && prompt="[y/n]? " | |
while REPLY=$(get_keypress "$prompt"); do | |
[[ $REPLY ]] && printf '\n' # $REPLY blank if user presses enter | |
case "$REPLY" in | |
Y|y) return 0;; | |
N|n) return 1;; | |
'') [[ $enter_return ]] && return "$enter_return" | |
esac | |
done | |
} | |
# Credit: http://unix.stackexchange.com/a/14444/143394 | |
# Prompt to confirm, defaulting to NO on <enter> | |
# Usage: confirm "Dangerous. Are you sure?" && rm * | |
function confirm { | |
local prompt="${*:-Are you sure} [y/N]? " | |
get_yes_keypress "$prompt" 1 | |
} | |
# Prompt to confirm, defaulting to YES on <enter> | |
function confirm_yes { | |
local prompt="${*:-Are you sure} [Y/n]? " | |
get_yes_keypress "$prompt" 0 | |
} | |
source /etc/os-release | |
ARCH=`uname --m` | |
[[ "$ARCH" == "x86_64" ]] && ARCH="amd64" | |
[[ "$ARCH" == "aarch64" ]] && ARCH="arm64" | |
echo "Checking system info" | |
echo " - Linux System: $ID" | |
echo " - Linux Release: $VERSION_CODENAME" | |
echo " - System Arch: $ARCH" | |
echo "Checking for latest mergerfs version" | |
PKG_VERSION=$(curl -s "https://github.com/trapexit/mergerfs/releases/latest/download" 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+) || { echo >&2 "Failed to get package version!"; exit 1; } | |
echo " - $PKG_VERSION" | |
PKG_NAME="mergerfs_${PKG_VERSION}.${ID}-${VERSION_CODENAME}_${ARCH}.deb" | |
PKG_URL="https://github.com/trapexit/mergerfs/releases/download/$PKG_VERSION" | |
echo "Downloading mergerfs $PKG_VERSION" && \ | |
wget -q -O "/tmp/$PKG_NAME" "$PKG_URL/$PKG_NAME" || { echo >&2 "Failed to get mergerfs!"; exit 1; } | |
echo " - Got the package" | |
confirm_yes "Install latest mergerfs $PKG_VERSION now?" || { exit 1; } | |
echo "Installing mergerfs package" | |
dpkg -i "/tmp/$PKG_NAME" || { echo >&2 "Failed to install mergerfs!"; exit 1; } | |
echo "All done!" | |
rm "/tmp/$PKG_NAME" > /dev/null |
Hi, looks like my command isn’t quite right. There are many ways to download a latest release…. Here’s a good gist: https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8
And here is the actual repo I’m downloading from, you can always just paste the link to the exact version instead: https://github.com/trapexit/mergerfs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
I stumbled on your gist when I realised my factory install latest versison was a long way behind the official builds.
However,
$(curl -s "https://github.com/trapexit/mergerfs/releases/latest/download" 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+)
does not pull back the latest version (nor indeed, any version) and so nothing downloads :(