Skip to content

Instantly share code, notes, and snippets.

@prail
Last active August 4, 2024 03:33
Show Gist options
  • Save prail/464bc582f7eab1e8e477c3096331cc98 to your computer and use it in GitHub Desktop.
Save prail/464bc582f7eab1e8e477c3096331cc98 to your computer and use it in GitHub Desktop.
Handbook Diffchecker
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
max-width: 800px;
margin: 0 auto;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>Yup.</h1>
</body>
</html>
#!/bin/bash
if [ "$#" != "1" ]; then
echo "not enough arguments supplied"
exit 1
fi
curl -I -s $1 > headers.txt
etag=$(sed '/etag/!d;s/^etag: //;s/"//g; s/\r//g' headers.txt)
#last modified date, storing as well, just in case something unexpected happens with the etag
lm=$(sed '/last-modified/!d;s/^last-modified: //; s/\r//g' headers.txt)
etag="$lm; $etag"
# file where the etag will have been stored
f_etag="etag.txt"
if [ -f "$f_etag" ]; then
read -r old_etag < "$f_etag"
if [ "$etag" != "$old_etag" ]; then
echo "Ahh sneaky buggers, they changed it~!"
echo "Old etag was $old_etag"
echo "New etag is $etag"
echo "Will be overwriting now..."
echo "$etag" > "$f_etag"
cp changed.html index.html
exit
else
echo "Must've been the wind."
fi
else
echo "First time setting up the script! So we're gonna write the etag file :)"
echo "$etag" > "$f_etag"
fi
cp unchanged.html index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
max-width: 800px;
margin: 0 auto;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>Nope.</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment