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

    The magical, mystical FOG post download script

    Scheduled Pinned Locked Moved
    Tutorials
    7
    20
    22.6k
    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.
    • Wayne WorkmanW
      Wayne Workman @george1421
      last edited by

      @george1421 said in The magical, mystical FOG post download script:

      hostbuilding # ??

      This is an old field in the hosts table left over from much older versions of fog. As far as I can tell, it is not used for anything anymore.

      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 0
      • D
        dburk @george1421
        last edited by

        @george1421 Update to part 5 Access FOG host data

        if [[ ! -z $mac ]]; then
            curl -A "" -Lkso /tmp/hinfo.sh ${web}/service/hostinfo.php -d "mac=$mac" 
            if [[ -f /tmp/hinfo.sh ]]; then
                . /tmp/hinfo.sh
            fi
        fi
        
        george1421G 1 Reply Last reply Reply Quote 1
        • george1421G
          george1421 Moderator @dburk
          last edited by george1421

          @dburk Great catch, thank you for the update. I’m not sure how I missed that one but great job. I’ll get my post updated so that it works correctly.

          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!

          1 Reply Last reply Reply Quote 0
          • E
            enswafford
            last edited by

            I am confused about the actual syntax of this post download script.
            In the sample script on the FOG server, it says:
            “# syntax of the post download scripts are”
            "#. ${postdownpath}<SCRIPTNAME>

            (assuming the script is called (without quotes) “mypostdlscript.sh”, and it is in “/images/postinstall/” directory)
            Should I be typing (without quotes) “. ${postdownpath}mypostdlscript.sh”
            or should I be typing it as (again without quotes) “. /images/postinstall/mypostdlscript.sh”?
            Can you explain what the ${postdownpath} means?

            george1421G 1 Reply Last reply Reply Quote 0
            • S
              Sebastian Roth Moderator
              last edited by

              @enswafford said in The magical, mystical FOG post download script:

              ${postdownpath}

              This is a variable in bash scripts. Should probably be set to /images/postdownloadscripts/

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

                @enswafford said in The magical, mystical FOG post download script:
                “. ${postdownpath}mypostdlscript.sh”
                First of all sebasian is spot on with this explanation.

                To break this post download script a bit more. The script is actually a bash shell script. Its akin to a DOS batch file, with 1000’s more capability. The bash variable is called postdownpath so the bash shell interpreter understands its a variable you prefix the variable name with a dollar sign. The interpreter can still get a bit confused at times so you wrap the variable with curly braces so it knows fore sure there is a variable call ${postdownpath} . The FOG server populates that variable before the post install script runs with the proper value so you don’t need to know where the post install scripts are run from.

                So the command is this “. ${postdownpath}mypostdlscript.sh” The preceding dot is shorthand way of saying run the mypostdlscript.sh in this context so all of my populated variables are shared with this new bash script. Its a little complicated to explain but that is what that entire command will do. So if you set a variable in the current script, that variable will be available to any subsequent bash scripts you create.

                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!

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

                  @george1421 I need to add,

                  the preceeding . is NOT just a way of saying run, it’s also a shorthand way of sourcing the file, the same as:

                  source mypostdlscript.sh

                  Basically, source means to bring the file in, similar to requiring other files in order to access different variables/functions that you may want separated from the purpose of the main running script.

                  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
                  • Z
                    zaboxmaster @george1421
                    last edited by Tom Elliott

                    @george1421 Looking at the code, say if I wanted to extract the hostimageid and assign it to $imageid in a while loop, would the following be correct :

                    while [[ $imageid -le 10 ]]; do
                        if [[ -z "imageid"]]; then
                            if [[ ! -z $mac ]]; then
                                curl -A "" -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d "mac=$mac&hostimageid=$imageid"
                                if [[ -f /tmp/hinfo.sh ]]; then
                                    . /tmp/hinfo.sh
                                fi
                                echo "Please wait"
                                sleep 60
                            fi
                    done
                    

                    This should in theory run the while loop until a value is given to the $imageid

                    george1421G Tom ElliottT 2 Replies Last reply Reply Quote 0
                    • george1421G
                      george1421 Moderator @zaboxmaster
                      last edited by george1421

                      @zaboxmaster said in The magical, mystical FOG post download script:

                      curl -A “” -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d “mac=$mac&hostimageid=$imageid”

                      That call returns all variables not just the one you pass to it. Only the mac address value is used and understood.

                      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!

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

                        @zaboxmaster I’ve updated your code into a code block so you can see a bit cleaner on what’s happening.

                        First, the loop you’re providing will not work. This is because it’s missing a fi (for the if [[ -z "imageid" ]] line).

                        Second: Why is the code looking if the value is less than or equal to 10? Why do you need to loop this code at all?

                        From what I understand of your needs, you want to get the image ID for a host if the host has no image id set. This makes 0 sense. In what scenario would you be able to get an image ID for a host that has no assigned image ID? This is circular referencing as no matter what happens, the host isn’t going to have an image id associated to it. So it will never be able to complete the loop.

                        You seem to be rebuilding the cart before you have built it. (I don’t know if the metaphor makes sense here.)

                        Too me, what you’re looking for seems rather strange. You would never be able to image a host if you don’t have an image assigned (and did not select an image during pxe boot.)

                        If this is during registration, what’s the point in this?

                        1. The host doesn’t exist, so calling hinfo.sh will gain you nothing.
                        2. You have to be in front of the host when registering (unless you are using quick reg - in which case why not set the quick reg image id for quick registration rather than re-invent the wheel) so why try an automate this part?
                        3. Why all the erroneous checking in the first place? First, your while loop is extremely limiting. You have it set to check if the imageid is less than or equal to 10. What about image id 1? Why is this a valid check on anything?
                        4. In side the while loop you have if [[ -z "$imageid" ]]; then Why not just make the while loop while [[ -z $imageid && $imageid -gt 0 ]]; do
                        5. In what scenario would you ever be able to do anything on a machine with the mac variable is not set (you should not need to check this variable as FOS kind of relies on it in the first place)?
                        6. Why are you waiting for a minute to do anything?

                        If there’s a valid reasoning for this I would redo the script to run:

                        while [[ -z $imageid && $imageid -gt 0 ]]; do
                            curl -A "" -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d "mac=$mac"
                            if [[ -f /tmp/hinfo.sh ]]; then
                                . /tmp/hinfo.sh
                            fi
                            echo "Please wait"
                            sleep 60
                        done

                        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

                        Z 1 Reply Last reply Reply Quote 1
                        • Z
                          zaboxmaster @Tom Elliott
                          last edited by

                          @Tom-Elliott Thank you for your input. I realize that i have made a mistake in the code. I am new to bash and fog in general.

                          The idea is to have a while loop running until an image has been assigned. Or a sort of pause before it continues. The reason being that this is being done remotely and I would be assigning the correct image to the host. I am not psychically in front of the computer. The hosts users would only select that they want an image to be deployed and not select an image to deploy.

                          Hope that makes sense.

                          So what I guess I was looking for and I do realize that this is n the wrong thread is a way inside a while loop to see if an image has been assigned before continuing on with the deployment. BTW I have modified the fog.man.reg to go straight to the fog.download and the end of the registration.

                          1 Reply Last reply Reply Quote 0
                          • S Sebastian Roth referenced this topic on
                          • S Sebastian Roth referenced this topic on
                          • S Sebastian Roth referenced this topic on
                          • george1421G george1421 referenced this topic on
                          • JJ FullmerJ JJ Fullmer referenced this topic on
                          • george1421G george1421 referenced this topic on
                          • george1421G george1421 referenced this topic on
                          • JJ FullmerJ JJ Fullmer referenced this topic on
                          • H HorizonG referenced this topic on
                          • jeje3346J jeje3346 referenced this topic on
                          • 1 / 1
                          • First post
                            Last post

                          165

                          Online

                          12.0k

                          Users

                          17.3k

                          Topics

                          155.2k

                          Posts
                          Copyright © 2012-2024 FOG Project