fs:~# apt-get install gcc make cvs
fs:~# cvs -d :pserver:cvs@cvs.fefe.de:/cvs -z9 co libowfat
fs:~# cd libowfat/
fs:~/libowfat# make
fs:~/libowfat# cd ..
fs:~# cvs -d:pserver:anoncvs@cvs.erdgeist.org:/home/cvsroot co opentracker
fs:~# cd opentracker/
fs:~/opentracker# make
fs:~/opentracker# cp opentracker /usr/local/bin/
fs:~# cat /etc/rc.local |grep opentracker
start-stop-daemon --start --quiet -m -b --pidfile /var/run/opentracker.pid --exec /usr/local/bin/opentracker
fs:~# wget www.murmeldjur.se/btpd/btpd-0.15.tar.gz
fs:~# tar -xf btpd-0.15.tar.gz
fs:~# cd btpd-0.15
fs:~/btpd-0.15# chmod +x configure
fs:~/btpd-0.15# ./configure
fs:~/btpd-0.15# make
fs:~/btpd-0.15# make install
fs:~# cat /etc/rc.local |grep btpd
/usr/local/bin/btpd -d /root/.btpd
fs:~# apt-get install ctorrent
mysql> desc torrents;
+--------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+----------------+
| id | int (16) | NO | PRI | NULL | auto_increment |
| file_id | int (16) | YES | | NULL | |
| is_torrent | enum( '1' , '0' ) | YES | | 0 | |
+------------+---------------+------+-----+---------+----------------+
3 rows in set (0.01 sec
mysql> show triggers;
+-----------+--------+-------+------ --
| Trigger | Event | Table | Statement | Timing |
+-----------+--------+-------+------ --
| on_insert| INSERT |files| insert into torrents (file_id) values (LAST_INSERT_ID())| AFTER
| on_update| UPDATE |files| update torrents set is_torrent= '0' where file_id= NEW .id | AFTER
| on_delete| DELETE |files| delete torrents.* from torrents where torrents.file_id= old .id | AFTER
+-----------+--------+-------+--------
fs:~# cat add_torrent.sh
#!/bin/bash
#
tracker= "http://tracker_domain:6969/announce"
#
video_home= "/home/video" ;
#
torrent_dir= " /var/www/torrents" ;
ctorrent= "/usr/bin/ctorrent" ;
btcli= "/usr/local/bin/btcli" ;
mysql= "/usr/bin/mysql -pdpass -u duser -D video" ;
# id
for i in `echo "select files.id from files,torrents where torrents.file_id=files.id and torrents.is_torrent='0' limit 1;" |${mysql}|sed 1d`
do
id=${i};
#
path=`echo "select files.path from files where files.id=" ${id} " limit 1;" |${mysql}|sed 1d`
#
torrent_file=${torrent_dir}/${id}.torrent
#
if [ -e ${torrent_file} ]
then
[ `${btcli} list|awk '{print $1}' |grep -w ${id}|wc -l` -ne 0 ] && ${btcli} del ${torrent_file}
rm ${torrent_file}
fi
cd ${video_home}
path1=`dirname "${path}" `
#
${ctorrent} -t -u ${tracker} -s ${torrent_file} "${path}" && echo "update torrents set is_torrent='1' where file_id=" ${id}|${mysql}
#
[ -e ${torrent_file} ] && ${btcli} add -d "${path1}" -n ${id} --topdir ${torrent_file}
done
#
ls ${torrent_dir}|sed 's/.torrent//' |sort -n > /tmp/tor_list.files
${btcli} list|awk '{print $1}' |sed 1d|sort -n > /tmp/tor_list.load
diff_list=(`diff /tmp/tor_list.files /tmp/tor_list.load|grep "<" |awk '{print $2}' `)
diff_num=$((${#diff_list[*]}-1))
for i in `seq 0 $diff_num`
do
id=${diff_list[${i}]};
path=`echo "select files.Path from files where files.id=" ${id} ";" |${mysql}|sed 1d`
torrent_file=${torrent_dir}/${id}.torrent
${btcli} del ${torrent_file}
if [ -z ${path[0]} ]
then
rm ${torrent_file};
else
path=`dirname "$path"`
${btcli} add -d ${path} -n ${id} --topdir ${torrent_file}
fi
done
Source: https://habr.com/ru/post/97574/
All Articles