@hzl201
2017-03-08T18:52:47.000000Z
字数 3690
阅读 1733
树莓派
首次需要运行raspi-config,开启ssh。超频至800mhz,语言设置为en.us-utf8
sudo nano /etc/apt/sources.list #更改源,添加以下两行
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
sudo apt-get update #更新
sudo apt-get upgrade
参考:https://www.zybuluo.com/hzl201/note/84075
sudo mkdir /home/pi/download #创建下载文件夹
sudo chmod 777 /home/pi/download #修改下载文件夹的权限
sudo apt-get install transmission-daemon -y #安装transmission-daemon
sudo service transmission-daemon stop #停止运行
sudo cp /etc/transmission-daemon/settings.json /etc/transmission-daemon/settings.json.bak #备份配置文件
sudo nano /etc/transmission-daemon/settings.json #修改配置文件
sudo cp /home/pi/settings.json /etc/transmission-daemon/settings.json #或者把以前的配置文件复制过来
sudo usermod -a -G debian-transmission pi #配置Transmission的权限
sudo chmod 777 -R /var/lib/transmission-daemon #最好给Transmission设置最高权限
sudo service transmission-daemon reload #重启 transmission
sudo service transmission-daemon restart
安装 transmissionrpc
若想要FlexGet支持Transmission,必须安装TransmissionRPC库文件。
sudo apt-get -y install python-transmissionrpc
安装准备
sudo apt-get install python-setuptools
easy_install flexget
或
sudo pip install flexget
将以下代码保存为/home/pi/trans_cleanup.sh
#! /bin/bash
#====================================================================
# trans_cleanup.sh
#
# Copyright (c) 2011, WangYan <webmaster@wangyan.org>
# All rights reserved.
# Distributed under the GNU General Public License, version 3.0.
#
# Monitor disk space, If the Over, delete some files.
#
# See: http://wangyan.org/blog/trans_cleanup.html
#
# V0.2, since 2012-10-29
#====================================================================
# The transmission remote login username
USERNAME="hzl201"
# The transmission remote login password
PASSWORD="hzl63155680"
# The transmission download dir
DLDIR="/home/pi/download"
# The maximum allowed disk (%)
DISK_USED_MAX="80"
# Enable auto shutdown support (Disable=0, Enable=1)
ENABLE_AUTO_SHUTDOWN="0"
# Log path settings
LOG_PATH="/var/log/trans_cleanup.log"
# Date time format setting
DATA_TIME=$(date +"%y-%m-%d %H:%M:%S")
#====================================================================
dist_check()
{
DISK_USED=`df -h $DLDIR | grep -v Mounted | awk '{print $5}' | cut -d '%' -f 1`
DISK_OVER=`awk 'BEGIN{print('$DISK_USED'>'$DISK_USED_MAX')}'`
}
dist_check
if [ "$DISK_OVER" = "1" ];then
for i in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep 100% | grep Done | awk '{print $1}' | grep -v ID`
do
[ "$i" -gt "0" ] && echo -n "$DATA_TIME [Done] " >> $LOG_PATH
transmission-remote --auth $USERNAME:$PASSWORD -t $i --remove-and-delete >> $LOG_PATH 2>&1
[ "$i" -gt "0" ] && sleep 10 && dist_check
[ "$DISK_OVER" = "0" ] && break
done
fi
if [ "$DISK_OVER" = "1" ];then
for ii in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep Stopped | awk '{print $1}' | grep -v ID`
do
[ "$ii" -gt "0" ] && echo -n "$DATA_TIME [Stopped] " >> $LOG_PATH
transmission-remote --auth $USERNAME:$PASSWORD -t $ii --remove-and-delete >> $LOG_PATH 2>&1
[ "$ii" -gt "0" ] && sleep 10 && dist_check
[ "$DISK_OVER" = "0" ] && break
done
fi
if [ "$DISK_OVER" = "1" ];then
for iii in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep -v Sum | awk '{print $1}' | grep -v ID`
do
[ "$iii" -gt "0" ] && echo -n "$DATA_TIME [Up or Down] " >> $LOG_PATH
transmission-remote --auth $USERNAME:$PASSWORD -t $iii --remove-and-delete >> $LOG_PATH 2>&1
[ "$iii" -gt "0" ] && sleep 10 && dist_check
[ "$DISK_OVER" = "0" ] && break
done
fi
if [ "$DISK_OVER" = "1" ];then
rm -rf $DLDIR/*
fi
if [ "$ENABLE_AUTO_SHUTDOWN" = "1" ];then
SHUTDOWN=1
for STATUS in `transmission-remote --auth $USERNAME:$PASSWORD -l | awk '{print $9}'`
do
if [[ "$STATUS" = "Up" || "$STATUS" = "Uploading" ]];then
SHUTDOWN=0
fi
done
TASK_TOTAL=`transmission-remote --auth $USERNAME:$PASSWORD -l | grep -Ev '(ID|Sum)' | wc -l`
if [ "$TASK_TOTAL" -gt "0" ] && [ "$SHUTDOWN" -eq "1" ];then
echo -n "$DATA_TIME " >> $LOG_PATH
shutdown now >> $LOG_PATH 2>&1
fi
fi
sudo chmod 777 /home/pi/trans_cleanup.sh #添加运行权限
crontab -e
*/5 * * * * sh /home/pi/trans_cleanup.sh #设置自动执行