blob: 473e6ef704a7ea90d32ef4594e67c1c5556ee3d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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!"
|