VSCode's portable mode doesn't support auto-updates, unlike its normal installer-based versions. I happen to use MSYS2's UCRT64 environment which makes the Linux tools I like play nice with the Windows environment I need, so I wrote a script to do the updating for me.
I prefer zsh, but shellcheck doesn't support zsh or the #!/bin/env $SHELL construct, so I had to use #!/bin/bash to get it to check my script. It also choked on one of my comments which started with # shellcheck, which it interpreted as meaning something, so I had to remove that. Nevertheless, here is the script as I wrote it originally (not getting shellcheck to run on it):
#!/bin/env bash
DEBUG=0
if [[ "$1" == "--debug" ]]; then
DEBUG=1
fi
instdir="/c/Users/User/Applications/vscode"
# code --version doesn't like sed, so we do it the janky way
lver=$(code --version | head -n 2 | tail -n 1)
lnam=$(code --version | head -n 1)
echo "Checking for updates..."
checkdir="$HOME/tmp-vsc-upd"
checkres="$checkdir/tmp-vsc-checkres"
mkdir -p "$checkdir"
curl -s "https://update.code.visualstudio.com/api/update/win32-x64-archive/stable/$lver" -o "$checkres"
if [[ $(wc -l "$checkres") = 0 ]]; then
[[ "$DEBUG" -ne 0 ]] && rm -r "$checkdir"
echo "No updates found."
exit 0
fi
uver=$(jq .version "$checkres" | cut -c 2- | rev | cut -c 3- | rev)
unam=$(jq .name "$checkres" | cut -c 2- | rev | cut -c 3- | rev)
echo "Local version: $lnam ($lver)"
echo "Upstream version: $unam ($uver)"
# shellcheck suggests pgrep, but MSYS2's pgrep can't see Windows processes
if [[ $(ps -eW | grep -c "Code.exe") -gt 0 ]]; then
[[ "$DEBUG" -ne 0 ]] && rm -r "$checkdir"
echo "Close VSCode before updating."
exit 0
fi
read -r -n 1 -p "Replace local version with upstream version? (y/N) " action
if [[ -z "$action" ]]; then
action="n"
else
echo ""
fi
case "$action" in
y|Y )
echo "Downloading new version..."
src=$(jq .url "$checkres" | cut -c 2- | rev | cut -c 3- | rev)
out="$checkdir/VSCode-win32-x64-$unam.zip"
curl -o "$out" "$src"
echo "Checking file integrity..."
upsum=$(jq .sha256hash "$checkres" | cut -c 2- | rev | cut -c 3- | rev)
acsum=$(sha256sum "$out" | cut -d ' ' -f 1)
if [[ "$upsum" == "$acsum" ]]; then
echo "File OK."
else
[[ "$DEBUG" -ne 0 ]] && rm -r "$checkdir"
echo "File may be corrupted:"
echo " Expected: $upsum"
echo " Received: $acsum"
echo "Aborting."
exit 0
fi
echo "Extracting files..."
unzip -u -o -qq "$out" -d "$instdir"
echo "Finished extracting."
echo ""
[[ "$DEBUG" -ne 0 ]] && rm -r "$checkdir"
echo "Finished updating."
exit 0
;;
* )
[[ "$DEBUG" -ne 0 ]] && rm -r "$checkdir"
echo "Aborting."
exit 0
;;
esac
I would have to download multiple versions of VSCode to properly test this out, so I didn't do that. But it did automate my 6 minute task in 6 hours once.
shellcheck is happy with my little script, but there are probably more improvements to be made that it can't see / wasn't designed to see.