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

Postdownload Script Issue

Scheduled Pinned Locked Moved Solved
FOG Problems
2
5
1.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.
  • R
    Richard Wise
    last edited by Aug 25, 2017, 8:45 PM

    Server
    • FOG Version: 1.4.4
    • OS: Ubuntu 16.04 Server
    Client
    • Service Version: N/A
    • OS: Windows 10
    Description

    I am trying to use the Fog Post Download Scripts to rename my computers as they are imaged. I have created a couple of scripts taken and modified from this site, however when I copy them to the postdownloadscripts directory on the server and deploy an image the host isn’t renamed (I don’t even see any reference to the postdownload script even attempting to run). Does anything need to be enabled for these scripts to run?

    I have no knowledge on how the scripting language used works so it is likely that there may be an issue with my scripts, can someone have a look over them and let me know how they look:

    fog.postdownload:

    #!/bin/bash
    . /usr/share/fog/lib/funcs.sh
    [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
    case $osid in
        5|6|7|9)
            clear
            [[ ! -d /ntfs ]] && mkdir -p /ntfs
            getHardDisk
            if [[ -z $hd ]]; then
                handleError "Could not find hdd to use"
            fi
            getPartitions $hd
            for part in $parts; do
                true
            done
            dots "Mounting partition $part"
            ntfs-3g -o force,rw $part /ntfs >/dev/null 2>&1
            if [[ ! $? -eq 0 ]]; then
                echo "Failed"
                debugPause
                handleError "Failed to mount $part ($0)\n Args: $*"
            fi
            echo "Done"
            debugPause
            . ${postdownpath}fog.ad
            umount /ntfs
            ;;
        *)
            echo "Invalid OS"
            debugPause
            return
            ;;
    esac
    

    fog.ad:

    #!/bin/sh
    unattend="/ntfs/Windows/Panther/Unattend.xml";
    if [ -f "$unattend" ]; then
        dots "Preparing Sysprep File";
        rm -f /ntfs/Windows/System32/Sysprep/Unattend.xml;
        echo "Done";
        dots "Writing Computer Name";
        sed -i "/ComputerName/s/*/$hostname/g" $unattend
        echo "Done";
        dots "ComputerName Set To";
        echo $hostname
    fi
    

    Thanks

    1 Reply Last reply Reply Quote 0
    • R
      Richard Wise
      last edited by Aug 27, 2017, 10:04 PM

      I ran a debug task and it showed that my fog.ad file had multiple $‘\r’ command not found errors which, after a bit of googling, turned out to be due to windows line returns being present in the file. I ran the command sed -i ‘s/\r$//’ fog.ad and everything is now running fine.

      Thanks

      G 1 Reply Last reply Aug 27, 2017, 10:44 PM Reply Quote 1
      • G
        george1421 Moderator
        last edited by Aug 25, 2017, 9:08 PM

        If the scripts have a mod of 755 then they should run.

        There are ways to debug these scripts. What you would do is add liberal echo statements to the scipts, then setup a debug deploy (check the debug box when you schedule the task). PXE boot a target computer and on the target computer it will display a few screens of commands. After a few enter key presses you will be dropped to a linux command prompt on the target computer. Key in fog and you can single step through a deployment. When you get just after the images have been pushed to the disk it should call your post download scripts. You can press crtl-C and exit out of the deployment scripts and then test your script.

        Its a bit of a back art debugging the scripts but you can get to what you need this way.

        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
        • G
          george1421 Moderator
          last edited by Aug 25, 2017, 9:12 PM

          looking at your sed call, it doesn’t look suffient. You might want to review my tutorial here: https://forums.fogproject.org/topic/7740/the-magical-mystical-fog-post-download-script/6

          More specifically my sed command to rename a host.

          sed -i -e "s#<ComputerName>\([^<][^<]*\)</ComputerName>#<ComputerName>$hostname</ComputerName>#gi" $unatendfile 
          

          The other thing is there is no warning if the unattend file doesn’t exist. The check just silently fails by design.

          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
          • R
            Richard Wise
            last edited by Aug 27, 2017, 10:04 PM

            I ran a debug task and it showed that my fog.ad file had multiple $‘\r’ command not found errors which, after a bit of googling, turned out to be due to windows line returns being present in the file. I ran the command sed -i ‘s/\r$//’ fog.ad and everything is now running fine.

            Thanks

            G 1 Reply Last reply Aug 27, 2017, 10:44 PM Reply Quote 1
            • G
              george1421 Moderator @Richard Wise
              last edited by Aug 27, 2017, 10:44 PM

              @richard-wise Right that is usually the case when windows is involved. There are a couple of ways to side step the issue.

              1. Not use windows at all.
              2. Use Notepad++ on windows
              3. Once the file gets to linux unaltered, use the linux command dos2unix to scrub out any remaining Windows bits left behind.

              With that said, well done on the debugging!!.

              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
                5/5
                Last post

              142

              Online

              12.1k

              Users

              17.3k

              Topics

              155.3k

              Posts
              Copyright © 2012-2024 FOG Project