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

    Custom Full Host Registration for 1.3.4

    Scheduled Pinned Locked Moved Solved
    FOG Problems
    3
    53
    26.2k
    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
      JGallo
      last edited by Tom Elliott

      @Tom-Elliott @george1421 This is what I have as far as post init scripts:

      code for fog.postinit

      #!/bin/bash
      ## This file serves as a starting point to call your custom pre-imaging/post init loading scripts.
      ## <SCRIPTNAME> should be changed to the script you're planning to use.
      ## Syntax of post init scripts are
      . ${postinitpath}fog.postselect
      

      code for fog.postselect

      #!/bin/bash
      . /usr/share/fog/lib/funcs.sh
      # place script commands here that should execute every time for every FOS action
      # I added some additional check here just in case you wanted to highly customize the postinit script's actions. This section is not mandatory.
      if [[ -n $mode && $mode != +(*debug*) && -z $type ]]; then
          case $mode in
              wipe)
                  # fog wipe disk
                  ;;
              checkdisk)
                  # fog check disk
                  ;;
              badblocks)
                  # fog disk surface test
                  ;;
              autoreg)
                  # fog quick registration
                  ;;
              manreg)
                  # fog full registration
                  . ${postinitpath}patch.fullreg
                  ;;
              inventory)
                  # fog full inventory
                  ;;
              quickimage)
                  # fog quick image
                  ;;
              *)
                  # all other generic operations
                  ;;
          esac
          # place script commands here that should be run for any of the utility functions
      else
          case $type in
              down)
                  # fog image deploy
                  ;;
              up)
                  # fog image capture
                  ;;
              *)
                  # the code should never get here, we'll just add so the script doesn't break
                  ;;
          esac
          # place script commands here that should be run for either image capture or deploy
      fi
      

      code for patch.fullreg

      #!/bin/bash
      
      dots "Patching Registration files"
      debugPause
      
      cp -f ${postinitpath}fog.reg.man.fix /bin/fog.reg.man
      
      dots "Done Patching Registration files"
      debugPause
      

      and finally the custom code I modified that removed questions we don’t need to be asked during full host registration

      #!/bin/bash
      . /usr/share/fog/lib/funcs.sh
      . /bin/fog.donate
      clearScreen
      displayBanner
      disks=""
      disk=""
      hd=""
      getHardDisk
      sysman=""
      sysman64=""
      sysproduct=""
      sysproduct64=""
      sysversion=""
      sysversion64=""
      sysserial=""
      systype=""
      biosversion=""
      biosvendor=""
      biosdate=""
      mbman=""
      mbproductname=""
      mbversion=""
      mbserial=""
      mbasset=""
      cpuman=""
      cpuversion=""
      cpucurrent=""
      cpumax=""
      mem=""
      hdinfo=""
      caseman=""
      casever=""
      caseserial=""
      casesasset=""
      sysserial64=""
      systype64=""
      biosversion64=""
      biosvendor64=""
      biosdate64=""
      mbman64=""
      mbproductname64=""
      mbversion64=""
      mbserial64=""
      mbasset64=""
      cpuman64=""
      cpuversion64=""
      cpucurrent64=""
      cpumax64=""
      mem64=""
      hdinfo64=""
      caseman64=""
      casever64=""
      caseserial64=""
      casesasset64=""
      dots "Using disk device"
      echo $hd
      echo " * Starting host registration"
      mac=$(getMACAddresses | base64)
      exists=$(curl -ks --data "mac=$mac" http://${web}service/man.hostexists.php 2>/dev/null)
      checkAndSet() {
          local testvar="$1"
          local onlynum="$2"
          [[ -z $testvar ]] && return
          if [[ $onlynum =~ [Tt][Rr][Uu][Ee] && $testvar =~ ^[0-9]+$ ]]; then
              echo $testvar | base64
          elif [[ $testvar =~ ^[0-9,]+$ ]]; then
              echo $testvar | base64
          else
              return
          fi
      }
      setIDs() {
          local varVar="$1"
          local str="$2"
          local csvstyle="$3"
          local dummy="$4"
          local max="$5"
          local res=""
          local url=""
          local oIFS=$IFS
          local line=""
          while [[ -z ${!varVar} ]]; do
              [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n "    Enter the $str IDs separated with , to associate with computer (? for listing): " || echo -n "    Enter the $str ID to associate with computer (? for listing): "
              read dummy
              dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//')
              case $dummy in
                  [?])
                      url="http://${web}service/${str}listing.php"
                      clearScreen
                      res=$(echo -e $(curl -ks $url 2>/dev/null))
                      i=0
                      IFS=$'\n'
                      for line in $res; do
                          let i+=1
                          echo $line
                          if [[ $i -eq $max ]]; then
                              [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n "    Press [Enter] to proceed or enter the $str IDs separated with , to associate with computer: " || echo -n "    Press [Enter] to proceed or enter the $str ID to associate with computer: "
                              read dummy
                              case $dummy in
                                  [?]|"")
                                      i=0
                                      clearScreen
                                      continue
                                      ;;
                              esac
                              case $csvstyle in
                                  [Tt][Rr][Uu][Ee])
                                      [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
                                      break
                                      ;;
                                  *)
                                      [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
                                      break
                                      ;;
                              esac
                              i=0
                              dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//')
                              clearScreen
                          fi
                      done
                      ;;
                  ""|0)
                      printf -v "$varVar" 0
                      ;;
                  *)
                      dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//')
                      [[ -z $dummy ]] && setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
                      case $csvstyle in
                          [Tt][Rr][Uu][Ee])
                              [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
                              ;;
                          *)
                              [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
                              ;;
                      esac
                      ;;
              esac
          done
          IFS=$oIFS
      }
      [[ $exists != "#!ok" ]] && handleError "Unable to register host: $exists ($0)\n   Args Passed: $*"
      host=""
      imageid=""
      blImage=""
      keyEnter=""
      res=""
      while [[ $res != "#!ok" ]]; do
          echo -n " * Enter hostname for this computer: "
          read host
          if [[ ${#host} -gt 15 ]]; then
              host=${host:0:15}
              echo " | Truncated to 15 characters: $host"
              usleep 2000000
          fi
          host=$(echo $host | base64)
          res=$(curl -ks --data "host=$host" http://${web}service/hostnameloop.php 2>/dev/null)
          [[ $res != "#!ok" ]] && echo "$res"
      done
      imageid=""
      setIDs "imageid" "image" "" "" 20
      if [[ $(curl -ks http://${web}service/locationcheck.php 2>/dev/null) == "##" ]]; then
          while [[ -z $askme ]]; do
              echo -n "    Would you like to assign a location for this host? (y/N) "
              read askme
              case $askme in
                  [Nn]|[Nn][Oo]|"")
                      askme="N"
                      ;;
                  [Yy]|[Yy][Ee][Ss])
                      setIDs "locationid" "location" "" "" 20
                      location64=$locationid
                      ;;
                  *)
                      askme=""
                      echo " * Invalid input, please try again"
                      ;;
              esac
          done
      fi
      echo " * You entered all required information, "
      askme=""
      while [[ -z $askme ]]; do
          echo -n "    Would you like to deploy image to this computer now? (y/N) "
          read askme
          case $askme in
              [Nn]|[Nn][Oo]|"")
                  askme="N"
                  ;;
              [Yy]|[Yy][Ee][Ss])
                  tmp=""
                  ret=""
                  retry=3
                  while [[ $ret != "#!ok" && ! $retry -eq 0 ]]; do
                      echo " * Enter FOG GUI Username and Password"
                      echo -n "    Username: "
                      read username
                      echo -n "    Password: "
                      read -s password
                      user64=$(echo $username | tr -d '\012' | base64)
                      pass64=$(echo $password | tr -d '\012' | base64)
                      ret=$(curl -ks --data "mac=$mac&username=$user64&password=$pass64" http://${web}service/checkcredentials.php 2>/dev/null)
                      case $ret in
                          '#!ok')
                              echo
                              echo " * This host will reboot and deployment will start!"
                              ret=$tmp
                              realdoimage=$(echo -n 1 | base64)
                              break
                              ;;
                          '#!il')
                              echo
                              echo " * Error: Invalid Login! ($retry remaining)"
                              let retry-=1
                              ;;
                      esac
                  done
                  askme="Y"
                  ;;
              *)
                  askme=""
                  echo " * Invalid input, please try again"
                  ;;
          esac
      done
      dots "Attempting to register host"
      res=""
      while [[ -z $res ]]; do
          res=$(curl -ks --data "mac=$mac&advanced=$(echo -n 1 | base64)&host=$host&imageid=$imageid&doimage=$realdoimage&location=$location64&username=$user64" http://${web}service/auto.register.php 2>/dev/null)
          echo "$res"
          usleep 2000000
      done
      . /bin/fog.inventory
      usleep 2000000
      
      george1421G 1 Reply Last reply Reply Quote 0
      • george1421G
        george1421 Moderator @JGallo
        last edited by

        @JGallo OK the forum really manged your code in the post.

        Let go back to basics. Insert this code in your fog.postinit

        
        echo "Installing Patch"
        debugPause
        
        cp -f ${postinitpath}fog.reg.man.fix /bin/fog.reg.man
        
        echo "Done Patching"
        debugPause
        

        If that doesn’t work then we will need to install the debug kernel parameters again and figure out what is going wrong on the other end. If you see the Installing Patch in registration mode then we know the script is being called.

        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!

        J 1 Reply Last reply Reply Quote 0
        • J
          JGallo @george1421
          last edited by

          @george1421 Yes. It is successful in echoing those words. I went as far as actually echoing “Installing my patch” and it works. LOL. So we know the script is being called but not too sure on the file copy. If I place the debug flags back, can I pull the fog.man.reg file to inspect it and confirm the file copy?

          george1421G 1 Reply Last reply Reply Quote 0
          • george1421G
            george1421 Moderator @JGallo
            last edited by george1421

            @JGallo Right in the code I provided, if you are in debug mode it will pause just before copying the file and just after copying the file.

            On the pause just after copying the file press ctrl-c to break out of the script. Then inspect the file date. If its not correct then manually key in the copy command to see what error is thrown. I might suspect I have the source path off for some reason.

            You might also want to key in echo "${postinitpath}" on the command line (after the control-c) to see if the postinitpath is properly set.

            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!

            J 1 Reply Last reply Reply Quote 0
            • J
              JGallo @george1421
              last edited by

              @george1421 So placed the debug flags back. Once the patching was done, I hit control-c and inspected /bin/fog.man.reg and looks like the original file because my changes aren’t there. I also echoed the postinitpath and it returned a blank line.

              Could I theoretically set the postinit path prior to cp the custom fog script? Or instead of using the variable postinit to manually enter the postinitpath?

              george1421G 1 Reply Last reply Reply Quote 0
              • george1421G
                george1421 Moderator @JGallo
                last edited by

                @JGallo well in this case the postinitpath should be set by the master fog script. If it is not set correctly then things will fall down.

                You could manually set it, but if you are still in debug mode, could you post the output of this command df -h at this point for the postinitpath to work, the FOS engine needs a connection back to the fog server over nfs to reach the script. Since the postinit script…

                Wait that variable needs to be set, because the main fog program calls the postinit by issuing . ${postinitpath}fog.postinit

                Instead of having you keep thrashing this around let me look at it tonight, there has to be something missing.

                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!

                J 1 Reply Last reply Reply Quote 0
                • J
                  JGallo @george1421
                  last edited by

                  @george1421 I will wait. While in debug mode, I typed

                  df -h
                  

                  and got

                  filesystem             Mounted on
                  /dev/root                 /
                  
                  george1421G 1 Reply Last reply Reply Quote 0
                  • Tom ElliottT
                    Tom Elliott
                    last edited by Tom Elliott

                    @george1421 said in Custom Full Host Registration for 1.3.4:

                    echo “Installing Patch”
                    debugPause

                    cp -f ${postinitpath}fog.reg.man.fix /bin/fog.reg.man

                    echo “Done Patching”
                    debugPause

                    I might recommend a script of:

                    currfile="/bin/fog.man.reg"
                    newfile="${postinitpath}fog.reg.man.fix"
                    
                    . /usr/share/fog/lib/funcs.sh
                    
                    echo "Testing path for our fixed file at ${postinitpath}fog.man.reg.fix"
                    debugPause
                    
                    # Test path and run copy if found and matched.
                    if [[ -r $newfile ]]; then
                        echo "Found file preparing to copy"
                        debugPause
                        cp -f $newfile $currfile >/dev/null 2>&1
                        [[ ! $? -eq 0 ]] && echo "Copy Failed" || echo "Copy Succeeded"
                        debugPause
                    else
                        echo "Failed to find file sorry"
                        debugPause
                    fi
                    

                    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 0
                    • george1421G
                      george1421 Moderator @JGallo
                      last edited by

                      @JGallo Ok setting this up on my home dev box, I’ve come to the conclusion that this works as I outlined IF I would have frick’n spelled the manual registration file correctly.

                      the real name is /bin/fog.man.reg and not fog.reg.man

                      Even Tom missed it because he copied my script to start with.

                      Using tom’s script but with the proper file names it works. It was working with the file names I was using, except it didn’t overwrite the manual registration file.

                      [moderator note, I’m going to correct Tom’s post to reflect the proper file names in question]

                      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!

                      J 1 Reply Last reply Reply Quote 0
                      • J
                        JGallo @george1421
                        last edited by

                        @george1421 LOL wow and of course it works now. I’m glad this was figured out. Making the changes and testing the scripts I can confirm that it works.

                        With that said, taking a step further, is the fog.postinit script suppose to have anything other than calling our custom scripts? Or should we skip the additional scripts (as you recommended earlier in the post ex - patch.fullreg, fog.postselect)? Once again thank you for taking a look at that. I’m glad there were some discoveries along the way that I’m sure will be useful for many others.

                        Tom ElliottT george1421G 2 Replies Last reply Reply Quote 0
                        • Tom ElliottT
                          Tom Elliott @JGallo
                          last edited by

                          @JGallo The postinit script that the system calls is intended to be a “caller” system. Meaning you should use it to call other scripts, but it is still a script none-the-less. For your particular use case, I don’t think the “postselect” script is necessary. All you need to do is replace the existing fog.man.reg file and let FOG handle it like it normally would.

                          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 0
                          • george1421G
                            george1421 Moderator @JGallo
                            last edited by george1421

                            @JGallo Its a matter of personal style and what you might do in the future.

                            But for your case, what I would do is this (as a compromise).

                            What we put into the fog.postinit, remove it from the postinit script and put it into a new file cleaning out the fog.postinit from any extra code. Lets say you place Tom’s code into a file (in the same directory as fog.postinit) called patch.fullreg and then in the fog.postinit you then would call the patch file only with
                            . ${postinitpath}patch.fullreg That way your patch code is maintained in its own container without the chance of it getting overwritten by a FOG update (as a FOG managed script might i.e. fog.postinit )

                            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!

                            J 1 Reply Last reply Reply Quote 0
                            • J
                              JGallo @george1421
                              last edited by

                              @george1421 @Tom-Elliott I will go ahead and restore the fog.postinit script back to its intended use. Call the patch.fullreg script to reflect exactly what we are trying to do, that is to copy our custom script and replace /bin/fog.man.reg That way as @george1421 has said to prevent any updates from replacing the script by accident.

                              1 Reply Last reply Reply Quote 1
                              • J
                                JGallo
                                last edited by

                                @george1421 @Tom-Elliott With the changes in 1.4.0-rc-2 that made us able to use the fog.postinit script with full host registration, those changes will be in the next release of FOG correct? I’m planning this summer to upgrade from 1.2.0 Definitely looking forward to this upgrade especially with the LDAP plug in.

                                Tom ElliottT 1 Reply Last reply Reply Quote 0
                                • Tom ElliottT
                                  Tom Elliott @JGallo
                                  last edited by

                                  @JGallo YEs, that is correct. rc-3 has the fix too and so it will remain going forward.

                                  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 0
                                  • 1
                                  • 2
                                  • 3
                                  • 3 / 3
                                  • First post
                                    Last post

                                  162

                                  Online

                                  12.0k

                                  Users

                                  17.3k

                                  Topics

                                  155.2k

                                  Posts
                                  Copyright © 2012-2024 FOG Project