-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpkg2dmg.sh
166 lines (144 loc) · 7.27 KB
/
pkg2dmg.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# Create a blank 16GB DMG file
create_blank_dmg() {
echo "Creating a 16GB DMG file at $dmg_path..."
dd if=/dev/zero of=$dmg_path bs=1M count=16384
}
# Format the DMG with HFS+
format_dmg_hfs() {
echo "Formatting with HFS+..."
mkfs.hfsplus -v macOS_Installer $dmg_path
}
# Extract .pkg file
extract_pkg() {
echo "Extracting .pkg..."
mkdir -p $extract_dir
7z x -txar $pkg_file -o$extract_dir SharedSupport.dmg Payload
}
# Mount the DMG file
mount_dmg() {
echo "Mounting $dmg_path at $mount_point..."
sudo mkdir -p $mount_point
sudo mount -o loop $dmg_path $mount_point
}
# Copy files to the mounted DMG
copy_to_dmg() {
echo "Copying files...(May take a while!)"
sudo cp -r $extract_dir/* $mount_point/
}
# Call pbzx.py to decompress the payload
decompress_payload() {
echo "Decompressing Payload..."
cp $(dirname "$0")/pbzx.py $mount_point
cd $mount_point
python3 $mount_point/pbzx.py -n Payload | cpio -idmu
mv Applications/* $mount_point/
rmdir ./Applications
rm Payload
rm pbzx.py
cd ./Install\ */Contents/
mkdir SharedSupport
mv $mount_point/SharedSupport.dmg $mount_point/Install\ */Contents/SharedSupport/
}
# Unmount the DMG file
unmount_dmg() {
cd /tmp
echo "Unmounting..."
sudo umount $mount_point
}
display_art(){
clear
printf '\e[8;46;101t'
cat << 'EOF'
##++%%#,,+##%+#+%#%++:%%%%##%#:++...................................................................
:+##%%+#:.:+####++##%%+%++%%###+:,..................................................................
#%::#%%%#+,+%%%##%%+%###%###%%#+::,,,...............................................................
####:+%%%##+%####++:.:%%%####%:::.,::...............................................................
#####%+#####+%####%++++%+:+%##%,,,.:+...............................................................
######%###############%++:,.,%#%,,.++,.,,...........................................................
%%%#############%:,+%##++:+:,.%%:+.,:+::............................................................
%+:+++########%+::::%%,,:::::::#++:.,::::,..........................................................
:+#+:::%#####+,.,,+%#:,++++++:+%::,......,,.........................................................
,,:#+:,:%#%+:,:+,:%#+,:%:..,,:::.,,,......,:........................................................
,,,:#+,:+#%::%+%%%##:,+%:....++#+:,,........+:......................................................
:,,::%+,+###%:,,:+#%+++%%,....:#%+,,+++,......+.....................................................
##%:++#+:+%:,,,.,+#+++%##.::..,++:,::,,:%:.....:....................................................
####%%%##%++,.,,,:%%:+###,,+++....,:,,...:%++:,:,...................................................
+#######+.,++,,..,%#:,+%##+:#%.,:,,+,,+:,,+###%+::,..............|| Developed by Kartik Joshi ||....
,::+#%:%+,,.,:+%%##:,:%####%#%,+:......,####,,....,::.......................... | ..................
:::+++,:#+..,+%###+::+::::+##%:.......,.:###+........:......................... | ..................
%%%++:::%++++%####%%%:::,,,%#%%:......,:,,,,:,::..,::+::,...................... | ..................
#####++:::++++%#######+%%++#%+:#+..:...:+:...,:,.,...,..,:..................... | ..................
%++%%%+++:...,:%:.%##+,+++%%%,,:::.:,.......,..,,..,,,::..,,................... | ..................
::+:,:%+:...,+%:.,+##,,,,,+++,,:%:..+,....,...,...,,..,+,..,,.................. v ..................
:,:%%%%%:,....:::%%##:%.,,::::+,::+,:::,,........,.....:++:+%,.........|| Just Few Clicks ||........
,,,:+###%+,::,..,%#%+##::,,::+%%.,,:+::......::,,::,.....:%##+................... | ................
++++%###%+%##:,,,+%:###+,,,.,::%%,:%,%......,::............+#:................... | ................
:+%%####%%##%::,,##%#%+%+:.,.,,,,,+#,:,.,.++#%%............,,:................... | ................
+%#####++%##%:+.:###%%+##%,..,,...:#:,:,+:##:,:,,,.........:.,................... & ................
%%##%++%##%%+.,,%%%#++%###,..++,,.,#,.::+:%,+%%#%%+:,......+:.................... | ................
##%:...:+:::+.,%+%+%+:%###+.,##,,.,%,.,%:,,+########%,....+%..................... | ................
##+:,.,+++:+%,+%,%+++,##+##,##%:,.,%:.,,,,,###%:,,:%#+%::%+:..............|| V O I L A ! ||.........
##+::%#######%:%,%:+::##+%##%#%::.:%:,..:%###:......,::,:#+...................... | ................
#############%:%,%:+:+#%++%#%#+,,.:%:...+%###%:.......,.%%,...................... | ................
#############%:+:%:::+%%:::%%%:,,,%%,...+###%#:,......,,%:....................... | ................
%%##+########+:+:%::,++%+:,+#+:,,:%+...,+####+::......,:+........................ | ................
+%#%%#######%%,+%+::,+:%%,:,%:+:,:%:,..,:##:#%:,......,.......................... | ................
%##%##%##%%#++,+#%::,::+%++:++++++%:,..,%##:+#:,....,,........................... | ................
##%#%%###++%:+,:##,:,,+::%+:+%+++%#+.,:%####:#:.,..::,........................... | ................
##%%%%%%%::%+%,+#%:::.+:,+%%++::%+#+:+%###%#%+:,,::.:,........................... v ................
##%+#%+%%:,%%%:%%%%::.,+.++#%+:+%+##%#####%##+%::%,:,........|| Basic PKG2DMG convertor utility ||..
####+:+%+,,%%%+#++%:%:,:,,%##++#+,+%#######%##:%+,:%:...............................................
##%#++:%,,,+%%%#++%%%+,.,:+##%+%,,:%%############+++:...............................................
#+%%+::%.,,%++#%:+%#+%,..:+##%#+.,:++%%#####%%######+...............................................
,+#+:::+..%++:#%::%#%%:,.:+%#%%::,,::%%#####+%%%####,...............................................
:##:::+::%#%+:#+,,###%%,.++%#%::+,,::%%####%%%%%%%%+,...............................................
##%:++#%##%#+:#+,:%##%#,,++###::+:,,:+%######%++%++,................................................
----------------------------------------------------------------------------------------------------
EOF
}
# Main function
main() {
printf '\e[107m\e[1;30m'
[ "$UID" -eq 0 ] || { echo "This script must be run as root."; exit 1;}
display_art
# Get user inputs
echo "Enter the output directory for the DMG file: "
read -r output_dir
output_dir=$(echo "$output_dir"| sed "s/'//g")
echo "Enter the path to the .pkg file: "
read -r pkg_file
pkg_file=$(echo "$pkg_file"| sed "s/'//g")
# Validate inputs
if [ ! -d "$output_dir" ]; then
echo "Error: Output directory $output_dir does not exist."
exit 1
fi
if [ ! -f "$pkg_file" ]; then
echo "Error: .pkg file $pkg_file does not exist."
exit 1
fi
dmg_path="$output_dir/InstallMacOS.dmg"
mount_point="/mnt/hfs_dmg"
extract_dir="/tmp/pkg_extracted"
# Create blank DMG
create_blank_dmg "$dmg_path"
# Format DMG with HFS+
format_dmg_hfs "$dmg_path"
# Extract .pkg
extract_pkg "$pkg_file" "$extract_dir"
# Mount DMG
mount_dmg "$dmg_path" "$mount_point"
# Copy extracted files to DMG
copy_to_dmg "$extract_dir" "$mount_point"
# Decompress payload using pbzx.py
decompress_payload "$mount_point"
# Unmount DMG
unmount_dmg "$mount_point"
# Clean up
echo "Cleaning up..."
rm -rf "$extract_dir"
echo "Process completed successfully."
}
# Run the main function
main