Scripted process to remove a file/folder before imaging


  • Is there a way we can script the removal of a file or folder before the capturing of an image. Or, can it be scripted to be done after the image is deployed. Before the final reboot?

  • Moderator

    @dashwell Normally you would delete the file before capture in our source OS. But I know sometimes you just need to edit / remove one file from the target system.

    You can do what you want with a FOG post install script. I have a tutorial on how to inject drivers into a target windows system that you can use as the basis. Start by reading this: https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed

    The only scripts you will need to start with is fog.custominstall

    In this section of the code you will need to change it for your purposes.

            debugPause
            . ${postdownpath}fog.copydrivers
            # . ${postdownpath}fog.updateunattend
            umount /ntfs
            ;;
    

    Lets change it to

            debugPause
            . ${postdownpath}fog.nukemyfile
            # . ${postdownpath}fog.updateunattend
            umount /ntfs
            ;;
    

    Now that above script will connect the C drive on the target computer disk to the /ntfs directory. The thing you have to remember is the FOG Post install script runs under linux and not a windows batch file. So there are some pain points you must remember. The first is the directory paths are forward slash ( / ) and not a backslash ( \ ). Second linux is case sensitive. So lets say you want to edit the unattend.xml file you would reference that file as /ntfs/Windows/Panther/Unattend.xml Note the path and case matching.

    So now you will need to create a file called fog.nukemyfile in the /images/postdownloadscripts directory on the fog server. Hint: If you first create the file on a windows box use notepad++ not windows notepad. You will save some headaches later.

    In that fog.nukemyfile file put the following.

    #!/bin/bash
    
    rm "/ntfs/apps/broadcom/config.ini"
    
    

    Assuming you wanted to remove the config.ini file in c:\apps\broadcom directory.

    The last bit from the tutorial you will need to hook the fog.custominstall script into the fog.postdownload script as mentioned.

258
Online

9.5k
Users

15.9k
Topics

147.5k
Posts