Skip to content

Instantly share code, notes, and snippets.

@dalehamel
Created October 2, 2021 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalehamel/369a6670102be1db02b13df539a7c8c6 to your computer and use it in GitHub Desktop.
Save dalehamel/369a6670102be1db02b13df539a7c8c6 to your computer and use it in GitHub Desktop.
Repack OpenPHT images to update certificate authority
#!/bin/bash
set -e
echo "Checking required dependencies..."
which wget >& /dev/null
which parted >& /dev/null
which mksquashfs >& /dev/null
which unsquashfs >& /dev/null
image_url=$1
currdir=$(pwd)
workdir=$(mktemp -d)
imagegz=$(basename ${image_url})
image=$(echo ${imagegz} | sed 's/\.gz//g')
cd $workdir
mkdir img target
echo "Getting new CA certs"
wget https://github.com/RasPlex/RasPlex/files/7270212/cacert.pem.txt
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
rm SYSTEM
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
target="${currdir}/FIXED-${image}"
cp ${image} ${target}
cd ${currdir}
rm -rf ${workdir}
echo "Repacked image is at ${target}"
@dalehamel
Copy link
Author

Usage is like this:

./repack.sh https://github.com/RasPlex/OpenPHT/releases/download/v1.8.0.148-573b6d73/OpenPHT-Embedded-1.8.0.148-573b6d73-Generic.x86_64.img.gz

@dalehamel
Copy link
Author

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

@sdmfdeeger
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?

@dalehamel
Copy link
Author

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