-
Notifications
You must be signed in to change notification settings - Fork 1
/
save_archivedmap
executable file
·54 lines (47 loc) · 1.84 KB
/
save_archivedmap
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
#!/bin/bash
DOMAIN="$1"
SUBDIR="archived_$DOMAIN"
type -P yawbdl &>/dev/null && ISINST=1 || ISINST=0
if [ $ISINST -eq 0 ]
then
echo "Install https://github.com/BGforgeNet/yawbdl"
exit 127
fi
if [ -f "$SUBDIR/snapshots.json" ]; then
PERLDATETIME=$(perl -e 'my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 30*86400); $year += 1900; $mon += 1; printf ("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, $hour, $min, $sec)')
mv "$SUBDIR/snapshots.json" "$SUBDIR/snapshots_moved_$PERLDATETIME.json" #TODO: snapshots_list_$(modification).json? https://stackoverflow.com/questions/16391208/print-a-files-last-modified-date-in-bash
fi
if yawbdl -d $DOMAIN -o $SUBDIR --no-fail --retries 10 --delay 2 -n; then
PERLDATETIME=$(perl -e 'my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 30*86400); $year += 1900; $mon += 1; printf ("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, $hour, $min, $sec)')
mv "$SUBDIR/snapshots.json" "$SUBDIR/snapshots_list_$PERLDATETIME.json"
fi
exit
type -P wayback_machine_downloader &>/dev/null && ISINST=1 || ISINST=0
if [ $ISINST -eq 0 ]
then
echo "Install Ruby, then execute 'sudo gem install wayback_machine_downloader'"
echo "See also https://linuxnightly.com/how-to-download-a-website-from-the-wayback-machine"
echo ""
exit 127
fi
FN="archivedmap_$DOMAIN.json"
if [ -e "$FN" ]; then
echo "$FN already exists (completely downloaded map, but when?)"
elif [ -e "~$FN" ]; then
echo "~$FN already exists (incompletely downloaded map), you should remove it"
exit 1
else
wayback_machine_downloader -s -l -p 1000000000 -c 1 http://$DOMAIN | tee -a "~$FN"
if [ $? -eq 0 ]
then
if [ -f "~$FN" ]; then
mv "~$FN" "$FN"
echo "$FN downloaded successfully (perhaps)"
else
exit
fi
else
echo "~$FN not downloaded"
exit 1
fi
fi