snips/get_neovim.sh

60 lines
1.9 KiB
Bash
Raw Normal View History

2024-04-07 20:07:53 +00:00
#!/bin/bash
function die() {
echo "ERROR! $1" && exit 1
}
START_DIR=$(pwd)
FILE_DIR="/opt/neovim"
FILE_NAME="nvim.appimage"
FILE_URL="https://github.com/neovim/neovim/releases/download/nightly"
TMP_FILE=$(mktemp $FILE_DIR/nvim.XXXXXX.appimage)
echo "Downloading latest nightly $FILE_NAME to $TMP_FILE"
# curl -L -o $TMP_FILE $FILE_URL/$FILE_NAME || die "Can't cURL $FILE_NAME"
2024-09-19 01:45:41 +00:00
wget -O $TMP_FILE $FILE_URL/$FILE_NAME > /dev/null 2>&1 || die "Can't cURL $FILE_NAME"
2024-04-07 20:07:53 +00:00
chmod +x $TMP_FILE || die "Can't chmod $TMP_FILE"
NEWVER=$($TMP_FILE --version | head -1)
EXTVER=$(test -e $FILE_DIR/.version && cat $FILE_DIR/.version || echo "")
echo "Version check - New version ($NEWVER) =?= current ($EXTVER)"
if [ "$NEWVER" == "$EXTVER" ]; then
echo "Not updating. New version ($NEWVER) same as current ($EXTVER)"
else
if [ -e $FILE_NAME ]; then
rm $FILE_NAME || die "Can't remove $FILE_NAME"
echo "Removed $FILE_NAME"
fi
cp $TMP_FILE $FILE_DIR/$FILE_NAME || die "Can't copy $TMP_FILE to $FILE_NAME"
echo "Making $FILE_DIR/$FILE_NAME executable"
chmod +x $FILE_DIR/$FILE_NAME || die "Can't chmod $FILE_DIR/$FILE_NAME"
echo $NEWVER > $FILE_DIR/.version || die "Can't write $FILE_DIR/.version"
# Extract nvim for other (non-root) users to run
if [ -d "$FILE_DIR/squashfs-root" ]; then
rm -rf $FILE_DIR/squashfs-root || die "Can't delete $FILE_DIR/squashfs-root"
fi
cd $FILE_DIR
2024-09-19 01:45:41 +00:00
echo "Extracting $NEWVER"
$TMP_FILE --appimage-extract > /dev/null 2>&1 || die "Can't extract appimage $FILE_NAME"
2024-04-07 20:07:53 +00:00
if [ -L "$FILE_DIR/nvim" ]; then
rm $FILE_DIR/nvim || die "Can't remove $FILE_DIR/nvim"
fi
if [ -x "$FILE_DIR/squashfs-root/AppRun" ]; then
ln -s $FILE_DIR/squashfs-root/AppRun nvim
else
die "$FILE_DIR/squash-root/AppRun not executable"
fi
cd $START_DIR
echo "Version $NEWVER ready!"
fi
rm $TMP_FILE || die "Can't delete $TMP_FILE"
echo "Done with Neovim"