diff options
Diffstat (limited to 'fix.sh')
-rwxr-xr-x | fix.sh | 103 |
1 files changed, 103 insertions, 0 deletions
@@ -0,0 +1,103 @@ +#!/bin/bash +function check_args() { + [[ $1 -eq 0 ]] && echo -e "Error: Missing argument for server path!\n\nExample usage: $0 ~/.vscode-server-oss" && exit 1 + + [ ! -d "$2" ] && echo "Error: Invalid VSCode server path '$2'! Non-existant directory!" && exit 1 + [ ! -d "$2/bin" ] && echo "Error: Invalid VSCode server path '$2'! Missing bin directory!" && exit 1 +} + +function add_line() { + [[ $1 == "" ]] && echo "$1$2" && return + echo "$1\n$2" +} + +function select_release() { + release_dirs=$1 + + declare -A releases=() + declare -A release_versions=() + + weird_releases="" + + release_index=0 + while IFS= read -r release; do + if [ ! -f "$release/package.json" ]; then + # Release is weird + weird_releases=$(add_line "$weird_releases" "$release") + continue + fi + + releases[$release_index]="$release" + + version=$(jq -r ".version" $release/package.json) + + if [[ "$version" == "null" ]]; then + # Release is weird + weird_releases=$(add_line "$weird_releases" "$release") + continue + fi + + release_versions["$version"]=$release_index + release_index=$(( $release_index + 1 )) + done < <(printf "%s\n" "$release_dirs") + + versions="" + for release_version in "${!release_versions[@]}"; do + versions=$(add_line "$versions" "$release_version") + done + + versions=$(echo -e "$versions" | sort -r) + + releases_final="" + while IFS= read -r ver; do + release_index="${release_versions[$ver]}" + release="${releases[$release_index]}" + + if [[ $releases_final == "" ]]; then + releases_final="$releases_final${release}_(latest)_(v$ver)" + continue + fi + + releases_final="$releases_final\n${release}_(v$ver)" + done < <(echo -e "$versions") + + releases_final="$releases_final\n$weird_releases" + + echo -e "$releases_final" | ./smenu/smenu -d -S "/_/\ /g" -c \ + -m "There are multiple releases inside of the specified VSCode server's bin directory. Please select one to fix:" +} + +check_args $# $1 + +find_releases="find $1/bin/ -maxdepth 1 -type d -regex \"$1/bin/[a-fA-F0-9]+\"" + +# Collect the releases +release_dirs=$(eval "$find_releases") +release_dir_cnt=$(eval "$find_releases" | wc -l) + +[ $release_dir_cnt -eq 0 ] && echo "Error: The VSCode server doesn't have any releases in it's bin directory!" && exit 1 + +target_release="" + +if [ $release_dir_cnt -eq 1 ]; then + target_release=$(head -n1 <<< "$release_dirs") +else + target_release=$(select_release "$release_dirs") +fi + +target_release=$(awk '{print $1}' <<< "$target_release") + +echo "Fixing release $(basename $target_release)." + +target_file="out/vs/server/remoteExtensionHostAgent.js" + +echo "Backing up $(basename $target_file)" +backup_output=$(cp "$target_release/$target_file" "$target_release/${target_file}.bak" 2>&1) + +[[ $? -eq 1 ]] && echo -e "Error: Failed to create backup of $target_release/$target_file!\nCommand output:\n$backup_output" && exit 1 + +sed_output=$(sed -E -i "s/if\(this\._environmentService\.isBuilt\)return \w{2}\(\"Unauthorized client refused\"\);//g" "$target_release/$target_file" 2>&1) + +[[ $? -eq 1 ]] && echo -e "Error: Failed to fix $target_release/$target_file!\nCommand output:\n$sed_output" && exit 1 + +echo "Finished successfully!" |