mdserver-web/plugins/webstats/install.sh

159 lines
5.0 KiB
Bash
Raw Permalink Normal View History

2022-07-18 13:54:10 -04:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
2023-11-17 12:04:50 -05:00
export PATH=$PATH:/opt/homebrew/bin
2022-07-18 13:54:10 -04:00
## https://www.yangshuaibin.com/detail/392251
2023-11-17 12:50:21 -05:00
# cd /www/server/mdserver-web/plugins/webstats && bash install.sh install 0.2.5
2025-04-13 04:04:55 -04:00
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/webstats && bash install.sh install 0.2.5
2022-07-18 13:54:10 -04:00
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
VERSION=$2
2022-07-18 23:59:11 -04:00
sys_os=`uname`
2023-01-04 08:24:40 -05:00
HTTP_PREFIX="https://"
2023-03-20 00:19:35 -04:00
LOCAL_ADDR=common
2023-09-17 11:22:56 -04:00
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then
2023-03-20 00:19:35 -04:00
LOCAL_ADDR=cn
2023-11-17 12:50:21 -05:00
HTTP_PREFIX="https://"
2023-01-04 08:24:40 -05:00
fi
2023-03-20 00:19:35 -04:00
PIPSRC="https://pypi.python.org/simple"
if [ "$LOCAL_ADDR" != "common" ];then
PIPSRC="https://pypi.tuna.tsinghua.edu.cn/simple"
fi
2022-07-18 23:59:11 -04:00
if [ "$sys_os" == "Darwin" ];then
BAK='_bak'
else
BAK=''
fi
2022-07-18 13:54:10 -04:00
2022-07-26 12:08:01 -04:00
if [ -f ${rootPath}/bin/activate ];then
source ${rootPath}/bin/activate
fi
2022-10-22 10:57:04 -04:00
get_latest_release() {
curl -sL "https://api.github.com/repos/$1/releases/latest" | grep '"tag_name":' | cut -d'"' -f4
}
2022-07-18 13:54:10 -04:00
Install_App()
{
2023-11-17 12:51:11 -05:00
echo '正在安装脚本文件...'
2022-07-18 13:54:10 -04:00
mkdir -p $serverPath/source/webstats
mkdir -p $serverPath/webstats
# 下载源码安装包
# curl -O $serverPath/source/webstats/lua-5.1.5.tar.gz https://www.lua.org/ftp/lua-5.1.5.tar.gz
# cd $serverPath/source/webstats && tar xvf lua-5.1.5.tar.gz
# cd lua-5.1.5
# make linux test && make install
# luarocks
if [ ! -f $serverPath/source/webstats/luarocks-3.5.0.tar.gz ];then
2022-07-23 13:03:23 -04:00
wget --no-check-certificate -O $serverPath/source/webstats/luarocks-3.5.0.tar.gz http://luarocks.org/releases/luarocks-3.5.0.tar.gz
2022-07-18 13:54:10 -04:00
fi
2023-11-17 12:50:21 -05:00
if [ ! -d $serverPath/source/webstats/luarocks-3.5.0 ];then
cd $serverPath/source/webstats && tar xvf luarocks-3.5.0.tar.gz
2022-07-18 13:54:10 -04:00
fi
2023-11-17 12:50:21 -05:00
cd $serverPath/source/webstats/luarocks-3.5.0 && ./configure --prefix=$serverPath/webstats/luarocks \
--with-lua-include=$serverPath/openresty/luajit/include/luajit-2.1 \
--with-lua-bin=$serverPath/openresty/luajit/bin
make -I${serverPath}/openresty/luajit/bin
2025-04-13 04:04:55 -04:00
make install
2022-07-18 13:54:10 -04:00
2025-04-13 04:04:55 -04:00
if [ ! -f $serverPath/source/webstats/lsqlite3_v096.zip ];then
2025-08-21 04:54:51 -04:00
wget --no-check-certificate -O $serverPath/source/webstats/lsqlite3_v096.zip https://github.com/midoks/mdserver-web/releases/download/0.18.4/lsqlite3_v096.zip
2023-11-17 12:50:21 -05:00
fi
2025-04-13 04:04:55 -04:00
if [ ! -d $serverPath/source/webstats/lsqlite3_v096 ];then
cd $serverPath/source/webstats && unzip lsqlite3_v096.zip
2022-07-18 13:54:10 -04:00
fi
2025-04-13 04:04:55 -04:00
2022-07-18 23:59:11 -04:00
PATH=${serverPath}/openresty/luajit:${serverPath}/openresty/luajit/include/luajit-2.1:$PATH
export PATH=$PATH:$serverPath/webstats/luarocks/bin
2022-07-26 12:08:01 -04:00
if [ ! -f $serverPath/webstats/lua/lsqlite3.so ];then
if [ "${sys_os}" == "Darwin" ];then
2025-04-13 04:04:55 -04:00
cd $serverPath/source/webstats/lsqlite3_v096
2022-07-26 12:08:01 -04:00
# SQLITE_DIR=/usr/local/Cellar/sqlite/3.36.0
2023-11-17 12:50:21 -05:00
BREW_DIR=`which brew`
BREW_DIR=${BREW_DIR/\/bin\/brew/}
echo "BREW_DIR:"${BREW_DIR}
2022-07-26 12:08:01 -04:00
find_cfg=`cat Makefile | grep 'SQLITE_DIR'`
if [ "$find_cfg" == "" ];then
2023-11-17 12:50:21 -05:00
LIB_SQLITE_DIR=`brew info sqlite | grep ${BREW_DIR}/Cellar/sqlite | cut -d \ -f 1 | awk 'END {print}'`
echo "LIB_SQLITE_DIR:"${LIB_SQLITE_DIR}
2022-07-26 12:08:01 -04:00
sed -i $BAK "s#\$(ROCKSPEC)#\$(ROCKSPEC) SQLITE_DIR=${LIB_SQLITE_DIR}#g" Makefile
fi
make
else
2025-04-13 04:04:55 -04:00
cd $serverPath/source/webstats/lsqlite3_v096 && make
2022-07-18 23:59:11 -04:00
fi
fi
2022-07-18 13:54:10 -04:00
2022-07-18 23:59:11 -04:00
# copy to code path
2022-07-19 11:02:05 -04:00
DEFAULT_DIR=$serverPath/webstats/luarocks/lib/lua/5.1
if [ -f ${DEFAULT_DIR}/lsqlite3.so ];then
2022-07-23 13:04:47 -04:00
mkdir -p $serverPath/webstats/lua
2022-07-19 11:02:05 -04:00
cp -rf ${DEFAULT_DIR}/lsqlite3.so $serverPath/webstats/lua/lsqlite3.so
2022-07-18 23:59:11 -04:00
fi
2022-07-18 13:54:10 -04:00
2022-07-26 12:08:59 -04:00
# https://github.com/P3TERX/GeoLite.mmdb
2023-03-20 00:19:35 -04:00
pip install geoip2 -i $PIPSRC
2022-10-22 10:57:04 -04:00
# if [ ! -f $serverPath/webstats/GeoLite2-City.mmdb ];then
# wget --no-check-certificate -O $serverPath/webstats/GeoLite2-City.mmdb https://github.com/P3TERX/GeoLite.mmdb/releases/download/2022.10.16/GeoLite2-City.mmdb
# fi
2022-10-16 12:44:04 -04:00
# 缓存数据
2022-10-22 10:57:04 -04:00
GEO_VERSION=$(get_latest_release "P3TERX/GeoLite.mmdb")
2025-07-16 03:29:21 -04:00
if [ ! -s $serverPath/source/webstats/GeoLite2-City.mmdb ];then
2023-11-17 12:50:21 -05:00
if [ "$LOCAL_ADDR" == "cn" ];then
2023-11-30 22:43:31 -05:00
wget --no-check-certificate -O $serverPath/source/webstats/GeoLite2-City.mmdb https://dl.midoks.icu/soft/webstats/GeoLite2-City.mmdb
2023-11-17 12:50:21 -05:00
else
wget --no-check-certificate -O $serverPath/source/webstats/GeoLite2-City.mmdb https://github.com/P3TERX/GeoLite.mmdb/releases/download/${GEO_VERSION}/GeoLite2-City.mmdb
fi
2022-10-22 10:57:04 -04:00
fi
2022-07-26 11:49:16 -04:00
2025-07-16 03:29:54 -04:00
if [ -s $serverPath/source/webstats/GeoLite2-City.mmdb ];then
2022-10-22 10:57:04 -04:00
cp -rf $serverPath/source/webstats/GeoLite2-City.mmdb $serverPath/webstats/GeoLite2-City.mmdb
fi
2024-12-11 05:56:37 -05:00
2024-11-23 16:10:19 -05:00
cd $rootPath && python3 plugins/webstats/index.py start
2024-12-11 05:56:37 -05:00
echo "${VERSION}" > $serverPath/webstats/version.pl
2022-12-21 09:28:40 -05:00
2023-11-17 12:51:11 -05:00
echo '网站统计安装完成'
2024-12-11 05:56:37 -05:00
2022-12-21 09:28:40 -05:00
# delete install data
2025-04-13 04:04:55 -04:00
if [ -d $serverPath/source/webstats/lsqlite3_v096 ];then
rm -rf $serverPath/source/webstats/lsqlite3_v096
2023-11-17 12:50:21 -05:00
fi
if [ -d $serverPath/source/webstats/luarocks-3.5.0 ];then
rm -rf $serverPath/source/webstats/luarocks-3.5.0
fi
2022-07-18 13:54:10 -04:00
}
Uninstall_App()
{
2024-11-23 16:18:34 -05:00
cd $rootPath && python3 plugins/webstats/index.py stop
2022-07-18 13:54:10 -04:00
rm -rf $serverPath/webstats
2023-11-17 12:51:25 -05:00
echo "网站统计卸载完成"
2022-07-18 13:54:10 -04:00
}
action=$1
if [ "${1}" == 'install' ];then
Install_App
else
Uninstall_App
fi