Skip to content

Instantly share code, notes, and snippets.

@fedek6 fedek6/selfpacker.sh
Created Dec 21, 2018

Embed
What would you like to do?
Packager for web projects on nix systems.
#!/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`
# Current date
now=$(date +"%d_%m_%Y")
machine=$(hostname)
# Database credentials
user="developer"
password="noodle"
host="localhost"
db_name="reklama_vogue"
/usr/bin/mysqldump --user=$user --password=$password --host=$host $db_name > ./devel/$db_name-$now.sql
/bin/tar -zcvf ../"$now"-"${PWD##*/}"-"$machine"-v"$version".tar.gz --exclude=../"${PWD##*/}"/node_modules --exclude=../"${PWD##*/}"/.sass-cache ../"${PWD##*/}"
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.