-
Notifications
You must be signed in to change notification settings - Fork 1
/
EasyConnect-fix.sh
143 lines (133 loc) · 4 KB
/
EasyConnect-fix.sh
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
#description: this script fix EasyConnect on linux
#author: du33169
installDir='/usr/share/sangfor/EasyConnect'
regInstallDir=$(echo $installDir|sed 's/\//\\\//g') # replace '/' with '\/' for regular expression
shortcutFile='/usr/share/applications/EasyConnect.desktop'
colored_echo()# $1 for color, $2 for text
{
case $1 in
"yellow") echo -e "\033[33m$2\033[0m" ;;
"red") echo -e "\033[31m$2\033[0m" ;;
"blue") echo -e "\033[34m$2\033[0m" ;;
*) echo "$2" ;;
esac
}
check_result()#$1=$?, $2=failed_text $3=success_text,
{
if test $1 -ne 0 ; then
colored_echo red "$2"
return 0 #true
else
echo "$3"
return 1 #false
fi
}
check_installation()
{
colored_echo blue "Checking EasyConnect installation..."
if [ ! -d "${installDir}" ]; then
# file not exist
colored_echo red "fatal: ${installDir} not found, check your EasyConnect installation. Exiting..."
exit 1
else
echo "found ${installDir}."
fi
}
check_patch()
{
colored_echo blue "Checking patch installation..."
if [ -e "${installDir}/RunEasyConnect.sh" ]; then
#patch file already existed
echo "Patch file ${installDir}/RunEasyConnect.sh found. Patched."
return 1
else #file not exist
echo "Not patched."
return 0
fi
}
askpass()# $1 for color, $2 for prompt
{
sudo -K #delete cached password
colored_echo "$1" "$2"
echo "Enter your password for sudo:(not display on screen for safety concern)"
read -s key
echo "got your password."
}
dump_patch()# $1=key
{
colored_echo blue "Patching..."
key=$1
#make executale
chmod +x ./patch/RunEasyConnect.sh
# #create symbol link
# for so in 'pango' 'pangocairo' 'pangoft' ; do
# ln -s lib${so}-1.0.so.0.4200.3 lib${so}-1.0.so.0
# done
#copy file
echo "Copying file..."
cp ./patch/RunEasyConnect.sh ./RunEasyConnect.sh.bak
sed -i "s/key=.*$/key=${key}/g" ./patch/RunEasyConnect.sh
echo ${key}|sudo -S cp -R ./patch/* ${installDir}/ 2>/dev/null
copyResult=$?
mv ./RunEasyConnect.sh.bak ./patch/RunEasyConnect.sh
if check_result $copyResult "fatal: copy file failed. Check your password and retry. Exiting..." "Copied." ; then
exit 1
fi
#edit shortcut
echo "Editing shortcut..."
if [ ! -e "${shortcutFile}" ]; then
# file not exist
colored_echo red "fatal: ${shortcutFile} not found, check your installation."
echo "Or you could just use ${installDir}/RunEasyConnect.sh. Exiting..."
exit 1
else
echo "Found ${shortcutFile}..."
# modifying .desktop file
echo ${key}|sudo -S sed -i "s/Exec=.*$/Exec=${regInstallDir}\/RunEasyConnect.sh/g" $shortcutFile 2>/dev/null
if check_result $? "fatal: modification failed. Check your password/installation and retry. Exiting..." "Edited."; then
exit 1
fi
fi
return 0
}
remove_patch()# $1=key
{
colored_echo blue "Removing patch..."
key=$1
for file in `ls ./patch`; do
echo ${key}|sudo -S rm ${installDir}/${file} 2>/dev/null
if check_result $? "fatal: failed to delete. Check your password/installation and retry. Exiting..." "deleted ${file}"; then
exit 1
fi
done
echo ${key}|sudo -S sed -i "s/Exec=.*$/Exec=${regInstallDir}\/EasyConnect/g" $shortcutFile 2>/dev/null
if check_result $? "fatal: failed to edit. Check your password/installation and retry. Exiting..." "Shortcut recovered."; then
exit 1
fi
return 0
}
# main process
if [[ -n "$1" && "$1" != "uninstall" ]] ; then
echo "Unrecognized param $1. Exiting..."
exit 1
fi
check_installation
check_patch
patched=$?
if [ -z "$1" ] ; then
if [ $patched == 1 ]; then # patched
colored_echo yellow "warning: already patched. Will OVERRIDE."
fi
askpass yellow "warning: sudo password required. Will written into RunEasyConnect.sh in PLAINTEXT, Ctrl+C if unacceptable."
dump_patch $key
colored_echo blue "Patch installed. Please run EasyConnect from launcher and enjoy."
elif [ "$1" = "uninstall" ] ; then
if [ $patched == 0 ]; then # not patched
colored_echo red "fatal: not patched. Nothing to uninstall, Exiting..."
else
askpass blue "notice: access required."
remove_patch $key
colored_echo blue "Patch uninstalled."
fi
fi