#!/usr/bin/env bash

git config core.ignorecase false

chmod 777 /app/data/tmp -R

service crond restart
hostname=`hostname`
domain=`php /app/bin/tools.php getDomain`
port=`php /app/bin/tools.php getPort`
#初始化统计数据
curl -s http://${domain}:${port}/v2/tools/init?key=statistics
#初始化报表
curl -s http://${domain}:${port}/v2/tools/init?key=report
#初始化票据
curl -s http://${domain}:${port}/v2/tools/init?key=bill
#初始化公司账户成功
curl -s http://${domain}:${port}/v2/tools/report-forms-data-init?key=reportAccount
#初始化销售单票据金额
curl -s http://${domain}:${port}/v2/tools/report-forms-data-init?key=billAmount
#初始化管理员权限
curl -s http://${domain}:${port}/v2/tools/init?key=rule
#初始化管理员权限
curl -s http://${domain}:${port}/v2/tools/report-forms-data-init?key=2019-02-14
#财务报表数据
curl -s http://${domain}:${port}/v2/tools/report-calculation?key=statement
#仓库报表数据
curl -s http://${domain}:${port}/v2/tools/report-calculation?key=inventory
#加工进仓报表数据
curl -s http://${domain}:${port}/v2/tools/report-calculation?key=processIn
#加工进度出仓报表数据
curl -s http://${domain}:${port}/v2/tools/report-calculation?key=processOut
#开票收票报表数据
curl -s http://${domain}:${port}/v2/tools/report-calculation?key=ticket
#初始化管理员权限
curl -s http://${domain}:${port}/v2/tools/report-forms-data-init?key=init_admin_rule
#更新产品库模板
curl -s http://${domain}:${port}/v2/tools/report-forms-data-init?key=product_template_update
#订单事务更新
curl -s http://${domain}:${port}/v2/tools/report-forms-data-init?key=order_affair_update

#安装wkhtmltopdf
if [ ! -x "$(command -v wkhtmltopdf)"  ]; then
    yum install -y urw-fonts libXext openssl-devel libXrender
    wget -O /usr/share/fonts/simsun.ttc  http://mi.lacecdn.com/docker/simsun.ttc
    wget -O /usr/share/fonts/simfang.ttf  http://mi.lacecdn.com/docker/simfang.ttf
    wget -O /tmp/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz http://mi.lacecdn.com/docker/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
    cd /tmp
    tar xvfJ wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
    rm -rf /usr/local/wkhtmltox
    mv wkhtmltox /usr/local/
    chmod +x /usr/local/wkhtmltox/bin/wkhtmltopdf
    chmod +x /usr/local/wkhtmltox/bin/wkhtmltoimage
    ln -sf /usr/local/wkhtmltox/bin/wkhtmltopdf /usr/bin/wkhtmltopdf
    ln -sf /usr/local/wkhtmltox/bin/wkhtmltoimage /usr/bin/wkhtmltoimage
    rm -rf /tmp/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
fi

sed -i 's/^max_allowed_packet = 1M/max_allowed_packet = 16M/' /etc/my.cnf

if [ ! -f /etc/init.d/redis ];then
    wget -O /etc/init.d/redis http://mi.lacecdn.com/docker/init.d.redis
    chmod +x /etc/init.d/redis
    service redis start
    chkconfig redis on
fi