Skip to content

Instantly share code, notes, and snippets.

@upsided
Created March 20, 2019 00:33
Show Gist options
  • Save upsided/6a484a3cdc911e44da7cea514f2e1cba to your computer and use it in GitHub Desktop.
Save upsided/6a484a3cdc911e44da7cea514f2e1cba to your computer and use it in GitHub Desktop.
Create a LBRY-compatible website archive out of a folder
#!/usr/bin/env fish
# pack up a folder in the x-lbry format so it can be hosted on LBRY as a web page.
#
# this requires
# - the fish shell (just get it already)
# - zstd compression tool ( https://github.com/facebook/zstd )
# - an index.html file in your folder (duh)
#
# usage:
# lpack YourSiteFolder YourFilename.lbry
#
# you can then upload YourFilename.lbry to LBRY
#
# cheers!
if test (count $argv) -lt 2
echo "Please specify a folder and a destination file:"
echo " lpack YourFolderName YourOutFile.lbry"
exit -1
end
#general failure: cleanup after ourselves
function bail
cd "$PREV_DIR"
if test -e "$theDir"; exit $argv[1] ; end
rm -rf "$theDir"/*
rmdir "$theDir"
exit $argv[1]
end
set PREV_DIR (pwd)
# make a temp directory to work with
set theDir (mktemp -d) ; or exit -1
# absolute paths and stuff
set folder "$argv[1]"
set FNAME (realpath $argv[2]) ; or bail $status
#copy to the temp dir
cp -r "$folder"/* "$theDir"/ ; or bail $status
#replace all files with their zstd compressed versions
for f in (find "$theDir" -type f ) ; cat $f | zstd -5f - > $f.zip ; mv $f.zip $f ; end ; or bail $status
#tar up the temp directory. Please note that the "sed" stuff is so the filenames in the
# archive don't confuse LBRY with a bunch of "./" prefixes
cd "$theDir" ; or bail $status
tar --exclude=".DS_*" --exclude="._*" -cvf "$FNAME" (find "." -type f | sed -e "s/^\.\///g") ; or bail $status
#remove our junk, report success
bail 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment