summaryrefslogtreecommitdiff
path: root/bootstrap.sh
blob: 7e484e3a514cf6d66ef3ed111b2f9fe97fcb771f (plain)
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
205
206
207
208
209
210
211
212
213
#!/bin/bash
set -e
shopt -s extglob nullglob

export PKG_BASE=$(realpath "$(dirname "$0")")
source "${PKG_BASE}/architect.sh"

export PKG_BOOT=${PKG_BASE}/Packager

rm -rf "${PKG_BOOT}"
svn export "${PKG_BASE}/over" "${PKG_BOOT}"

mkdir -p "${PKG_BOOT}/var/lib/dpkg/info"

#PKG_REQS=(apt7)
#PKG_REQS=(adv-cmds apt7 base coreutils cydia cydia-sources diffutils diskdev-cmds essential findutils firmware-sbin grep inetutils less network-cmds openssh pam-modules profile.d sed sqlite3-lib system-cmds uikittools unzip wget zip)
#PKG_REQS=(base cydia-sources dpkg essential firmware-sbin openssh pam-modules profile.d system-cmds wget)
#PKG_REQS=(adv-cmds apt7 base coreutils cydia-sources diffutils diskdev-cmds findutils firmware-sbin grep inetutils less network-cmds openssh pam-modules profile.d sed sqlite3-lib system-cmds unzip wget zip)
PKG_REQS=(adv-cmds apr-lib apt7 base coreutils cydia-sources darwintools diffutils diskdev-cmds essential findutils firmware-sbin grep inetutils less network-cmds openssh pam-modules pcre profile.d sed shell-cmds sqlite3-lib system-cmds unzip wget zip)
#PKG_REQS=(base cydia cydia-sources diskdev-cmds essential firmware-sbin pam-modules profile.d sqlite3-lib system-cmds uikittools libxml2-lib yellowsn0w.com)

cd "${PKG_BASE}/data"
PKG_REQS=($({
    echo "${PKG_REQS[@]}" | tr ' ' $'\n'
    find -L "${PKG_REQS[@]}" -name '*.dep' | grep -v '/_[^/]*\.dep' | sed -e 's/.*\/\([^\/]*\)\.dep/\1/'
} | sort -u | grep -Ev '^(libxml2|sqlite3)-dylib$'))

function merge() {
    deb=$1
    name=$2

    rm -rf "${PKG_BASE}/temp"
    dpkg -x "${deb}" "${PKG_BASE}/temp"

    files=("${PKG_BASE}/temp"/*)
    if [[ ${#files[@]} -ne 0 && ${name} != firmware-sbin ]]; then
        cp -a "${PKG_BASE}/temp"/* "${PKG_BOOT}"
    fi

    (cd "${PKG_BASE}/temp"; find | sed -e '
        s/^\.\///
        s/^/\//
    ') >"${PKG_BOOT}/var/lib/dpkg/info/${name}.list"
}

for PKG_NAME in "${PKG_REQS[@]}"; do
    PKG_NAME=${PKG_NAME%/_metadata/priority}
    PKG_NAME=${PKG_NAME##*/}

    cd "${PKG_BASE}"
    #./package.sh "${PKG_NAME}"
    source "${PKG_BASE}/helper.sh"

    echo "merging ${PKG_NAME} ${PKG_VRSN}-${PKG_RVSN}..."
    merge "${PKG_BASE}/debs/${PKG_NAME}_${PKG_VRSN}-${PKG_RVSN}_${PKG_ARCH}.deb" "${PKG_NAME}"

    "${PKG_BASE}/control.sh" "${PKG_NAME}" available >>"${PKG_BOOT}/var/lib/dpkg/available"
    "${PKG_BASE}/control.sh" "${PKG_NAME}" status >>"${PKG_BOOT}/var/lib/dpkg/status"
done

merge debs/cydia_1.0.3366-1_iphoneos-arm.deb cydia
merge debs/uikittools_1.1.0_iphoneos-arm.deb uikittools

rm -rf "${PKG_BASE}/temp"
cd "${PKG_BOOT}"

"${PKG_BASE}"/fix.sh

PKG_RSLT="${PKG_BASE}/rslt"
mkdir -p "${PKG_RSLT}"

rm -rf "${PKG_RSLT}/CydiaInstaller.bundle"
mkdir "${PKG_RSLT}/CydiaInstaller.bundle"

mkdir "${PKG_RSLT}/CydiaInstaller.bundle/files"
cp -a * "${PKG_RSLT}/CydiaInstaller.bundle/files"

{
    cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Name</key>
    <string>Cydia Installer</string>
    <key>Identifier</key>
    <string>org.saurik.cydia</string>
    <key>Description</key>
    <string>Unix Subsystem w/ Advanced Installer</string>
    <key>SupportedFirmware</key>
    <array>
EOF

    cat "${PKG_BASE}/arch/${PKG_ARCH}/firmware" | sed -e '
        s/^/        <string>/
        s/$/<\/string>/
    '

    cat <<EOF
    </array>
    <key>Commands</key>
    <array>
EOF

    find \( -not -uid 0 -o -not -gid 0 \) -printf '%U %G %p\n' | while IFS= read -r line; do
        set ${line}

        cat <<EOF
        <dict>
            <key>Action</key>
            <string>SetOwner</string>
            <key>File</key>
            <string>${3#./}</string>
            <key>Owner</key>
            <string>$1:$2</string>
        </dict>
EOF
    done

    find -perm /6000 -printf '%m %p\n' | while IFS= read -r line; do
        set ${line}

        cat <<EOF
        <dict>
            <key>Action</key>
            <string>SetPermission</string>
            <key>File</key>
            <string>${2#./}</string>
            <key>Permission</key>
            <string>$1</string>
        </dict>
EOF
    done

    cat <<EOF
        <dict>
            <key>Action</key>
            <string>RunScript</string>
            <key>File</key>
            <string>space.sh</string>
        </dict>
    </array>
    <key>Size</key>
    <integer>$(du -bs "${PKG_RSLT}/CydiaInstaller.bundle/files" | cut -d $'\t' -f 1)</integer>
</dict>
</plist>
EOF
} >"${PKG_RSLT}/CydiaInstaller.bundle/Info.plist"

cp -a "${PKG_BASE}"/pwnr/* "${PKG_RSLT}"/CydiaInstaller.bundle
tar -zcf "${PKG_RSLT}/Pwnage_${PKG_ARCH}.tgz" -C "${PKG_RSLT}" CydiaInstaller.bundle

function stash() {
    src=$1
    dst=var/stash/${src##*/}
    mv "${src}" "${dst}"
    dst=${src//+([A-Za-z])/..}/${dst}
    ln -s "${dst#../}" "${src}"
}

mkdir -p var/stash
mkdir -p usr/include

mv -v usr/lib/_ncurses/* usr/lib
rmdir usr/lib/_ncurses
ln -s /usr/lib usr/lib/_ncurses

rmdir --ignore-fail-on-non-empty System/Library/LaunchDaemons

#stash usr/share/gettext

rm -f "${PKG_RSLT}/Manual_${PKG_ARCH}.tgz"
tar -zcf "${PKG_RSLT}/Manual_${PKG_ARCH}.tgz" *
tar -Jcf "${PKG_RSLT}/Manual_${PKG_ARCH}.txz" *

rm -f "${PKG_RSLT}/Manual_${PKG_ARCH}.zip"
zip -qry "${PKG_RSLT}/Manual_${PKG_ARCH}.zip" *

if [[ ${PKG_ARCH} == darwin-arm ]]; then
    "${PKG_TARG}-gcc" -o "${PKG_BOOT}/usr/libexec/cydia_/godmode" "${PKG_BASE}/util/godmode.c"
    "${PKG_TARG}-gcc" -o "${PKG_BOOT}/usr/libexec/cydia_/symlink" "${PKG_BASE}/util/symlink.c"
    chmod +s "${PKG_BOOT}/usr/libexec/cydia_"/{godmode,symlink}

    cp -a bin/bash usr/libexec/cydia_
    cp -a bin/chmod usr/libexec/cydia_
    cp -a bin/chown usr/libexec/cydia_
    cp -a bin/cp usr/libexec/cydia_
    cp -a bin/df usr/libexec/cydia_
    cp -a bin/grep usr/libexec/cydia_
    cp -a bin/ln usr/libexec/cydia_
    cp -a bin/mkdir usr/libexec/cydia_
    cp -a bin/mktemp usr/libexec/cydia_
    cp -a bin/rm usr/libexec/cydia_
    cp -a bin/sed usr/libexec/cydia_
    cp -a sbin/reboot usr/libexec/cydia_
    cp -a usr/bin/basename usr/libexec/cydia_
    cp -a usr/bin/du usr/libexec/cydia_
    cp -a usr/lib/libhistory.5.2.dylib usr/libexec/cydia_
    cp -a usr/lib/libintl.8.0.2.dylib usr/libexec/cydia_
    cp -a usr/lib/libncurses.5.dylib usr/libexec/cydia_
    cp -a usr/lib/libreadline.5.2.dylib usr/libexec/cydia_

    rm -f "${PKG_RSLT}/AppTapp_${PKG_ARCH}.xml"
    find * -type l -print -o -name "terminfo" -prune | while read -r link; do
        echo "<array><string>Exec</string><string>/usr/libexec/cydia_/symlink $(readlink "${link}") /${link}</string></array>"
        rm -f "${link}"
    done >"${PKG_RSLT}/AppTapp_${PKG_ARCH}.xml"

    rm -f "${PKG_RSLT}/AppTapp_${PKG_ARCH}.zip"
    zip -qry "${PKG_RSLT}/AppTapp_${PKG_ARCH}.zip" *
fi

#rm -rf "${PKG_BOOT}"