Last active
August 17, 2022 12:23
-
-
Save MorphyDK/946aaabbc0384537667e8ebfa3e06c07 to your computer and use it in GitHub Desktop.
Reinstall script of your own Ubuntu server (Own passwds etc are needed to adjust the script for your needs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Set UserName | |
echo "Ready to start" | |
read -rp 'UserName: ' uservar | |
echo "$uservar added" | |
#adduser $uservar && echo -e "$userPass\n$userPass\n" | passwd $uservar > /dev/null 2>&1 && echo " User account has been created." || echo " ERR -- User acount creation failed!" | |
adduser $uservar | |
usermod -aG sudo $uservar | |
USER=$uservar | |
GROUP=$uservar | |
### Create directories for install | |
sudo -u $USER mkdir -p /home/$USER/{MAINFOLDER/{FOLDER1,FOLDER2,ETC},.ssh,logs,mnt,.config/rclone,scripts} >/dev/null 2>&1 | |
#### | |
sleep 3 | |
clear | |
### Installer diverse tools | |
{ | |
echo "Installing system updates, might take a while..." | |
apt -y update | |
apt -y upgrade | |
apt -y dist-upgrade | |
sleep 3 | |
echo "System upgrades installed, installing packages..." | |
if command -v curl >/dev/null 2>&1; then | |
echo "Curl is installed." | |
else | |
echo "Installing curl..." | |
sudo apt -y install curl >/dev/null 2>&1 | |
fi | |
sleep 3 | |
if command -v unzip >/dev/null 2>&1; then | |
echo "Unzip is installed" | |
else | |
echo "Installing unzip..." | |
sudo apt -y install unzip >/dev/null 2>&1 | |
fi | |
sleep 3 | |
if command -v fuse >/dev/null 2>&1; then | |
echo "Fuse is installed." | |
else | |
echo "Installing Fuse..." | |
apt -y install fuse >/dev/null 2>&1 | |
fi | |
sleep 3 | |
if command -v rclone >/dev/null 2>&1; then | |
echo "Rclone is installed." | |
else | |
curl https://rclone.org/install.sh | sudo bash >/dev/null 2>&1; | |
echo "Installing Rclone..." | |
fi | |
sleep 3 | |
if command -v ufw ->/dev/null 2>&1; then | |
echo "UFW is installed." | |
else | |
echo "Installing UFW...remember to configure firewall rules!!!" | |
sudo apt -y install ufw >/dev/null 2>&1 | |
fi | |
sleep 3 | |
if command -v mc ->/dev/null 2>&1; then | |
echo "Midnight Commander is installed." | |
else | |
echo "Installing Midnight Commander..." | |
apt -y install mc >/dev/null 2>&1; | |
fi | |
sleep 3 | |
if command -v nano ->/dev/null 2>&1; then | |
echo "Nano is installed." | |
else | |
echo "Installing Nano..." | |
apt -y install nano ->dev/null 2>&1; | |
fi | |
if command -v htop ->/dev/null 2>&1; then | |
echo "Htop is installed." | |
else | |
echo "Installing Htop..." | |
apt -y install htop >/dev/null 2>&1; | |
fi | |
if command -v fail2ban ->/dev/null 2>&1; then | |
echo "Fail2ban is installed." | |
else | |
echo "Installing Fail2ban..." | |
apt -y install fail2ban ->/dev/null 2>&1 | |
fi | |
if command -v plexmediaserver ->/dev/null 2>&1; then | |
ehco "Plexmediaserver is installed." | |
else | |
echo "Installing Plexmediaserver..." | |
bash -c "$(wget -qO - https://raw.githubusercontent.com/mrworf/plexupdate/master/extras/installer.sh)" | |
fi | |
if command -v rutorrent ->/dev/null 2>&1; then | |
echo "Rutorrent is installed." | |
else | |
echo "Installing Rutorrent..." | |
bash -c "$(wget --no-check-certificate -qO - https://raw.githubusercontent.com/arakasi72/rtinst/master/rtsetup)" | |
sudo rtinst | |
fi | |
} | |
##### | |
#### Update fuse.conf allow other | |
echo "user_allow_other" >> /etc/fuse.conf | |
###### | |
touch /etc/systemd/system/rclonemount.service >/dev/null 2>&1 | |
sudo -u $USER touch /home/$USER/.config/rclone/rclone.conf >/dev/null 2>&1 | |
sudo -u $USER chown $USER:$GROUP /home/$USER/{MAINFOLDER/{FOLDER1,FOLDER2,FOLDER3},mnt,.config/rclone,scripts/logs} >/dev/null 2>&1 | |
sudo -u $USER chown $USER:$GROUP /home/$USER/.config/rclone/rclone.conf >/dev/null 2>&1 | |
#### Rclone.config | |
cat >> /home/$USER/.config/rclone/rclone.conf <<EOF | |
[Google] | |
type = drive | |
client_id = YOUR_OWN_PERSONAL_CLIENTID_HERE.apps.googleusercontent.com | |
client_secret = YOUR_OWN_PERSONAL_SECRETID_HERE | |
scope = drive | |
token = {"access_token":"YOUR_OWN_PRIVATE_TOKEN_HERE"} | |
[Googlecrypt] | |
type = crypt | |
remote = Google:Private | |
filename_encryption = standard | |
directory_name_encryption = true | |
password = YOUR_ENCRYPTET_PASS_HERE | |
[FTPcrypt] | |
type = crypt | |
remote = FTP:Backup | |
filename_encryption = standard | |
directory_name_encryption = true | |
password = YOUR_ENCRYPTET_PASS_HERE | |
[FTP] | |
type = ftp | |
host = yourserver.domain.here | |
user = username | |
pass = YOUR_ENCRYPTET_PASS_HERE | |
[Scripts] | |
type = crypt | |
remote = Google:Scripts | |
filename_encryption = standard | |
directory_name_encryption = true | |
password = YOUR_ENCRYPTET_PASS_HERE | |
EOF | |
#### rclonemount.service | |
cat >> /etc/systemd/system/rclonemount.service <<EOF | |
[Unit] | |
Description=RClone Service | |
After=network-online.target | |
Wants=network-online.target | |
[Service] | |
Type=notify | |
ExecStart=/usr/bin/rclone mount --allow-other --read-only --dir-cache-time 48h --vfs-read-chunk-size 16M --buffer-size 16M Googlecrypt: /home/$USER/mnt/ | |
ExecStop=/bin/fusermount -uz /home/$USER/mnt/ | |
Restart=on-abort | |
User=$USER | |
Group=$USER | |
[Install] | |
WantedBy=default.target | |
EOF | |
####Download scripts from Googledrive | |
sleep 3 | |
echo "Downloading upload scripts from your Googledrive..." | |
echo "Scripts will be located at /home/plex/scripts/" | |
sudo -u $USER rclone --config=/home/$USER/.config/rclone/rclone.conf copy Scripts:/ /home/plex/scripts/ | |
sudo -u $USER chown $USER:$GROUP /home/$USER/scripts/{yourscript1,yourscript2,yourscript3} >/dev/null 2>&1 | |
sudo -u $USER chmod a+x /home/$USER/scripts/{yourscript1,yourscript2,yourscipt3} >/dev/null 2>&1 | |
mv /home/plex/scripts/sshd_config /etc/ssh/sshd_config | |
##### start rclone Mount | |
systemctl daemon-reload | |
systemctl enable rclonemount.service | |
systemctl start rclonemount.service | |
####Reboot | |
echo "Server is ready for reboot" | |
echo "SSH Port is set to xxxxx" | |
echo "Remember to set your UFW rules to your system needs" | |
sleep 1 | |
read -p "Press Enter to reboot the server now." | |
sudo -s reboot | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment