Created
December 21, 2018 21:16
-
-
Save fedek6/9d9dfbf4ee32b62ba67fcfb215a951b3 to your computer and use it in GitHub Desktop.
Packager for web projects on nix systems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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