浏览代码

Move local restore of gogs to app script

Bob Mottram 9 年前
父节点
当前提交
e6a937e541
共有 2 个文件被更改,包括 88 次插入67 次删除
  1. 87
    11
      src/freedombone-app-gogs
  2. 1
    56
      src/freedombone-restore-local

+ 87
- 11
src/freedombone-app-gogs 查看文件

@@ -50,21 +50,93 @@ function upgrade_gogs {
50 50
 }
51 51
 
52 52
 function backup_local_gogs {
53
-	if grep -q "Gogs domain" $COMPLETION_FILE; then
54
-		if [ -d /home/git/gogs-repositories ]; then
55
-			GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
53
+	if ! grep -q "Gogs domain" $COMPLETION_FILE; then
54
+		return
55
+	fi
56
+
57
+	if [ ! -d /home/git/gogs-repositories ]; then
58
+		return
59
+	fi
60
+
61
+	GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
62
+
63
+	echo $"Backing up gogs"
64
+
65
+	function_check backup_database_to_usb
66
+	backup_database_to_usb gogs
56 67
 
57
-			echo $"Backing up gogs"
68
+	function_check backup_directory_to_usb
69
+	backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs
70
+	backup_directory_to_usb /home/git/gogs-repositories gogsrepos
71
+	backup_directory_to_usb /home/git/.ssh gogsssh
58 72
 
59
-			function_check backup_database_to_usb
60
-			backup_database_to_usb gogs
73
+	echo $"Gogs backup complete"
74
+}
61 75
 
62
-			function_check backup_directory_to_usb
63
-			backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs
64
-			backup_directory_to_usb /home/git/gogs-repositories gogsrepos
65
-			backup_directory_to_usb /home/git/.ssh gogsssh
76
+function restore_local_gogs {
77
+	if ! grep -q "Gogs domain" $COMPLETION_FILE; then
78
+		return
79
+	fi
80
+	if [ ! -d /home/git/gogs-repositories ]; then
81
+		return
82
+	fi
66 83
 
67
-			echo $"Gogs backup complete"
84
+	GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
85
+
86
+	export GVM_ROOT=$GVM_HOME
87
+	if [ -d $GVM_ROOT/bin ]; then
88
+		cd $GVM_ROOT/bin
89
+		[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
90
+		gvm use go${GO_VERSION} --default
91
+		systemctl set-environment GOPATH=$GOPATH
92
+	fi
93
+
94
+	if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
95
+		function_check restore_database
96
+		restore_database gogs ${GIT_DOMAIN_NAME}
97
+		temp_restore_dir=/root/tempgogs
98
+		if [ -d $USB_MOUNT/backup/gogs ]; then
99
+			echo $"Restoring Gogs settings"
100
+			if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
101
+				mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
102
+			fi
103
+			cp -r ${temp_restore_dir}/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
104
+			if [ ! "$?" = "0" ]; then
105
+				function_check set_user_permissions
106
+				set_user_permissions
107
+				function_check backup_unmount_drive
108
+				backup_unmount_drive
109
+				exit 981
110
+			fi
111
+			echo $"Restoring Gogs repos"
112
+			function_check restore_directory_from_usb
113
+			restore_directory_from_usb ${temp_restore_dir}repos gogsrepos
114
+			cp -r ${temp_restore_dir}repos/home/git/gogs-repositories/* /home/git/gogs-repositories/
115
+			if [ ! "$?" = "0" ]; then
116
+				function_check set_user_permissions
117
+				set_user_permissions
118
+				function_check backup_unmount_drive
119
+				backup_unmount_drive
120
+				exit 67574
121
+			fi
122
+			echo $"Restoring Gogs authorized_keys"
123
+			function_check restore_directory_from_usb
124
+			restore_directory_from_usb ${temp_restore_dir}ssh gogsssh
125
+			if [ ! -d /home/git/.ssh ]; then
126
+				mkdir /home/git/.ssh
127
+			fi
128
+			cp -r ${temp_restore_dir}ssh/home/git/.ssh/* /home/git/.ssh/
129
+			if [ ! "$?" = "0" ]; then
130
+				function_check set_user_permissions
131
+				set_user_permissions
132
+				function_check backup_unmount_drive
133
+				backup_unmount_drive
134
+				exit 8463
135
+			fi
136
+			rm -rf ${temp_restore_dir}
137
+			rm -rf ${temp_restore_dir}repos
138
+			rm -rf ${temp_restore_dir}ssh
139
+			chown -R git:git /home/git
68 140
 		fi
69 141
 	fi
70 142
 }
@@ -73,6 +145,10 @@ function backup_remote_gogs {
73 145
 	echo -n ''
74 146
 }
75 147
 
148
+function restore_remote_gogs {
149
+	echo -n ''
150
+}
151
+
76 152
 function remove_gogs {
77 153
 	if ! grep -Fxq "install_gogs" $COMPLETION_FILE; then
78 154
 		return

+ 1
- 56
src/freedombone-restore-local 查看文件

@@ -38,7 +38,7 @@ RESTORE_APP='all'
38 38
 export TEXTDOMAIN=${PROJECT_NAME}-restore-local
39 39
 export TEXTDOMAINDIR="/usr/share/locale"
40 40
 
41
-# include utils which allow function_check and drive mount
41
+# include utils which allow function_check, go and drive mount
42 42
 UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
43 43
 for f in $UTILS_FILES
44 44
 do
@@ -980,60 +980,6 @@ function restore_mediagoblin {
980 980
     fi
981 981
 }
982 982
 
983
-function restore_gogs {
984
-    export GVM_ROOT=$GVM_HOME
985
-    if [ -d $GVM_ROOT/bin ]; then
986
-        cd $GVM_ROOT/bin
987
-        [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
988
-        gvm use go${GO_VERSION} --default
989
-        systemctl set-environment GOPATH=$GOPATH
990
-    fi
991
-
992
-    if [[ $RESTORE_APP != 'all' ]]; then
993
-        if [[ $RESTORE_APP != 'gogs' ]]; then
994
-            return
995
-        fi
996
-    fi
997
-    if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
998
-        restore_database gogs ${GIT_DOMAIN_NAME}
999
-        if [ -d $USB_MOUNT/backup/gogs ]; then
1000
-            echo $"Restoring Gogs settings"
1001
-            if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
1002
-                mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
1003
-            fi
1004
-            cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
1005
-            if [ ! "$?" = "0" ]; then
1006
-                set_user_permissions
1007
-                backup_unmount_drive
1008
-                exit 981
1009
-            fi
1010
-            echo $"Restoring Gogs repos"
1011
-            restore_directory_from_usb /root/tempgogsrepos gogsrepos
1012
-            cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
1013
-            if [ ! "$?" = "0" ]; then
1014
-                set_user_permissions
1015
-                backup_unmount_drive
1016
-                exit 67574
1017
-            fi
1018
-            echo $"Restoring Gogs authorized_keys"
1019
-            restore_directory_from_usb /root/tempgogsssh gogsssh
1020
-            if [ ! -d /home/git/.ssh ]; then
1021
-                mkdir /home/git/.ssh
1022
-            fi
1023
-            cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
1024
-            if [ ! "$?" = "0" ]; then
1025
-                set_user_permissions
1026
-                backup_unmount_drive
1027
-                exit 8463
1028
-            fi
1029
-            rm -rf /root/tempgogs
1030
-            rm -rf /root/tempgogsrepos
1031
-            rm -rf /root/tempgogsssh
1032
-            chown -R git:git /home/git
1033
-        fi
1034
-    fi
1035
-}
1036
-
1037 983
 function restore_email {
1038 984
     if [[ $RESTORE_APP != 'all' ]]; then
1039 985
         if [[ $RESTORE_APP != 'email' ]]; then
@@ -1128,7 +1074,6 @@ restore_hubzilla
1128 1074
 restore_rss
1129 1075
 restore_syncthing
1130 1076
 restore_mediagoblin
1131
-restore_gogs
1132 1077
 
1133 1078
 restore_email
1134 1079
 restore_apps