-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwlibrary_extractor.sh
executable file
·95 lines (75 loc) · 2.51 KB
/
jwlibrary_extractor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# 30-07-2022 JoelKle 1.0.0 Initial Version
# 15-03-2023 JoelKle 1.1.0 Fix
set -euo pipefail
if ! command -v adb >/dev/null; then
echo "Required command > adb < not found!"
echo "Ubuntu/Debian: Install with $ apt install adb"
exit 1
fi
if ! command -v zlib-flate >/dev/null; then
echo "Required command > zlib-flate < not found!"
echo "Ubuntu/Debian: Install with $ apt install qpdf"
exit 1
fi
today=$(date '+%Y-%m-%d')
today_time=$(date '+%Y-%m-%dT%H:%M:%S')
today_time_underscore=$(date '+%Y-%m-%dT%H_%M_%S')
while ! (adb devices -l | grep -qoP 'model:\S+')
do
adb devices -l
echo "Could not found your device model"
echo "Make sure Developer Options and USB Debugging are enabled on your device"
echo " Settings > Developer Options > USB Debugging > Enable"
echo "Confirm the authorization message."
echo "Try again?"
read
done
device_name=$(adb devices -l | grep -oP 'model:\S+' | cut -d':' -f2)
echo "Found device $device_name"
echo "Continue?"
read
echo "Start backup of JW Library on device ${device_name} ..."
folder="backups/${device_name}_${today_time_underscore}_jwlibrary_backup"
mkdir -p $folder && cd $folder
echo "A screen should have popped up to start the backup."
echo "Do not enter a passwort!"
echo
adb backup -f org.jw.jwlibrary.mobile.ab -noapk org.jw.jwlibrary.mobile
echo
echo "Backup was successful!"
echo "Start extraction..."
echo
mkdir extracted
dd if=org.jw.jwlibrary.mobile.ab bs=24 skip=1 | zlib-flate -uncompress | tar xf - -C extracted/
if [ ! -f extracted/apps/org.jw.jwlibrary.mobile/db/userData.db ]; then
echo ""
echo "Unfortunately I couldn't find any notes in the backup."
echo "EXIT"
exit 0
fi
cp extracted/apps/org.jw.jwlibrary.mobile/db/userData.db .
sha256sum_userdata=$(sha256sum userData.db)
device_name_manual="${device_name}_manual"
jwlibrary_filename=UserDataBackup_${today}_${device_name_manual}.jwlibrary
cat <<EOF > manifest.json
{
"name": "UserDataBackup_${today}_${device_name_manual}",
"creationDate": "${today}",
"version": 1,
"type": 0,
"userDataBackup": {
"userMarkCount": 1,
"lastModifiedDate": "${today}+00:00",
"deviceName": "${device_name_manual}",
"databaseName": "userData.db",
"hash": "${sha256sum_userdata}",
"schemaVersion": 8
}
}
EOF
zip $jwlibrary_filename userData.db manifest.json
adb push $jwlibrary_filename /storage/emulated/0/Download/
echo
echo "Pushed file $jwlibrary_filename to /storage/emulated/0/Download/ folder on your device"
echo "Start the recovery in the JW Library app!"