Skip to content

Instantly share code, notes, and snippets.

@flk92
Created May 14, 2012 18:37
Show Gist options
  • Save flk92/2695563 to your computer and use it in GitHub Desktop.
Save flk92/2695563 to your computer and use it in GitHub Desktop.
Transforms any folder structure to a script
#!/bin/bash
# Scriptizer.sh: transforms any folder structure to a script
# Fabio K
# Add header
echo "#!/bin/bash"
for file in `find .`
do
type="`file --mime-type -b $file`"
case $type in
text/*)
# Do text file stuff
echo "# Create file $file"
echo "cat > $file << SCRIPT_END_OF_FILE"
cat $file
echo "SCRIPT_END_OF_FILE"
;;
application/x-directory)
# Do directory stuff
echo "# Create directory $file"
echo "mkdir -p $file"
;;
application/x-empty)
# Do empty file stuff
echo "# Touch $file"
echo "touch $file"
;;
application/octet-stream | *)
# Fallback, binary files
echo "# Decompress $file"
echo "cat > $file.gz.b64 << SCRIPT_END_OF_FILE"
gzip -c $file | base64
echo "SCRIPT_END_OF_FILE"
echo "base64 -D -i $file.gz.b64 -o $file.gz"
echo "rm $file.gz.b64"
echo "gunzip $file.gz"
;;
esac
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment