Automation of installing transmission on Ubuntu 16.04 server version

Hello everyone I would like to share with you this script which I made to install transmission on Ubuntu 16.04 server version because I always do some Stupid things on my server which cause me to reinstall the operating system to undo stupid things and that is because I don’t have any backup or snapshots.
The first thing I did was installing transmission manually than I figured that I could backup the settings.json file which is the most important file and write a script to install transmission and then copy the old settings.json file which was previously backed up from the server and then the script will do the whole thing in a matter of seconds instead of doing it manually in about 10 to 15 minutes.





sorry for hiding the password because I am not comfortable with including the Hashes of my password on a public server.

here is the code of the script:

#!/bin/bash
sudo add-apt-repository ppa:transmissionbt/ppa -y
sudo apt-get update -y
sudo apt-get install transmission-cli transmission-common transmission-daemon -y
sudo service transmission-daemon stop
sudo cp settings.json /var/lib/transmission-daemon/info/
sudo cp stats.json /var/lib/transmission-daemon/info/
sudo service transmission-daemon start
sudo usermod -a -G debian-transmission "USER" #change "USER" to your user name and try not to use the root privileged user
sudo touch /home/"USER"/.bash_aliases
sudo cat >> /home/"USER"/.bash_aliases
alias t-start='sudo service transmission-daemon start'
alias t-stop='sudo service transmission-daemon stop'
alias t-reload='sudo service transmission-daemon reload'
alias t-list='transmission-remote -n 'transmission:transmission' -l'
alias t-basicstats='transmission-remote -n 'transmission:transmission' -st'
alias t-fullstats='transmission-remote -n 'transmission:transmission' -si'
^D
source /home/"USER"/.bash_aliases

I will be more than happy to see suggestions and thanks for reading this topic and being a member on fortmactech.com .

@miguel do you have any suggestions for me.

Hi Diyaa,

You can make code look better on the forum by putting it in ‘preformatted’ text.

Highlight the text and click this:

It’s much better to do that, rather than post screenshots of code that is hard to read, and impossible to copy and paste.

Another thing you can do is use the ` character three times like this:

hello this is code
do you like this code?

quote

As well, in your script, it’s not a good idea to use sudo all the time like that. Just sudo the entire script.

Otherwise it’s pretty good!

thank you for your suggestions.
I will start using the "``"`" to write a pretty code.

here is the script

#!/bin/bash
sudo add-apt-repository ppa:transmissionbt/ppa -y
sudo apt-get update -y
sudo apt-get install transmission-cli transmission-common transmission-daemon -y
sudo service transmission-daemon stop
sudo cp settings.json /var/lib/transmission-daemon/info/
sudo cp stats.json /var/lib/transmission-daemon/info/
sudo service transmission-daemon start
sudo usermod -a -G debian-transmission "USER" #change "USER" to your user name and try not to use the root privileged user
sudo touch /home/"USER"/.bash_aliases
sudo cat >> /home/"USER"/.bash_aliases
alias t-start='sudo service transmission-daemon start'
alias t-stop='sudo service transmission-daemon stop'
alias t-reload='sudo service transmission-daemon reload'
alias t-list='transmission-remote -n 'transmission:transmission' -l'
alias t-basicstats='transmission-remote -n 'transmission:transmission' -st'
alias t-fullstats='transmission-remote -n 'transmission:transmission' -si'
^D
source /home/"USER"/.bash_aliases
1 Like

@miguel need help with the script

once it reaches line number 8 which is this service transmission-daemon stop it just freezes the whole server.

#!/bin/bash
apt -y update
apt -y upgrade
apt install -y software-properties-common
add-apt-repository -y ppa:transmissionbt/ppa
apt-get update -y
apt-get install -y transmission-cli transmission-common transmission-daemon
service transmission-daemon stop
cp settings.json /var/lib/transmission-daemon/info/
cp stats.json /var/lib/transmission-daemon/info/
cp dht.dat /var/lib/transmission-daemon/info/
cp blocklists.zip /var/lib/transmission-daemon/info/
service transmission-daemon start
usermod -a -G debian-transmission diyaa #change "USER" to your user name and try not to use the root privileged user
touch /home/diyaa/.bash_aliases
cat >> /home/diyaa/.bash_aliases
alias t-start='sudo service transmission-daemon start'
alias t-stop='sudo service transmission-daemon stop'
alias t-reload='sudo service transmission-daemon reload'
alias t-list='transmission-remote -n 'transmission:transmission' -l'
alias t-basicstats='transmission-remote -n 'transmission:transmission' -st'
alias t-fullstats='transmission-remote -n 'transmission:transmission' -si'
^D
source /home/"USER"/.bash_aliases 

and I run the script as a root like this sudo ./install-transmission.sh

and then what I did is I added this line before sleep 5 before the line service transmission-daemon stop to see where the problem is and what happen is that the script started from the beginning after 5 second and freeze the whole server again

nerve mind
problem solved using echo instead of cat
I will make this the best automation and reusing of time wasting script in the world
I will show it to you @miguel on Monday

The Final tested release of the script

first of all run the following commands which will help the script to run:
1-" sudo apt-get install dos2unix -y "
2-" cd /home/diyaa/script "
3-" dos2unix install.sh "
4- " sudo chmod u+x install.sh && sudo ./install.sh "

#!/bin/bash
sudo apt install -y htop python python3 nano wget curl speedtest-cli \
tasksel python-pip git software-properties-common
add-apt-repository -y ppa:transmissionbt/ppa
apt-get update -y
apt-get install -y transmission-cli transmission-common transmission-daemon
service transmission-daemon stop
cp settings.json /var/lib/transmission-daemon/info/
cp stats.json /var/lib/transmission-daemon/info/
cp dht.dat /var/lib/transmission-daemon/info/
cp blocklists.zip /var/lib/transmission-daemon/info/
service transmission-daemon start
usermod -a -G debian-transmission diyaa #change diyaa to your user name and try not to use the root privileged user
chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon/info
touch /home/diyaa/.bash_aliases
echo "alias t-start='sudo service transmission-daemon start'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-stop='sudo service transmission-daemon stop'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-reload='sudo service transmission-daemon reload'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-list='transmission-remote -n 'transmission:transmission' -l'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-basicstats='transmission-remote -n 'transmission:transmission' -st'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-fullstats='transmission-remote -n 'transmission:transmission' -si'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
source /home/diyaa/.bash_aliases  #change diyaa to your user name directory
chown -R diyaa:diyaa /home/diyaa/.bash_aliases #change diyaa to your user name directory
cd /home/diyaa/ #change diyaa to your user name directory
wget https://downloads.plex.tv/plex-media-server-new/1.15.6.1079-78232c603/debian/plexmediaserver_1.15.6.1079-78232c603_amd64.deb
dpkg -i plexmediaserver_1.15.6.1079-78232c603_amd64.deb
cp Preferences.xml /var/lib/plexmediaserver/Library/'Application Support'/'Plex Media Server'/
chown -R plex:plex /var/lib/plexmediaserver/Library/'Application Support'/'Plex Media Server'/
cd /home/diyaa #change diyaa to your user name directory
curl -O https://raw.githubusercontent.com/Angristan/openvpn-install/master/openvpn-install.sh
chmod +x openvpn-install.sh
cd /home/diyaa #change diyaa to your user name directory
curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
chmod a+rx /usr/local/bin/youtube-dl
apt -y update
apt -y upgrade
reboot

all in one file

#!/bin/bash
: '
initial notes:
first of all run the following commands which will help the script to run:
1-" sudo apt-get install dos2unix -y "
2-" cd /home/diyaa/script "
3-" dos2unix install.sh "
4- " sudo chmod u+x install.sh && sudo ./install.sh "
'
sudo apt install -y htop python python3 nano wget curl speedtest-cli \
tasksel python-pip git software-properties-common
add-apt-repository -y ppa:transmissionbt/ppa
apt-get update -y
apt-get install -y transmission-cli transmission-common transmission-daemon
service transmission-daemon stop
cp settings.json /var/lib/transmission-daemon/info/
cp stats.json /var/lib/transmission-daemon/info/
cp dht.dat /var/lib/transmission-daemon/info/
cp blocklists.zip /var/lib/transmission-daemon/info/
service transmission-daemon start
usermod -a -G debian-transmission diyaa #change diyaa to your user name and try not to use the root privileged user
chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon/info
touch /home/diyaa/.bash_aliases
echo "alias t-start='sudo service transmission-daemon start'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-stop='sudo service transmission-daemon stop'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-reload='sudo service transmission-daemon reload'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-list='transmission-remote -n 'transmission:transmission' -l'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-basicstats='transmission-remote -n 'transmission:transmission' -st'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
echo "alias t-fullstats='transmission-remote -n 'transmission:transmission' -si'" >> /home/diyaa/.bash_aliases #change diyaa to your user name directory
source /home/diyaa/.bash_aliases  #change diyaa to your user name directory
chown -R diyaa:diyaa /home/diyaa/.bash_aliases #change diyaa to your user name directory
cd /home/diyaa/ #change diyaa to your user name directory
wget https://downloads.plex.tv/plex-media-server-new/1.15.6.1079-78232c603/debian/plexmediaserver_1.15.6.1079-78232c603_amd64.deb
dpkg -i plexmediaserver_1.15.6.1079-78232c603_amd64.deb
cp Preferences.xml /var/lib/plexmediaserver/Library/'Application Support'/'Plex Media Server'/
chown -R plex:plex /var/lib/plexmediaserver/Library/'Application Support'/'Plex Media Server'/
cd /home/diyaa #change diyaa to your user name directory
curl -O https://raw.githubusercontent.com/Angristan/openvpn-install/master/openvpn-install.sh
chmod +x openvpn-install.sh
cd /home/diyaa #change diyaa to your user name directory
curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
chmod a+rx /usr/local/bin/youtube-dl
apt -y update
apt -y upgrade
touch installation-notes
echo "if you can see this script that means the script have successfully done the work." >> /home/diyaa/installation-notes
echo "the first thing you should do after installing this script is reboot the system to apply all changes." >> /home/diyaa/installation-notes
echo "after rebooting the system you can run the openvpn-install script in your user directory to install and make an openvpn server." >> /home/diyaa/installation-notes
echo "now after everything is done, youe can use the system and delete this script if you would like to do so." >> /home/diyaa/installation-notes
echo "read the file installtion script"
: '
I just wanted to tell you that if you think that there is a single line
in the script that is stupid or being used in the wrong way,time or place just send me contact me through
my email address: [email protected]
'

Hi Diyaa,

These are just minor notes, and not really wrong. More like a stylistic or accent type of thing, so don’t worry too much about them:

instead of

cp settings.json /var/lib/transmission-daemon/info/
cp stats.json /var/lib/transmission-daemon/info/
cp dht.dat /var/lib/transmission-daemon/info/
cp blocklists.zip /var/lib/transmission-daemon/info/

you can do it all on one command:

cp blocklists.zip dht.dat stats.json settings.json /var/lib/transmission-daemon/info/

 

 

You don’t need to do

touch /home/diyaa/.bash_aliases

Since it will create the file on the next line if it doesn’t already exist.

 

 

If you’re using bash, you don’t need to do “source” in this line:

source /home/diyaa/.bash_aliases

It will run that file as long as it’s executable if you just leave out the source part.

 

 

If you’re intending that this script be run by other people, replace everywhere that has /home/diyaa/ with the variable $HOME.

For example,

echo "alias blah blah blah" >> $HOME/.bash_aliases
cd $HOME

This is much better because not all systems use /home/username as the home folder either. Some systems use /users/username instead, for example. But $HOME should always work.

 

Finally, why 16.04 ? If someone is installing a new server today, they’re going to use 18.04.

I love these suggestions.
Thank you so much @miguel