Postdownload Script Issue
-
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
#!/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
-
-
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.
-
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.
-
-
@richard-wise Right that is usually the case when windows is involved. There are a couple of ways to side step the issue.
- Not use windows at all.
- Use Notepad++ on windows
- 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!!.