diff options
-rw-r--r-- | .gitmodules | 3 | ||||
-rwxr-xr-x | fix.sh | 103 | ||||
-rwxr-xr-x | setup.sh | 8 | ||||
m--------- | smenu | 0 |
4 files changed, 114 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c955819 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "smenu"] + path = smenu + url = https://github.com/p-gen/smenu.git @@ -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!" diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..f9b9d2b --- /dev/null +++ b/setup.sh @@ -0,0 +1,8 @@ +#!/bin/bash +[ ! -d "smenu" ] && git submodule init && git submodule update && echo skit + +[ -f "smenu/smenu" ] && echo "Smenu has already been built. There's nothing more to set up" && exit + +cd smenu +./build.sh +cd .. diff --git a/smenu b/smenu new file mode 160000 +Subproject f3978ef8fbf8277a757240faffd4e8b0f73762c |