Browse Source

vim config remote backup and restore

Bob Mottram 8 years ago
parent
commit
4cbb0ee745

+ 1
- 1
src/freedombone-app-blog View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS="full writer"
31
+VARIANTS="full full-vim writer"
32 32
 
33 33
 FULLBLOG_DOMAIN_NAME=
34 34
 FULLBLOG_CODE=

+ 1
- 1
src/freedombone-app-dlna View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full media'
31
+VARIANTS='full full-vim media'
32 32
 
33 33
 dlna_variables=(SYSTEM_TYPE
34 34
                 USB_MOUNT

+ 1
- 1
src/freedombone-app-emacs View File

@@ -55,7 +55,7 @@ function backup_local_emacs {
55 55
                     cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
56 56
                 fi
57 57
                 function_check backup_directory_to_usb
58
-                backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
58
+                backup_directory_to_usb /home/$USERNAME/.emacs.d emacs/$USERNAME
59 59
             fi
60 60
         fi
61 61
     done

+ 1
- 1
src/freedombone-app-gnusocial View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full media'
31
+VARIANTS='full full-vim media'
32 32
 
33 33
 MICROBLOG_DOMAIN_NAME=
34 34
 MICROBLOG_CODE=

+ 1
- 1
src/freedombone-app-gogs View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full developer'
31
+VARIANTS='full full-vim developer'
32 32
 
33 33
 GOGS_USERNAME='gogs'
34 34
 GOGS_VERSION='0.9.97'

+ 1
- 1
src/freedombone-app-hubzilla View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full social'
31
+VARIANTS='full full-vim social'
32 32
 
33 33
 HUBZILLA_DOMAIN_NAME=
34 34
 HUBZILLA_CODE=

+ 1
- 1
src/freedombone-app-irc View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full chat'
31
+VARIANTS='full full-vim chat'
32 32
 
33 33
 IRC_PORT=6697
34 34
 IRC_ONION_PORT=6697

+ 1
- 1
src/freedombone-app-mumble View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full chat'
31
+VARIANTS='full full-vim chat'
32 32
 
33 33
 # Password used for mumble server
34 34
 MUMBLE_SERVER_PASSWORD=

+ 1
- 1
src/freedombone-app-rss View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full writer'
31
+VARIANTS='full full-vim writer'
32 32
 
33 33
 RSS_READER_REPO="https://tt-rss.org/git/tt-rss.git"
34 34
 RSS_READER_COMMIT='48007463861d8db8b2b79c2f4f54e0564edb0ec0'

+ 1
- 1
src/freedombone-app-sip View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full chat'
31
+VARIANTS='full full-vim chat'
32 32
 
33 33
 SIP_SERVER_PASSWORD=
34 34
 SIP_PORT=5060

+ 1
- 1
src/freedombone-app-syncthing View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full cloud'
31
+VARIANTS='full full-vim cloud'
32 32
 
33 33
 SYNCTHING_ID=
34 34
 SYNCTHING_CONFIG_PATH=/root/.config/syncthing

+ 1
- 1
src/freedombone-app-tox View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full chat'
31
+VARIANTS='full full-vim chat'
32 32
 
33 33
 TOX_PORT=33445
34 34
 TOXCORE_REPO="https://github.com/bashrc/toxcore"

+ 239
- 0
src/freedombone-app-vim View File

@@ -0,0 +1,239 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Vim editor
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2016 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+VARIANTS='full-vim'
32
+
33
+vim_variables=(MY_USERNAME)
34
+VIM_TEMP_DIR='.vimtemp'
35
+
36
+function change_password_vim {
37
+    echo -n ''
38
+}
39
+
40
+function reconfigure_vim {
41
+    echo -n ''
42
+}
43
+
44
+function upgrade_vim {
45
+    echo -n ''
46
+}
47
+
48
+function backup_local_vim {
49
+    for d in /home/*/ ; do
50
+        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
51
+        if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
52
+            echo $"Backing up Vim config for $USERNAME"
53
+
54
+            # create a temporary directory
55
+            if [ ! -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
56
+                mkdir /home/$USERNAME/$VIM_TEMP_DIR
57
+            fi
58
+
59
+            # copy config files into the directory
60
+            if [ -f /home/$USERNAME/.vimrc ]; then
61
+                cp /home/$USERNAME/.vimrc /home/$USERNAME/$VIM_TEMP_DIR
62
+                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
63
+            fi
64
+            if [ -f /home/$USERNAME/.viminfo ]; then
65
+                cp /home/$USERNAME/.viminfo /home/$USERNAME/$VIM_TEMP_DIR
66
+                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
67
+            fi
68
+
69
+            # backup the directory
70
+            function_check backup_directory_to_usb
71
+            backup_directory_to_usb /home/$USERNAME/$VIM_TEMP_DIR vim/$USERNAME
72
+
73
+            # remove temporary directory
74
+            if [ -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
75
+                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
76
+            fi
77
+        fi
78
+    done
79
+}
80
+
81
+function restore_local_vim {
82
+    temp_restore_dir=/root/tempvim
83
+    if [ -d $USB_MOUNT/backup/vim ]; then
84
+        for d in $USB_MOUNT/backup/vim/*/ ; do
85
+            USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
86
+            if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
87
+                if [ ! -d /home/$USERNAME ]; then
88
+                    ${PROJECT_NAME}-adduser $USERNAME
89
+                fi
90
+                echo $"Restoring Vim config for $USERNAME"
91
+                function_check restore_directory_from_usb
92
+                restore_directory_from_usb $temp_restore_dir vim/$USERNAME
93
+                cp -r $temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR /home/$USERNAME/
94
+                if [ ! "$?" = "0" ]; then
95
+                    rm -rf $temp_restore_dir
96
+                    function_check set_user_permissions
97
+                    set_user_permissions
98
+                    function_check backup_unmount_drive
99
+                    backup_unmount_drive
100
+                    exit 664
101
+                fi
102
+                cp /home/$USERNAME/$VIM_TEMP_DIR/* /home/$USERNAME
103
+                if [ -f /home/$USERNAME/.viminfo ]; then
104
+                    chown $USERNAME:$USERNAME /home/$USERNAME/.viminfo
105
+                fi
106
+                if [ -f /home/$USERNAME/.vimrc ]; then
107
+                    chown $USERNAME:$USERNAME /home/$USERNAME/.vimrc
108
+                fi
109
+                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
110
+                rm -rf $temp_restore_dir
111
+            fi
112
+        done
113
+    fi
114
+}
115
+
116
+function backup_remote_vim {
117
+    for d in /home/*/ ; do
118
+        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
119
+        if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
120
+            echo $"Backing up Vim config for $USERNAME"
121
+
122
+            # create a temporary directory
123
+            if [ ! -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
124
+                mkdir /home/$USERNAME/$VIM_TEMP_DIR
125
+            fi
126
+
127
+            # copy config files into the directory
128
+            if [ -f /home/$USERNAME/.vimrc ]; then
129
+                cp /home/$USERNAME/.vimrc /home/$USERNAME/$VIM_TEMP_DIR
130
+                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
131
+            fi
132
+            if [ -f /home/$USERNAME/.viminfo ]; then
133
+                cp /home/$USERNAME/.viminfo /home/$USERNAME/$VIM_TEMP_DIR
134
+                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
135
+            fi
136
+
137
+            # backup the directory
138
+            function_check backup_directory_to_friend
139
+            backup_directory_to_friend /home/$USERNAME/$VIM_TEMP_DIR vim/$USERNAME
140
+
141
+            # remove temporary directory
142
+            if [ -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
143
+                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
144
+            fi
145
+        fi
146
+    done
147
+}
148
+
149
+function restore_remote_vim {
150
+    temp_restore_dir=/root/tempvim
151
+    if [ -d $USB_MOUNT/backup/vim ]; then
152
+        for d in $USB_MOUNT/backup/vim/*/ ; do
153
+            USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
154
+            if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
155
+                if [ ! -d /home/$USERNAME ]; then
156
+                    ${PROJECT_NAME}-adduser $USERNAME
157
+                fi
158
+                echo $"Restoring Vim config for $USERNAME"
159
+                function_check restore_directory_from_friend
160
+                restore_directory_from_friend $temp_restore_dir vim/$USERNAME
161
+                cp -r $temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR /home/$USERNAME/
162
+                if [ ! "$?" = "0" ]; then
163
+                    rm -rf $temp_restore_dir
164
+                    function_check set_user_permissions
165
+                    set_user_permissions
166
+                    function_check backup_unmount_drive
167
+                    backup_unmount_drive
168
+                    exit 664
169
+                fi
170
+                cp /home/$USERNAME/$VIM_TEMP_DIR/* /home/$USERNAME
171
+                if [ -f /home/$USERNAME/.viminfo ]; then
172
+                    chown $USERNAME:$USERNAME /home/$USERNAME/.viminfo
173
+                fi
174
+                if [ -f /home/$USERNAME/.vimrc ]; then
175
+                    chown $USERNAME:$USERNAME /home/$USERNAME/.vimrc
176
+                fi
177
+                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
178
+                rm -rf $temp_restore_dir
179
+            fi
180
+        done
181
+    fi
182
+}
183
+
184
+function remove_vim {
185
+    apt-get -y remove --purge vim
186
+    update-alternatives --set editor /usr/bin/nano
187
+    sed -i '/install_vim/d' $COMPLETION_FILE
188
+
189
+    # remove Vim as the mutt email editor
190
+    if [ -f /etc/Muttrc ]; then
191
+        if grep -q "set editor=" /etc/Muttrc; then
192
+            sed -i '/set editor=/d' /etc/Muttrc
193
+        fi
194
+        for d in /home/*/ ; do
195
+            USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
196
+            if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
197
+                if [ -f /home/$USERNAME/.muttrc ]; then
198
+                    if grep -q "set editor=" /home/$USERNAME/.muttrc; then
199
+                        sed -i '/set editor=/d' /home/$USERNAME/.muttrc
200
+                    fi
201
+                fi
202
+            fi
203
+        done
204
+    fi
205
+}
206
+
207
+function install_vim {
208
+    apt-get -y install vim
209
+    update-alternatives --set editor /usr/bin/vim
210
+
211
+    # add a mutt entry to use Vim to compose emails
212
+    if [ -f /etc/Muttrc ]; then
213
+        if ! grep -q "set editor=" /etc/Muttrc; then
214
+            echo 'set editor="vim"' >> /etc/Muttrc
215
+        else
216
+            sed -i 's|set editor=.*|set editor="vim"|g' /etc/Muttrc
217
+        fi
218
+        for d in /home/*/ ; do
219
+            USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
220
+            if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
221
+                if [ -f /home/$USERNAME/.muttrc ]; then
222
+                    if ! grep -q "set editor=" /home/$USERNAME/.muttrc; then
223
+                        echo 'set editor="vim"' >> /home/$USERNAME/.muttrc
224
+                    else
225
+                        sed -i 's|set editor=.*|set editor="vim"|g' /home/$USERNAME/.muttrc
226
+                    fi
227
+                fi
228
+            fi
229
+        done
230
+    fi
231
+
232
+    APP_INSTALLED=1
233
+}
234
+
235
+function install_interactive_vim {
236
+    install_vim
237
+}
238
+
239
+# NOTE: deliberately no exit 0

+ 1
- 1
src/freedombone-app-wiki View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full writer'
31
+VARIANTS='full full-vim writer'
32 32
 
33 33
 WIKI_DOMAIN_NAME=
34 34
 WIKI_ADMIN_PASSWORD=

+ 1
- 1
src/freedombone-app-xmpp View File

@@ -28,7 +28,7 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='full chat'
31
+VARIANTS='full full-vim chat'
32 32
 
33 33
 # Directory where XMPP settings are stored
34 34
 XMPP_DIRECTORY="/var/lib/prosody"