在做ODOO的前提下需要PostgreSQL, SO....
#!/bin/bash
PID=`echo $$`
echo -e "\033[35m
该脚本只在CentOS 7.4.1708版本上进行了测试,
其他Linux发行版本并未进行测试(如Ubuntu、Debian、Mint、Fedora、FreeBSD、SUSE等)
\033[0m
"
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty raw
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
kk=11
echo "按任意键开始安装....."
while [ $kk -gt 0 ];do
echo -n $kk
sleep 1
kk=$(($kk - 1))
echo -ne "\r \r"
done
char=`get_char`
if [ $char == 'q' ];then
kill -9 $PID
fi
groupadd gooderp
useradd -g gooderp gooderp
echo "123456" | passwd --stdin gooderp
usermod -aG wheel gooderp
#设置gooderp用户权限
sed -i '/%wheel/a\gooderp ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
#判断GIT
opop="git wget"
for i in $opop
do
which $i
if [ $? -ne 0 ];then
yum -y install $i
fi
done
#下载源码:
su - gooderp -c "sudo mkdir /source_package"
su - gooderp -c "cd /source_package && sudo git clone http://github.com/osbzr/gooderp_addons"
su - gooderp -c "cd /source_package && sudo git clone http://github.com/osbzr/base"
su - gooderp -c "cd ~ && curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash"
#安装nodejs
su - gooderp -c "curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash"
su - gooderp -c "echo export NVM_DIR="\$HOME/.nvm" >> ~/.bashrc"
su - gooderp -c 'echo "[ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\"" >> ~/.bashrc'
su - gooderp -c 'echo "[ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\"" >> ~/.bashrc'
sleep 3
su - gooderp -c 'source ~/.bashrc'
#安装nodejs
su - gooderp -c 'nvm install --lts'
#安装less
su - gooderp -c 'npm install -g less'
#安装postgresql(使用root用户)
cd /source_package
wget https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
yum -y install pgdg-redhat10-10-2.noarch.rpm
#安装服务端
yum -y install postgresql10-server
#安装客户端
yum -y install postgresql10
#初始化postgresql数据库
/usr/pgsql-10/bin/postgresql-10-setup initdb
#启动postgresql
systemctl start postgresql-10
#设置开机启动服务
systemctl enable postgresql-10
#安装python(pyenv)
su - gooderp -c 'curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash'
su - gooderp -c 'echo export PATH="/home/gooderp/.pyenv/bin:\$PATH" >> ~/.bashrc'
su - gooderp -c 'echo eval \"\$\(pyenv init -\)\" >> ~/.bashrc'
su - gooderp -c 'echo eval \"\$\(pyenv virtualenv-init -\)\" >> ~/.bashrc'
su - gooderp -c 'source ~/.bashrc'
#安装python
yum -y install readline-devel zlib-devel bzip2-devel libsqlite3x-devel openssl-devel
su - gooderp -c 'pyenv install 2.7.14'
su - gooderp -c 'pyenv global 2.7.14 && pip install --upgrade pip'
yum -y install libxml2-devel python-devel openldap-devel libxslt libxslt-devel gcc*
su - gooderp -c 'pip install -r /source_package/base/requirements.txt'
su - gooderp -c 'pip install simplejson httplib2' #如果这两个没有安装则安装界面会没有css样式
#安装wkhtmltopdf
su - gooderp -c 'cd /source_package && sudo wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm'
su - gooderp -c 'sudo yum -y install /source_package/wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm'
#配置数据库
echo -e "\033[31m自定义建立数据库用户:\033[0m"
echo -e "-d: --createdb \033[31m此角色可以创建新数据库\033[0m"
echo -e "-U: --username=USERNAME \033[31m联接用户(不是要创建的用户名)\033[0m"
echo -e "-R: --no-createrole \033[31m这个角色没有创建其它角色的权限(默认)\033[0m"
echo -e "-S: --no-superuser \033[31m角色不能是超级用户(默认)\033[0m"
echo -e "-P: --pwprompt \033[31m给新角色指定口令\033[0m"
echo -e "\033[35m gooderp \033[0m是要在postgres数据库中创建的新用户"
echo -e "\033[34m请牢记自己接下来输入的密码\033[0m"
su - postgres -c 'createuser -d -U postgres -R -S -P gooderp'
#修改两个文件夹的权限不然会报错(以root用户执行)
chown -Rf gooderp.gooderp /source_package/{base,gooderp_addons}
#之后启动gooderp
su - gooderp -c 'cd /source_package/ && python base/odoo-bin --addons-path=gooderp_addons &'
#postgres Ident 认证设置
sudo sed -i '/# IPv6 local connections/i\host all all 0.0.0.0/0 md5' /var/lib/pgsql/10/data/pg_hba.conf
echo "[Service]" >> /usr/lib/systemd/system/gooderp.service
echo "Type=simple" >> /usr/lib/systemd/system/gooderp.service
echo "User=gooderp" >> /usr/lib/systemd/system/gooderp.service
echo "ExecStart=/home/gooderp/.pyenv/versions/2.7.14/bin/python /source_package/base/odoo-bin --addons-path=/source_package/gooderp_addons" >> /usr/lib/systemd/system/gooderp.service
echo "[Install]" >> /usr/lib/systemd/system/gooderp.service
echo "WantedBy=multi-user.targe" >> /usr/lib/systemd/system/gooderp.service
#让配置文件生效
sudo systemctl daemon-reload
#开机自启
sudo systemctl enable gooderp.service