Improved handling of Go version

This commit is contained in:
Bob Mottram 2016-04-29 13:55:17 +01:00
parent d334fbf399
commit 81ed974d4b
No known key found for this signature in database
GPG Key ID: BA68F26108DC9F87
5 changed files with 2286 additions and 2222 deletions

View File

@ -89,6 +89,8 @@ SSH_PORT=2222
IRC_PORT=6697 IRC_PORT=6697
IRC_ONION_PORT=6697 IRC_ONION_PORT=6697
GO_VERSION=1.5
# password used for accessing your repo mirrors # password used for accessing your repo mirrors
MY_MIRRORS_PASSWORD= MY_MIRRORS_PASSWORD=
# friend's repo mirrors # friend's repo mirrors
@ -2635,6 +2637,16 @@ function create_mirrors {
echo 'create_mirrors' >> $COMPLETION_FILE echo 'create_mirrors' >> $COMPLETION_FILE
} }
function select_go_version {
if [ ! -d $HOME/.gvm/scripts ]; then
echo $'GVM was not installed'
exit 629532
fi
cd $HOME/.gvm/scripts
gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH
}
function mesh_cjdns_tools { function mesh_cjdns_tools {
if grep -Fxq "mesh_cjdns_tools" $COMPLETION_FILE; then if grep -Fxq "mesh_cjdns_tools" $COMPLETION_FILE; then
return return
@ -2646,31 +2658,30 @@ function mesh_cjdns_tools {
mesh_cjdns mesh_cjdns
fi fi
select_go_version
apt-get -y install golang mercurial apt-get -y install golang mercurial
if [ ! -f ~/.bashrc ]; then if [ ! -f ~/.bashrc ]; then
touch ~/.bashrc touch ~/.bashrc
fi fi
export GOPATH=/home/git/go
if [ ! -d /home/git ]; then if [ ! -d /home/git ]; then
# add a gogs user account # add a gogs user account
adduser --disabled-login --gecos 'Gogs' git adduser --disabled-login --gecos 'Gogs' git
# install Go # install Go
export GOPATH=/home/git/go if ! grep -q "export GOPATH=" ~/.bashrc; then
if ! grep -q "export GOPATH=/home/git/go" ~/.bashrc; then echo "export GOPATH=$GOPATH" >> ~/.bashrc
echo 'export GOPATH=/home/git/go' >> ~/.bashrc
fi fi
systemctl set-environment GOPATH=/home/git/go systemctl set-environment GOPATH=$GOPATH
if ! grep -q "systemctl set-environment GOPATH=/home/git/go" ~/.bashrc; then if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
echo 'systemctl set-environment GOPATH=/home/git/go' >> ~/.bashrc echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
fi fi
if [ ! -d $GOPATH ]; then if [ ! -d $GOPATH ]; then
mkdir -p $GOPATH mkdir -p $GOPATH
fi fi
fi fi
export GOPATH=$GOPATH
if ! grep -q "export GOPATH=" ~/.bashrc; then if ! grep -q "export GOPATH=" ~/.bashrc; then
echo "export GOPATH=$GOPATH" >> ~/.bashrc echo "export GOPATH=$GOPATH" >> ~/.bashrc
fi fi
@ -6309,12 +6320,12 @@ function upgrade_golang {
gvm install go1.4 gvm install go1.4
gvm use go1.4 gvm use go1.4
export GOROOT_BOOTSTRAP=$GOROOT export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.5 gvm install go${GO_VERSION}
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $'Unable to upgrade golang' echo $'Unable to upgrade golang'
exit 529252 exit 529252
fi fi
gvm use go1.5 --default gvm use go${GO_VERSION} --default
if ! grep -q "gvm commit" $COMPLETION_FILE; then if ! grep -q "gvm commit" $COMPLETION_FILE; then
echo "gvm commit:$GVM_COMMIT" >> $COMPLETION_FILE echo "gvm commit:$GVM_COMMIT" >> $COMPLETION_FILE
@ -6333,8 +6344,7 @@ function install_gogs {
return return
fi fi
export GOPATH=/home/git/go select_go_version
systemctl set-environment GOPATH=/home/git/go
# update to the next commit # update to the next commit
set_repo_commit $GOPATH/src/github.com/gogits/gogs "Gogs commit" "$GOGS_COMMIT" $GIT_DOMAIN_REPO set_repo_commit $GOPATH/src/github.com/gogits/gogs "Gogs commit" "$GOGS_COMMIT" $GIT_DOMAIN_REPO
@ -6354,13 +6364,12 @@ function install_gogs {
# install Go # install Go
apt-get -y install golang libpam0g-dev apt-get -y install golang libpam0g-dev
export GOPATH=/home/git/go if ! grep -q "export GOPATH=" ~/.bashrc; then
if ! grep -q "export GOPATH=/home/git/go" ~/.bashrc; then echo "export GOPATH=$GOPATH" >> ~/.bashrc
echo 'export GOPATH=/home/git/go' >> ~/.bashrc
fi fi
systemctl set-environment GOPATH=/home/git/go systemctl set-environment GOPATH=$GOPATH
if ! grep -q "systemctl set-environment GOPATH=/home/git/go" ~/.bashrc; then if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
echo 'systemctl set-environment GOPATH=/home/git/go' >> ~/.bashrc echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
fi fi
if [ ! -d $GOPATH ]; then if [ ! -d $GOPATH ]; then
mkdir -p $GOPATH mkdir -p $GOPATH
@ -6430,7 +6439,7 @@ function install_gogs {
echo $'Check "Enable Register Confirmation"' >> /home/$MY_USERNAME/README echo $'Check "Enable Register Confirmation"' >> /home/$MY_USERNAME/README
echo $'Check "Enable Mail Notification"' >> /home/$MY_USERNAME/README echo $'Check "Enable Mail Notification"' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README echo '' >> /home/$MY_USERNAME/README
echo $'After the initial install edit /home/git/go/src/github.com/gogits/gogs/custom/conf/app.ini' >> /home/$MY_USERNAME/README echo $"After the initial install edit ${GOPATH}/src/github.com/gogits/gogs/custom/conf/app.ini" >> /home/$MY_USERNAME/README
echo $'and within the [server] section set:' >> /home/$MY_USERNAME/README echo $'and within the [server] section set:' >> /home/$MY_USERNAME/README
echo " DOMAIN = $GIT_DOMAIN_NAME" >> /home/$MY_USERNAME/README echo " DOMAIN = $GIT_DOMAIN_NAME" >> /home/$MY_USERNAME/README
echo " ROOT_URL = http://$GIT_DOMAIN_NAME/" >> /home/$MY_USERNAME/README echo " ROOT_URL = http://$GIT_DOMAIN_NAME/" >> /home/$MY_USERNAME/README
@ -6456,14 +6465,14 @@ function install_gogs {
create_database gogs "$GOGS_ADMIN_PASSWORD" create_database gogs "$GOGS_ADMIN_PASSWORD"
chmod 600 /home/git/go/src/github.com/gogits/gogs/custom/conf/app.ini chmod 600 $GOPATH/src/github.com/gogits/gogs/custom/conf/app.ini
chown -R git:git /home/git chown -R git:git /home/git
cp $GOPATH/src/github.com/gogits/gogs/scripts/systemd/gogs.service /etc/systemd/system cp $GOPATH/src/github.com/gogits/gogs/scripts/systemd/gogs.service /etc/systemd/system
sed -i 's|#After=mysqld.service|After=mysqld.service|g' /etc/systemd/system/gogs.service sed -i 's|#After=mysqld.service|After=mysqld.service|g' /etc/systemd/system/gogs.service
sed -i "s|WorkingDirectory=.*|WorkingDirectory=$GOPATH/src/github.com/gogits/gogs|g" /etc/systemd/system/gogs.service sed -i "s|WorkingDirectory=.*|WorkingDirectory=$GOPATH/src/github.com/gogits/gogs|g" /etc/systemd/system/gogs.service
sed -i "s|ExecStart=.*|ExecStart=$GOPATH/src/github.com/gogits/gogs/gogs web|g" /etc/systemd/system/gogs.service sed -i "s|ExecStart=.*|ExecStart=$GOPATH/src/github.com/gogits/gogs/gogs web|g" /etc/systemd/system/gogs.service
sed -i "s|Environment.*|Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=/home/git/go\"|g" /etc/systemd/system/gogs.service sed -i "s|Environment.*|Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=$GOPATH\"|g" /etc/systemd/system/gogs.service
systemctl enable gogs systemctl enable gogs
systemctl daemon-reload systemctl daemon-reload
systemctl restart gogs systemctl restart gogs
@ -10079,11 +10088,10 @@ function install_ipfs {
return return
fi fi
export GOPATH=/home/git/go select_go_version
systemctl set-environment GOPATH=/home/git/go
# update to the next commit # update to the next commit
set_repo_commit /home/git/go/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
if grep -Fxq "install_ipfs" $COMPLETION_FILE; then if grep -Fxq "install_ipfs" $COMPLETION_FILE; then
return return
@ -10096,21 +10104,19 @@ function install_ipfs {
adduser --disabled-login --gecos 'Gogs' git adduser --disabled-login --gecos 'Gogs' git
# install Go # install Go
export GOPATH=/home/git/go if ! grep -q "export GOPATH=" ~/.bashrc; then
if ! grep -q "export GOPATH=/home/git/go" ~/.bashrc; then echo "export GOPATH=$GOPATH" >> ~/.bashrc
echo 'export GOPATH=/home/git/go' >> ~/.bashrc
fi fi
systemctl set-environment GOPATH=/home/git/go systemctl set-environment GOPATH=$GOPATH
if ! grep -q "systemctl set-environment GOPATH=/home/git/go" ~/.bashrc; then if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
echo 'systemctl set-environment GOPATH=/home/git/go' >> ~/.bashrc echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
fi fi
export GOPATH=/home/git/go
if [ ! -d $GOPATH ]; then if [ ! -d $GOPATH ]; then
mkdir -p $GOPATH mkdir -p $GOPATH
fi fi
fi fi
IPFS_PATH=/home/git/go/bin IPFS_PATH=$GOPATH/bin
export PATH="$GOPATH/bin:$PATH:" export PATH="$GOPATH/bin:$PATH:"
if ! grep -q 'GOPATH/bin' ~/.bashrc; then if ! grep -q 'GOPATH/bin' ~/.bashrc; then
echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
@ -10118,7 +10124,7 @@ function install_ipfs {
# set gopath for the user # set gopath for the user
if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
echo 'export GOPATH=/home/git/go' >> /home/$MY_USERNAME/.bashrc echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
fi fi
@ -10129,7 +10135,7 @@ function install_ipfs {
exit 8242 exit 8242
fi fi
cd /home/git/go/src/$IPFS_GO_REPO2 cd $GOPATH/src/$IPFS_GO_REPO2
git checkout $IPFS_COMMIT -b $IPFS_COMMIT git checkout $IPFS_COMMIT -b $IPFS_COMMIT
if ! grep -q "ipfs commit" $COMPLETION_FILE; then if ! grep -q "ipfs commit" $COMPLETION_FILE; then
echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
@ -10171,7 +10177,7 @@ function install_ipfs {
echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=/home/git/go\"" >> /etc/systemd/system/ipfs.service echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\"" >> /etc/systemd/system/ipfs.service
echo '' >> /etc/systemd/system/ipfs.service echo '' >> /etc/systemd/system/ipfs.service
echo '[Install]' >> /etc/systemd/system/ipfs.service echo '[Install]' >> /etc/systemd/system/ipfs.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service

View File

@ -42,9 +42,16 @@ USB_MOUNT=/mnt/usb
# get default USB from config file # get default USB from config file
CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
if [ -f $CONFIG_FILE ]; then if [ -f $CONFIG_FILE ]; then
if grep -q "USB_DRIVE=" $CONFIG_FILE; then if grep -q "USB_DRIVE=" $CONFIG_FILE; then
USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}') USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
fi fi
fi
# get the version of Go being used
if [ -f /usr/local/bin/${PROJECT_NAME} ]; then
GO_VERSION=$(cat /usr/local/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
else
GO_VERSION=$(cat /usr/bin/${PROJECT_NAME} | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
fi fi
ADMIN_USERNAME= ADMIN_USERNAME=
@ -56,270 +63,270 @@ SUSPENDED_SITE=
DATABASE_PASSWORD='' DATABASE_PASSWORD=''
if [ -f /root/dbpass ]; then if [ -f /root/dbpass ]; then
DATABASE_PASSWORD=$(cat /root/dbpass) DATABASE_PASSWORD=$(cat /root/dbpass)
fi fi
function suspend_site { function suspend_site {
# suspends a given website # suspends a given website
if [[ $ENABLE_VERIFICATION != "yes" ]]; then if [[ $ENABLE_VERIFICATION != "yes" ]]; then
return return
fi fi
SUSPENDED_SITE="$1" SUSPENDED_SITE="$1"
nginx_dissite $SUSPENDED_SITE nginx_dissite $SUSPENDED_SITE
service nginx reload service nginx reload
} }
function restart_site { function restart_site {
# restarts a given website # restarts a given website
if [ ! $SUSPENDED_SITE ]; then if [ ! $SUSPENDED_SITE ]; then
return return
fi fi
nginx_ensite $SUSPENDED_SITE nginx_ensite $SUSPENDED_SITE
service nginx reload service nginx reload
SUSPENDED_SITE= SUSPENDED_SITE=
} }
function update_domains { function update_domains {
RSS_READER_DOMAIN_NAME='ttrss' RSS_READER_DOMAIN_NAME='ttrss'
if grep -q "RSS reader domain" $COMPLETION_FILE; then if grep -q "RSS reader domain" $COMPLETION_FILE; then
RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') RSS_READER_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
fi fi
GIT_DOMAIN_NAME='gogs' GIT_DOMAIN_NAME='gogs'
if grep -q "Gogs domain" $COMPLETION_FILE; then if grep -q "Gogs domain" $COMPLETION_FILE; then
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}') GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
fi fi
MICROBLOG_DOMAIN_NAME='microblog' MICROBLOG_DOMAIN_NAME='microblog'
if grep -q "GNU Social domain" $COMPLETION_FILE; then if grep -q "GNU Social domain" $COMPLETION_FILE; then
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}') MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
fi fi
HUBZILLA_DOMAIN_NAME='hubzilla' HUBZILLA_DOMAIN_NAME='hubzilla'
if grep -q "Hubzilla domain" $COMPLETION_FILE; then if grep -q "Hubzilla domain" $COMPLETION_FILE; then
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}') HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
fi fi
FULLBLOG_DOMAIN_NAME='blog' FULLBLOG_DOMAIN_NAME='blog'
if grep -q "Blog domain" $COMPLETION_FILE; then if grep -q "Blog domain" $COMPLETION_FILE; then
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}') FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
fi fi
MEDIAGOBLIN_DOMAIN_NAME='mediagoblin' MEDIAGOBLIN_DOMAIN_NAME='mediagoblin'
if grep -q "Mediagoblin domain" $COMPLETION_FILE; then if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}') MEDIAGOBLIN_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Mediagoblin domain" | awk -F ':' '{print $2}')
fi fi
} }
function mount_drive { function mount_drive {
if [ $1 ]; then if [ $1 ]; then
USB_DRIVE=/dev/${1}1 USB_DRIVE=/dev/${1}1
fi fi
# get the admin user # get the admin user
ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}') ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
if [ $2 ]; then if [ $2 ]; then
ADMIN_USERNAME=$2 ADMIN_USERNAME=$2
fi fi
ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1) ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
# check that the backup destination is available # check that the backup destination is available
if [ ! -b $USB_DRIVE ]; then if [ ! -b $USB_DRIVE ]; then
echo $"Please attach a USB drive" echo $"Please attach a USB drive"
exit 1 exit 1
fi fi
# unmount if already mounted # unmount if already mounted
umount -f $USB_MOUNT umount -f $USB_MOUNT
if [ ! -d $USB_MOUNT ]; then if [ ! -d $USB_MOUNT ]; then
mkdir $USB_MOUNT mkdir $USB_MOUNT
fi fi
if [ -f /dev/mapper/encrypted_usb ]; then if [ -f /dev/mapper/encrypted_usb ]; then
rm -rf /dev/mapper/encrypted_usb rm -rf /dev/mapper/encrypted_usb
fi fi
cryptsetup luksClose encrypted_usb cryptsetup luksClose encrypted_usb
# mount the encrypted backup drive # mount the encrypted backup drive
cryptsetup luksOpen $USB_DRIVE encrypted_usb cryptsetup luksOpen $USB_DRIVE encrypted_usb
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
USB_DRIVE=/dev/mapper/encrypted_usb USB_DRIVE=/dev/mapper/encrypted_usb
fi fi
mount $USB_DRIVE $USB_MOUNT mount $USB_DRIVE $USB_MOUNT
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"There was a problem mounting the USB drive to $USB_MOUNT" echo $"There was a problem mounting the USB drive to $USB_MOUNT"
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
exit 2 exit 2
fi fi
} }
function unmount_drive { function unmount_drive {
sync sync
umount $USB_MOUNT umount $USB_MOUNT
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"Unable to unmount the drive. This means that the backup did not work" echo $"Unable to unmount the drive. This means that the backup did not work"
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
exit 9 exit 9
fi fi
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then
echo $"Unmount encrypted USB" echo $"Unmount encrypted USB"
cryptsetup luksClose encrypted_usb cryptsetup luksClose encrypted_usb
fi fi
if [ -f /dev/mapper/encrypted_usb ]; then if [ -f /dev/mapper/encrypted_usb ]; then
rm -rf /dev/mapper/encrypted_usb rm -rf /dev/mapper/encrypted_usb
fi fi
echo $"Backup to USB drive is complete. You can now unplug it." echo $"Backup to USB drive is complete. You can now unplug it."
} }
function backup_database { function backup_database {
if [ ${#DATABASE_PASSWORD} -lt 2 ]; then if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
echo $"No MariaDB password was given" echo $"No MariaDB password was given"
restart_site restart_site
exit 10 exit 10
fi fi
if [ ! -d $USB_MOUNT/backup/${1} ]; then if [ ! -d $USB_MOUNT/backup/${1} ]; then
mkdir -p $USB_MOUNT/backup/${1} mkdir -p $USB_MOUNT/backup/${1}
fi fi
if [ ! -d $USB_MOUNT/backup/${1}data ]; then if [ ! -d $USB_MOUNT/backup/${1}data ]; then
mkdir -p $USB_MOUNT/backup/${1}data mkdir -p $USB_MOUNT/backup/${1}data
fi fi
if [ ! -d /root/temp${1}data ]; then if [ ! -d /root/temp${1}data ]; then
mkdir -p /root/temp${1}data mkdir -p /root/temp${1}data
fi fi
echo $"Obtaining ${1} database backup" echo $"Obtaining ${1} database backup"
mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > /root/temp${1}data/${1}.sql
if [ ! -s /root/temp${1}data/${1}.sql ]; then if [ ! -s /root/temp${1}data/${1}.sql ]; then
echo $"${1} database could not be saved" echo $"${1} database could not be saved"
shred -zu /root/temp${1}data/* shred -zu /root/temp${1}data/*
rm -rf /root/temp${1}data rm -rf /root/temp${1}data
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
restart_site restart_site
exit 5 exit 5
fi fi
} }
function backup_directory_to_usb { function backup_directory_to_usb {
if [ ! -d ${1} ]; then if [ ! -d ${1} ]; then
echo $"WARNING: directory does not exist: ${1}" echo $"WARNING: directory does not exist: ${1}"
else else
BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)") BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo $"Backup key could not be found" echo $"Backup key could not be found"
restart_site restart_site
exit 6 exit 6
fi fi
MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}') MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
if [ ! -d $USB_MOUNT/backup/${2} ]; then if [ ! -d $USB_MOUNT/backup/${2} ]; then
mkdir -p $USB_MOUNT/backup/${2} mkdir -p $USB_MOUNT/backup/${2}
fi fi
obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
if [[ $ENABLE_VERIFICATION == "yes" ]]; then if [[ $ENABLE_VERIFICATION == "yes" ]]; then
obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1} obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/* shred -zu ${1}/*
rm -rf ${1} rm -rf ${1}
fi fi
restart_site restart_site
exit 71 exit 71
fi fi
fi fi
obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/* shred -zu ${1}/*
rm -rf ${1} rm -rf ${1}
fi fi
restart_site restart_site
exit 7 exit 7
fi fi
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/* shred -zu ${1}/*
rm -rf ${1} rm -rf ${1}
fi fi
fi fi
} }
function make_backup_directory { function make_backup_directory {
# make a backup directory on the drive # make a backup directory on the drive
if [ ! -d $USB_MOUNT/backup ]; then if [ ! -d $USB_MOUNT/backup ]; then
mkdir $USB_MOUNT/backup mkdir $USB_MOUNT/backup
fi fi
if [ ! -d $USB_MOUNT/backup ]; then if [ ! -d $USB_MOUNT/backup ]; then
echo $"There was a problem making the directory $USB_MOUNT/backup." echo $"There was a problem making the directory $USB_MOUNT/backup."
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
exit 3 exit 3
fi fi
} }
function check_storage_space_remaining { function check_storage_space_remaining {
# Check space remaining on the usb drive # Check space remaining on the usb drive
used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}') used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
if [ $used_percent -gt 95 ]; then if [ $used_percent -gt 95 ]; then
echo $"Less than 5% of space remaining on backup drive" echo $"Less than 5% of space remaining on backup drive"
umount $USB_MOUNT umount $USB_MOUNT
rm -rf $USB_MOUNT rm -rf $USB_MOUNT
exit 4 exit 4
fi fi
} }
function backup_users { function backup_users {
# Backup user files # Backup user files
for d in /home/*/ ; do for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}') USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
# Backup any gpg keys # Backup any gpg keys
if [ -d /home/$USERNAME/.gnupg ]; then if [ -d /home/$USERNAME/.gnupg ]; then
echo $"Backing up gpg keys for $USERNAME" echo $"Backing up gpg keys for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME
fi fi
# Backup any personal settings # Backup any personal settings
if [ -d /home/$USERNAME/personal ]; then if [ -d /home/$USERNAME/personal ]; then
echo $"Backing up personal settings for $USERNAME" echo $"Backing up personal settings for $USERNAME"
backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME
fi fi
# Backup ssh keys # Backup ssh keys
if [ -d /home/$USERNAME/.ssh ]; then if [ -d /home/$USERNAME/.ssh ]; then
echo $"Backing up ssh keys for $USERNAME" echo $"Backing up ssh keys for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME
fi fi
# Backup fin database if it exists # Backup fin database if it exists
if [ -d /home/$USERNAME/.fin ]; then if [ -d /home/$USERNAME/.fin ]; then
echo $"Backing up fin files for $USERNAME" echo $"Backing up fin files for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
fi fi
# Backup syncthing # Backup syncthing
if [ -d /home/$USERNAME/Sync ]; then if [ -d /home/$USERNAME/Sync ]; then
echo $"Backing up syncthing files for $USERNAME" echo $"Backing up syncthing files for $USERNAME"
backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
# ensure that device IDs will be backed up as part of user config settings # ensure that device IDs will be backed up as part of user config settings
if [ ! -d /home/$USERNAME/.config/syncthing ]; then if [ ! -d /home/$USERNAME/.config/syncthing ]; then
mkdir -p /home/$USERNAME/.config/syncthing mkdir -p /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi fi
if [ -f /home/$USERNAME/.syncthing-server-id ]; then if [ -f /home/$USERNAME/.syncthing-server-id ]; then
cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi fi
if [ -f /home/$USERNAME/.syncthingids ]; then if [ -f /home/$USERNAME/.syncthingids ]; then
cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
fi fi
fi fi
# Backup user configs # Backup user configs
if [ -d /home/$USERNAME/.config ]; then if [ -d /home/$USERNAME/.config ]; then
echo $"Backing up config files for $USERNAME" echo $"Backing up config files for $USERNAME"
backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
fi fi
# Backup user local # Backup user local
if [ -d /home/$USERNAME/.local ]; then if [ -d /home/$USERNAME/.local ]; then
echo $"Backing up local files for $USERNAME" echo $"Backing up local files for $USERNAME"
@ -370,6 +377,12 @@ function backup_users {
} }
function backup_directories { function backup_directories {
if [ -d $HOME/.gvm/scripts ]; then
cd $HOME/.gvm/scripts
gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH
fi
# directories to be backed up (source,dest) # directories to be backed up (source,dest)
backup_dirs=( backup_dirs=(
"none, none, /etc/letsencrypt, letsencrypt" "none, none, /etc/letsencrypt, letsencrypt"
@ -382,8 +395,8 @@ function backup_directories {
"none, none, /etc/nginx/sites-available, web" "none, none, /etc/nginx/sites-available, web"
"none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs" "none, none, /home/$ADMIN_USERNAME/.ipfs, ipfs"
"none, none, /var/cache/minidlna, dlna" "none, none, /var/cache/minidlna, dlna"
"/home/git/go/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata" "$GOPATH/src/github.com/gogits, gogs, /root/tempgogsdata, gogsdata"
"none, none, /home/git/go/src/github.com/gogits/gogs/custom, gogs" "none, none, $GOPATH/src/github.com/gogits/gogs/custom, gogs"
"none, none, /home/git/gogs-repositories, gogsrepos" "none, none, /home/git/gogs-repositories, gogsrepos"
"none, none, /home/git/.ssh, gogsssh" "none, none, /home/git/.ssh, gogsssh"
"none, none, /var/lib/tox-bootstrapd, tox" "none, none, /var/lib/tox-bootstrapd, tox"
@ -451,8 +464,14 @@ function remove_backup_directory {
} }
function prepare_directories { function prepare_directories {
if [ -d $HOME/.gvm/scripts ]; then
cd $HOME/.gvm/scripts
gvm use go${GO_VERSION} --default
systemctl set-environment GOPATH=$GOPATH
fi
# Some miscellaneous preparation for backing up directories # Some miscellaneous preparation for backing up directories
if [ -d /home/git/go/src/github.com/gogits ]; then if [ -d $GOPATH/src/github.com/gogits ]; then
mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/$ADMIN_USERNAME
fi fi
if [ -d /var/lib/tox-bootstrapd ]; then if [ -d /var/lib/tox-bootstrapd ]; then

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff