Last active
March 15, 2017 00:52
-
-
Save slavama/e1eef844c650c3b731c6a2bec97b3c54 to your computer and use it in GitHub Desktop.
Simple shell script for django project creation
This file contains 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
#!/usr/bin/env bash | |
# | |
# Simple shell script for django project creation | |
# Edit variables section and run: create_django_app.sh projectname | |
# | |
NAME=$1 | |
DOMAIN="$NAME.dev" | |
HOSTS_FILE="/etc/hosts" | |
BOILERPLATE_REPO="https://github.com/slavama/dartcms-boilerplate.git" | |
PROJECT_REPO="https://bitbucket.org/YOUR_USERNAME/$NAME" | |
PROJECT_DIR="/home/YOUR_USERNAME/projects/$NAME" | |
REQUIREMENTS_FILE="./requirements.txt" | |
STATIC_DIR="./static" | |
DARTCMS_DIR="/home/YOUR_USERNAME/projects/dartcms/dartcms" | |
PROJECT_DARTCMS_DIR="./venv/lib/python3.5/site-packages/dartcms" | |
read -p "Do you want add $DOMAIN to $HOSTS_FILE ?" -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
echo "127.0.0.1 $DOMAIN www.$DOMAIN wk.$DOMAIN" | sudo tee -a $HOSTS_FILE | |
fi | |
if [ ! -d "$PROJECT_DIR" ]; then | |
echo "Create project cat $PROJECT_DIR" | |
mkdir $PROJECT_DIR | |
else | |
echo "The project cat $PROJECT_DIR exist." | |
fi | |
cd $PROJECT_DIR | |
read -p "Do you want clone boilerplate to $PROJECT_DIR ?" -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
git clone $BOILERPLATE_REPO . | |
rm -rf .git | |
git remote add origin $PROJECT_REPO | |
fi | |
read -p "Do you want create dbuser $NAME ?" -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
createuser -d -R -S -U postgres $NAME | |
fi | |
read -p "Do you want create db $NAME ?" -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
createdb -U $NAME $NAME | |
fi | |
if [ ! -d "./venv" ]; then | |
echo "Create venv" | |
virtualenv -p python3 --prompt="($NAME)" venv | |
. ./venv/bin/activate | |
pip install -r $REQUIREMENTS_FILE | |
cd $STATIC_DIR | |
npm i | |
cd $PROJECT_DIR | |
else | |
echo "Activate venv" | |
. ./venv/bin/activate | |
fi | |
read -p "Create simlink to local dartcms ? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
rm -rf $PROJECT_DARTCMS_DIR | |
ln -s $DARTCMS_DIR $PROJECT_DARTCMS_DIR | |
fi | |
read -p "Configure ? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
sed -i "s/example.com/$DOMAIN/g" ./conf/dev/project_settings.py | |
sed -i "s/boilerplate/$NAME/g" ./conf/dev/project_settings.py | |
fi | |
read -p "Migrate ?" -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
python manage.py migrate | |
python manage.py createsuperuser | |
psql -U $NAME -d $NAME -c "UPDATE django_site SET domain='$DOMAIN:8000', name='$DOMAIN' WHERE id=1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment