代码拉取完成,页面将自动刷新
#!/bin/bash
cd "$(dirname "$0")"
VIRTUALENV="$(pwd -P)/env"
which python3
if [ $? -ne 0 ];then
echo "Need install python3 version."
fi
# Remove the existing virtual environment (if any)
if [ -d "$VIRTUALENV" ]; then
COMMAND="rm -rf ${VIRTUALENV} db.sqlite3"
echo "Removing old virtual environment..."
eval $COMMAND
else
WARN_MISSING_VENV=1
fi
# Create a new virtual environment
COMMAND="/usr/bin/python3 -m venv ${VIRTUALENV}"
echo "Creating a new virtual environment at ${VIRTUALENV}..."
eval $COMMAND || {
echo "--------------------------------------------------------------------"
echo "ERROR: Failed to create the virtual environment. Check that you have"
echo "the required system packages installed and the following path is"
echo "writable: ${VIRTUALENV}"
echo "--------------------------------------------------------------------"
exit 1
}
# Activate the virtual environment
source "${VIRTUALENV}/bin/activate"
# Install system dependent packages
yum install -y gcc python3-devel
# Install necessary system packages
COMMAND="pip install wheel -i https://mirrors.aliyun.com/pypi/simple"
echo "Installing Python system packages ($COMMAND)..."
eval $COMMAND || exit 1
# Install requirement packages
COMMAND="pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple"
echo "Installing Python requirement packages ($COMMAND)..."
eval $COMMAND || exit 1
COMMAND="pip install -r requirements-prod.txt -i https://mirrors.aliyun.com/pypi/simple"
echo "Installing Python requirement prod packages ($COMMAND)..."
eval $COMMAND || exit 1
# settings secret key
SECRET_KEY=$(openssl rand -base64 37|cut -b 1-50)
NEW_SECRET_KEY="SECRET_KEY='${SECRET_KEY}'"
sed -i "/^SECRET_KEY/c ${NEW_SECRET_KEY}" idcops_proj/settings.py
# settings databases
# Use sqlite3 by default
# migrate
source "${VIRTUALENV}/bin/activate"
python manage.py makemigrations
python manage.py migrate
# collect static files
python manage.py collectstatic --no-input
# create django super user
UserName=admin
UserEmail=admin@idcops.cn
UserPass=$(openssl rand -base64 12)
ImportUser="from django.contrib.auth import get_user_model; User = get_user_model();"
DeleteUser="User.objects.filter(username='${UserName}').delete();"
CreateUser="User.objects.create_superuser('${UserName}', '${UserEmail}', '${UserPass}')"
echo "${ImportUser} ${DeleteUser} ${CreateUser}" | python manage.py shell
echo -e "用户名:${UserName}\n用户密码:${UserPass}"
mkdir media
python manage.py runserver 0.0.0.0:9977
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。