Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Installs Bittorrent Sync (btsync) under a FreeNAS jail
- # http://forums.freenas.org/threads/bittorrent-sync-install.12722/
- # 2013-08-20
- cd /tmp
- echo -n "Would you like to install Bittorrent Sync (y/n)? [n] : "
- read install_btsync
- if [ $install_btsync = "y" ]; then
- echo "Initialization of btsync user"
- if [ `more /etc/passwd | grep btsync | wc -l` -gt 0 ]; then
- echo "The btsync user already exists"
- else
- echo "Creation of btsync user"
- pw useradd btsync -m -c "User Bittorrent Sync" -s /bin/sh -w yes
- fi
- echo "Initialization of directory"
- home_dir="/home/btsync"
- config_dir="$home_dir/.config"
- config_btsync_dir="$config_dir/btsync"
- if [ ! -e $config_dir ]; then
- mkdir $config_dir
- fi
- if [ ! -e $config_btsync_dir ]; then
- mkdir $config_btsync_dir
- fi
- chown -R btsync $home_dir
- chmod -R 744 $home_dir
- if [ ! -e btsync_freebsd_x64.tar.gz ]; then
- echo "Downloading Bittorrent Sync."
- fetch "http://btsync.s3-website-us-east-1.amazonaws.com/btsync_freebsd_x64.tar.gz"
- fi
- if [ -e btsync ]; then
- rm btsync
- fi
- echo "Extraction of Bittorrent Sync."
- tar xvfz btsync_freebsd_x64.tar.gz
- echo "Copying Bittorrent Sync."
- cp btsync /usr/local/sbin/btsync
- chmod 755 /usr/local/sbin/btsync
- echo "Initialization of the daemon...ROAR"
- cat > "/etc/rc.d/btsync" <<EOF
- #!/bin/sh
- # PROVIDE: btsync
- # REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
- # btsync service
- # Take from <https://gist.github.com/MendelGusmao/5398362>
- # Replace with linux users you want to run BTSync clients for
- BTSYNC_USERS="btsync"
- DAEMON=/usr/local/sbin/btsync
- name="btsync"
- rcvar="btsync_enable"
- command="/usr/local/sbin/\${name}"
- start() {
- echo "Starting btsync..."
- for btsuser in \$BTSYNC_USERS; do
- echo " - for \$btsuser"
- HOMEDIR=\`getent passwd \$btsuser | cut -d: -f6\`
- if [ -d \$HOMEDIR/.config ]; then
- su -l \$btsuser -c "\$command --config \$HOMEDIR/.config/btsync/config.json"
- fi
- done
- }
- stop() {
- echo "Stopping btsync..."
- for btsuser in \$BTSYNC_USERS; do
- HOMEDIR=\`getent passwd \$btsuser | cut -d: -f6\`
- if [ -d \$HOMEDIR/.config ]; then
- dbpid=\`pgrep -u \$btsuser btsync\`
- if [ -z "\$dbpid" ]; then
- echo "btsync for USER \$btsuser: not running."
- else
- echo "Stopping btsync for USER \$btsuser: running (pid \$dbpid)"
- kill \$dbpid
- until [ -z "\$dbpid" ]
- do
- dbpid=\`pgrep -u \$btsuser btsync\`
- echo -n "."
- sleep 1
- done
- echo ""
- fi
- fi
- done
- }
- status() {
- for btsuser in \$BTSYNC_USERS; do
- dbpid=\`pgrep -u $btsuser btsync\`
- if [ -z "\$dbpid" ]; then
- echo "btsync for USER \$btsuser: not running."
- else
- echo "btsync for USER \$btsuser: running (pid \$dbpid)"
- fi
- done
- }
- case "\$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart|reload|force-reload)
- stop
- start
- ;;
- status)
- status
- ;;
- *)
- echo "Usage: /etc/rc.d/btsync {start|stop|reload|force-reload|restart|status}"
- exit 1
- esac
- exit 0
- EOF
- chmod 755 /etc/rc.d/btsync
- if [ `more /etc/rc.conf | grep btsync | wc -l` -lt 1 ]; then
- echo "btsync_enable=\"YES\"" >> /etc/rc.conf
- fi
- echo "Web Interface configuration"
- echo -n "User login to the web interface : "
- read user
- echo -n "Password to connect to the web interface : "
- read pwd
- cat > "$config_btsync_dir/config.json" <<EOF
- {
- "device_name": "Freenas",
- "listening_port" : 0, // 0 - randomize port
- /* storage_path dir contains auxilliary app files
- if no storage_path field: .sync dir created in the directory
- where binary is located.
- otherwise user-defined directory will be used
- */
- "storage_path" : "/home/btsync/.config/btsync",
- // uncomment next line if you want to set location of pid file
- // "pid_file" : "/var/run/syncapp/syncapp.pid",
- "check_for_updates" : true,
- "use_upnp" : true, // use UPnP for port mapping
- /* limits in kB/s
- 0 - no limit
- */
- "download_limit" : 0,
- "upload_limit" : 0,
- /* remove "listen" field to disable WebUI
- remove "login" and "password" fields to disable credentials check
- */
- "webui" :
- {
- "listen" : "0.0.0.0:8888",
- "login" : "$user",
- "password" : "$pwd"
- }
- }
- EOF
- chown btsync $config_btsync_dir/config.json
- chmod 744 $config_btsync_dir/config.json
- echo "Launching btsync :"
- /etc/rc.d/btsync start
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement