Fri Mar 22, 2013 11:53 pm
Sat Mar 23, 2013 1:35 am
Sat Mar 23, 2013 5:23 am
Sat Mar 23, 2013 12:19 pm
#!/bin/bash
# Licensed under the GNU General Public License Version 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
####################################################################################################
# Copyright 2008,2009,2010,2012 Under the GNU GPL2 License
# Authors Tony Brijeski, Anthony Nordquist http://www.salineos.com [email protected]
## Set options for yet another dialog, this makes creating dialogs much easier.
Info='yad --center --title=SalineOS-Backup --window-icon=/usr/share/pixmaps/salineos-backup.png'
Question='yad --wrap --center --image=gtk-dialog-question --button=gtk-no:1 --button=gtk-yes:0 --title=SalineOS-Backup --window-icon=/usr/share/pixmaps/salineos-installer.png'
SingleMenu='yad --center --list --column=Choices --title=SalineOS-Backup --window-icon=/usr/share/icons/pixmaps/salineos-installer.png'
Menu='yad --print-column=1 --center --list --title=SalineOS-Backup --window-icon=/usr/share/pixmaps/salineos-installer.png'
Progress='yad --center --progress --auto-close --title=SalineOS-Backup --no-buttons --window-icon=/usr/share/pixmaps/salineos-installer.png'
TextEntry='yad --center --entry --title=SalineOS-Backup --window-icon=/usr/share/pixmaps/salineos-installer.png'
StartBackup () {
SaveFolder=$(yad --file-selection --title="SalineOS-Backup" --height=450 --width=600 --directory --text="\n Select the folder to save the backup image to\n" --button=$"gtk-quit:3" --button=$"gtk-ok:2")
ret="$?"
if [ "$ret" = "252" ]; then
StartBackup
exit 0
elif [ "$ret" = "3" ]; then
exit 0
elif [ "$SaveFolder" = "" ]; then
StartBackup
exit 0
fi
ImageName=$($TextEntry --wrap --width=250 --text="Enter a name for the backup file, or select time to use the current time and date." --button=$"gtk-quit:3" --button=$"Time:5" --button=$"gtk-ok:2")
ret="$?"
#added
#ImageName=$(date +%Y%m%d-%H%M)
#print $ImageName
if [ "$ret" = "252" ]; then
exit 0
elif [ "$ret" = "3" ]; then
exit 0
elif [ "$ret" = "5" ]; then
ImageName=$(date +%Y%m%d-%H%M)
elif [ "$ImageName" = "" ]; then
ImageName=SalineOS
ImageName=($ImageName_$(date +%Y%m%d-%H%M))
fi
if [ "$BackupPart" = "root" ]; then
$Info --text="Please close all other running applications before continuing and refrain from opening any applications until this operation has completed." --wrap --width=250 --button=$"gtk-ok:1"
UseRoot='/'
elif [ "$(mount | grep "$BackupPart" | awk '{print $3}')" != "" ]; then
$Info --text="Please close all other running applications before continuing and refrain from opening any applications until this operation has completed." --wrap --width=250 --button=$"gtk-ok:1"
UseRoot="$(mount | grep "$BackupPart" | awk '{print $3}')"
if [ "$HomePart" != "" ]; then
HomeMountPoint="$(mount | grep "$HomePart" | awk '{print $3}')"
if [ "$HomeMountPoint" != "" ]; then
umount "$HomePart"
umount -l "$HomePart"
if [ "$(echo "$SaveFolder" | grep "$HomeMountPoint")" != "" ]; then
SaveFolder=$(echo "$SaveFolder" | sed -u "s|"$HomeMountPoint"|"$UseRoot"/home|g")
fi
fi
mount "$HomePart" "$UseRoot/home" -o rw
fi
else
mkdir -p /mnt/Super-Happy-Mount-Point
mount "$BackupPart" /mnt/Super-Happy-Mount-Point -o rw
UseRoot="/mnt/Super-Happy-Mount-Point"
if [ "$HomePart" != "" ]; then
HomeMountPoint="$(mount | grep "$HomePart" | awk '{print $3}')"
if [ "$HomeMountPoint" != "" ]; then
umount "$HomePart"
umount -l "$HomePart"
if [ "$(echo "$SaveFolder" | grep "$HomeMountPoint")" != "" ]; then
SaveFolder=$(echo "$SaveFolder" | sed -u "s|"$HomeMountPoint"|"$UseRoot"/home|g")
fi
fi
mount "$HomePart" /mnt/Super-Happy-Mount-Point/home -o rw
fi
fi
/usr/bin/time --output=/tmp/TimeTaken -p mksquashfs "$UseRoot" "$SaveFolder/$ImageName.backup" -always-use-fragments -b 1M -no-duplicates -no-recovery -e \
.bash_history \
.cache \
.thumbnails \
boot/grub \
Cache \
media \
"$SaveFolder/$ImageName.backup" \
mnt \
proc \
swap \
sys \
tmp \
var/run\>>/tmp/salineos-backup-temp-file &
sleep 1
(while [ "$(pidof mksquashfs)" != "" ]; do
CurrentOutput="$(tail --lines=1 /tmp/salineos-backup-temp-file)"
echo "$CurrentOutput" | awk -F ' ' '{print $NF}' | awk -F '%' '{print $1}'
done)| $Progress --text="Creating backup image $ImageName.backup, Please wait..."
## Let all users move the file around
chmod o+rwx "$SaveFolder/$ImageName.backup"
ls /home>>/tmp/salineos-backup-home-list
UserNameTemp=$(tail --lines=1 /tmp/salineos-backup-home-list)
chown "$UserNameTemp" "$SaveFolder/$ImageName.backup"
## Unmount partitions if needed
if [ "$HomePart" != "" ]; then
umount "$HomePart"
fi
if [ "$BackupPart" != "root" ]; then
umount "$BackupPart"
fi
## Cleanup some
if [ -d /mnt/Super-Happy-Mount-Point ]; then
rm -rf /mnt/Super-Happy-Mount-Point
fi
TimeTaken=$(($(grep "real" /tmp/TimeTaken | awk '{print $2}' | awk -F '.' '{print $1}') / 60))
rm /tmp/TimeTaken
rm /tmp/salineos-backup-temp-file
$Info --text="Creation of backup image "$ImageName.backup" complete.\nImage saved to directory $SaveFolder\nThis operation took "$TimeTaken" minutes." --button=$"gtk-quit:1"
exit 0
}
SelectBackupHomePart () {
PartMenu=""
Partitions=$(cat /proc/partitions | awk '{print $4}' | grep "[0-9]" | grep -v 'p1' | grep -v "$BackupPart")
TempParts="$(echo $Partitions)"
for i in $Partitions; do
TempSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
if [ "$TempSize" = "1" ]; then
TempParts=$(echo $TempParts | sed -r "s/$i//")
fi
done
for i in $TempParts; do
Part="$i"
PartSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
PartMenu="$PartMenu $Part $PartSize"
done
HomePart=$($Menu --height=300 --width=300 --wrap --column="Partition Name" --column="Size In Megabytes" --button=$"gtk-quit:3" --button=$"Use Selected:2" --text="Please select the home partition for "$BackupPart"." $PartMenu )
ret=$?
if [ "$ret" = "252" ]; then
SelectBackupHomePart
exit 0
elif [ "$ret" = "3" ]; then
exit 0
elif [ "$HomePart" = "" ]; then
SelectBackupHomePart
exit 0
fi
HomePart=$(echo "$HomePart" | awk -F '|' '{print $1}')
HomePart="/dev/$HomePart"
StartBackup
}
SelectBackupPart () {
PartMenu=""
Partitions=$(cat /proc/partitions | awk '{print $4}' | grep "[0-9]" | grep -v 'p1')
TempParts="$(echo $Partitions)"
for i in $Partitions; do
TempSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
if [ "$TempSize" = "1" ]; then
TempParts=$(echo $TempParts | sed -r "s/$i//")
fi
done
for i in $TempParts; do
Part="$i"
PartSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
PartMenu="$PartMenu $Part $PartSize"
done
BackupPart=$($Menu --height=300 --width=300 --wrap --column="Partition Name" --column="Size In Megabytes" --button=$"gtk-quit:3" --button=$"Use Selected:2" --text="Please select the root partition you want to backup." $PartMenu )
ret=$?
if [ "$ret" = "252" ]; then
SelectBackupPart
exit 0
elif [ "$ret" = "3" ]; then
exit 0
elif [ "$BackupPart" = "" ]; then
SelectBackupPart
exit 0
fi
BackupPart=$(echo "$BackupPart" | awk -F '|' '{print $1}')
BackupPart="/dev/$BackupPart"
$Question --text="Is /home for this instance on a seperate partition?"
if [ "$?" = "0" ]; then
$Info --wrap --width=250 --button=$"gtk-quit:3" --button=$"gtk-ok:1" --text="If the /home folder for "$BackupPart" is shared with SalineOS, then you will have to run SalineOS backup from a live environment."
ret=$?
if [ "$ret" = "3" ]; then
exit 0
else
SelectBackupHomePart
fi
else
StartBackup
fi
}
RunInstallation () {
tail -f /usr/bin/salineos-backup | $Progress --pulsate --text=" Preparing disk and partitions " &
if [ "$Input" = "ext3" ]; then
FilesystemType="ext3"
else
FilesystemType="ext4"
fi
if [ "$AutoPart" = "Auto" ]; then
parted --script --align optimal /dev/$PartDrive mklabel msdos
parted --script --align optimal /dev/$PartDrive mkpart primary 1 -- -1
parted --script --align optimal /dev/$PartDrive set 1 boot on
TargetHomePart="root"
TargetPart="$PartDrive"1
fi
if [ "$(mount | grep $TargetPart)" != "" ]; then
umount /dev/$TargetPart
sleep 3
fi
mke2fs -t $FilesystemType /dev/$TargetPart
mkdir -p /Target
sleep 3
killall -KILL tail
tail -f /usr/bin/salineos-backup | $Progress --pulsate --text=" Mounting $TargetPart " &
mount /dev/$TargetPart /Target -o rw
sleep 3
killall -KILL tail
tail -f /usr/bin/salineos-backup | $Progress --pulsate --text="Configure the filesystem to be checked\nevery 35 mounts" &
tune2fs -c 35 -i 0 /dev/$TargetPart
sleep 3
rm -rf /Target/lost+found
killall -KILL tail
if [ "$TargetHomePart" != "root" ]; then
if [ "$FormatHome" = "True" ]; then
tail -f /usr/bin/salineos-backup | $Progress --pulsate --text=" Formatting $TargetHomePart for /home " &
umount /dev/$TargetHomePart
sleep 2
mke2fs -t $FilesystemType /dev/$TargetHomePart
sleep 3
killall -KILL tail
fi
tail -f /usr/bin/salineos-backup | $Progress --pulsate --text=" Mounting $TargetHomePart " &
mkdir -p /Target/home
mount /dev/$TargetHomePart /Target/home -o rw
tune2fs -c 35 -i 0 /dev/$TargetHomePart
rm -rf /Target/home/lost+found
TargetHomeUUID=$(blkid /dev/$TargetHomePart | awk -F 'UUID="' '{print $2}' | awk -F '"' '{print $1}')
## Get fs type for the home partition in case the user chose not to format it
HomeFilesystemType=$(mount | grep "/dev/$TargetHomePart" | awk '{print $5}' | awk -F ' ' '{print $1}')
killall -KILL tail
fi
tail -f /usr/bin/salineos-backup | $Progress --pulsate --text=" Generating UUID values for fstab " &
TargetPartUUID=$(blkid /dev/$TargetPart | awk -F 'UUID="' '{print $2}' | awk -F '"' '{print $1}')
TargetCDRom="/dev/cdrom"
sleep 3
killall -KILL tail
## Copy the live system to $Target
tail -f /usr/bin/salineos-backup | $Progress --text=" Copying files to $TargetPart " --pulsate &
## Mount the backup image
mkdir -p /mnt/Super-Happy-Mount-Point
mount "$BackupImage" -o loop /mnt/Super-Happy-Mount-Point
rsync -a /mnt/Super-Happy-Mount-Point/ /Target --ignore-existing --exclude=/{Target,live,cdrom,mnt,proc,sys,media}
sleep 3
## Unmount backup image
umount "/mnt/Super-Happy-Mount-Point"
sleep 1
## Remove mount point
rm -rf /mnt/Super-Happy-Mount-Point
## Make needed aditional folders on the system.
mkdir -p /Target/{proc,dev,mnt,sys,tmp,media/cdrom}
mkdir -p /Target/var/run
sleep 3
killall -KILL tail
tail -f /usr/bin/salineos-backup | $Progress --text=" Setting up swap space " --pulsate &
if [ "$UseSwapFile" = "True" ]; then
mkdir -p /Target/swap
fallocate --l "$SwapFileSize"m /Target/swap/salineos-swap
sleep 2
mkswap /Target/swap/salineos-swap
SwapFstab="/swap/salineos-swap"
else
mkswap $Swap
sleep 2
blkid
sleep 2
TargetSwapUUID=$(blkid /dev/$Swap | awk -F 'UUID="' '{print $2}' | awk -F '"' '{print $1}')
SwapFstab="UUID=$TargetSwapUUID"
fi
killall -KILL tail
tail -f /usr/bin/salineos-backup | $Progress --text="Changing configuration files on installed system" --pulsate &
## Prepare a chroot envoirnment for post install changes
mount -o bind /proc /Target/proc
mount -o bind /dev /Target/dev
mount -o bind /sys /Target/sys
rm -rf /Target/etc/fstab
## Create a new fstab file for the system
if [ "$TargetHomePart" = "root" ]; then
cat > /Target/etc/fstab <<FOO
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# Root was on /dev/$TargetPart during install
UUID=$TargetPartUUID / $FilesystemType relatime,errors=remount-ro 0 1
# Swap space created during install
$SwapFstab none swap sw 0 0
# cdrom
$TargetCDRom /media/cdrom udf,iso9660 user,noauto,exec,utf8 0 0
FOO
else
cat > /Target/etc/fstab <<FOO
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# Root was on /dev/$TargetPart during install
UUID=$TargetPartUUID / $FilesystemType relatime,errors=remount-ro 0 1
# /dev/$TargetHomePart home
UUID=$TargetHomeUUID /home $HomeFilesystemType relatime 0 0
# Swap space created during install
$SwapFstab none swap sw 0 0
# cdrom
$TargetCDRom /media/cdrom udf,iso9660 user,noauto,exec,utf8 0 0
FOO
fi
## Make the users on the system own their home folders
for i in $(ls /Target/home); do
chown -R "$i" /Target/home/"$i"
done
## Fix permissions on /tmp
chmod og+rw /Target/tmp
sleep 3
killall -KILL tail
## Install GRUB2
tail -f /usr/bin/salineos-backup | $Progress --text=" Installing and configuring GRUB2 " --pulsate &
chroot /Target chmod -x /etc/grub.d/20_memtest86+
chroot /Target grub-install --force --no-floppy "$GrubLocation"
sleep 2
chroot /Target update-grub
sleep 2
killall -KILL tail
## Unmount the target partition
tail -f /usr/bin/salineos-backup | $Progress --text=" Unmounting $TargetPart " --pulsate &
sleep 2
umount /Target/home
sleep 2
umount /Target/proc
sleep 2
umount /Target/dev
sleep 2
umount /Target/sys
sleep 2
umount /Target
sleep 2
## Remove Target
rm -rf /Target
killall -KILL tail
$Question --text="\nRestoration is complete.\n\nIf everything went well you should have your\nnew system installed and ready.\n\nDo you want to reboot now to try it out?"
if [ $? = 0 ]; then
reboot
else
exit 0
fi
}
FinishedMenu () {
Change=""
if [ "$AutoPart" = "Manual" ]; then
if [ "$UseSwapFile" = "True" ]; then
SwapFinished='Swap-File'
SwapFinished2="A $SwapFileSize Megabytes swap file will be created"
else
SwapFinished='Swap-Partition'
SwapFinished2="$Swap will be used as the swap partition"
fi
RootPartition="Root-Partition"
if [ "$Input" = "ext3" ]; then
RootPartition2="$TargetPart will be formatted (erased) ext3 and used for root"
else
RootPartition2="$TargetPart will be formatted (erased) ext4 and used for root"
fi
HomePartFinished="Home"
if [ "$TargetHomePart" = "root" ]; then
HomePartFinished2="The home folder will be placed on the root partition"
else
if [ "$FormatHome" = "True" ]; then
if [ "$Input" = "ext3" ]; then
HomePartFinished2="$TargetHomePart will be formated (erased) ext3 and used for /home"
else
HomePartFinished2="$TargetHomePart will be formated (erased) ext4 and used for /home"
fi
else
HomePartFinished2="$TargetHomePart will be used for /home without erasing data"
fi
fi
else
SwapFinished='Swap-File'
SwapFinished2="A $SwapFileSize Megabytes swap file will be created"
RootPartition="Use-Disk"
RootPartition2="$PartDrive will be erased and the entire disk used"
fi
GrubFinished="Boot-Loader"
GrubFinished2="The GRUB2 boot loader will be installed to "$GrubLoc""
if [ "$AutoPart" = "Auto" ]; then
Change=$($Menu --height=300 --column="Option" --column="Current Status" --text="Please review the settings you have chosen carefully, you may go back and change any \nof these settings now.\n" --button=$"gtk-quit:3" --button=$"Change Selected:2" --button=$"Run Installation:5" "$RootPartition" "$RootPartition2" "$SwapFinished" "$SwapFinished2" "$GrubFinished" "$GrubFinished2")
else
Change=$($Menu --height=300 --column="Option" --column="Current Status" --text="Please review the settings you have chosen carefully, you may go back and change any \nof these settings now.\n" --button=$"gtk-quit:3" --button=$"Change Selected:2" --button=$"Run Installation:5" "$RootPartition" "$RootPartition2" "$SwapFinished" "$SwapFinished2" "$HomePartFinished" "$HomePartFinished2" "$GrubFinished" "$GrubFinished2")
fi
ret="$?"
Change=$(echo "$Change" | awk -F '|' '{print $1}')
if [ "$ret" = "252" ]; then
FinishedMenu
exit 0
elif [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the restoration?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
exit 1
else
FinishedMenu
exit 0
fi
elif [ "$ret" = "5" ]; then
rm -rf /tmp/Finished-Menu
RunInstallation
exit 0
elif [ "$Change" = "Swap-Partition" ]; then
SelectSwapPart
exit 0
elif [ "$Change" = "Root-Partition" ]; then
SelectRootPart
exit 0
elif [ "$Change" = "Swap-File" ]; then
SwapFile
exit 0
elif [ "$Change" = "Home" ]; then
SelectHomePart
exit 0
elif [ "$Change" = "Boot-Loader" ]; then
GrubSelect
exit 0
elif [ "$Change" = "Use-Disk" ]; then
ChooseDrive
exit 0
elif [ "$Change" = "" ]; then
$Info --text="No change selected" --button=$"gtk-ok:1"
FinishedMenu
exit 0
fi
rm -rf /tmp/Finished-Menu
}
GrubSelect () {
## Grub location
GrubLocation=""
GrubLoc=""
GrubLoc=$($Menu --width=300 --height=250 --column='Location' --column=' ' --button=$"gtk-quit:3" --button=$"gtk-ok:2" --text="Please select where to install the grub boot loader\n" $GrubMenu root "Root partition - (Advanced)")
ret="$?"
if [ "$ret" = "252" ]; then
GrubSelect
exit 0
elif [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the restoration?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
exit 1
else
GrubSelect
exit 0
fi
elif [ "$GrubLoc" = "" ]; then
$Info --text="The grub location cannot be blank, please choose where to install grub." --button=$"gtk-ok:1"
GrubSelect
exit 0
fi
GrubLoc=$(echo "$GrubLoc" | awk -F '|' '{print $1}')
if [ "$GrubLoc" != "root" ]; then
GrubLocation="/dev/$GrubLoc"
else
GrubLocation="/dev/$TargetPart"
fi
touch /tmp/Finished-Menu
FinishedMenu
}
SelectHomePart () {
HomePartMenu=""
ExtraParts="$(fdisk -l | grep '/dev/' | grep -v "Disk" | grep -v "Extended" | grep -v "$TargetPart" | grep -v "swap" | grep -v 'p1' | grep -v "extended" | grep -v "Hidden" | cut -d " " -f1)"
## Cleanup the fdisk output
HomeParts=$(echo "$ExtraParts" | sed -r "s/\/dev\///g")
for i in $HomeParts; do
HomePart="$i"
HomePartSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
HomePartMenu="$HomePartMenu $HomePart $HomePartSize"
done
HomePart=$($Menu --text=" Select a seperate partition for /home (User files) if desired\n" --height=400 --column=Partition --column="Size in Megabytes" --button=$"gtk-quit:3" --button=$"Use Selected:2" --button=$"Put /home on the root partition:5" $HomePartMenu)
ret=$?
if [ "$ret" = "252" ]; then
SelectHomePart
exit 0
elif [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the installation?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
exit 1
else
SelectSwapPart
exit 0
fi
elif [ "$ret" = "5" ]; then
if [ -f /tmp/Finished-Menu ]; then
TargetHomePart="root"
FinishedMenu
exit 0
fi
TargetHomePart="root"
GrubSelect
exit 0
elif [ "$HomePart" = "" ]; then
SelectHomePart
exit 0
else
TargetHomePart=$(echo "$HomePart" | awk -F '|' '{print $1}')
$Question --text="Format (Erase all data) on the target home partition, $TargetHomePart?"
if [ "$?" = "0" ]; then
FormatHome="True"
else
FormatHome="False"
fi
fi
if [ -f /tmp/Finished-Menu ]; then
FinishedMenu
exit 0
else
GrubSelect
exit 0
fi
}
SelectSwapPart () {
SwapPartMenu=""
Swap=""
## Find swap partitions and find out which to use.
TargetSwap=$(fdisk -l | grep "swap" | cut -d " " -f1)
TargetSwap=$(echo "$TargetSwap" | sed -r "s/\/dev\///g")
for i in $TargetSwap; do
SwapPart="$i"
SwapPartSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
SwapPartMenu="$SwapPartMenu $SwapPart $SwapPartSize"
done
Swap=$($Menu --width=300 --height=250 --text=" Please select the partition to use for swap\n" --column=Partition --column="Size in Megabytes" --button=$"gtk-quit:3" --button=$"Use Swap File:5" --button=$"Use Selected:2" $SwapPartMenu)
ret=$?
if [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the restoration?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
exit 1
else
SelectSwapPart
exit 0
fi
elif [ "$ret" = "252" ]; then
SelectSwapPart
exit 0
elif [ "$ret" = "5" ]; then
SwapFile
exit 0
elif [ "$Swap" = "" ]; then
SelectSwapPart
exit 0
elif [ -f /tmp/Finished-Menu ]; then
Swap=$(echo "$Swap" | awk -F '|' '{print $1}')
FinishedMenu
exit 0
else
HomePartTest="$(fdisk -l | grep '/dev/' | grep -v "Disk" | grep -v 'p1' | grep -v "Extended" | grep -v "$TargetPart" | grep -v "Swap")"
if [ "$HomePartTest" != "" ]; then
Swap=$(echo "$Swap" | awk -F '|' '{print $1}')
SelectHomePart
exit 0
fi
Swap=$(echo "$Swap" | awk -F '|' '{print $1}')
GrubSelect
exit 0
fi
}
SwapFile () {
SwapFileSize=""
if [ "$AutoPart" = "Auto" ]; then
SwapFileSize=$($Menu --column="Size" --column=" " --text=" Please select the size of the swap file to be created.\n" --button=$"Continue:2" 32 Megabytes 64 Megabytes 128 Megabytes 256 Megabytes 512 Megabytes 1024 Megabytes 2048 "Megabytes It is recommended to choose this setting" 3072 Megabytes 4096 Megabytes 5120 Megabytes 6144 Megabytes 8192 Megabytes 16384 Megabytes 30000 Megabytes --height=350 )
else
SwapFileSize=$($Menu --column="Size" --column=" " --text=" Please select the size of the swap file to be created.\n" --button=$"Use Swap Partition (Advanced):3" --button=$"Continue using swap file:2" 32 Megabytes 64 Megabytes 128 Megabytes 256 Megabytes 512 Megabytes 1024 Megabytes 2048 "Megabytes It is recommended to choose this setting" 3072 Megabytes 4096 Megabytes 5120 Megabytes 6144 Megabytes 8192 Megabytes 16384 Megabytes 30000 Megabytes --height=350 )
fi
ret=$?
if [ "$ret" = "3" ]; then
UseSwapFile="False"
SelectSwapPart
exit 0
elif [ "$ret" = "252" ]; then
SwapFile
exit 0
elif [ "$SwapFileSize" = "" ]; then
SwapFile
exit 0
else
UseSwapFile="True"
SwapFileSize=$(echo "$SwapFileSize" | awk -F '|' '{print $1}')
if [ -f /tmp/Finished-Menu ]; then
FinishedMenu
exit 0
elif [ "$AutoPart" = "Auto" ]; then
GrubSelect
exit 0
fi
HomePartTest="$(fdisk -l | grep '/dev/' | grep -v "Disk" | grep -v 'p1' | grep -v "Extended" | grep -v "$TargetPart" | grep -v "Swap")"
if [ "$HomePartTest" != "" ]; then
SelectHomePart
exit 0
fi
GrubSelect
exit 0
fi
}
## Choose the partition to install to
SelectRootPart () {
PartMenu=""
Partitions=$(cat /proc/partitions | grep "$PartDrive" | awk '{print $4}' | grep "[0-9]" | grep -v 'p1')
InstallPart="$(echo $Partitions)"
for i in $Partitions; do
TempSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
if [ "$TempSize" = "1" ]; then
InstallPart=$(echo $InstallPart | sed -r "s/$i//")
fi
done
for i in $InstallPart; do
Part="$i"
PartSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
PartMenu="$PartMenu $Part $PartSize"
done
TargetPart=$($Menu --height=300 --width=300 --wrap --column="Partition Name" --column="Size In Megabytes" --button=$"gtk-quit:3" --button=$"Use Selected:2" --text="Please select a partition to install the root (Main) directory to.\n" $PartMenu )
ret=$?
if [ "$ret" = "252" ]; then
SelectRootPart
exit 0
elif [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the restoration?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
exit 1
else
SelectRootPart
exit 0
fi
elif [ "$TargetPart" = "" ]; then
SelectRootPart
exit 0
fi
TargetPart=$(echo "$TargetPart" | awk -F '|' '{print $1}')
## Since unlike the salineos-installer this utility can be run from a non live envoirnment
## We need to make sure that the user doesn't try to install to the current partition
RootDir="$(mount | grep -B 0 ' / ')"
if [ "$(echo "$RootDir" | grep "$TargetPart")" != "" ]; then
$Info --wrap --width=300 --text="You cannot erase the partition this utility is running from, please select another partition to install to, or run this utility from a live environment.\n"
SelectRootPart
fi
if [ -f /tmp/Finished-Menu ]; then
FinishedMenu
exit 0
else
SwapFile
exit 0
fi
}
## Choose the drive to partition
ChooseDrive () {
GrubMenu=""
PartDriveMenu=""
PartDrive=""
Drives=$(cat /proc/partitions | grep -v loop | grep -v major | grep -v "^$" | awk '{print $4}' | grep -v "[0-9]")
for i in $Drives; do
PartDrive="$i"
PartDriveSize=$(grep -m 1 "$i" /proc/partitions | awk '{print $3}')
PartDriveMenu="$PartDriveMenu $PartDrive $PartDriveSize"
GrubMenu="$PartDrive Master-Boot-Record $GrubMenu"
done
if [ "$AutoPart" = "Auto" ]; then
PartDrive=$($Menu --width=300 --height=300 --column="Drive" --column="Size In Megabytes" --text="Please select a drive to erase and use.\n" --button=$"gtk-quit:3" --button=$"gtk-ok:2" $PartDriveMenu )
else
PartDrive=$($Menu --width=300 --height=300 --column="Drive" --column="Size In Megabytes" --text="Please select a drive to partition.\n" --button=$"gtk-quit:3" --button=$"gtk-ok:2" $PartDriveMenu )
fi
ret=$?
if [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the resoration?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
exit 1
else
ChooseDrive
exit 0
fi
elif [ "$ret" = "252" ]; then
ChooseDrive
exit 0
elif [ "$PartDrive" = "" ]; then
ChooseDrive
exit 0
fi
PartDrive=$(echo "$PartDrive" | awk -F '|' '{print $1}')
## Since unlike the salineos-installer this utility can be run from a non live envoirnment
## We need to make sure that the user doesn't try to autopartition the currently used disk.
RootDir="$(mount | grep -B 0 ' / ')"
if [ "$AutoPart" = "Auto" ]; then
if [ "$(echo "$RootDir" | grep "$PartDrive")" != "" ]; then
$Info --wrap --width=300 --text="You cannot erase the partition this utility is running from, please select another disk or use manual partitioning to select another partition on this disk.\n"
AutoPartitioning
fi
fi
## Launch GParted
if [ "$AutoPart" != "Auto" ]; then
gparted /dev/$PartDrive
fi
if [ "$AutoPart" = "Auto" ]; then
SwapFile
exit 0
else
SelectRootPart
exit 0
fi
}
## Ask the user if they wish to use automatic partitioning.
AutoPartitioning () {
$Info --width=400 --wrap --text="You will need at least one partition in order to restore your backup image.\n\nThe installer can erase all data on a hard drive, USB flash drive, or solid state disk of your choice and create this partition for you automatically, or you can manually partition your storage media using GParted.\n\nManual partitioning will allow you to preserve other operating systems and information on your hard disk." --button=$"Partition disk manually:3" --button=$"Erase and use an entire disk:5"
ret=$?
if [ "$ret" = "252" ]; then
AutoPartitioning
exit 0
elif [ "$ret" = "5" ]; then
AutoPart="Auto"
ChooseDrive
exit 0
elif [ "$ret" = "3" ]; then
AutoPart="Manual"
ChooseDrive
exit 0
fi
}
SelectBackupImage () {
BackupImage=""
BackupImage=$(yad --file-selection --title="SalineOS-Backup" --height=450 --width=600 --text="\n Select the backup image you wish to restore\n" --button=$"gtk-quit:3" --button=$"gtk-ok:2")
ret="$?"
BackupImage=$(echo $BackupImage | awk -F '|' '{print $1}')
if [ "$ret" = "252" ]; then
SelectBackupImage
exit 0
elif [ "$ret" = "3" ]; then
$Question --text="Are you sure you want to cancel the resoration?"
if [ "$?" = "0" ]; then
if [ -f /tmp/Finished-Menu ]; then
rm /tmp/Finished-Menu
fi
fi
exit 1
elif [ "$BackupImage" = "" ]; then
SelectBackupImage
exit 0
elif [ "$(echo "$BackupImage" | grep ".backup")" = "" ]; then
$Info --button=$"gtk-ok:1" --text="$BackupImage is not a valid backup image"
SelectBackupImage
exit 0
fi
AutoPartitioning
exit 0
}
MainMenu () {
Operation=$($SingleMenu --wrap --height=300 --width=400 --text="Please select the operation you wish to perform" "Create a backup image of this SalineOS instance" "Create a backup image of another Linux instance" "Restore a backup image" --button=$"gtk-quit:3" --button=$"gtk-ok:2")
ret="$?"
Operation=$(echo "$Operation" | awk -F '|' '{print $1}')
if [ "$ret" = "3" ]; then
exit 0
elif [ "$ret" = "252" ]; then
MainMenu
exit 0
elif [ "$Operation" = "" ]; then
$Info --text="You must select an operation in order to continue" --button=$"gtk-ok:1"
MainMenu
exit 0
elif [ "$Operation" = "Create a backup image of this SalineOS instance" ]; then
BackupPart="root"
StartBackup
exit 0
elif [ "$Operation" = "Create a backup image of another Linux instance" ]; then
SelectBackupPart
exit 0
elif [ "$Operation" = "Restore a backup image" ]; then
SelectBackupImage
exit 0
fi
}
## Check for root and cry like a little girl if we don't have it.
TestRoot="$(whoami)"
if [ "$TestRoot" != "root" ]; then
$Info --button=$"gtk-quit:1" --text="SalineOS Backup must be run as root."
exit 1
fi
if [ "$1" = "Restore" ]; then
BackupImage="$2"
AutoPartitioning
else
MainMenu
fi
Sat Mar 23, 2013 3:59 pm
Sat Mar 23, 2013 5:48 pm
Sat Mar 23, 2013 7:39 pm
nadir wrote:Is your username "user" ?
If not, then this is wrong:
# Examples:
- /home/user/Downloads/*
- /home/user/Documents/*
#- /home/*/Music/*
#- /home/user/Pictures/*
- /home/user/Videos/*
nadir wrote:I see your point about trying not to break anything. As far it is me "apt-get clean" is really super-safe. And cans safe quite some space. If the above is the problem then it should be superfluous anyway.
nadir wrote:off-the-hook (urgh... off-topic): You were warned to be banned at the thank-you-mr-without-you-a-crap-forum-wouldn't-exist-forum? Ridiculous. Well: i always misunderstand everything ... Probably understood it wrong. Ridiculous anyway ... No one ever thanks me. Without me there would be no interent at all. To start with. Not to speak of the stars in the sky ...
Sat Mar 23, 2013 8:37 pm
Sat Mar 23, 2013 10:04 pm
Oh boy. Don't know how I missed that, but /home/user/whatever refers to the user whose username is user. If you change the username, those entries won't do anything.
Sat Mar 23, 2013 10:19 pm
find ~ -type f -size +100M -exec du -h {} \; 2> /dev/null