Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Version 1.7: Rework compression of ramdisks
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao-Long Chen committed Sep 20, 2013
1 parent 9672b6a commit bf6cea2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
*.swp
DualBootPatcher-*.zip
DualBootPatcher-*/
pythonportable.exe
windowsbinaries/
68 changes: 54 additions & 14 deletions scripts/makedist.sh
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="1.6.3"
VERSION="1.7"
MINGW_PREFIX=i486-mingw32-

set -e
Expand All @@ -17,12 +17,13 @@ cd "${CURDIR}"
create_portable_python() {
local URL="http://ftp.osuosl.org/pub/portablepython/v3.2/PortablePython_3.2.5.1.exe"
local MD5SUM="5ba055a057ce4fe1950a0f1f7ebae323"
if [ ! -f pythonportable.exe ] || \
! md5sum pythonportable.exe | grep -q ${MD5SUM}; then
if [ ! -f windowsbinaries/pythonportable.exe ] || \
! md5sum windowsbinaries/pythonportable.exe | grep -q ${MD5SUM}; then
mkdir -p windowsbinaries
if which axel >/dev/null; then
axel -an10 "${URL}" -o pythonportable.exe
axel -an10 "${URL}" -o windowsbinaries/pythonportable.exe
else
wget "${URL}" -O pythonportable.exe
wget "${URL}" -O windowsbinaries/pythonportable.exe
fi
fi

Expand Down Expand Up @@ -96,7 +97,7 @@ create_portable_python() {
rm Lib/{calendar.py,cgi.py,cgitb.py,chunk.py,cmd.py,code.py,codeop.py,colorsys.py,compileall.py,configparser.py,contextlib.py,cProfile.py,csv.py}
rm Lib/{datetime.py,decimal.py,difflib.py,dis.py,doctest.py,dummy_threading.py}
rm Lib/{filecmp.py,fileinput.py,formatter.py,fractions.py,ftplib.py}
rm Lib/{getopt.py,getpass.py,gettext.py,glob.py,gzip.py}
rm Lib/{getopt.py,getpass.py,gettext.py,glob.py}
rm Lib/hmac.py
rm Lib/{imaplib.py,imghdr.py,inspect.py}
rm Lib/{macpath.py,macurl2path.py,mailbox.py,mailcap.py,mimetypes.py,modulefinder.py}
Expand Down Expand Up @@ -133,16 +134,50 @@ build_windows() {
rm mkbootimg/mkbootimg.windows.c mkbootimg/unpackbootimg.windows.c
popd

wget 'http://downloads.sourceforge.net/project/mingw/MSYS/Extension/patch/patch-2.6.1-1/patch-2.6.1-1-msys-1.0.13-bin.tar.lzma'
wget 'http://downloads.sourceforge.net/project/mingw/MSYS/Base/msys-core/msys-1.0.18-1/msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma'
mkdir -p windowsbinaries
pushd windowsbinaries

local URLBASE="http://downloads.sourceforge.net/project/mingw/MSYS"

if [ ! -f patch-2.6.1-1-msys-1.0.13-bin.tar.lzma ]; then
wget "${URLBASE}/Extension/patch/patch-2.6.1-1/patch-2.6.1-1-msys-1.0.13-bin.tar.lzma"
fi

if [ ! -f msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma ]; then
wget "${URLBASE}/Base/msys-core/msys-1.0.18-1/msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma"
fi

if [ ! -f libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma ]; then
wget "${URLBASE}/Base/gettext/gettext-0.18.1.1-1/libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma"
fi

if [ ! -f libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma ]; then
wget "${URLBASE}/Base/libiconv/libiconv-1.14-1/libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma"
fi

if [ ! -f liblzma-5.0.3-1-msys-1.0.17-dll-5.tar.lzma ]; then
wget "${URLBASE}/Base/xz/xz-5.0.3-1/liblzma-5.0.3-1-msys-1.0.17-dll-5.tar.lzma"
fi

if [ ! -f xz-5.0.3-1-msys-1.0.17-bin.tar.lzma ]; then
wget "${URLBASE}/Base/xz/xz-5.0.3-1/xz-5.0.3-1-msys-1.0.17-bin.tar.lzma"
fi

tar Jxvf patch-2.6.1-1-msys-1.0.13-bin.tar.lzma bin/patch.exe \
--to-stdout > "${TARGETDIR}/binaries/hctap.exe"
tar Jxvf msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma bin/msys-1.0.dll \
--to-stdout > "${TARGETDIR}/binaries/msys-1.0.dll"
chmod +x "${TARGETDIR}/binaries/hctap.exe" \
"${TARGETDIR}/binaries/msys-1.0.dll"
rm -v patch-2.6.1-1-msys-1.0.13-bin.tar.lzma \
msysCORE-1.0.18-1-msys-1.0.18-bin.tar.lzma
tar Jxvf libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma bin/msys-intl-8.dll \
--to-stdout > "${TARGETDIR}/binaries/msys-intl-8.dll"
tar Jxvf libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma bin/msys-iconv-2.dll \
--to-stdout > "${TARGETDIR}/binaries/msys-iconv-2.dll"
tar Jxvf liblzma-5.0.3-1-msys-1.0.17-dll-5.tar.lzma bin/msys-lzma-5.dll \
--to-stdout > "${TARGETDIR}/binaries/msys-lzma-5.dll"
tar Jxvf xz-5.0.3-1-msys-1.0.17-bin.tar.lzma bin/xz.exe \
--to-stdout > "${TARGETDIR}/binaries/xz.exe"

chmod +x "${TARGETDIR}"/binaries/*.{exe,dll}
popd
}

build_linux() {
Expand All @@ -164,11 +199,16 @@ compress_ramdisks() {
for i in ramdisks/*; do
if [ -d "${i}" ]; then
pushd "${i}"
find . | cpio -o -H newc | gzip > \
"${TARGETDIR}/ramdisks/$(basename "${i}").cpio.gz"
find . | cpio -o -H newc > \
"${TARGETDIR}/ramdisks/$(basename "${i}").cpio"
popd
fi
done

pushd "${TARGETDIR}/ramdisks/"
tar cvf - *.cpio | xz -9 > ramdisks.tar.xz
rm *.cpio
popd
}

TARGETNAME="DualBootPatcher-${VERSION}"
Expand Down
64 changes: 48 additions & 16 deletions scripts/patchfile.py
Expand Up @@ -2,11 +2,13 @@

# For Qualcomm based Samsung Galaxy S4 only!

import gzip
import os
import re
import shutil
import subprocess
import sys
import tarfile
import tempfile
import zipfile

Expand Down Expand Up @@ -99,9 +101,39 @@ def patch_boot_image(boot_image, file_info):
print("No ramdisk specified")
return None

# Extract ramdisk from tar.xz
if sys.hexversion >= 50528256: # Python 3.3
with tarfile.open(os.path.join(ramdiskdir, "ramdisks.tar.xz")) as f:
f.extract(file_info.ramdisk, path = ramdiskdir)
else:
xz = "xz"
if os.name == "nt":
xz = os.path.join(binariesdir, "xz.exe")

run_command(
[ xz, '-d', '-k', '-f', os.path.join(ramdiskdir, "ramdisks.tar.xz") ]
)

with tarfile.open(os.path.join(ramdiskdir, "ramdisks.tar")) as f:
f.extract(file_info.ramdisk, path = ramdiskdir)

os.remove(os.path.join(ramdiskdir, "ramdisks.tar"))

ramdisk = os.path.join(ramdiskdir, file_info.ramdisk)

# Compress ramdisk with gzip if it isn't already
if not file_info.ramdisk.endswith(".gz"):
with open(ramdisk, 'rb') as f_in:
with gzip.open(ramdisk + ".gz", 'wb') as f_out:
f_out.writelines(f_in)

os.remove(os.path.join(ramdiskdir, file_info.ramdisk))
ramdisk = ramdisk + ".gz"

shutil.copyfile(ramdisk, os.path.join(tempdir, "ramdisk.cpio.gz"))

os.remove(os.path.join(ramdiskdir, file_info.ramdisk + ".gz"))

exit_status, output = run_command(
[ os.path.join(binariesdir, mkbootimg),
'--kernel', os.path.join(tempdir, "kernel.img"),
Expand Down Expand Up @@ -166,51 +198,51 @@ def get_file_info(path):
if re.search(r"^.*\.img$", filename):
print("Detected boot.img file")
print("WILL USE CYANOGENMOD RAMDISK. USE replaceramdisk SCRIPT TO CHOOSE ANOTHER RAMDISK")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"

elif re.search(r"^KT-SGS4-JB4.3-AOSP-.*.zip$", filename):
print("Detected ktoonsez kernel zip")
print("Using patched ktoonsez ramdisk")
file_info.ramdisk = "ktoonsez.dualboot.cpio.gz"
file_info.ramdisk = "ktoonsez.dualboot.cpio"
file_info.patch = "ktoonsez.dualboot.patch"

elif re.search(r"^jflte[a-z]+-aosp-faux123-.*.zip$", filename):
print("Detected faux kernel zip")
print("Using patched Cyanogenmod ramdisk (compatible with faux)")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"
file_info.patch = "faux.dualboot.patch"

elif re.search(r"^ChronicKernel-JB4.3-AOSP-.*.zip$", filename):
print("Detected ChronicKernel kernel zip")
print("Using patched ChronicKernel ramdisk")
file_info.ramdisk = "chronickernel.dualboot.cpio.gz"
file_info.ramdisk = "chronickernel.dualboot.cpio"
file_info.patch = "chronickernel.dualboot.patch"

elif re.search(r"^Infamous_S4_Kernel.v.*.zip$", filename):
print("Detected Infamous kernel zip")
print("Using patched Infamous kernel ramdisk")
file_info.ramdisk = "infamouskernel.dualboot.cpio.gz"
file_info.ramdisk = "infamouskernel.dualboot.cpio"
file_info.patch = "infamouskernel.dualboot.patch"

elif re.search(r"^v[0-9]+-Google-edition-ausdim-Kernel-.*.zip$", filename):
print("Detected Ausdim kernel zip")
print("Using patched Ausdim kernel ramdisk")
print("NOTE: The ramdisk is based on Ausdim v17. If a newer version has ramdisk changes, let me know")
file_info.ramdisk = "ausdim.dualboot.cpio.gz"
file_info.ramdisk = "ausdim.dualboot.cpio"
file_info.patch = "ausdim.dualboot.patch"

elif re.search(r"^.*_AdamKernel.V[0-9\.]+\.CWM\.zip$", filename):
print("Detected Adam kernel zip")
print("Using patched Adam kernel zip")
file_info.ramdisk = "adam.dualboot.cpio.gz"
file_info.ramdisk = "adam.dualboot.cpio"
file_info.patch = "adam.dualboot.patch"
file_info.bootimg = "wanam/boot.img"

# Cyanogenmod ROMs
elif re.search(r"^cm-[0-9\.]+-[0-9]+-NIGHTLY-[a-z0-9]+.zip$", filename):
print("Detected official Cyanogenmod nightly ROM zip")
print("Using patched Cyanogenmod ramdisk")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"
file_info.patch = "cyanogenmod.dualboot.patch"

elif re.search(r"^cm-[0-9\.]+-[0-9]+-.*.zip$", filename):
Expand All @@ -221,47 +253,47 @@ def get_file_info(path):

print("Detected Cyanogenmod based ROM zip")
print("Using patched Cyanogenmod ramdisk")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"
file_info.patch = "cyanogenmod.dualboot.patch"

elif re.search(r"^Slim-.*.zip$", filename):
print("Detected Slim Bean ROM zip")
print("Using patched Cyanogenmod ramdisk (compatible with Slim Bean)")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"
file_info.patch = "slim.dualboot.patch"

# AOKP ROMs
elif re.search(r"^aokp_[0-9\.]+_[a-z0-9]+_task650_[0-9\.]+.zip$", filename):
print("Detected Task650's AOKP ROM zip")
print("Using patched Task650's AOKP ramdisk")
file_info.ramdisk = "aokp-task650.dualboot.cpio.gz"
file_info.ramdisk = "aokp-task650.dualboot.cpio"
file_info.patch = "aokp-task650.dualboot.patch"

# PAC-Man ROMs
elif re.search(r"^pac_[a-z0-9]+_.*.zip$", filename):
print("Detected PAC-Man ROM zip")
print("Using patched Cyanogenmod ramdisk (compatible with PAC-Man)")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"
file_info.patch = "cyanogenmod.dualboot.patch"

elif re.search(r"^pac_[a-z0-9]+-nightly-[0-9]+.zip$", filename):
print("Detected PAC-Man nightly ROM zip")
print("Using patched Cyanogenmod ramdisk (compatible with PAC-Man)")
file_info.ramdisk = "cyanogenmod.dualboot.cpio.gz"
file_info.ramdisk = "cyanogenmod.dualboot.cpio"
file_info.patch = "cyanogenmod.dualboot.patch"

# ParanoidAndroid ROMs
elif re.search(r"^pa_[a-z0-9]+-.*-[0-9]+.zip$", filename):
print("Detected ParanoidAndroid ROM zip")
print("using patched ParanoidAndroid ramdisk")
file_info.ramdisk = "paranoidandroid.dualboot.cpio.gz"
file_info.ramdisk = "paranoidandroid.dualboot.cpio"
file_info.patch = "paranoidandroid.dualboot.patch"

# Google Edition ROMs
elif re.search(r"^i9505-ge-untouched-4.3-.*.zip$", filename):
print("Detected MaKTaiL's Google Edition ROM zip")
print("Using patched Google Edition ramdisk")
file_info.ramdisk = "googleedition.dualboot.cpio.gz"
file_info.ramdisk = "googleedition.dualboot.cpio"
file_info.patch = "ge-MaKTaiL.dualboot.patch"

# MIUI ROMs
Expand All @@ -273,7 +305,7 @@ def get_file_info(path):
else:
print("Detected MIUI ROM zip")
print("Using patched MIUI ramdisk")
file_info.ramdisk = "miui.dualboot.cpio.gz"
file_info.ramdisk = "miui.dualboot.cpio"
file_info.patch = "miui.dualboot.patch"

# Google Apps
Expand Down

0 comments on commit bf6cea2

Please sign in to comment.