Skip to content

Instantly share code, notes, and snippets.

@fedek6 fedek6/zippacker.sh
Created Jun 24, 2019

Embed
What would you like to do?
Packer for web projects. It will pack public dir in current path. Archive name will include info from package.json.
#!/bin/sh
# Extract JSON value
parse_json () {
echo $1 | \
sed -e 's/[{}]/''/g' | \
sed -e 's/", "/'\",\"'/g' | \
sed -e 's/" ,"/'\",\"'/g' | \
sed -e 's/" , "/'\",\"'/g' | \
sed -e 's/","/'\"---SEPERATOR---\"'/g' | \
awk -F=':' -v RS='---SEPERATOR---' "\$1~/\"$2\"/ {print}" | \
sed -e "s/\"$2\"://" | \
tr -d "\n\t" | \
sed -e 's/\\"/"/g' | \
sed -e 's/\\\\/\\/g' | \
sed -e 's/^[ \t]*//g' | \
sed -e 's/^"//' -e 's/"$//'
}
# Path
result=${PWD##*/}
# Get version
json=`cat package.json`
version=`parse_json "$json" version`
name=`parse_json "$json" name`
# Current date
now=$(date +"%d_%m_%Y")
machine=$(hostname)
(cd ./public && /usr/bin/zip -r ../"$now"-"$name"-"$machine"-v"$version".zip .)
echo "OK! It's all packed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.