Created
April 28, 2020 09:04
-
-
Save floydawong/be68480616788e5836f66c1086a09bda to your computer and use it in GitHub Desktop.
Patch Sublime Text (only tested under Windows x64, Ubuntu 18.04)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# @see https://gist.github.com/n6333373/c15e8ae61f5e0421cf9091affb733312 | |
# the path of the Sublime Text executable | |
BIN_PATH="./sublime_text.exe" | |
# (optional) the Data directory for non-portable mode | |
# such as "C:\Users\David\AppData\Roaming\Sublime Text 3" | |
DATA_DIR="" | |
patch_sublime_text_exe () { | |
local BIN_PATH="$1" | |
local BIN_HEX="${BIN_PATH}.hex" | |
xxd -ps "${BIN_PATH}" "${BIN_HEX}" | |
sed -i'' \ | |
`# skip revoked license (TwitterInc) check` \ | |
-e 's/97940d/000000/g' \ | |
`# replace "license.sub" with "license_sub"` \ | |
-e 's/6c6963656e73652e7375/6c6963656e73655f7375/g' \ | |
"${BIN_HEX}" | |
mv "${BIN_PATH}" "${BIN_PATH}.bak" | |
xxd -r -ps "${BIN_HEX}" "${BIN_PATH}" | |
chmod a+x "${BIN_PATH}" | |
rm -f "${BIN_HEX}" | |
} | |
apply_license () { | |
local LICENSE_CODE="$1" | |
local DATA_DIR_USER="$2" | |
local is_data_dir_found=0 | |
local data_dirs=( | |
# portable mode (always highest priority) | |
"Data/" | |
# user specified | |
"${DATA_DIR_USER}" | |
# traditional | |
"${APPDATA}/Sublime Text/" | |
"${APPDATA}/Sublime Text 3/" | |
) | |
for data_dir in "${data_dirs[@]}"; do | |
if [ ! -d "${data_dir}" ] || [[ "${data_dir}" = "" ]]; then | |
continue | |
fi | |
is_data_dir_found=1 | |
pushd "${data_dir}" || exit | |
mkdir -p "Local/" | |
echo "${LICENSE_CODE}" > "Local/License.sublime_license" | |
echo "* license has been added to '${data_dir}'" | |
popd || exit | |
break | |
done | |
if [[ "${is_data_dir_found}" = "0" ]]; then | |
echo "* cannot find the Data directory, fill the following license by yourself:" | |
echo "${LICENSE_CODE}" | |
fi | |
} | |
# ------------------ # | |
# let the work begin # | |
# ------------------ # | |
BIN_DIR="$(dirname "${BIN_PATH}")" | |
pushd "${BIN_DIR}" || exit | |
if [ ! -f "${BIN_PATH}" ]; then | |
echo "${BIN_PATH} not found..." | |
exit 1 | |
fi | |
patch_sublime_text_exe "${BIN_PATH}" | |
apply_license "$(cat <<-EOT | |
----- BEGIN LICENSE ----- | |
TwitterInc | |
200 User License | |
EA7E-890007 | |
1D77F72E 390CDD93 4DCBA022 FAF60790 | |
61AA12C0 A37081C5 D0316412 4584D136 | |
94D7F7D4 95BC8C1C 527DA828 560BB037 | |
D1EDDD8C AE7B379F 50C9D69D B35179EF | |
2FE898C4 8E4277A8 555CE714 E1FB0E43 | |
D5D52613 C3D12E98 BC49967F 7652EED2 | |
9D2D2E61 67610860 6D338B72 5CF95C69 | |
E36B85CC 84991F19 7575D828 470A92AB | |
------ END LICENSE ------ | |
EOT | |
)" "${DATA_DIR}" | |
popd || exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment