You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.9 KiB
Plaintext

1 year ago
#!/bin/sh /etc/rc.common
START=99
get_config()
{
config_get_bool enable "$1" enable 0
}
config_qbittorrent()
{
local download_dir
local profile_dir
local port
local socks5_server
local socks5_port
local socks5_user
local socks5_pass
config_get download_dir "$1" "download_dir"
config_get port "$1" "port"
config_get socks5_server "$1" "socks5_server"
config_get socks5_port "$1" "socks5_port"
config_get socks5_user "$1" "socks5_user"
config_get socks5_pass "$1" "socks5_pass"
config_get profile_dir "$1" "profile_dir"
mkdir -p "$download_dir"
mkdir -p "$2" "$2/qBittorrent" "$2/qBittorrent/config"
{ [ "$2" != "/etc" ] && [ "$2" != "/etc/" ]; } && ln -sf "/etc/qBittorrent/ipfilter.dat" "$2/qBittorrent/ipfilter.dat"
if [ -f "$2/qBittorrent/config/qBittorrent.conf" ]; then
sed -i 's/WebUI\\Port=[0-9]*/WebUI\\Port='"$port"'/g' "$2/qBittorrent/config/qBittorrent.conf"
sed -i "/Downloads\\\SavePath/c\Downloads\\\SavePath=$download_dir" "$2/qBittorrent/config/qBittorrent.conf"
sed -i "/Proxy\\\IP/c\Proxy\\\IP=$socks5_server" "$2/qBittorrent/config/qBittorrent.conf"
sed -i "/Proxy\\\Port/c\Proxy\\\Port=$socks5_port" "$2/qBittorrent/config/qBittorrent.conf"
sed -i "/Proxy\\\Username/c\Proxy\\\Username=$socks5_user" "$2/qBittorrent/config/qBittorrent.conf"
sed -i "/Proxy\\\Password/c\Proxy\\\Password=$socks5_pass" "$2/qBittorrent/config/qBittorrent.conf"
else
cat >"$2/qBittorrent/config/qBittorrent.conf"<<EOF
[AutoRun]
enabled=false
program=
[BitTorrent]
Session\DefaultSavePath=/mnt/download
Session\IPFilter=/.config/qBittorrent/ipfilter.dat
Session\IPFilteringEnabled=false
Session\Port=15935
Session\ProxyPeerConnections=true
Session\QueueingSystemEnabled=true
Session\TrackerFilteringEnabled=false
[LegalNotice]
Accepted=true
[Network]
Cookies=@Invalid()
Proxy\IP=${socks5_server}
Proxy\OnlyForTorrents=true
Proxy\Password=${socks5_pass}
Proxy\Port=${socks5_port}
Proxy\Type=SOCKS5_PW
Proxy\Username=${socks5_user}
[Preferences]
Advanced\AutoBanUnknownPeer=true
Bittorrent\AutoUpdateTrackers=true
Bittorrent\CustomizeTrackersListUrl=https://trackerslist.com/all.txt
Downloads\SavePath=${download_dir}
General\Locale=en
IPFilter\Enabled=false
IPFilter\File=$2/qBittorrent/ipfilter.dat
IPFilter\FilterTracker=false
WebUI\CSRFProtection=false
WebUI\Port=${port}
EOF
fi
}
run_qbittorrent()
{
local enable
config_get_bool enable "$1" enable
if [ $enable ]; then
local profile_dir
config_get profile_dir "$1" profile_dir
config_foreach config_qbittorrent "qbittorrent" "$profile_dir"
if [ "$profile_dir" != "" ]; then
qbittorrent-nox -d --profile="$profile_dir"
else
echo "No profile_dir found, stop!"
fi
fi
}
start()
{
stop
local profile_path
config_load "qbittorrent"
config_foreach get_config "qbittorrent"
[ $enable -eq 0 ] && exit 0
config_foreach run_qbittorrent "qbittorrent"
}
stop()
{
killall "qbittorrent-nox" >/dev/null 2>&1
}