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

Post Install script Hostname changer

Scheduled Pinned Locked Moved Solved
Linux Problems
2
7
1.0k
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.
  • M
    mdxlp
    last edited by Jun 9, 2023, 8:45 AM

    Hello,
    I am now working on a project where I need FOG to deploy or capture many OS (Linux) images on any part of the disk I want. I need to run a post install script to change the hostname of the image I have just deployed on a partition. I don’t know how to give it the precise name of the partition I’m gonna deploy the image on. I have seen that you have to mention the partition you want the image to be deployed on, but I have four of them where I can deploy an image and I don’t know how to make that like “automatic”, the fact that I don’t have to change the name of the partition every time in the script.
    (If my english is terrible its because I’m french)

    G 1 Reply Last reply Jun 9, 2023, 2:12 PM Reply Quote 0
    • G
      george1421 Moderator @mdxlp
      last edited by Jun 9, 2023, 2:12 PM

      @mdxlp No worries my french is terrible, and my english is not much better 😉

      So we have an example of a post install script for windows, what it does is search through all of the partitions on the deployment disk looking for the windows folder or file. Once that key or flag file is found it knows its the “C Drive”. You should be able to use the same concept with your task. Look for a directory or specific file (like “/etc/hostname”) to know you found the correct partition. From there you can then cat/echo the FOG hostname variable into that file.

      Here is the windows focused solution
      https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed

      Look at the fog.custominstall script. That script locates the partition with the windows directory on it.

      This tutorial has the fog variables avaialble for the post install script
      https://forums.fogproject.org/topic/7740/the-magical-mystical-fog-post-download-script/18?_=1686319619362

      $hostname is the name assigned to the computer in the FOG web ui

      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!

      M 1 Reply Last reply Jun 9, 2023, 2:35 PM Reply Quote 0
      • M
        mdxlp @george1421
        last edited by Jun 9, 2023, 2:35 PM

        @george1421 Thank you. I’m gonna have a look at it and see what I can do with

        1 Reply Last reply Reply Quote 0
        • [[undefined-on, S Sebastian Roth, Jun 11, 2023, 6:52 AM]]
        • M
          mdxlp
          last edited by Jun 22, 2023, 9:33 AM

          I come back to you here because I tested things that included in my script the variables of the fog database, unfortunately I could not call or use most of these variables in my script because it did not work. After further research more specifically on windows, I heard about the netdom command. Does a command similar to netdom exist for linux ?

          G 1 Reply Last reply Jun 23, 2023, 1:25 AM Reply Quote 0
          • G
            george1421 Moderator @mdxlp
            last edited by Jun 23, 2023, 1:25 AM

            @mdxlp You may need to add this code to your fog post install script to load in all of the variables that fog has to offer into your post install script.

            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
            

            This basically makes a call to the fog server to collect the host info for that specific mac address. then it loads the hinfo.sh script created by the php program.

            FOG is linux based, and linux can not step into the windows realm, so there is no equivalent linux command for netdom that is windows only.

            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
            • M
              mdxlp
              last edited by Jun 23, 2023, 6:48 AM

              Thank you for your help. I tried to include this piece of code at the beginning of my script and run the deployment twice but it didn’t work. By the way the variables that I would like to use are that of the fog.imagePartitionType. To introduce it simply it would be : “If imagePartitionTypeID = 3 then mounts /dev/nvmeOn1p1”, “If imagePartitionTypeID = 4 then mounts /dev/nvmeOn1p2” to rename the following part that your deploying. Hope this clarification can bring the light on my problem.

              G 1 Reply Last reply Jun 23, 2023, 11:38 AM Reply Quote 0
              • G
                george1421 Moderator @mdxlp
                last edited by Jun 23, 2023, 11:38 AM

                @mdxlp Let me tell you how I debug post install scripts. At the top of the post install script I insert an echo with something notable so you can quickly identify it. And then right after insert a debugPause; command.

                Now schedule a deploy task to your target computer, but before you hit the schedule task button tick the debug checkbox. Now schedule the deployment task.

                PXE boot the target computer and it should drop you to a linux command prompt after a few screens of text you need to clear with the enter key. This is debug mode.

                To start the debugging process in single step mode key in fog and press enter.

                {sidebar} If you want to remote debug your post install script get the current ip address of the target computer with ip a s and then set root’s password on the target computer with passwd. Set it to something simple like hello. Now you can connect to the target computer using ssh or putty from a remote computer. Key in fog to start the single step imaging process {/sidebar}

                The deployment script will stop at each debugPause command. Keep pressing enter until you see your echo statement you put at the beginning of the post install script. At this time if you press ctrl-c you can exit the deployment script. This will give you a command shell with all of the proper environment variables you can inspect with the set command. Running the curl command from my previous post should produce all of the fog variables.

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

                152

                Online

                12.0k

                Users

                17.3k

                Topics

                155.2k

                Posts
                Copyright © 2012-2024 FOG Project