Move local restore of gogs to app script

This commit is contained in:
Bob Mottram 2016-07-08 23:01:37 +01:00
parent e3f0ae969e
commit e6a937e541
2 changed files with 88 additions and 67 deletions

View File

@ -50,21 +50,93 @@ function upgrade_gogs {
}
function backup_local_gogs {
if grep -q "Gogs domain" $COMPLETION_FILE; then
if [ -d /home/git/gogs-repositories ]; then
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
if ! grep -q "Gogs domain" $COMPLETION_FILE; then
return
fi
echo $"Backing up gogs"
if [ ! -d /home/git/gogs-repositories ]; then
return
fi
function_check backup_database_to_usb
backup_database_to_usb gogs
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
function_check backup_directory_to_usb
backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs
backup_directory_to_usb /home/git/gogs-repositories gogsrepos
backup_directory_to_usb /home/git/.ssh gogsssh
echo $"Backing up gogs"
echo $"Gogs backup complete"
function_check backup_database_to_usb
backup_database_to_usb gogs
function_check backup_directory_to_usb
backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs
backup_directory_to_usb /home/git/gogs-repositories gogsrepos
backup_directory_to_usb /home/git/.ssh gogsssh
echo $"Gogs backup complete"
}
function restore_local_gogs {
if ! grep -q "Gogs domain" $COMPLETION_FILE; then
return
fi
if [ ! -d /home/git/gogs-repositories ]; then
return
fi
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
export GVM_ROOT=$GVM_HOME
if [ -d $GVM_ROOT/bin ]; then
cd $GVM_ROOT/bin
[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH
fi
if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
function_check restore_database
restore_database gogs ${GIT_DOMAIN_NAME}
temp_restore_dir=/root/tempgogs
if [ -d $USB_MOUNT/backup/gogs ]; then
echo $"Restoring Gogs settings"
if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
fi
cp -r ${temp_restore_dir}/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
if [ ! "$?" = "0" ]; then
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 981
fi
echo $"Restoring Gogs repos"
function_check restore_directory_from_usb
restore_directory_from_usb ${temp_restore_dir}repos gogsrepos
cp -r ${temp_restore_dir}repos/home/git/gogs-repositories/* /home/git/gogs-repositories/
if [ ! "$?" = "0" ]; then
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 67574
fi
echo $"Restoring Gogs authorized_keys"
function_check restore_directory_from_usb
restore_directory_from_usb ${temp_restore_dir}ssh gogsssh
if [ ! -d /home/git/.ssh ]; then
mkdir /home/git/.ssh
fi
cp -r ${temp_restore_dir}ssh/home/git/.ssh/* /home/git/.ssh/
if [ ! "$?" = "0" ]; then
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 8463
fi
rm -rf ${temp_restore_dir}
rm -rf ${temp_restore_dir}repos
rm -rf ${temp_restore_dir}ssh
chown -R git:git /home/git
fi
fi
}
@ -73,6 +145,10 @@ function backup_remote_gogs {
echo -n ''
}
function restore_remote_gogs {
echo -n ''
}
function remove_gogs {
if ! grep -Fxq "install_gogs" $COMPLETION_FILE; then
return

View File

@ -38,7 +38,7 @@ RESTORE_APP='all'
export TEXTDOMAIN=${PROJECT_NAME}-restore-local
export TEXTDOMAINDIR="/usr/share/locale"
# include utils which allow function_check and drive mount
# include utils which allow function_check, go and drive mount
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
do
@ -980,60 +980,6 @@ function restore_mediagoblin {
fi
}
function restore_gogs {
export GVM_ROOT=$GVM_HOME
if [ -d $GVM_ROOT/bin ]; then
cd $GVM_ROOT/bin
[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH
fi
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'gogs' ]]; then
return
fi
fi
if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
restore_database gogs ${GIT_DOMAIN_NAME}
if [ -d $USB_MOUNT/backup/gogs ]; then
echo $"Restoring Gogs settings"
if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
fi
cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
if [ ! "$?" = "0" ]; then
set_user_permissions
backup_unmount_drive
exit 981
fi
echo $"Restoring Gogs repos"
restore_directory_from_usb /root/tempgogsrepos gogsrepos
cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
if [ ! "$?" = "0" ]; then
set_user_permissions
backup_unmount_drive
exit 67574
fi
echo $"Restoring Gogs authorized_keys"
restore_directory_from_usb /root/tempgogsssh gogsssh
if [ ! -d /home/git/.ssh ]; then
mkdir /home/git/.ssh
fi
cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
if [ ! "$?" = "0" ]; then
set_user_permissions
backup_unmount_drive
exit 8463
fi
rm -rf /root/tempgogs
rm -rf /root/tempgogsrepos
rm -rf /root/tempgogsssh
chown -R git:git /home/git
fi
fi
}
function restore_email {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'email' ]]; then
@ -1128,7 +1074,6 @@ restore_hubzilla
restore_rss
restore_syncthing
restore_mediagoblin
restore_gogs
restore_email
restore_apps