#!/bin/bash #Written by David Tate #This works on my 4Pi, but use this at your own risk. #This script is designed to make a copy/backup of your Stellarmate Profile #So if you have to reimage, you can copy these file back over. #Assumptions: #1. That you will use the Pictures Directory (just because it's accessible right-away) #2. The profile name will be: 'ProfileCopy' #3. The profile file will be zipped to: ProfileCopy.tar.gz #4. You must copy this file and the zipped file to a PC or some other compatible # machine prior to re-imaging your SD card #5. You must run this command against this script (to make it executable): # sudo chmod 777 CopyProfile.sc #Directory/Files to copy (only items I see changed): #.local/share/kstars #.config #.indi #Note: I do all the archive and restore from the Pictures directory because we # all have access to it from PCs. DIR_BKUP="/home/stellarmate/Pictures/ProfileCopy" DIR_KSTARS=${DIR_BKUP}"/kstars" DIR_CONFIG=${DIR_BKUP}"/config" DIR_INDI=${DIR_BKUP}"/indi" function backup_profile { if [ -f "/home/stellarmate/Pictures/ProfileCopy.tar.gz" ]; then zenity --width=400 --title "Profile Backup Failed" \ --error --text="You have a previous backup in the Pictures directory, please remove or move it." 2>/dev/null exit fi #Check to see if the directories exist, if not, create them. if [ ! -d "$DIR_BKUP" ]; then mkdir ${DIR_BKUP} fi if [ ! -d "$DIR_KSTARS" ]; then mkdir ${DIR_KSTARS} fi if [ ! -d "$DIR_CONFIG" ]; then mkdir ${DIR_CONFIG} fi if [ ! -d "$DIR_INDI" ]; then mkdir ${DIR_INDI} fi #Copying the kstars files cp /home/stellarmate/.local/share/kstars/image_url.dat ${DIR_KSTARS} & cp /home/stellarmate/.local/share/kstars/mycitydb.sqlite ${DIR_KSTARS} & cp /home/stellarmate/.local/share/kstars/userdb.sqlite ${DIR_KSTARS} & cp /home/stellarmate/.local/share/kstars/wishlist.obslist ${DIR_KSTARS} & #Copying the .config directory (only the directories I see that changed) cp -R /home/stellarmate/.config/dconf* ${DIR_CONFIG} & cp -R /home/stellarmate/.config/pluma* ${DIR_CONFIG} & cp -R /home/stellarmate/.config/session* ${DIR_CONFIG} & cp -R /home/stellarmate/.config/caja* ${DIR_CONFIG} & cp -R /home/stellarmate/.config/gtk-3.0* ${DIR_CONFIG} & cp /home/stellarmate/.config/mimeapps.list ${DIR_CONFIG} & cp /home/stellarmate/.config/kstarsrc ${DIR_CONFIG} & #Copying the .indi files cp /home/stellarmate/.indi/*.* ${DIR_INDI} & wait echo Zipping... tar -czf ~/Pictures/ProfileCopy.tar.gz --absolute-names ${DIR_BKUP} if [ $? -eq 0 ]; then rm -r ${DIR_BKUP} zenity --width=400 --title "Profile Backup Complete" --info --text="Created the tar file: /Pictures/ProfileCopy.tar.gz \nCopy that file to your PC for later restoral if needed. Don't forget to copy this script too." 2>/dev/null else zenity --width=400 --title "Profile Backup Failed" --error --text="There was an error creating the tar zip file." 2>/dev/null fi } function restore_profile { RESTORE_FROM_ZIP=/home/stellarmate/Pictures/ProfileCopy.tar.gz if [ ! -f "$RESTORE_FROM_ZIP" ]; then zenity --width=400 --title "Restore Profile" --error --text="The ProfileCopy.tar.gz has not been created in the Pictures directory." 2>/dev/null exit fi #Unzip the tar file tar xfP ${RESTORE_FROM_ZIP} if [ $? -ne 0 ]; then rm -r ${DIR_BKUP} zenity --width=400 --title "Profile Restore Fail" --error --text="Something went wrong with unzipping the Profile tar file." 2>/dev/null exit fi RESTORE_FROM_DIR=/home/stellarmate/Pictures/ProfileCopy #Copying the kstars files cp ${RESTORE_FROM_DIR}/kstars/image_url.dat /home/stellarmate/.local/share/kstars/ & cp ${RESTORE_FROM_DIR}/kstars/mycitydb.sqlite /home/stellarmate/.local/share/kstars/ & cp ${RESTORE_FROM_DIR}/kstars/userdb.sqlite /home/stellarmate/.local/share/kstars/ & cp ${RESTORE_FROM_DIR}/kstars/wishlist.obslist /home/stellarmate/.local/share/kstars/ & #Copying the .config directory (only the directories I see that changed) cp -r ${RESTORE_FROM_DIR}/config/* /home/stellarmate/.config/ & #Copying the .indi files cp ${RESTORE_FROM_DIR}/indi/* /home/stellarmate/.indi/ & wait #Deleting the extracted directory if [ $? -eq 0 ]; then rm -r /home/stellarmate/Pictures/ProfileCopy zenity --width=400 --title "Profile Restore Complete" --info --text="Restoring your profile was successfull." 2>/dev/null else zenity --width=400 --title "Profile Restore Failed" --error --text="Restoring your profile failed." 2>/dev/null fi } function main_menu { HEIGHT=15 WIDTH=40 CHOICE_HEIGHT=4 BACKTITLE="Stellarmate Profile Backup/Restore" TITLE="User Profile Backup" MENU="Choose one of the following options:" OPTIONS=(1 "Backup Profile" 2 "Restore Profile" 3 "Quit") CHOICE=$(dialog --clear \ --backtitle "$BACKTITLE" \ --title "$TITLE" \ --menu "$MENU" \ $HEIGHT $WIDTH $CHOICE_HEIGHT \ "${OPTIONS[@]}" \ 2>&1 >/dev/tty) clear case $CHOICE in 1) echo "You chose to backup your Profile" backup_profile ;; 2) echo "You chose to restore your Profile" restore_profile ;; 3) echo "You chose to Quit" ;; esac } function main_menu_2 { # source # https://www.raspberrypi.org/forums/viewtopic.php?t=78057 clear RETVAL=$(whiptail --title "Make a selection and Enter" \ --menu --nocancel "Menu Script" 10 50 4 \ "a" "Backup Stellarmate profile" \ "b" "Restore Stellarmate profile" \ "c" "Quit" \ 3>&1 1>&2 2>&3) # Below you can enter the corresponding commands case $RETVAL in a) backup_profile ;; b) restore_profile ;; c) exit;; *) echo "Invalid option. Quitting";; esac } # Acapulco Rolf # 16 February 2020 # this alternate menu dialog uses whiptail which comes installed on raspbian by default # this is the same menu dialog that is used by raspi-config main_menu_2 # if [ $CHOICE == 3 ]; then # exit # fi