1 Star 0 Fork 13

yagerya/idcops

forked from decbe/idcops 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
auto_install.sh 5.17 KB
一键复制 编辑 原始数据 按行查看 历史
YourN 提交于 2024-11-13 15:32 . fix auto_install.sh cp config/.env file bug
#!/bin/bash
#
# 要求:
# CentOS 7+
# Python 3.6+ (系统自带即可)
#
# 安装目录: /opt/idcops/
# 默认端口号: 18113 (gunicorn),参数:SrvPort
# idcops 版本: develop 或 master,参数:VERSION
WorkDir=/opt
[ -d ${WorkDir} ]||mkdir -p ${WorkDir}
VERSION=master
SrvAddr=0.0.0.0
SrvPort=18113
# gunicorn logfile and pid file
ProjDir=${WorkDir}/idcops
LogFile=${ProjDir}/logs/idcops.log
PidFile=${ProjDir}/run/idcops.pid
# Install system dependent packages
OS=$(cat /etc/os-release |grep -w '^ID'|awk -F= '{print $2}'|sed 's/\"//g')
case $OS in
debian|ubuntu)
apt update
apt install -y gcc python3 python3-dev python3-venv libjpeg-dev openssl git default-libmysqlclient-dev pkg-config redis-server
;;
centos|fedora|rhel)
yum install -y gcc python3-devel openssl git
;;
alpine)
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev \
tiff-dev tk-dev tcl-dev harfbuzz-dev fribidi-dev jpeg g++ openssl \
gcc python3 python3-dev git
;;
*)
echo "unknow os ${OS}, exit!"
exit 1
;;
esac
# 检查 Python 和 Python 版本
PYTHON="${PYTHON:-python3}"
which $PYTHON
if [ $? -ne 0 ];then
echo "Need install python3 version."
exit 1
else
# Check Python version
PY_VERSION=$(${PYTHON} -V 2>&1 | awk '{print $NF}' | awk -F'.' '{print $1, $2}')
read -r major minor <<<$(echo $PY_VERSION)
if [ ${major} -lt 3 ] || [ ${minor} -gt 10 ];then
echo "Python version unsupported, require python version 3.6 <= 3.10"
exit 1
fi
fi
# 下载项目放到 /opt/ 目录下,最终项目目录为: /opt/idcops/
cd ${WorkDir}
git clone -b ${VERSION} https://gitee.com/decbe/idcops.git
cd ${ProjDir}
# Check install.lock file exists
if [ -f 'install.lock' ];then
echo "install.lock is already exists."
exit 1
fi
# Check db.sqlite3 file exists
if [ -f 'db.sqlite3' ];then
COMMAND="\cp -raf db.sqlite3 db.sqlite3.save-$(date +'%F')"
echo "db.sqlite3 is already exists, will backup to db.sqlite3.save-$(date +'%F') ."
eval $COMMAND
fi
VIRTUALENV="${ProjDir}/venv"
# 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="$PYTHON -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
. ${VIRTUALENV}/bin/activate
# 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
# default .env settings
if [ -f 'config/.env' ]; then
echo "Not found config/.env configure file, Use default configure by config/.env.dev"
cp config/.env.dev config/.env
fi
mkdir -p /opt/idcops/data/
# settings databases
# Use sqlite3 by default
# migrate
python manage.py makemigrations
python manage.py migrate --no-input
# 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}"
echo -e "账户密码可以查看 install.log 文件"
echo -e "SECRET_KEY: ${SECRET_KEY}\n" > install.log
echo -e "Server: http://${SrvAddr}:${SrvPort}/\nUsername: ${UserName}\nPassword: ${UserPass}\nEmail: ${UserEmail}" >> install.log
echo -e "Server: http://${SrvAddr}:${SrvPort}/\nUsername: ${UserName}\nPassword: ${UserPass}\nEmail: ${UserEmail}"
touch install.lock
RUN_SERVER="nohup ${VIRTUALENV}/bin/gunicorn --workers 3 \
--bind ${SrvAddr}:${SrvPort} \
--pid ${PidFile} \
--access-logfile ${LogFile} \
--pythonpath ${ProjDir} \
--reload \
proj.wsgi:application > /dev/null 2>&1 &"
eval ${RUN_SERVER}
echo '#!/bin/sh' > ${ProjDir}/scripts/start.sh
echo "${RUN_SERVER}" >> ${ProjDir}/scripts/start.sh
echo '#!/bin/sh' > ${ProjDir}/scripts/stop.sh
echo "kill \`cat ${PidFile}\`" >> ${ProjDir}/scripts/stop.sh
chmod +x ${ProjDir}/scripts/start.sh ${ProjDir}/scripts/stop.sh
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yagerya/idcops.git
git@gitee.com:yagerya/idcops.git
yagerya
idcops
idcops
master

搜索帮助