Created
March 6, 2021 20:53
-
-
Save fakuivan/ee66d88e8b7f42fa4e148c4b9e92c1d8 to your computer and use it in GitHub Desktop.
Small script to port xcas program changes made throughout hp prime backups to a git repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
decode_hp_xcas_program () { | |
python3.8 -c ' | |
import sys | |
enc = "utf-16le" | |
delims = ("#cas".encode(enc), "#end".encode(enc)) | |
print(((lambda conts: conts[conts.find(delims[0])+len(delims[0]):conts.rfind(delims[1])])( | |
open(sys.argv[1], mode="rb").read())).decode(enc))' \ | |
"$1" | |
} | |
extract_and_decode_backup () { | |
local backup_file="$1" | |
local extracted | |
extracted="$(mktemp -d)" || return $? | |
trap 'rm -rf "$extracted"' RETURN | |
unzip -d "$extracted" -- "$backup_file" || return $? | |
for program in "$extracted"/*.hpprgm; do | |
echo "Decoding ${program@Q}" | |
decode_hp_xcas_program "$program" > "${program%.*}.xcas" || return $? | |
cp "${program%.*}.xcas" . || return $? | |
done | |
} | |
# In my case these all happen to be ordered by date from old to new | |
# that way changes get commited in the right order | |
for bkp_file in ../*.zip; do | |
rm -- * && | |
backup_date="$(stat -c '%y' -- "$backup_file")" && | |
extract_and_decode_backup "$bkp_file" && | |
git add . && | |
git commit -m "Add history from backup" --date "$backup_date" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment