-
Notifications
You must be signed in to change notification settings - Fork 1
/
provision.sh
80 lines (64 loc) · 1.99 KB
/
provision.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
echo 'Start!'
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
cd /vagrant
sudo apt-get update
sudo apt-get install tree
# 安装配置mysql8
if ! [ -e /vagrant/mysql-apt-config_0.8.15-1_all.deb ]; then
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb
fi
sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
sudo DEBIAN_FRONTEND=noninteractivate apt-get install -y mysql-server
sudo apt-get install -y libmysqlclient-dev
if [ ! -f "/usr/bin/pip" ]; then
sudo apt-get install -y python3-pip
sudo apt-get install -y python-setuptools
sudo ln -s /usr/bin/pip3 /usr/bin/pip
else
echo "pip3 已安装"
fi
# 升级pip,目前存在问题,read timed out,看脸,有时候可以,但大多时候不行
# python -m pip install --upgrade pip
# 换源完美解决
# 安装pip所需依赖
pip install --upgrade setuptoolse
pip install --ignore-installed wrapt
# 安装pip最新版
pip install -U pip
# 根据 requirements.txt 里的记录安装 pip package,确保所有版本之间的兼容性
pip install -r requirements.txt
# 设置mysql的root账户的密码为yourpassword
# 创建名为twitter的数据库
sudo mysql -u root << EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
flush privileges;
show databases;
CREATE DATABASE IF NOT EXISTS twitter;
EOF
# fi
# superuser名字
USER="admin"
# superuser密码
PASS="admin"
# superuser邮箱
MAIL="admin@twitter.com"
script="
from django.contrib.auth.models import User;
username = '$USER';
password = '$PASS';
email = '$MAIL';
if not User.objects.filter(username=username).exists():
User.objects.create_superuser(username, email, password);
print('Superuser created.');
else:
print('Superuser creation skipped.');
"
printf "$script" | python manage.py shell
# 如果想直接进入/vagrant路径下
# 请输入vagrant ssh命令进入
# 手动输入
# 输入ls -a
# 输入 vim .bashrc
# 在最下面,添加cd /vagrant
echo 'All Done!'