Skip to content

Instantly share code, notes, and snippets.

Created October 2, 2021 16:52
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Repack OpenPHT images to update certificate authority
set -e
echo "Checking required dependencies..."
which wget >& /dev/null
which parted >& /dev/null
which mksquashfs >& /dev/null
which unsquashfs >& /dev/null
workdir=$(mktemp -d)
imagegz=$(basename ${image_url})
image=$(echo ${imagegz} | sed 's/\.gz//g')
cd $workdir
mkdir img target
echo "Getting new CA certs"
mv cacert.pem.txt cacert.pem
echo "Retrieving target image"
wget $image_url
gunzip $imagegz
offset=$(parted ${image} -s "unit B print" | grep fat16 | awk '{print $2}' | cut -d B -f 1)
sudo mount -o loop,offset=${offset} ${image} img
cp img/SYSTEM* target
cd target
unsquashfs SYSTEM
echo "Installing fixed certificates"
cp ../cacert.pem squashfs-root/etc/ssl/cert.pem
cp ../cacert.pem squashfs-root/usr/share/XBMC/system/cacert.pem
echo "Repackaging image"
sudo mksquashfs squashfs-root SYSTEM -comp gzip
cd ..
md5sum target/SYSTEM > target/SYSTEM.md5
sudo cp target/SYSTEM* img
sudo umount img
cp ${image} ${target}
cd ${currdir}
rm -rf ${workdir}
echo "Repacked image is at ${target}"
Copy link

Usage is like this:


Copy link

If you are missing dependencies, run with bash -x to see what dependency it failed to detect.

Copy link

Please forgive my ignorance, but what program do you use to run this script? I have a different version that I need updated and I have no idea how to do it. Willing to do some research but is there any program name you could give me to at least point me in the right direction?

Copy link

you basically need to run this on any linux machine, the script itself is written in BASH, but you'll need to have a few tools installed (gparted, squashfs-tools, wget). If you don't have a linux computer, you can try installing ubuntu in Virtualbox or with Vagrant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment