├── README.md ├── init.sh ├── install.sh ├── settings.json └── src.zip /README.md: -------------------------------------------------------------------------------- 1 | # Transmission-install-script 2 | 3 | ## 脚本说明 4 | 5 | - 脚本说明: Transmission最新版自动安装脚本 6 | - 系统支持: CentOS7 7 | - 使用方法: https://www.shkong.com/80.html 8 | - 项目地址: https://github.com/ishkong/Transmission-install-script 9 | 10 | ## 使用方法 11 | 12 | ``` bash 13 | wget -N --no-check-certificate https://raw.githubusercontent.com/ishkong/Transmission-install-script/master/install.sh && chmod +x install.sh && bash install.sh 14 | ``` 15 | -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################### 3 | # chkconfig: - 16 84 # 4 | # description: Start up transmission-daemon # 5 | # Shkong # 6 | # www.shkong.com # 7 | # processname: transmission-daemon # 8 | # config: /etc/sysconfig/transmission # 9 | # source function library 10 | . /etc/rc.d/init.d/functions 11 | # Get network config 12 | . /etc/sysconfig/network 13 | [ "${NETWORKING}" = "no" ] && exit 0 14 | # Defaults 15 | TRANSMISSION_HOME=/home/transmission 16 | DAEMON_USER="transmission" 17 | DAEMON_ARGS="-g $TRANSMISSION_HOME/.config/transmission" 18 | # Daemon 19 | NAME=transmission-daemon 20 | DAEMON=$(which $NAME) 21 | DAEMON_PIDFILE=/var/run/$NAME.pid 22 | DAEMON_LOCKFILE=/var/lock/subsys/$NAME 23 | DAEMON_SCRIPTNAME=/etc/init.d/$NAME 24 | DAEMON_LOGFILE=/var/log/$NAME.log 25 | [ -x "$DAEMON" ] || exit 0 26 | start() { 27 | echo -n $"Starting ${NAME}: " 28 | if [ -n "$TRANSMISSION_HOME" ]; then 29 | export TRANSMISSION_HOME 30 | fi 31 | su - $DAEMON_USER -c "$DAEMON $DAEMON_ARGS" 32 | sleep 2 33 | status $NAME &> /dev/null && echo_success || echo_failure 34 | RETVAL=$? 35 | if [ $RETVAL -eq 0 ]; then 36 | touch $DAEMON_LOCKFILE 37 | pidof -o %PPID -x $NAME > $DAEMON_PIDFILE 38 | fi 39 | echo 40 | } 41 | stop() { 42 | echo -n $"Shutting down ${NAME}: " 43 | killproc $NAME 44 | RETVAL=$? 45 | [ $RETVAL -eq 0 ] && /bin/rm -f $DAEMON_LOCKFILE $DAEMON_PIDFILE 46 | echo 47 | } 48 | case "$1" in 49 | start) 50 | start 51 | ;; 52 | stop) 53 | stop 54 | ;; 55 | restart) 56 | stop 57 | start 58 | ;; 59 | status) 60 | status $NAME 61 | ;; 62 | *) 63 | echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2 64 | exit 3 65 | ;; 66 | esac 67 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 3 | export PATH 4 | 5 | #================================================= 6 | # System Required: CentOS7 7 | # Description: Transmission for CentOS7 Auto-Install Script 8 | # Version: 1.0.6 9 | # Author: Shkong 10 | # Blog: https://www.shkong.com/80.html 11 | #================================================= 12 | 13 | sh_ver="1.0.6" 14 | Transmission_file="/usr/share/transmission" 15 | Transmission_conf="/home/transmission/.config/transmission/settings.json" 16 | Now_username="Shkong" 17 | Now_password="DefaultPassword" 18 | Now_port="9417" 19 | 20 | Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" 21 | Info="${Green_font_prefix}[信息]${Font_color_suffix}" 22 | Error="${Red_font_prefix}[错误]${Font_color_suffix}" 23 | Tip="${Green_font_prefix}[注意]${Font_color_suffix}" 24 | 25 | #检查ROOT权限 26 | check_root(){ 27 | [[ $EUID != 0 ]] && echo -e "${Error} 当前非ROOT账号(或没有ROOT权限),无法继续操作,请更换ROOT账号或使用 ${Green_background_prefix}sudo su${Font_color_suffix} 命令获取临时ROOT权限(执行后可能会提示输入当前账号的密码)。" && exit 1 28 | } 29 | #检查Transmission安装状态 30 | check_installed_status(){ 31 | [[ ! -e ${Transmission_file} ]] && echo -e "${Error} Transmission 没有安装,请检查 !" && exit 1 32 | } 33 | #检查Transmission运行状态 34 | check_pid(){ 35 | PID=`ps -ef| grep "transmission-da"| grep -v "grep" | grep -v ".sh"| grep -v "init.d" |grep -v "service" |awk '{print $2}'` 36 | } 37 | check_ver_comparison(){ 38 | check_pid 39 | [[ ! -z $PID ]] && kill -9 ${PID} 40 | rm -rf ${Transmission_file} 41 | Download_Transmission 42 | Start_Transmission 43 | } 44 | #检查Transmission最新版本 45 | check_new_ver(){ 46 | echo -e "${Info} 请输入 Transmission 版本号,格式如:[ 2.94 ],获取地址:[ https://github.com/transmission/transmission/releases ]" 47 | read -e -p "默认回车自动获取最新版本号:" transmission_new_ver 48 | if [[ -z ${transmission_new_ver} ]]; then 49 | transmission_new_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/transmission/transmission/releases | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g') 50 | if [[ -z ${transmission_new_ver} ]]; then 51 | echo -e "${Error} Transmission 最新版本获取失败,请手动获取最新版本号[ https://github.com/transmission/transmission/releases ]" 52 | read -e -p "请输入版本号 [ 格式如 2.94 ] :" transmission_new_ver 53 | [[ -z "${transmission_new_ver}" ]] && echo "取消..." && exit 1 54 | else 55 | echo -e "${Info} 检测到 Transmission 最新版本为 [ ${transmission_new_ver} ]" 56 | fi 57 | else 58 | echo -e "${Info} 即将准备下载 Transmission 版本为 [ ${transmission_new_ver} ]" 59 | fi 60 | } 61 | #下载Transmission版本 62 | Download_Transmission(){ 63 | check_new_ver 64 | wget -c --no-check-certificate https://github.com/transmission/transmission-releases/raw/master/transmission-${transmission_new_ver}.tar.xz 65 | tar -Jxf transmission-${transmission_new_ver}.tar.xz 66 | cd transmission-${transmission_new_ver} 67 | ./configure --prefix=/usr 68 | make && make install 69 | cd .. 70 | } 71 | Set_Config(){ 72 | if [[ -e ${Transmission_conf} ]]; then 73 | Now_username = $(grep -Po 'rpc-username[" :]+\K[^"]+' ${Transmission_conf}) 74 | Now_password = $(grep -Po 'rpc-password[" :]+\K[^"]+' ${Transmission_conf}) 75 | Now_port = $(grep -Po 'rpc-port[" :]+\K[^"]+' ${Transmission_conf}) 76 | fi 77 | read -e -p "${Info} 请输入新的控制面板用户名(当前:${Now_username}):" rpc_username 78 | read -e -p "${Info} 请输入新的控制面板密码(当前:${Now_password}):" rpc_password 79 | read -e -p "${Info} 请输入新的控制面板端口(当前:${Now_port}):" Port 80 | } 81 | Service_Transmission(){ 82 | useradd -m transmission 83 | passwd -d transmission 84 | if ! wget -c --no-check-certificate https://raw.githubusercontent.com/ishkong/Transmission-install-script/master/init.sh -O /etc/init.d/transmissiond; then 85 | echo -e "${Error} Transmission服务 管理脚本下载失败 !" && rm -rf /etc/init.d/transmissiond && exit 1 86 | fi 87 | chmod +x /etc/init.d/transmissiond 88 | chkconfig --add transmissiond 89 | chkconfig --level 2345 transmissiond on 90 | echo -e "${Info} Transmission服务 管理脚本下载完成 !" 91 | mkdir -p /home/transmission/Downloads/ 92 | chmod g+w /home/transmission/Downloads/ 93 | mkdir -p /home/transmission/.config/transmission/ 94 | if ! wget -c --no-check-certificate https://raw.githubusercontent.com/ishkong/Transmission-install-script/master/settings.json -O /home/transmission/.config/transmission/settings.json; then 95 | echo -e "${Error} Transmission服务 配置文件下载失败 !" && rm -rf /home/transmission/.config/transmission/settings.json && exit 1 96 | fi 97 | sed -i 's/Shkong/'${rpc_username}'/g' /home/transmission/.config/transmission/settings.json 98 | sed -i 's/DefaultPassword/'${rpc_password}'/g' /home/transmission/.config/transmission/settings.json 99 | sed -i 's/9417/'${Port}'/g' /home/transmission/.config/transmission/settings.json 100 | chown -R transmission.transmission /home/transmission/ 101 | cd /usr/share/transmission/web/ 102 | wget -c --no-check-certificate https://raw.githubusercontent.com/ishkong/Transmission-install-script/master/src.zip 103 | rm -f index.html 104 | unzip -o src.zip 105 | iptables -t nat -F 106 | iptables -t nat -X 107 | iptables -t nat -P PREROUTING ACCEPT 108 | iptables -t nat -P POSTROUTING ACCEPT 109 | iptables -t nat -P OUTPUT ACCEPT 110 | iptables -t mangle -F 111 | iptables -t mangle -X 112 | iptables -t mangle -P PREROUTING ACCEPT 113 | iptables -t mangle -P INPUT ACCEPT 114 | iptables -t mangle -P FORWARD ACCEPT 115 | iptables -t mangle -P OUTPUT ACCEPT 116 | iptables -t mangle -P POSTROUTING ACCEPT 117 | iptables -F 118 | iptables -X 119 | iptables -P FORWARD ACCEPT 120 | iptables -P INPUT ACCEPT 121 | iptables -P OUTPUT ACCEPT 122 | iptables -t raw -F 123 | iptables -t raw -X 124 | iptables -t raw -P PREROUTING ACCEPT 125 | iptables -t raw -P OUTPUT ACCEPT 126 | service iptables save 127 | } 128 | Installation_dependency(){ 129 | yum clean all 130 | yum -y update 131 | yum -y install wget screen xz gcc git gcc-c++ m4 make automake libtool gettext openssl-devel pkgconfig perl-libwww-perl perl-XML-Parser curl curl-devel vsftpd libevent-devel libevent libidn-devel zlib-devel intltool unzip which 132 | cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 133 | rm -rf /home/transmission 134 | rm -rf /usr/share/transmission 135 | mkdir /home/transmission 136 | wget -c --no-check-certificate https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz 137 | tar -zxvf libevent-2.1.10-stable.tar.gz 138 | cd libevent-2.1.10-stable 139 | ./configure --prefix=/usr 140 | make && make install 141 | ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5 142 | echo "安装libevent完毕!当前libevent版本:2.1.10" 143 | cd .. 144 | } 145 | Install_Transmission(){ 146 | [[ -e ${Transmission_file} ]] && echo -e "${Error} 检测到 Transmission 已安装 !" && exit 1 147 | echo -e "${Info} 开始安装/配置 依赖..." 148 | Installation_dependency 149 | echo -e "${Info} 开始下载/安装..." 150 | Download_Transmission 151 | echo -e "${Info} 开始下载/安装 服务脚本(init)..." 152 | Set_Config 153 | Service_Transmission 154 | echo -e "${Info} 开始设置 iptables防火墙..." 155 | Set_iptables 156 | echo -e "${Info} 开始添加 iptables防火墙规则..." 157 | Add_iptables 158 | echo -e "${Info} 开始保存 iptables防火墙规则..." 159 | Save_iptables 160 | echo -e "${Info} 所有步骤 安装完毕,开始启动..." 161 | Start_Transmission 162 | } 163 | Remove_Transmission(){ 164 | [[ ! -e ${Transmission_file} ]] && echo -e "${Error} 检测到 Transmission 已安装 !" && exit 1 165 | Stop_Transmission 166 | echo -e "${Info} 开始卸载..." 167 | rm -rf /etc/init.d/transmissiond 168 | rm -rf /home/transmission/.config/transmission/settings.json 169 | rm -rf /home/transmission/ 170 | rm -rf /usr/share/transmission/ 171 | userdel transmission --force 172 | echo -e "${Info} 卸载完毕 !" 173 | } 174 | Start_Transmission(){ 175 | check_installed_status 176 | check_pid 177 | [[ ! -z ${PID} ]] && echo -e "${Error} Transmission 正在运行,请检查 !" && exit 1 178 | service transmissiond start 179 | sleep 1s 180 | } 181 | Stop_Transmission(){ 182 | check_installed_status 183 | check_pid 184 | [[ -z ${PID} ]] && echo -e "${Error} Transmission 没有运行,请检查 !" && exit 1 185 | service transmissiond stop 186 | } 187 | Restart_Transmission(){ 188 | check_installed_status 189 | check_pid 190 | [[ ! -z ${PID} ]] && service transmissiond stop 191 | service transmissiond start 192 | sleep 1s 193 | check_pid 194 | [[ ! -z ${PID} ]] && View_Transmission 195 | } 196 | Add_iptables(){ 197 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${Port} -j ACCEPT 198 | iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${Port} -j ACCEPT 199 | } 200 | Save_iptables(){ 201 | service iptables save 202 | } 203 | Set_iptables(){ 204 | service iptables save 205 | chkconfig --level 2345 iptables on 206 | } 207 | Change_Config(){ 208 | Stop_Transmission 209 | Set_Config 210 | sed -i 's/'${Now_username}'/'${rpc_username}'/g' /home/transmission/.config/transmission/settings.json 211 | sed -i 's/'${Now_password}'/'${rpc_password}'/g' /home/transmission/.config/transmission/settings.json 212 | sed -i 's/'${Now_port}'/'${Port}'/g' /home/transmission/.config/transmission/settings.json 213 | Start_Transmission 214 | echo "${Info} 配置更换完成!" 215 | } 216 | 217 | echo && echo -e " Transmission 一键管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} 218 | ---- Shkong | shkong.com/80.html ---- 219 | 220 | ———————————— 221 | ${Green_font_prefix} 1.${Font_color_suffix} 安装 Transmission 222 | ${Green_font_prefix} 2.${Font_color_suffix} 卸载 Transmission 223 | ———————————— 224 | ${Green_font_prefix} 3.${Font_color_suffix} 启动 Transmission 225 | ${Green_font_prefix} 4.${Font_color_suffix} 停止 Transmission 226 | ${Green_font_prefix} 5.${Font_color_suffix} 重启 Transmission 227 | ———————————— 228 | ${Green_font_prefix} 6.${Font_color_suffix} 更改 Transmission 配置 229 | ————————————" && echo 230 | if [[ -e ${Transmission_file} ]]; then 231 | check_pid 232 | if [[ ! -z "${PID}" ]]; then 233 | echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" 234 | else 235 | echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" 236 | fi 237 | else 238 | echo -e " 当前状态: ${Red_font_prefix}未安装${Font_color_suffix}" 239 | fi 240 | echo 241 | stty erase '^H' && read -p " 请输入数字 [1-6]:" num 242 | case "$num" in 243 | 1) 244 | Install_Transmission 245 | ;; 246 | 2) 247 | Remove_Transmission 248 | ;; 249 | 3) 250 | Start_Transmission 251 | ;; 252 | 4) 253 | Stop_Transmission 254 | ;; 255 | 5) 256 | Restart_Transmission 257 | ;; 258 | 6) 259 | Change_Config 260 | ;; 261 | *) 262 | echo "请输入正确数字 [1-6]" 263 | ;; 264 | esac 265 | -------------------------------------------------------------------------------- /settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "alt-speed-down": 50, 3 | "alt-speed-enabled": false, 4 | "alt-speed-time-begin": 540, 5 | "alt-speed-time-day": 127, 6 | "alt-speed-time-enabled": false, 7 | "alt-speed-time-end": 1020, 8 | "alt-speed-up": 50, 9 | "bind-address-ipv4": "0.0.0.0", 10 | "bind-address-ipv6": "::", 11 | "blocklist-enabled": false, 12 | "blocklist-url": "http://www.example.com/blocklist", 13 | "cache-size-mb": 2, 14 | "dht-enabled": true, 15 | "download-dir": "/home/transmission/Downloads", 16 | "download-queue-enabled": false, 17 | "download-queue-size": 5, 18 | "encryption": 1, 19 | "idle-seeding-limit": 30, 20 | "idle-seeding-limit-enabled": false, 21 | "incomplete-dir": "/home/transmission/Downloads", 22 | "incomplete-dir-enabled": false, 23 | "lpd-enabled": true, 24 | "message-level": 2, 25 | "peer-congestion-algorithm": "", 26 | "peer-id-ttl-hours": 6, 27 | "peer-limit-global": 2000, 28 | "peer-limit-per-torrent": 1500, 29 | "peer-port": 22222, 30 | "peer-port-random-high": 65535, 31 | "peer-port-random-low": 20000, 32 | "peer-port-random-on-start": false, 33 | "peer-socket-tos": "default", 34 | "pex-enabled": true, 35 | "port-forwarding-enabled": true, 36 | "preallocation": 1, 37 | "prefetch-enabled": 1, 38 | "queue-stalled-enabled": true, 39 | "queue-stalled-minutes": 30, 40 | "ratio-limit": 2, 41 | "ratio-limit-enabled": false, 42 | "rename-partial-files": true, 43 | "rpc-authentication-required": true, 44 | "rpc-bind-address": "0.0.0.0", 45 | "rpc-enabled": true, 46 | "rpc-password": "DefaultPassword", 47 | "rpc-port": 9417, 48 | "rpc-url": "/web/", 49 | "rpc-username": "Shkong", 50 | "rpc-whitelist": "127.0.0.1", 51 | "rpc-whitelist-enabled": false, 52 | "scrape-paused-torrents-enabled": true, 53 | "script-torrent-done-enabled": false, 54 | "script-torrent-done-filename": "", 55 | "seed-queue-enabled": false, 56 | "seed-queue-size": 10, 57 | "speed-limit-down": 100, 58 | "speed-limit-down-enabled": false, 59 | "speed-limit-up": 100, 60 | "speed-limit-up-enabled": false, 61 | "start-added-torrents": true, 62 | "trash-original-torrent-files": false, 63 | "umask": 0, 64 | "upload-slots-per-torrent": 50, 65 | "utp-enabled": true 66 | } 67 | -------------------------------------------------------------------------------- /src.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ishkong/Transmission-install-script/6da73e8150ac19b1ee2bc9683816bc40ddea95db/src.zip --------------------------------------------------------------------------------