[关闭]
@hzl201 2017-03-08T18:52:47.000000Z 字数 3690 阅读 1733

树莓派系统初始化

树莓派


首次需要运行raspi-config,开启ssh。超频至800mhz,语言设置为en.us-utf8

修改为阿里源

  1. sudo nano /etc/apt/sources.list #更改源,添加以下两行
  2. deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
  3. deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
  4. sudo apt-get update #更新
  5. sudo apt-get upgrade

修改时区

参考:https://www.zybuluo.com/hzl201/note/84075

安装transmission-daemon

  1. sudo mkdir /home/pi/download #创建下载文件夹
  2. sudo chmod 777 /home/pi/download #修改下载文件夹的权限
  3. sudo apt-get install transmission-daemon -y #安装transmission-daemon
  4. sudo service transmission-daemon stop #停止运行
  5. sudo cp /etc/transmission-daemon/settings.json /etc/transmission-daemon/settings.json.bak #备份配置文件
  6. sudo nano /etc/transmission-daemon/settings.json #修改配置文件
  7. sudo cp /home/pi/settings.json /etc/transmission-daemon/settings.json #或者把以前的配置文件复制过来
  8. sudo usermod -a -G debian-transmission pi #配置Transmission的权限
  9. sudo chmod 777 -R /var/lib/transmission-daemon #最好给Transmission设置最高权限
  10. sudo service transmission-daemon reload #重启 transmission
  11. sudo service transmission-daemon restart

安装flexget

安装 transmissionrpc
若想要FlexGet支持Transmission,必须安装TransmissionRPC库文件。

  1. sudo apt-get -y install python-transmissionrpc

安装准备

  1. sudo apt-get install python-setuptools
  2. easy_install flexget

  1. sudo pip install flexget

配置transmission自动删除

将以下代码保存为/home/pi/trans_cleanup.sh

  1. #! /bin/bash
  2. #====================================================================
  3. # trans_cleanup.sh
  4. #
  5. # Copyright (c) 2011, WangYan <webmaster@wangyan.org>
  6. # All rights reserved.
  7. # Distributed under the GNU General Public License, version 3.0.
  8. #
  9. # Monitor disk space, If the Over, delete some files.
  10. #
  11. # See: http://wangyan.org/blog/trans_cleanup.html
  12. #
  13. # V0.2, since 2012-10-29
  14. #====================================================================
  15. # The transmission remote login username
  16. USERNAME="hzl201"
  17. # The transmission remote login password
  18. PASSWORD="hzl63155680"
  19. # The transmission download dir
  20. DLDIR="/home/pi/download"
  21. # The maximum allowed disk (%)
  22. DISK_USED_MAX="80"
  23. # Enable auto shutdown support (Disable=0, Enable=1)
  24. ENABLE_AUTO_SHUTDOWN="0"
  25. # Log path settings
  26. LOG_PATH="/var/log/trans_cleanup.log"
  27. # Date time format setting
  28. DATA_TIME=$(date +"%y-%m-%d %H:%M:%S")
  29. #====================================================================
  30. dist_check()
  31. {
  32. DISK_USED=`df -h $DLDIR | grep -v Mounted | awk '{print $5}' | cut -d '%' -f 1`
  33. DISK_OVER=`awk 'BEGIN{print('$DISK_USED'>'$DISK_USED_MAX')}'`
  34. }
  35. dist_check
  36. if [ "$DISK_OVER" = "1" ];then
  37. for i in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep 100% | grep Done | awk '{print $1}' | grep -v ID`
  38. do
  39. [ "$i" -gt "0" ] && echo -n "$DATA_TIME [Done] " >> $LOG_PATH
  40. transmission-remote --auth $USERNAME:$PASSWORD -t $i --remove-and-delete >> $LOG_PATH 2>&1
  41. [ "$i" -gt "0" ] && sleep 10 && dist_check
  42. [ "$DISK_OVER" = "0" ] && break
  43. done
  44. fi
  45. if [ "$DISK_OVER" = "1" ];then
  46. for ii in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep Stopped | awk '{print $1}' | grep -v ID`
  47. do
  48. [ "$ii" -gt "0" ] && echo -n "$DATA_TIME [Stopped] " >> $LOG_PATH
  49. transmission-remote --auth $USERNAME:$PASSWORD -t $ii --remove-and-delete >> $LOG_PATH 2>&1
  50. [ "$ii" -gt "0" ] && sleep 10 && dist_check
  51. [ "$DISK_OVER" = "0" ] && break
  52. done
  53. fi
  54. if [ "$DISK_OVER" = "1" ];then
  55. for iii in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep -v Sum | awk '{print $1}' | grep -v ID`
  56. do
  57. [ "$iii" -gt "0" ] && echo -n "$DATA_TIME [Up or Down] " >> $LOG_PATH
  58. transmission-remote --auth $USERNAME:$PASSWORD -t $iii --remove-and-delete >> $LOG_PATH 2>&1
  59. [ "$iii" -gt "0" ] && sleep 10 && dist_check
  60. [ "$DISK_OVER" = "0" ] && break
  61. done
  62. fi
  63. if [ "$DISK_OVER" = "1" ];then
  64. rm -rf $DLDIR/*
  65. fi
  66. if [ "$ENABLE_AUTO_SHUTDOWN" = "1" ];then
  67. SHUTDOWN=1
  68. for STATUS in `transmission-remote --auth $USERNAME:$PASSWORD -l | awk '{print $9}'`
  69. do
  70. if [[ "$STATUS" = "Up" || "$STATUS" = "Uploading" ]];then
  71. SHUTDOWN=0
  72. fi
  73. done
  74. TASK_TOTAL=`transmission-remote --auth $USERNAME:$PASSWORD -l | grep -Ev '(ID|Sum)' | wc -l`
  75. if [ "$TASK_TOTAL" -gt "0" ] && [ "$SHUTDOWN" -eq "1" ];then
  76. echo -n "$DATA_TIME " >> $LOG_PATH
  77. shutdown now >> $LOG_PATH 2>&1
  78. fi
  79. fi
  1. sudo chmod 777 /home/pi/trans_cleanup.sh #添加运行权限
  2. crontab -e
  3. */5 * * * * sh /home/pi/trans_cleanup.sh #设置自动执行
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注