PDA

View Full Version : Initial Setup Script & Ongoing backup



pembo
25-05-15, 11:14
Thought I'd share this - something I've built/grown as I've has the need but find it a great timesaver.

When I flash with a new image, there's a series of things I nearly always do, so I've scripted a lot of that into a setup script.

The script runs a series of setup tasks

Sets up CIFS shares to a NAS SERVER
Installs packages that I always install
Prompts to change the root password
Creates a swap file
Creates a link to the backup script in the VIX script runner location so it's available in the vix menu.


So.. onto the file. Where you See {{SOMETHING}} you need to replace this with your own values

initial.sh


#!/bin/sh

#Check it is being run as the root user
if [ "$(id -u)" != "0" ]; then
echo "ERROR: This script must be run as root" 1>&2
exit 1
fi

echo Enigma 2 Initial Setup
echo ----------------------------------------------------
echo

#
# NAS Server Mount
#
echo - Adding NAS Server Mount Locations
mkdir /media/net/{{DIRECTORY1}}
mkdir /media/net/{{DIRECTORY2}}
echo //{[MOUNT POINT 1}} /media/net/{{DIRECTORY1}} cifs user={{USERNAME}},pass={{PASSWORD}},_netdev,rw,sec =ntlm,iocharset=utf8 0 0 >> /etc/fstab
echo //{{MOUNT POINT 2}} /media/net/{{DIRECTORY2}} cifs user={{USERNAME}},pass={{PASSWORD}},_netdev,rw,sec =ntlm,iocharset=utf8 0 0 >> /etc/fstab
echo --- Mount Adds Complete
echo

#
# Packages to be installed
#
echo - Installing packages
opkg install rsync
opkg install vim
echo --- Pacakges installed
echo

#
# Change the root password
#
echo - Now change the root password
passwd root
echo --- Root password Change complete
echo

#
# Create the swap
#
echo - Creating swap
dd if=/dev/zero of=/hdd/swapfile bs=1M count=1024
mkswap /hdd/swapfile
echo "/hdd/swapfile swap swap defaults 0 0" >> /etc/fstab
echo --- swap created
echo

#
# Move backup script to the vix script
# runner location so it's available on box
#
echo - Creating Link to Backup Script in /usr/script
ln -s backup.sh /usr/script/backupE2.sh
echo --- Link file created
echo
echo "**********************************"
echo "* Done - please restart your box *"
echo "**********************************"



and then the backup file that backsup various things to a mounted nas server

backup.sh


#!/bin/sh

#Check it is being run as the root user
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi

#Set properties
#--------------------------------------------------
#Start date
before="$(date +%s)"

#log file location
logfile="/hdd/logs/backup.log"

#current script name
me=`basename $0`
#--------------------------------------------------

#From directory
fromdir="/hdd/"
#to directory
todir="{{DIRECTORY1}}"
#--------------------------------------------------

#Now do the backup job writing to the log file
echo . >> $logfile
echo Executing background sync task...
echo Executing background sync task $basename >> $logfile
date >> $logfile
echo "----------------------------" >>$logfile
echo "Syncing $fromdir /backup"
rsync -vrE "$fromdir/backup" "$todir" >>$logfile
echo "Syncing $fromdir /imagebackups"
rsync -vrE "$fromdir/imagebackups" "$todir" >>$logfile
echo "Syncing $fromdir /picon"
rsync -vrE "$fromdir/picon" "$todir" >>$logfile

echo "-FILES----------------------" >>$logfile
echo "Pausing STB"

init 4
cp /etc/enigma2/*.xml $todir/etc/enigma2/ >> $logfile
cp /etc/enigma2/settings $todir/etc/enigma2/ >> $logfile
cp /etc/enigma2/userbouquet* $todir/etc/enigma2/ >> $logfile
cp /etc/lcd4linux.conf $todir/etc/ >> $logfile
cp /etc/lcd4config $todir/etc/ >> $logfile
cp /etc/fstab $todir/etc/ >> $logfile
echo "Resuming STB"
init 3

echo "----------------------------> Completed" >>$logfile
after="$(date +%s)"
elapsed_seconds="$(expr $after - $before)"
date >>$logfile
echo Elapsed time: $elapsed_seconds secs >>$logfile
echo Completed - Elapsed time: $elapsed_seconds secs


Either of these scripts can be easily manipulated to add additional setup tasks or backup files/locations.

Just be aware that I edited the script inline here, so I've not tested what I posted ;)