-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiftool.sh
executable file
·106 lines (86 loc) · 2.4 KB
/
iftool.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
#!/bin/zsh
# -- Functions -----------------------------------------------------------------
print_info() {
printf "⚙️ $@"
}
exit_error() {
printf >&2 "😱 \033[31;1;4m$@\033[0m"
exit 1
}
get_wine_app() {
if mdfind "kMDItemKind == 'Application'" | grep -q CrossOver; then
wine_app=CrossOver
elif mdfind "kMDItemKind == 'Application'" | grep -q 'Wine Stable'; then
wine_app='Wine Stable'
fi
printf "%s" "$wine_app"
}
init() {
vpn="$1"
smb_path="$2"
internal_ip_regex="^(128\.130\.106|128\.131)"
print_info "Determine external IP\n"
external_ips="$(curl ifconfig.me)"
print_info "External IPs:\n%s\n" "$external_ips"
if ! printf '%s' "$external_ips" | grep -Eq "$internal_ip_regex"; then
print_info 'Connect to VPN “%s”\n' "$vpn"
networksetup -connectpppoeservice "$vpn"
timeout=10
time_left="$timeout"
while ! scutil --nc list | grep "$vpn" | grep -q Connected; do
if [ "$time_left" -lt 1 ]; then
exit_error "Unable to connect to VPN “$vpn” in $timeout seconds"
fi
sleep 1
time_left=$((time_left - 1))
done
fi
print_info "Mount SMB volume\n"
message="$(osascript -e "mount volume \"$smb_path\"" 2>&1 > /dev/null)"
if [ "$?" -ne 0 ]; then
error_message="Unable to mount SMB volume: $message\n"
exit_error "$error_message"
fi
}
iftool() {
iftool_path="$1"
wine_app="$(get_wine_app)"
print_info "Open IFTool\n"
open -jga "$wine_app" "$iftool_path"
if [ $wine_app = "CrossOver" ]; then
# Hide CrossOver window
osascript -e '
tell application "System Events"
set visible of application process "CrossOver" to false
end tell'
fi
# Wait until IFTool is ready
while ! pgrep -lq IFT_Tool.exe; do
sleep 1
done
# Wait until IFTool is closed
print_info "Wait until IFTool is closed…\n"
while pgrep -lq IFT_Tool.exe; do
sleep 1
done
}
cleanup() {
vpn="$1"
iftool_mountpoint="$2"
diskutil unmount "$iftool_mountpoint" > /dev/null
networksetup -disconnectpppoeservice "$vpn"
killall "$(get_wine_app)"
}
main() {
vpn='TU Vienna'
iftool_directory_prefix='30_IT'
iftool_directory='01_IFT_Tool'
smb_path="smb://data.ift.tuwien.ac.at/$iftool_directory_prefix"
iftool_mountpoint="/Volumes/$iftool_directory_prefix"
iftool_path="$iftool_mountpoint/$iftool_directory/IFT_Tool.exe"
init "$vpn" "$smb_path"
iftool "$iftool_path"
cleanup "$vpn" "$iftool_mountpoint"
}
# -- Main ----------------------------------------------------------------------
main