Browse Source

emacs config remote backup and restore

Bob Mottram 8 years ago
parent
commit
fd7fda6c57
1 changed files with 38 additions and 2 deletions
  1. 38
    2
      src/freedombone-app-emacs

+ 38
- 2
src/freedombone-app-emacs View File

@@ -90,11 +90,47 @@ function restore_local_emacs {
90 90
 }
91 91
 
92 92
 function backup_remote_emacs {
93
-    echo -n ''
93
+    for d in /home/*/ ; do
94
+        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
95
+        if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
96
+            if [ -d /home/$USERNAME/.emacs.d ]; then
97
+                echo $"Backing up Emacs config for $USERNAME"
98
+                if [ -f /home/$USERNAME/.emacs ]; then
99
+                    cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
100
+                fi
101
+                function_check backup_directory_to_friend
102
+                backup_directory_to_friend /home/$USERNAME/.emacs.d emacs/$USERNAME
103
+            fi
104
+        fi
105
+    done
94 106
 }
95 107
 
96 108
 function restore_remote_emacs {
97
-    echo -n ''
109
+    temp_restore_dir=/root/tempemacs
110
+    if [ -d $USB_MOUNT/backup/emacs ]; then
111
+        for d in $USB_MOUNT/backup/emacs/*/ ; do
112
+            USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
113
+            if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
114
+                if [ ! -d /home/$USERNAME ]; then
115
+                    ${PROJECT_NAME}-adduser $USERNAME
116
+                fi
117
+                echo $"Restoring Emacs config for $USERNAME"
118
+                function_check restore_directory_from_friend
119
+                restore_directory_from_friend $temp_restore_dir emacs/$USERNAME
120
+                cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
121
+                if [ ! "$?" = "0" ]; then
122
+                    rm -rf $temp_restore_dir
123
+                    function_check set_user_permissions
124
+                    set_user_permissions
125
+                    function_check backup_unmount_drive
126
+                    backup_unmount_drive
127
+                    exit 664
128
+                fi
129
+                cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
130
+                rm -rf $temp_restore_dir
131
+            fi
132
+        done
133
+    fi
98 134
 }
99 135
 
100 136
 function remove_emacs {