taupinfada
Cadet
- Joined
- May 12, 2013
- Messages
- 3
I create a script to install BtSync in the Plugging Jail.
So If you want use your Freenas as a dropbox you can use this one.
Of course, I am open to all suggestions ...
So If you want use your Freenas as a dropbox you can use this one.
Of course, I am open to all suggestions ...
Code:
#!/bin/sh
cd /tmp
echo "Souhaitez-vous installer Bittorrent Sync (o/n)? [n] : "
read install_btsync
if [ $install_btsync = "o" ]; then
echo "Initialisation de l'utilisateur btsync"
if [ `more /etc/passwd | grep btsync | wc -l` -gt 0 ]; then
echo "L'utilisateur btsync existe déjà"
else
echo "Création de l'utilisateur btsync"
pw useradd btsync -m -c "Utilisateur Bittorrent Sync" -s /bin/sh -w yes
fi
echo "Initialisation des répertoire"
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-1.0.128.tar.gz ]; then
echo "Téléchargement de Bittorrent Sync."
wget "http://syncapp.bittorrent.com/1.0.128/btsync_freebsd_x64-1.0.128.tar.gz"
fi
if [ -e btsync ]; then
rm btsync
fi
echo "Extraction de Bittorrent Sync."
tar xvfz btsync_freebsd_x64-1.0.128.tar.gz
echo "Copie de Bittorrent Sync."
cp btsync /usr/local/bin/btsync
chmod 755 /usr/local/bin/btsync
echo "Initialisation du daemon"
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 UNIX users you want to run BTSync clients for
BTSYNC_USERS="btsync"
DAEMON=/usr/bin/btsync
name="btsync"
rcvar="btsync_enable"
command="/usr/bin/\${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 "/usr/local/bin/btsync --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 "Configuration de l'interface web"
echo "Utilisateur de connexion à l'interface web : "
read user
echo "Mot de passe de connexion à l'interface web : "
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 "Lancement de BtSync :"
/etc/rc.d/btsync start
fi