• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Automating Git Updates for FOG

Scheduled Pinned Locked Moved
General
3
4
2.5k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    JJ Fullmer Testers
    last edited by JJ Fullmer Dec 11, 2015, 10:23 AM Dec 10, 2015, 5:34 PM

    In the past I made a script for automating svn updates. Since sourceforge has been making a habit of crashing lately, I decided to start using the git repo instead and adjusted my script to work with git.
    I figured others might benefit from it so why not share…

    #!/bin/bash
    clear
    # -------------------------------------------
    # Fog Git Updater
    # -------------------------------------------
    # -------------------------------------------
    # Script Purpose
    # -------------------------------------------
    # This script is designed to run an automated update of the latest FOG Git dev build and it's cron friendly
    # -------------------------------------------
    # -------------------------------------------
    # Some prereqs for this script
    # -------------------------------------------
    # 1. Already have an existing working install/configuration of FOG 1.0 or later
    #
    # 2. Have git installed and setup. You can do that by doing....
    # 	sudo apt-get install git
    #  	mkdir /home/fog/fogInstalls/git
    #	git clone https://github.com/FOGProject/fogproject.git /home/fog/fogInstalls/git
    #
    # 3. A script to echo the encrypted version of your sudo password, create one with this function
    #	just put in your password into the following in place of your_super_secret_password (leave the quotes)
    #	and then uncomment and copy paste the function into a terminal and then run it with just the name of the function pw
    	# pw(){
    	# 	touch /home/fog/fogInstalls/.~
    	# 	ossl=`echo "your_super_secret_password" | openssl enc -des -a -e -pass pass:PASSWORD`
    	# 	echo 'echo "$(echo '$ossl' | openssl enc -des -a -d -pass pass:PASSWORD)"' >> /home/fog/fogInstalls/.~
    	# 	sudo chown fog.root /home/fog/fogInstalls/.~
    	# 	sudo chmod 700 /home/fog/fogInstalls/.~ 
    	# }
    # -------------------------------------------
    # -------------------------------------------
    # Variables
    # -------------------------------------------
    # -------------------------------------------
    echo "Creating Script variables..."
    fogInstalls='/home/fog/fogInstalls'
    gitPath="$fogInstalls/git"
    backup="$fogInstalls/backups"
    pw=`sh $fogInstalls/.~` 
    # -------------------------------------------
    # -------------------------------------------
    # Functions
    # -------------------------------------------
    # -------------------------------------------
    perms(){
    	sudo chmod -R 775 $1
    	sudo chown -R fog.fog $1
    }
    
    srvUpdate(){
    	# Enter sudo mode aand do some quick server maintenance update fun times
    	# First, enter sudo mode by echoing the output of decrypting your encrypted password and pipe that into an apt-get update
    	#	Don't worry, it doesn't output the password into the terminal
    	#	Now that the password is in once the terminal will keep it stored for the next bunch of sudo commands
    	echo "Running Sever updates!..."
    	echo $pw | sudo -S apt-get update -y
    	sudo apt-get upgrade -y # install any upgrades you just downloaded
    }
    
    backupConfig(){
    	# Backup custom config and other files
    	# Copy the latest versions of any files you've changed that will be overwritten by the update and backup the database just in case.
    	# For example you may want to back up...
    	# Config.php
    	# 	To be on the safe side your config file in the /opt folder that has may have a corrected webroot for ubuntu 14.04 and may have stored encrypted credentials (i.e mysql)
    	# 		I think that the installer uses this file and keeps it anyway, but I like to be careful
    	# Exports file
    	#	Because this runs the installer with a yes pipe, it ends up telling it that the image path is "y",
    	# 		simply backing up and restoring your current one avoids the issue of fog not finding your precious images. 
    	# Custom pxe boot background
    	# 	If you have a custom background for the pxe menu, the bg.png file
    	# Mysql database dump
    	#	It would be rather troublesome if something went horribly wrong in the update and your database goes kaboom, it's unlikely but backups are a good thing 
    	# Just a note, It's a good policy to also have backups of these outside of your server, which you could add to this script with an scp command or something like that
    	# -------------------------------------------
    	echo "make sure backup dir exists..."
    	if [ ! -d $backup ]; then
    		mkdir $backup
    	fi
    	echo "Dumping the database..."
    	mysqldump -u root --all-databases --events > $backup/DatabaseBeforeLastUpdate.sql #backup database
    	echo "Backing up config and custom files..."
    	echo "config.php..."
    	sudo cp /opt/fog/service/etc/config.php $backup/config.php
    	echo "fog settings..."
    	sudo cp /opt/fog/.fogsettings $backup/.fogsettings
    	echo "nfs exports..."
    	sudo cp /etc/exports $backup/exports
    	echo "custom pxe background..."
    	sudo cp /var/www/html/fog/service/ipxe/bg.png $backup/bg.png 
    }
    
    gitP(){
            perms $gitPath
    	echo "git pull...."
    	cd $gitPath
    	git pull
    }
    
    updateFOG(){
    	echo "running FOG installer..."
    	cd $gitPath/bin
    	sudo bash installfog.sh -Y
    }
    
    restoreConfig(){
    	# Restore backed up files
    	# Restore the backed up files to their proper places and make sure they're formatted correct too.
    	echo "restoring custom pxe background..."
    	sudo cp $backup/bg.png /var/www/html/fog/service/ipxe # Restore Custom Background 
    	# I found that I needed to do this in some configurations, but it may no longer be neccesarry...
    	echo "Creating undionly for iPxe boot in ipxe folder, just in case..." 
    	sudo cp /tftpboot/undionly.kpxe /tftpboot/undionly.0 # backup original then rename undionly 
    	sudo cp /tftpboot/undionly.0 /var/www/html/fog/service/ipxe/undionly.0
    	sudo cp /var/www/html/fog/service/ipxe/undionly.0 /var/www/html/fog/service/ipxe/undionly.kpxe
    }
    
    fixPerms(){
    	echo "Changing Permissions of webroot..."
    	perms '/var/www/html/fog'
    	echo "Changing permissions of images...."
    	perms '/images'
    	echo "Changing permissions of tftpboot...."
    	perms '/tftpboot'
    }
    
    # -------------------------------------------
    # -------------------------------------------
    # Run the script
    # -------------------------------------------
    # -------------------------------------------
    srvUpdate
    backupConfig
    gitP
    updateFOG
    restoreConfig
    fixPerms
    echo "Done!"
    

    Have you tried the FogApi powershell module? It's pretty cool IMHO
    https://github.com/darksidemilk/FogApi
    https://fogapi.readthedocs.io/en/latest/
    https://www.powershellgallery.com/packages/FogApi
    https://forums.fogproject.org/topic/12026/powershell-api-module

    1 Reply Last reply Reply Quote 3
    • J
      JJ Fullmer Testers
      last edited by Dec 11, 2015, 4:31 PM

      Also, if you happen to have btsync set up, which I just gave a try using the guide here https://wiki.fogproject.org/wiki/index.php/Upgrade_to_trunk (Side note, I didn’t have to untar anything in a downloads folder and someone should probably edit the typo that says chrmod instead of chmod)

      I set up my btsync to a folder called /home/fog/fogInstalls/btsync/fog Which is in a variable in the following script if you put it somewhere else and need to change it.

      Another side note/question. For git my git pulls are around 300 MB or so, but the BTSYNC is a little less than 20 MB, am I getting all the files or is there something wrong with my config? That size difference is slightly concerning to me is all.

      Anyway, here’s the btsync version of the update script that you could run whenever you get a btsync update.

      #!/bin/bash
      clear
      # -------------------------------------------
      # Fog Git Updater
      # -------------------------------------------
      # -------------------------------------------
      # Script Purpose
      # -------------------------------------------
      # This script is designed to run an automated update of the latest FOG Git dev build and it's cron friendly
      # -------------------------------------------
      # -------------------------------------------
      # Some prereqs for this script
      # -------------------------------------------
      # 1. Already have an existing working install/configuration of FOG 1.0 or later
      #
      # 2. Have git installed and setup. You can do that by doing....
      # 	sudo apt-get install git
      #  	mkdir /home/fog/fogInstalls/git
      #	git clone https://github.com/FOGProject/fogproject.git /home/fog/fogInstalls/git
      #
      # 3. A script to echo the encrypted version of your sudo password, create one with this function
      #	just put in your password into the following in place of your_super_secret_password (leave the quotes)
      #	and then uncomment and copy paste the function into a terminal and then run it with just the name of the function pw
      	# pw(){
      	# 	touch /home/fog/fogInstalls/.~
      	# 	ossl=`echo "your_super_secret_password" | openssl enc -des -a -e -pass pass:PASSWORD`
      	# 	echo 'echo "$(echo '$ossl' | openssl enc -des -a -d -pass pass:PASSWORD)"' >> /home/fog/fogInstalls/.~
      	# 	sudo chown fog.root /home/fog/fogInstalls/.~
      	# 	sudo chmod 700 /home/fog/fogInstalls/.~ 
      	# }
      # -------------------------------------------
      # -------------------------------------------
      # Variables
      # -------------------------------------------
      # -------------------------------------------
      echo "Creating Script variables..."
      fogInstalls='/home/fog/fogInstalls'
      btsyncPath="$fogInstalls/btsync/fog"
      backup="$fogInstalls/backups"
      pw=`sh $fogInstalls/.~` 
      # -------------------------------------------
      # -------------------------------------------
      # Functions
      # -------------------------------------------
      # -------------------------------------------
      perms(){
      	sudo chmod -R 775 $1
      	sudo chown -R fog.fog $1
      }
      
      srvUpdate(){
      	# Enter sudo mode aand do some quick server maintenance update fun times
      	# First, enter sudo mode by echoing the output of decrypting your encrypted password and pipe that into an apt-get update
      	#	Don't worry, it doesn't output the password into the terminal
      	#	Now that the password is in once the terminal will keep it stored for the next bunch of sudo commands
      	echo "Running Sever updates!..."
      	echo $pw | sudo -S apt-get update -y
      	sudo apt-get upgrade -y # install any upgrades you just downloaded
      }
      
      backupConfig(){
      	# Backup custom config and other files
      	# Copy the latest versions of any files you've changed that will be overwritten by the update and backup the database just in case.
      	# For example you may want to back up...
      	# Config.php
      	# 	To be on the safe side your config file in the /opt folder that has may have a corrected webroot for ubuntu 14.04 and may have stored encrypted credentials (i.e mysql)
      	# 		I think that the installer uses this file and keeps it anyway, but I like to be careful
      	# Exports file
      	#	Because this runs the installer with a yes pipe, it ends up telling it that the image path is "y",
      	# 		simply backing up and restoring your current one avoids the issue of fog not finding your precious images. 
      	# Custom pxe boot background
      	# 	If you have a custom background for the pxe menu, the bg.png file
      	# Mysql database dump
      	#	It would be rather troublesome if something went horribly wrong in the update and your database goes kaboom, it's unlikely but backups are a good thing 
      	# Just a note, It's a good policy to also have backups of these outside of your server, which you could add to this script with an scp command or something like that
      	# -------------------------------------------
      	echo "make sure backup dir exists..."
      	if [ ! -d $backup ]; then
      		mkdir $backup
      	fi
      	echo "Dumping the database..."
      	mysqldump -u root --all-databases --events > $backup/DatabaseBeforeLastUpdate.sql #backup database
      	echo "Backing up config and custom files..."
      	echo "config.php..."
      	sudo cp /opt/fog/service/etc/config.php $backup/config.php
      	echo "fog settings..."
      	sudo cp /opt/fog/.fogsettings $backup/.fogsettings
      	echo "nfs exports..."
      	sudo cp /etc/exports $backup/exports
      	echo "custom pxe background..."
      	sudo cp /var/www/html/fog/service/ipxe/bg.png $backup/bg.png 
      }
      
      updateFOG(){
      	echo "running FOG installer..."
              perms $btsyncPath
      	cd $btsyncPath/bin
      	sudo bash installfog.sh -Y
      }
      
      restoreConfig(){
      	# Restore backed up files
      	# Restore the backed up files to their proper places and make sure they're formatted correct too.
      	echo "restoring custom pxe background..."
      	sudo cp $backup/bg.png /var/www/html/fog/service/ipxe # Restore Custom Background 
      	# I found that I needed to do this in some configurations, but it may no longer be neccesarry...
      	echo "Creating undionly for iPxe boot in ipxe folder, just in case..." 
      	sudo cp /tftpboot/undionly.kpxe /tftpboot/undionly.0 # backup original then rename undionly 
      	sudo cp /tftpboot/undionly.0 /var/www/html/fog/service/ipxe/undionly.0
      	sudo cp /var/www/html/fog/service/ipxe/undionly.0 /var/www/html/fog/service/ipxe/undionly.kpxe
      }
      
      fixPerms(){
      	echo "Changing Permissions of webroot..."
      	perms '/var/www/html/fog'
      	echo "Changing permissions of images...."
      	perms '/images'
      	echo "Changing permissions of tftpboot...."
      	perms '/tftpboot'
      }
      
      # -------------------------------------------
      # -------------------------------------------
      # Run the script
      # -------------------------------------------
      # -------------------------------------------
      srvUpdate
      backupConfig
      updateFOG
      restoreConfig
      fixPerms
      echo "Done!"
      

      Have you tried the FogApi powershell module? It's pretty cool IMHO
      https://github.com/darksidemilk/FogApi
      https://fogapi.readthedocs.io/en/latest/
      https://www.powershellgallery.com/packages/FogApi
      https://forums.fogproject.org/topic/12026/powershell-api-module

      T 1 Reply Last reply Dec 12, 2015, 12:03 AM Reply Quote 2
      • W
        Wayne Workman
        last edited by Dec 11, 2015, 11:10 PM

        This is good stuff.

        It never hurts to have extra backups.
        But fog does backup the web directory now, along with the database too. automatically. And the installer also updates only the packages that need updated. This is probably more stable than updating everything, because you have less things in motion at one time. Inside of the /opt/fog/.fogsnapins file, there is a backup setting now, which defines the backup path. The default is the home directory.
        But again I’ll say that it never hurts to have extra backups.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
        Daily Clean Installation Results:
        https://fogtesting.fogproject.us/
        FOG Reporting:
        https://fog-external-reporting-results.fogproject.us/

        1 Reply Last reply Reply Quote 1
        • T
          Tom Elliott @JJ Fullmer
          last edited by Dec 12, 2015, 12:03 AM

          @Arrowhead-IT the size difference is the folder that stores the data for btsync. For git and svn you’re pulling the whole tree, including past revisions. In the case of btsync the initial pull is of the same size as the svn or git pulls but you’re only getting he changed files rather than a whole new revision.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          1 Reply Last reply Reply Quote 1
          • 1 / 1
          1 / 1
          • First post
            2/4
            Last post

          162

          Online

          12.0k

          Users

          17.3k

          Topics

          155.2k

          Posts
          Copyright © 2012-2024 FOG Project