forked from andreyvit/yoursway-eclipse-osx-repackager
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EclipseOSXRepackagerUI
executable file
·97 lines (81 loc) · 3.01 KB
/
EclipseOSXRepackagerUI
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
#! /bin/bash
DLG="./CocoaDialog.app/Contents/MacOS/CocoaDialog"
WORKER="./EclipseOSXRepackager"
if ! test -z "$TEST_REPACKAGER_UI"; then
DLG="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog"
WORKER="./EclipseOSXRepackager"
fi
title="Eclipse OS X Repackager 2012"
function display_fatal_error() {
"$DLG" msgbox --title "$title" --text "Fatal error" --informative-text "$1" --button1 "Give up and exit"
exit 1
}
# borrowed from http://yost.com/computers/MacStuff/reveal/index.html
# unix path -> old-style Mac path for AppleScript
function colonize() {
sed 's,.*,"&",
s,/,\&,g
s,:,/,g
s,^"&Volumes&,",
s,^"&.*,& of startup disk,' \
| sed 's,&,:,g' \
| tr -d '\012'
}
source_dir="$1"
if test -z "$source_dir"; then
source_dir="$("$DLG" fileselect --select‑directories --title "$title" --text "Choose any file inside Eclipse installation to turn into OS X bundle")"
test -z "$source_dir" && exit 1
end_string="${source_dir:${#source_dir}-4:4}"
if [[ -f "$source_dir" || $end_string = ".app" ]]; then
# if the path is a file or the app bundle, find the parent directory's path which is needed by the shell script
source_dir="$(dirname "$source_dir")"
fi
fi
info="$("$WORKER" --explore $source_dir)" || display_fatal_error "$info"
{
read bname
read bver
} < <("$WORKER" --explore $source_dir | awk '
/^BundleName:/ { bname = $2 }
/^BundleVersion:/ { bver = $2 }
END {
print bname
print bver
}
')
source_parent_dir="$(dirname $source_dir)"
{
read button
read destination_bundle_name
} < <("$DLG" dropdown --string-output --title "$title" --text "Choose where to save the bundle" --button1 "Start repackaging!" --button2 "Cancel" --items "/Applications/$bname $bver" "/Applications/$bname" "$source_parent_dir/$bname $bver" "$source_parent_dir/$bname")
test "$button" = "Cancel" && exit 1
destination_bundle="$destination_bundle_name.app"
if test -d "$destination_bundle"; then
choice="$("$DLG" msgbox --title "$title" --text "Overwritexx?" --informative-text "Directory $destination_bundle already exists." --button1 "Overwrite" --button2 "Cancel")"
test "$choice" -ne 1 && exit 0
rm -r "$destination_bundle"
fi
{
line=""
activity=""
while ! test "$line" == "Done."; do
read line
test "${line:0:5}" = "FATAL" && display_fatal_error "$line"
test "${line:${#line}-3:3}" = "..." && activity="${line:0:${#line}-3}"
test "${line:0:1}" = "/" -a ! -z "$activity" && line="$activity: $(basename "$line")"
echo "0 $line"
done
} < <("$WORKER" --verbose "$source_dir" "$destination_bundle") > >("$DLG" progressbar --title "$title" --text "Starting..." --indeterminate)
choice="$("$DLG" msgbox --title "$title" --text "Done!" --informative-text "Now you can enjoy $destination_bundle_name." --button1 "Ah, that was amazing")"
case $choice in
1)
exit 0;;
2)
itemColonized="$(echo -n "$destination_bundle" | colonize)"
osascript -e "
tell application \"Finder\"
reveal $itemColonized
activate
end tell
";;
esac