-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkakaotalk.bash
executable file
·204 lines (172 loc) · 4.43 KB
/
kakaotalk.bash
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env bash
#
# Copyright (c) 2019 - 2023 Jeong Han Lee
#
# The program is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of the
# License, or any newer version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt
#
# author : Jeong Han Lee
# email : jeonghan.lee@gmail.com
# version : 0.0.6
declare -g SC_SCRIPT;
SC_SCRIPT="$(realpath "$0")";
declare -gr version="0.0.5"
declare -gr ProgramFiles1="${HOME}/.wine/drive_c/Program Files"
declare -gr ProgramFiles2="${HOME}/.wine/drive_c/Program Files (x86)"
declare -gr KakaoTalk="/Kakao/KakaoTalk"
declare -gr KakaoTalkPath1="${ProgramFiles1}${KakaoTalk}"
declare -gr KakaoTalkPath2="${ProgramFiles2}${KakaoTalk}"
EXIST=1
NON_EXIST=0
function pushdd { builtin pushd "$@" > /dev/null || exit; }
function popdd { builtin popd > /dev/null || exit; }
function die
{
error=${1:-1}
## exits with 1 if error number not given
shift
[ -n "$*" ] &&
printf "%s%s: %s\n" "$SC_SCRIPT" ${version:+" ($version)"} "$*" >&2
exit "$error"
}
function checkIfVar()
{
local var=$1
local result=""
if [ -z "$var" ]; then
result=$NON_EXIST
# doesn't exist
else
result=$EXIST
# exist
fi
echo "${result}"
}
## if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
## EXIST
## fi
##
function checkIfDir
{
local dir=$1
local result=""
if [ ! -d "$dir" ]; then
result=$NON_EXIST
# doesn't exist
else
result=$EXIST
# exist
fi
echo "${result}"
};
function get_ip
{
local realip="";
realip=$(ip -4 route get 8.8.8.8 | awk \{'print $7'\} | tr -d '\n')
printf "Real IP address %s\n" "$realip"
}
function start_kakaotalk
{
local target=""
if [[ $(checkIfDir "${KakaoTalkPath1}") -eq "$EXIST" ]]; then
target="${KakaoTalkPath1}"
elif [[ $(checkIfDir "${KakaoTalkPath2}") -eq "$EXIST" ]]; then
target="${KakaoTalkPath2}"
else
die "There is no path for Kakaotalk"
fi
pushdd "${target}"
wine KakaoTalk.exe &
popdd
}
function uninstall_kakaotalk
{
local target=""
if [[ $(checkIfDir "${KakaoTalkPath1}") -eq "$EXIST" ]]; then
target="${KakaoTalkPath1}"
elif [[ $(checkIfDir "${KakaoTalkPath2}") -eq "$EXIST" ]]; then
target="${KakaoTalkPath2}"
else
die "There is no path for Kakaotalk"
fi
pushdd "${target}"
wine uninstall.exe &
popdd
}
function stop_kakaotalk
{
local name=""
name="KakaoTalk.exe";
# If we can use an expect script, we can kill KakaoTalk process without sudo
# $ winedbg
# $ info proc
# Wine-dbg>info proc
# pid threads executable (all id:s are in hex)
# 00000061 1 'winedbg.exe'
# 00000023 4 'explorer.exe'
# 0000000e 5 'services.exe'
# 0000001e 4 \_ 'winedevice.exe'
# 00000019 3 \_ 'plugplay.exe'
# 00000011 4 \_ 'winedevice.exe'
# 00000008 55 'KakaoTalk.exe'
# Wine-dbg>attach 00000008
# 0x00000000f7f22067: int $0x80
# Wine-dbg>kill
# Wine-dbg>quit
# $
#
# It turns out, we don't need to be sudo. ;)
#
pid=$(pgrep "KakaoTalk.exe")
if [[ $(checkIfVar "${pid}") -eq "$NON_EXIST" ]]; then
printf ">> Wine %s application is not running\n" "$name";
else
printf ">> Wine %s application was found with PID %s\n" "$name" "${pid}"
printf " Killing the running application ....\n"
kill -9 "${pid}"
fi
}
## Interesting..
function winedbg_stop_kakaotalk
{
local name=""
local hex_wid=""
name="KakaoTalk.exe";
hex_wid=$(winedbg --command "info proc" |grep "${name}" | awk '{print $1}')
echo "$hex_wid"
}
case "$1" in
start)
start_kakaotalk
;;
stop)
stop_kakaotalk
;;
restart)
stop_kakaotalk
start_kakaotalk
;;
uninstall)
uninstall_kakaotalk
;;
ip)
get_ip;
;;
dbg)
winedbg_stop_kakaotalk
;;
*)
echo "Usage: $0 {start|stop|restart|ip}"
exit 2
esac
exit