#! /bin/bash SOFT_NAME="qBittorrent" QBITTORENT_DIR="/root/.config/qBittorrent" QBITTORENT_CONF="$QBITTORENT_DIR/qBittorrent.conf" QBITTORENT_SCRIPT_DIR="$QBITTORENT_DIR/script" WEBUI_PROT=2020 QBITTORENT_DL_DIR="/root/Download" RCLONEDIR="/root/.config/rclone" Info_font_prefix="\033[32m" && Error_font_prefix="\033[31m" && Info_background_prefix="\033[42;37m" && Error_background_prefix="\033[41;37m" && Font_suffix="\033[0m" source /etc/os-release &>/dev/null check_system(){ KernelBit="$(getconf LONG_BIT)" if [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]];then echo -e "${Info_font_prefix}[信息]${Font_suffix} 当前系统为 Debian ${VERSION_ID} " #elif [[ "${ID}" == "ubuntu" && `echo "${VERSION_ID}" | cut -d '.' -f1` -ge 16 ]];then # echo -e "${Info_font_prefix}[信息]${Font_suffix} 当前系统为 Ubuntu ${VERSION_ID} " else echo -e "${Error_font_prefix}[错误]${Font_suffix} 当前系统为不在支持的系统列表内,安装中断" exit 1 fi } init_install(){ stty erase '^H' && read -p "请输入想安装的 $SOFT_NAME 版本(defatult:4.1.5,4.2.0以下(不包括4.2.0)):" qb_ver if [ ! -n "$qb_ver" ]; then qb_ver="4.1.5" fi qb_ver_sub=$qb_ver if [ ${#qb_ver} -gt 5 ]; then qb_ver_sub=${qb_ver:0:5} elif [ ${#qb_ver} -lt 5 ]; then echo -e "${Error_font_prefix}[错误]${Font_suffix} $SOFT_NAME 版本输入有误!" exit 1 fi qb_ver_code=${qb_ver_sub//.} if [ ${qb_ver_code} -gt 419 ]; then echo -e "${Error_font_prefix}[错误]${Font_suffix} 最高只支持编译安装 ${SOFT_NAME} 4.1.9.1" exit 1 fi read -p "是否安装 Fclone 进行数据上传(y/n,defatult:y):" fcloned if [ ! -n "$fcloned" ]; then fcloned="y" fi if [ $fcloned == y ]; then read -p "是否安装还原Fclone配置(y/n,defatult:y):" restoreFclone if [[ $restoreFclone != n ]]; then restoreFclone=y fi if [[ $restoreFclone == y ]]; then read -p "请输入备份包链接(.zip):" restorePath if [[ $restorePath != *.zip ]]; then echo -e "${Error_font_prefix}[错误]${Font_suffix} 备份包地址输入错误!" exit 1 fi fi fi } install_fclone(){ if [ $fcloned == y ] ;then echo -e "${Info_font_prefix}[信息]${Font_suffix} fclone 开始安装..." bash <(wget -qO- https://git.io/JJYE0) if [ $restoreFclone == y ]; then workDir="/root/fcloneTemp" mkdir "${workDir}" wget --no-check-certificate -c -q $restorePath -O configs.zip unzip -q -o configs.zip && rm -rf configs.zip mkdir -p "$RCLONEDIR" cp -r -p ${workDir}/. $RCLONEDIR/. rm -rf ${workDir} fi echo -e "${Info_font_prefix}[信息]${Font_suffix} fclone 安装结束。" fi } install_common_lib(){ apt-get -yqq update; apt-get -yqq upgrade; \ apt-get -y install wget zip unzip ca-certificates libboost-dev libboost-system-dev build-essential \ libboost-chrono-dev libboost-random-dev libssl-dev libgeoip-dev \ pkg-config automake libtool \ python geoip-database zlib1g-dev } install_qb(){ echo -e "${Info_font_prefix}[信息]${Font_suffix} $SOFT_NAME 开始安装..." cd ~ if [ ${VERSION_ID} -eq 8 ]; then install_common_lib echo "deb http://deb.debian.org/debian stretch main" >> /etc/apt/sources.list apt-get update apt-get install -y qtbase5-dev qttools5-dev-tools sed -i '$d' /etc/apt/sources.list apt-get update elif [ ${VERSION_ID} -gt 8 ]; then install_common_lib apt-get install -y qtbase5-dev qttools5-dev-tools else echo -e "${Error_font_prefix}[错误]${Font_suffix} 当前系统为不在支持的系统列表内,安装中断" exit 1 fi libtorrent_link="https://github.com/arvidn/libtorrent/releases/download/libtorrent-1_1_13/libtorrent-rasterbar-1.1.13.tar.gz" wget --no-check-certificate -c -q ${libtorrent_link} tar zxvf libtorrent-*.tar.gz && rm -rf libtorrent-*.tar.gz && cd libtorrent-* ./configure --disable-debug --enable-encryption --with-libgeoip=system CXXFLAGS=-std=c++11 make -j$(nproc) && make install ldconfig cd ~ wget -c -q https://github.com/qbittorrent/qBittorrent/archive/release-${qb_ver}.tar.gz tar zxvf release-*.tar.gz && rm -rf release-*.tar.gz && cd qBittorrent-* ./configure --disable-gui --disable-debug make -j$(nproc) && make install mkdir -p "$QBITTORENT_DIR" mkdir -p "$QBITTORENT_SCRIPT_DIR" mkdir -p "$QBITTORENT_DL_DIR" echo "[LegalNotice] Accepted=true [Preferences] WebUI\Port=$WEBUI_PROT General\Locale=zh " > "$QBITTORENT_CONF" cd "$QBITTORENT_SCRIPT_DIR" wget -qN --no-check-certificate "https://github.com/Godcic/script_center/raw/main/qBittorrent/copy2gd.sh" wget -qN --no-check-certificate "https://github.com/Godcic/script_center/raw/main/qBittorrent/move2gd.sh" wget -qN --no-check-certificate "https://github.com/Godcic/script_center/raw/main/qBittorrent/allupload.sh" wget -qN --no-check-certificate "https://github.com/Godcic/script_center/raw/main/qBittorrent/upload_files.sh" touch upload_files_names.conf chmod +x ./*.sh cd ~ rm -rf libtorrent-* rm -rf qBittorrent-* echo "[Unit] Description=qBittorrent Daemon Service After=network.target [Service] Type=forking ExecStart=/usr/local/bin/qbittorrent-nox -d ExecStop=/usr/bin/killall -w -s 9 /usr/local/bin/qbittorrent-nox TimeoutSec=300 Restart=always RestartSec=10 [Install] WantedBy=multi-user.target" > /etc/systemd/system/qbittorrent.service systemctl daemon-reload systemctl enable qbittorrent.service systemctl start qbittorrent.service echo -e "${Info_font_prefix}[信息]${Font_suffix} $SOFT_NAME 安装结束。 默认的WebUI:http://服务器IP:$WEBUI_PROT/ 默认用户名:admin 默认密码:adminadmin 请在控制台运行 qbittorrent-nox 并同意协议。" } main(){ check_system init_install install_qb install_fclone } main