set -e binary_name=xochitl workdir=/home/rmhacks patched="$workdir/$binary_name.patched" if [ ! -d $workdir ]; then mkdir -p $workdir # migrate stuff and clean old patches mv /home/root/xochitl.* $workdir 2> /dev/null || true rm /home/root/patch_* 2> /dev/null || true fi; function checkspace(){ part=$1 needed=$2 available=$(df $part | tail -n1 | awk '{print $4}'); let available=$available/1024 if [ $available -lt $needed ];then echo "Less than ${needed}MB free, ${available}MB" return 1; fi; } checkspace / 3 || (echo "Trying to free space..."; journalctl --vacuum-time=1m) checkspace / 3 || (echo "Aborting..."; exit 10) checkspace /home 10 || (echo "Not enough space on /home"; exit 10) echo "Disk space seems to be enough." trap onexit INT function onexit(){ cleanup auto_install exit 0 } function cleanup(){ echo "Cleaning up..." rm /tmp/*crash* 2> /dev/null || true rm -fr /home/root/.cache/remarkable/xochitl/qmlcache/* } function purge(){ if [ ! -f "$backup_file" ]; then echo "The backup file is missing" exit 1 fi hash=$(sha1sum "$backup_file" | cut -c 1-40) if [ "$expectedhash" != "$hash" ]; then echo "The backup $backup_file is not the original file (was it replaced/ deleted? / wrong hash)" echo "Expected hash: $expectedhash" echo "Actual hash: $hash" echo "cowardly aborting..." exit 1 fi systemctl stop xochitl cleanup cp "$backup_file" /usr/bin/xochitl systemctl start xochitl echo -n "Remove all traces [Y/n]? " read yn case $yn in [Nn]* ) ;; * ) rm -fr "$workdir" ;; esac exit 0 } function auto_install(){ if [ -z "$1" ]; then echo -n "If everything worked, do you want to make it permanent [N/y]? " read yn else yn=$1 fi case $yn in [Yy]* ) echo "Making it permanent, DON'T DELETE $backup_file !!!" mv $patched /usr/bin/$binary_name echo "IMPORTANT: Do not forget to disable 'Automatic updates' on your reMarkable to avoid losing the hack unintentionally." echo "Starting the UI..." systemctl start xochitl return 0 ;; * ) echo "Use the $patched binary if you change your mind / provide it if it segfaulted." echo "Starting the original..." systemctl start xochitl ;; esac return 1 } currentVersion="$(