#!/bin/sh
echo "Installing rtorrent.sh script"
repaddress=`cat ginst.conf|grep repaddress|sed s/[[:alnum:]]*=//g`
mntpoint=`cat ginst.conf|grep mntpoint|sed s/[[:alnum:]]*=//g`
export TMPDIR=$mntpoint/tmp
if [ -e /opt/etc/init.d/S99rtorrent ]
then
/opt/etc/init.d/S99rtorrent stop
fi
echo "Installing rtorrent package"
ipkg -t $mntpoint/tmp install rtorrent
ipkg -t $mntpoint/tmp install coreutils
wget $repaddress/conf/rtorrent.conf -O /opt/etc/rtorrent.conf
echo "Configuring links"
if [ -e /opt/share/torrent ]
then
if [ ! -L /opt/share/torrent ]
then
mv /opt/share/torrent/ $mntpoint/files/
fi
else
mkdir -p $mntpoint/files/torrent
fi
ln -s -t /opt/share/ $mntpoint/files/torrent
echo "Creating folders for rtorrent"
mkdir -p /opt/share/torrent/dl
mkdir -p /opt/share/torrent/work
mkdir -p /opt/share/torrent/session
echo "Adding user p2p"
mkdir -p /opt/home/p2p
adduser -D --home /opt/home/p2p p2p
chown p2p /opt/home/p2p
chown p2p /opt/share/torrent
chown p2p /opt/share/torrent/dl
chown p2p /opt/share/torrent/work
chown p2p /opt/share/torrent/session
chmod a+r /opt/etc/rtorrent.conf
chmod a+x /opt/bin/rtorrent
echo "Updating for Novik binaries"
wget
http://vif2ne.ru/nvk/stuff/novik/rtorrent/rtorrent.gz -O $mntpoint/tmp/rtorrent.gz
wget
http://vif2ne.ru/nvk/stuff/novik/rto...torrent.tar.gz -O $mntpoint/tmp/libtorrent.tar.gz
gunzip $mntpoint/tmp/rtorrent.gz
mv $mntpoint/tmp/rtorrent.gz /opt/bin
chmod a+x /opt/bin/rtorrent
tar -xzf $mntpoint/tmp/libtorrent.tar.gz -C /opt/lib
mv /opt/lib/libtorrent/* /opt/lib
echo "Configuring system for rtorrent startup"
wget $repaddress/conf/S99rtorrent -O /opt/etc/init.d/S99rtorrent
chmod +x /opt/etc/init.d/S99rtorrent
echo "alias rt='su -c \"screen -r\" p2p'" >> /tmp/local/root/.profile
echo "chmod a+rw \`tty\`" >> /tmp/local/root/.profile
echo "stty start undef" >> /tmp/local/root/.profile
echo "stty stop undef" >> /tmp/local/root/.profile
cp /tmp/local/root/.profile /opt/home/p2p/.profile
echo "/etc/passwd" > /usr/tmp/local/.files
echo "/etc/group" >> /usr/tmp/local/.files
echo "if [ -e \"/opt/share/torrent/session/*.lock\" ]" >> /usr/local/sbin/post-mount
echo "then rm /opt/share/torrent/session/*.lock" >> /usr/local/sbin/post-mount
echo "fi" >> /usr/local/sbin/post-mount
echo "Configuring firewall settings"
echo "iptables -I INPUT -p tcp --dport 51777:51780 -j ACCEPT" >> /usr/local/sbin/post-firewall
echo "iptables -I INPUT -p udp --dport 51777:51780 -j ACCEPT" >> /usr/local/sbin/post-firewall
flashfs save && flashfs commit && flashfs enable