Skip to content

Instantly share code, notes, and snippets.

@unRob
Last active April 14, 2016 06:48
Show Gist options
  • Save unRob/3759807f7d2f9200a88e92aa2a913fc5 to your computer and use it in GitHub Desktop.
Save unRob/3759807f7d2f9200a88e92aa2a913fc5 to your computer and use it in GitHub Desktop.
Bukkit generator http://bukkit.rob.mx

Bukkit Generator

Syncs a folder of images to a remote server, creating a fancy index

Setup

Download sync.sh and mx.rob.bukkit.plist somewhere, edit the latter accordingly, setting the correct script, local/remote bukkit, and STDIN/STDOUT, paths.

Then, install it

mkdir -p /path/to/local-bukkit/_preview
chmod +x ./sync.sh
cp ./sync.sh /path/to/bukkit.sh
cp mx.rob.bukkit.plist ~/Library/LaunchAgents
launchctl start ~/Library/LaunchAgents

Go ahead and add some images to /path/to/local-bukkit/, hilarity ensues.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mx.rob.bukkit</string>
<key>Program</key>
<string>/path/to/bukkit.sh</string>
<key>ProgramArguments</key>
<array>
<string>bukkit.sh</string>
<string>/path/to/local-bukkit</string>
<string>myhost.tld:/path/to/remote-bukkit</string>
</array>
<key>WatchPaths</key>
<array>
<string>/path/to/local-bukkit</string>
</array>
<key>KeepAlive</key>
<false />
<key>LowPriorityIO</key>
<true/>
<key>Nice</key>
<integer>12</integer>
<key>StandardOutPath</key>
<string>/Users/me/Library/Logs/bukkit.log</string>
<key>StandardErrorPath</key>
<string>/Users/me/Library/Logs/bukkit.log</string>
</dict>
</plist>
#!/bin/zsh
#
# Bukkit generator
#
# Roberto Hidalgo, 2016
# http://bukkit.rob.mx
#
# Syncs a folder of images to a remote server, creating a fancy index and fake previews
echo `date -j`
LOCAL_BUKKIT=$1
REMOTE_BUKKIT=$2
echo "Looking for files at $LOCAL_BUKKIT"
files=("${(f)$(find "$LOCAL_BUKKIT" -name '*.gif' -o -name '*.jpg' -depth 1)}")
images=()
for file in $files; do
name=$(basename "${file:r}")
preview="$LOCAL_BUKKIT/_preview/$name.jpg"
url="${file:t}"
read -r -d '' html <<-HTML
<li>
<a href="$url" style="background-image:url(_preview/${name}.jpg)">
<span>$name</span>
</a>
</li>
HTML
if [ ! -f $preview ]; then
echo "Generating preview for $file"
convert "${file}[0]" -thumbnail '200x200>' -quality 40 "$preview"
fi
images+=$html
done
cat > "$LOCAL_BUKKIT/index.html" <<-HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<title>🚽 Bukkit</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href='//fonts.googleapis.com/css?family=Ropa+Sans|Muli:300,400' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="//rob.mx/css/v5.css" />
<style>
main {
max-width: 600px;
margin: 1em auto;
}
li {
list-style: none;
margin: 1em 0;
padding: 0;
}
a {
display: block;
height: 100px;
background-color: #eee;
background-position: center left;
background-repeat: repeat-x;
border-radius: 2px;
overflow: hidden;
}
span {
-webkit-backdrop-filter: blur(2px) saturate(.5);
background: linear-gradient(to right,
rgba(238,238,238,.9),
rgba(238,238,238,.7) 30%,
rgba(238,238,238,0) 70%,
rgba(238,238,238,0)
);
display: block;
line-height: 100px;
padding-left: 1em;
border-radius: 2px;
overflow: hidden;
}
</style>
</head>
<body>
<main>
<ul>
$images
</ul>
</main>
</body>
</html>
HTML
echo "Filling up $REMOTE_BUKKIT"
/usr/local/bin/rsync "$LOCAL_BUKKIT/" \
-avz \
--include='*.gif' \
--include='*.jpg' \
--include='index.html' \
--include='_preview' \
--exclude='*' "$REMOTE_BUKKIT"
/usr/bin/osascript -e 'display notification "Much gifs. Wow." with title "Bukkit very sync"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment