-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·62 lines (52 loc) · 1.78 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
set -e
trap "exit" INT
echo "Importing config.ini..."
grep = config.ini > config
source config
vars=($(grep -aoP ".*(?=\=)" config.ini))
for var in ${vars[@]}; do
if [ -z ${!var} ] && [[ ! "$var" =~ "REMOTE" || ! "$1" == "--no-remote" ]]; then
echo "$var is unset. Edit config.ini"
exit 1
fi
done
echo "Creating venv..."
mv project $PROJECT_NAME
cd $PROJECT_NAME
python3 -mvenv venv 2>/dev/null || py -mvenv venv #<-- hack for windows
source venv/bin/activate 2>/dev/null || source venv/Scripts/activate #<-- hack for windows
echo "Installing requirements..."
pip3 install --quiet -r requirements.txt
echo "Creating django project..."
django-admin startproject $PROJECT_NAME .
cat ../deploy/settings.py >> $PROJECT_NAME/settings.py
echo "Changing configs..."
cd ..
for file in `ls deploy`; do
for var in ${vars[@]}; do
sed -i "s#$var#${!var}#g" deploy/$file
done
done
echo "Deploying on remote host..."
if [ "$1" != "--no-remote" ]; then
scp -r deploy -p $REMOTE_PORT $REMOTE_USER@$REMOTE_HOST:~
scp -r deploy/update.sh -p $REMOTE_PORT $REMOTE_USER@$REMOTE_HOST:~
fi
echo "Removing temp files..."
rm -rf deploy config.ini config init.sh README.md
echo "Creating new README..."
echo "# $PROJECT_NAME" > README.md
echo "Creating git..."
rm -rf .git
git init
git add -A
git commit -m "Initial commit" > /dev/null
git remote add origin $GITHUB_URL
git push -q --set-upstream origin master
if [ "$1" != "--no-remote" ]; then
echo "Configuring remote:"
ssh -t $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT "bash ~/deploy/genkeys.sh"
read -p "!!!!You should add deploy key to the GITHUB first, then tap ENTER to continue"
ssh -t $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT "bash ~/deploy/deploy.sh"
fi