Updating a registry file after deployment
-
I have a small organization that stores its asset tag in a registry file on Windows 10. I want to take “Other Tag #1” from the host’s inventory and input it into this registry file. I am having a hard time trying to make this possible. Thank you in advance.
-
You will need to do this with a FOG Post install script. Let me see if I can get an example for you.
-
@devrick The bash script variables are listed towards the bottom of this post. https://forums.fogproject.org/post/69723
The code to update the registry is listed in the fog.copydrivers section of this post: https://forums.fogproject.org/post/105078
So how should you start, but looking over this tutorial: https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed
I would copy over the fog.custominstall script as is.
Create a new bash script that looked similar to the fog.copydrivers script from the above post. Name it fog.updatereg
#!/bin/bash regfile="/ntfs/Windows/System32/config/SOFTWARE" key="\Microsoft\Windows\MyTags\SystemTag" devtag= ${othertag1} reged -e "$regfile" &>/dev/null <<EOFREG ed $key $devtag q y EOFREG
Change the regfile and key to the appropriate ones for your enviornment.
Finally update the fog.custominstall replacing the line with fog.copydrivers with fog.updatereg. And the last bit is to hook the fog.custominstall script into fog by following the fog.postdownload section of this post: https://forums.fogproject.org/post/105078
-
@george1421 Thank you very much!
-
@devrick You will still need to glue all of the bits together but in principal it is possible to do and should work well.
-
@george1421 I have been reading it over and I can’t locate the funcs.sh script. Located at
/usr/share/fog/lib/funcs.sh
There doesn’t seem to be a “fog” folder in “/usr/share”. Would you know where it would be located or maybe if I am overlooking a detail?
-
-
@devrick said in Updating a registry file after deployment:
/usr/share/fog/lib/funcs.sh
To extend what Tom said…
These post install scripts are run from the context of the target computer running FOS Linux. That file contains a swiss army knife of useful scripts that is needed for both imaging as well as post install script functions. That referenced file is on the virtual hard drive that is downloaded to the target computer during the pxe booting process.
When you get to the point where you want to start debugging your post install script we can give you some additional guidance to make debugging a lot easier. But I don’t want to flood this thread with useless stuff until you are ready.
-
@george1421 In the example code that you shared.
#!/bin/bash regfile="/ntfs/Windows/System32/config/SOFTWARE" key="\Microsoft\Windows\MyTags\SystemTag" devtag= ${othertag1} reged -e "$regfile" &>/dev/null <<EOFREG ed $key $devpath q y EOFREG
There is a variable “$devpath” that is defined in fog.copydrivers. Is this something that I should add or could I remove the variable?
EDIT: I believe that $devpath is suppose to be $devtag
-
@devrick That is a copy/paste artifact (but good catch) Change
$devpath
to this${devtag}
and you are good to go.If you are not familiar with bash variables.
$devtag
and${devtag}
are usually equivalent. Its just that${devtag}
describes exactly that its a variable and sometimes bash gets confused with just$devtag
thinking its something other than a variable so its best to enclose the variable name in curly braces. -
@george1421 I am getting the following error:
No such file or directory//fog.custominstall: line 2: /usr/share/fog/lib/funcs.sh /images/postdownloadscripts/fog.custominstall: line 4: syntax error near unexpected token '$' in\r'' 'images/postdownloadscripts//fog.custominstall: line 4: 'case $osid in
The scripts that I have set up.
fog.postdownload
#!/bin/bash ## This file serves as a starting point to call your custom postimaging scripts. ## <SCRIPTNAME> should be changed to the script you're planning to use. ## Syntax of post download scripts are #. ${postdownpath}<SCRIPTNAME> . ${postdownpath}/fog.custominstall
fog.custominstall
#!/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 umount /ntfs >/dev/null 2>&1 fsTypeSetting "$part" case $fstype in ntfs) dots "Testing partition $part" ntfs-3g -o force,rw $part /ntfs ntfsstatus="$?" if [[ ! $ntfsstatus -eq 0 ]]; then echo "Skipped" continue fi if [[ ! -d /ntfs/windows && ! -d /ntfs/Windows && ! -d /ntfs/WINDOWS ]]; then echo "Not found" umount /ntfs >/dev/null 2>&1 continue fi echo "Success" break ;; *) echo " * Partition $part not NTFS filesystem" ;; esac done if [[ ! $ntfsstatus -eq 0 ]]; then echo "Failed" debugPause handleError "Failed to mount $part ($0)\n Args: $*" fi echo "Done" debugPause . ${postdownpath}fog.updateregbarcode umount /ntfs ;; *) echo "Non-Windows Deployment" debugPause return ;; esac
fog.updateregbarcode
#!/bin/bash ${othertag} > "/ntfs/barcode.txt" regfile="/ntfs/Windows/System32/config/SYSTEM" key="\UNITS Barcode\Barcode" devtag= ${othertag} reged -e "$regfile" &>/dev/null <<EOFREG ed $key $devtag q y EOFREG
I am not sure on how to move forward. Thank you for your help.
-
@devrick Ok lets start a crash course in FOG debugging.
First of all the error message with a
\r
I think is telling. Did you use a windows computer at any time when you created or edited these scripts? Of so that is why things are a bit crazy. Windows Notepad add a carriage return\r
to the end of every line. This drives linux crazy. You will need to find and load the dos2unix for your fog server’s distro and scrub your post install bash files. If you want to edit these files on a windows computer use notepad++ and your life will be much easier.Now to the debugging steps.
Using vi or nano add this just below the
#!/bin/bash
in fog.custominstallecho "Running my script" debugPause
What this will do is display “Running my script” during image deployment then wait. When its waiting hit ctrl-c to exit out of the script. This will toss you back to the FOS Linux command prompt.
Now how to get there.
If you have any open image deployment tasks for this specific target computer cancel them .Schedule a new deployment task for this target computer, but before you hit the schedule task button, tick the debug checkbox then schedule the task.
PXE boot the target computer. After a few screens of text you will be dropped to the fos linux command prompt.
Key in
ip a s
and get the IP address of the target computer
Now give root a password withpasswd
make it something simple like hello. This password will be reset on the next reboot so no worries. Now you have the IP address and the root password set you can use Putty or SSH to connect to this target computer remotely. This will help with debugging, copying and pasting.Now that you have connected remotely, or working right from the target computer’s console lets start the debugging process. Key in
fog
at the fos linux command prompt. This will start the imaging process. The system will pause at eachdebugPause
statements in the deployment process. You will need to hit enter to move to the next step.After you see the partclone screens close out the next step is your post install script. When you see “Running my script” you can hit ctrl-c and exit the script. Your post install scripts will be in /images/postinstall directory on the target computer. Only
vi
is loaded on the target computer, but you can also edit the scripts via the fog server so you can use vi there or nano. If you want to test the deployment scripts again (without needing to reboot) just key infog
at the FOS Linux command prompt and it will deploy again without needed to touch the FOG WebUI. You can do this over and over again until the target computer reaches the end of the deployment task and tells the FOG server its done. Then the task will be removed from the queue.My bet is that once you get the extra carrage
-
@george1421 This helped a lot. So you were right. Scrubbing my scripts with dos2unix fixed the issue for the most part. I was using vscode and assumed that it would be ok, but I guess it adds carriage returns as well. I was able to use reged and found some issues that I hope to be able to address.
I am running into the issue of not being able to call the additional variables from here.
For example the ${othertag}
The way I was seeing if the variables could be called was by adding the following to fog.updateregbarcodeecho "Hello" > /ntfs/test.txt ${othertag} > /ntfs/barcode.txt
I even tried
echo "Hello" > /ntfs/test.txt echo ${othertag} > /ntfs/barcode.txt
The test.txt worked had “Hello”, but the barcode.txt was blank in both instances. I have verified that the host’s inventory has information in “Other Tag #1”. I noticed in the link that you previously shared that went over the various variables. And added the following code to fog.custominstall without success.
if [[ ! -z $mac ]]; then curl -A "" -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d "mac=$mac" if [[ -f /tmp/hinfo.sh ]]; then . /tmp/hinfo.sh fi fi
I am assuming that the variables come from /usr/share/fog/lib/funcs.sh, but I was not able to locate the variable “othertag”.
-
@devrick If you stop the script where/when it displays “Running my script” those variables should have been set. Now its been several years so I might be not thinking right.
But this code should pull those variables.
if [[ ! -z $mac ]]; then wget -q -O /tmp/hinfo.txt "http://${web}service/hostinfo.php?mac=$mac" if [[ -f /tmp/hinfo.txt ]]; then . /tmp/hinfo.txt fi fi
What this does is makes a call to the FOG server using the network adapters mac address. The returned file contains the code to set the environment variables into hinfo.txt Then it stats hinfo.txt to load the variables into bash. That hinfo.txt file should contain the other1 tag.
You could test this from the FOS Linux command prompt by just issuing the wget command replacing the variable with real values. Then look through the hinfo.txt file to make sure it has the variables you need.
-
@george1421 Thinking about it a bit more when you see the “Running my script” text in your postinstall script hit ctrl-c and drop to the FOS Linux command prompt then just issue
set | more
orset | grep other
to see the environment variables. If the other tags are not there then you need to use the wget into hinfo.txt and stat it, then the variables will be set. -
@george1421 The following is my fog.custominstall. Would this be correct?
#!/bin/bash echo "Running my script" debugPause if [[ ! -z $mac ]]; then curl -A "" -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d "mac=$mac" if [[ -f /tmp/hinfo.sh ]]; then . /tmp/hinfo.sh fi fi . /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 umount /ntfs >/dev/null 2>&1 fsTypeSetting "$part" case $fstype in ntfs) dots "Testing partition $part" ntfs-3g -o force,rw $part /ntfs ntfsstatus="$?" if [[ ! $ntfsstatus -eq 0 ]]; then echo "Skipped" continue fi if [[ ! -d /ntfs/windows && ! -d /ntfs/Windows && ! -d /ntfs/WINDOWS ]]; then echo "Not found" umount /ntfs >/dev/null 2>&1 continue fi echo "Success" break ;; *) echo " * Partition $part not NTFS filesystem" ;; esac done if [[ ! $ntfsstatus -eq 0 ]]; then echo "Failed" debugPause handleError "Failed to mount $part ($0)\n Args: $*" fi echo "Done" debugPause . ${postdownpath}fog.updateregbarcode umount /ntfs ;; *) echo "Non-Windows Deployment" debugPause return ;; esac
-
@devrick I would move the call to funcs to the top just below the call to bash.
I’ll have a little time in about 30 minutes to fire up my fog server and debug this a bit. I think you are very close though.
-
@george1421 My fog.custominstall script
#!/bin/bash . /usr/share/fog/lib/funcs.sh echo "Running my script" debugPause if [[ ! -z $mac ]]; then curl -A "" -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d "mac=$mac" if [[ -f /tmp/hinfo.sh ]]; then . /tmp/hinfo.sh fi fi [[ -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 umount /ntfs >/dev/null 2>&1 fsTypeSetting "$part" case $fstype in ntfs) dots "Testing partition $part" ntfs-3g -o force,rw $part /ntfs ntfsstatus="$?" if [[ ! $ntfsstatus -eq 0 ]]; then echo "Skipped" continue fi if [[ ! -d /ntfs/windows && ! -d /ntfs/Windows && ! -d /ntfs/WINDOWS ]]; then echo "Not found" umount /ntfs >/dev/null 2>&1 continue fi echo "Success" break ;; *) echo " * Partition $part not NTFS filesystem" ;; esac done if [[ ! $ntfsstatus -eq 0 ]]; then echo "Failed" debugPause handleError "Failed to mount $part ($0)\n Args: $*" fi echo "Done" debugPause . ${postdownpath}fog.updateregbarcode umount /ntfs ;; *) echo "Non-Windows Deployment" debugPause return ;; esac
I went through and tried both wget and curl solutions.
This one gave me errors. I am running 1.5.9 and here states that curl should be used after 1.4.1if [[ ! -z $mac ]]; then wget -q -O /tmp/hinfo.txt "http://${web}service/hostinfo.php?mac=$mac" if [[ -f /tmp/hinfo.txt ]]; then . /tmp/hinfo.txt fi fi
For this one, I don’t get an error.
if [[ ! -z $mac ]]; then curl -A "" -Lkso /tmp/hinfo.sh ${web}/fog/service/hinfo.php -d "mac=$mac" if [[ -f /tmp/hinfo.sh ]]; then . /tmp/hinfo.sh fi fi
This is what is in /tmp/hinfo.sh. It is pulling my web login page.
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width, initial-scale=1"/><title>Login</title><link href="../management/css/animate.min.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/font-awesome.min.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/jquery-ui.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/jquery-ui.theme.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/jquery-ui.structure.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/jquery-ui-timepicker-addon.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/select2.min.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/bootstrap.min.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/bootstrap-theme.min.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/theme.bootstrap_3.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/theme.blue.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/bootstrap-dialog.min.css?ver=135" rel="stylesheet" type="text/css"/><link href="../management/css/default/fog.css?ver=135" rel="stylesheet" type="text/css"/><link rel="shortcut icon" href="../favicon.ico" type="image/x-icon"/></head><body><nav class="navbar navbar-inverse navbar-fixed-top"><div class="container-fluid"><div class="navbar-header"><button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse"><span class="sr-only">Toggle Navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button></div><div class="collapse navbar-collapse"><ul class="nav navbar-nav"><a class="navbar-brand" href="../management/index.php?node=home"><b>FOG</b> Project</a></ul></div></div></nav><div class="container-fluid dashboard"><div class="form-signin"><form class="form-horizontal" method="post" action="?node=home"><h3 class="form-signin-heading text-center"><span class="col-xs-1"><img src="../favicon.ico" class="logoimg" alt="Open Source Computer Cloning Solution"/></span>FOG Project</h3><hr/><div class="form-group"><label class="control-label col-md-2" for="uname">Username</label><div class="col-md-10"><input type="text" class="form-control" name="uname" required="" autofocus="" id="uname"/></div></div><div class="form-group"><label class="control-label col-md-2" for="upass">Password</label><div class="col-md-10"><input type="password" class="form-control" name="upass" required="" id="upass"/></div></div><div class="form-group"><label class="control-label col-md-2" for="ulang">Language</label><div class="col-md-10"><select class="form-control" name="ulang" id="ulang"><option value="中国的">中国的</option><option value="English" selected>English</option><option value="Español">Español</option><option value="Français">Français</option><option value="Deutsch">Deutsch</option><option value="Italiano">Italiano</option><option value="Português">Português</option></select></div></div><div class="form-group"><div class="col-md-offset-2 col-md-10"><button class="btn btn-default btn-block" type="submit" name="login">Login</button></div></div></form><hr/><div class="row"><div class="form-group"><div id="login-form-info"><p>Estimated FOG Sites: <b><i class="icon fa fa-circle-o-notch fa-spin fa-fw"></i></b></p><p>Latest Version: <b><i class="icon fa fa-circle-o-notch fa-spin fa-fw"></i></b></p><p>Latest Development Version: <b><i class="icon fa fa-circle-o-notch fa-spin fa-fw"></i></b></p></div></div></div></div></div><div class="collapse navbar-collapse"><footer class="footer"><nav class="navbar navbar-inverse navbar-fixed-bottom"><div class="container-fluid"><ul class="nav navbar-nav"><li><a href="https://wiki.fogproject.org/wiki/index.php?title=Credits">Credits</a></li><li><a href="?node=client">FOG Client</a></li><li><a href="https://www.paypal.com/cgi-bin/webscr?item_name=Donation+to+FOG+-+A+Free+Cloning+Solution&cmd=_donations&business=fogproject.org@gmail.com" target="_blank">Donate to FOG</a></li></ul></div></nav></footer></div><script src="js/jquery-latest.min.js?ver=135" type="text/javascript"></script><script src="js/jquery.validate.min.js?ver=135" type="text/javascript"></script><script src="js/additional-methods.min.js?ver=135" type="text/javascript"></script><script src="js/jquery.tablesorter.combined.js?ver=135" type="text/javascript"></script><script src="js/select2.min.js?ver=135" type="text/javascript"></script><script src="js/jquery-migrate-latest.min.js?ver=135" type="text/javascript"></script><script src="js/jquery.progressbar.js?ver=135" type="text/javascript"></script><script src="js/jquery.tmpl.js?ver=135" type="text/javascript"></script><script src="js/jquery.placeholder.js?ver=135" type="text/javascript"></script><script src="js/jquery-ui.min.js?ver=135" type="text/javascript"></script><script src="js/flot/jquery.flot.js?ver=135" type="text/javascript"></script><script src="js/flot/jquery.flot.time.js?ver=135" type="text/javascript"></script><script src="js/flot/jquery.flot.pie.js?ver=135" type="text/javascript"></script><script src="js/flot/jquery.flot.JUMlib.js?ver=135" type="text/javascript"></script><script src="js/flot/jquery.flot.gantt.js?ver=135" type="text/javascript"></script><script src="js/jquery-ui-timepicker-addon.js?ver=135" type="text/javascript"></script><script src="js/bootstrap.min.js?ver=135" type="text/javascript"></script><script src="js/bootstrap-dialog.min.js?ver=135" type="text/javascript"></script><script src="js/fog/fog.js?ver=135" type="text/javascript"></script><script src="js/jscolor.min.js?ver=135" type="text/javascript"></script><script src="js/fog/fog.login.js?ver=135" type="text/javascript"></script><!-- Memory Usage: 4.00 MiB--><!-- Memory Peak: 5.46 MiB--></body></html>
-
@devrick Ok let me power up my dev environment again. I did some bad things to my Centos server working on nfsv4 so I could not image with it. Let me start up the ubuntu server and see if I left that in a sane state to debug your code. I know the code should work correctly.
-
@devrick I found the first problem in that I gave you some bad intel. I need to update that old post about hinfo. For security the developers changed how that file can be called to prevent data leakage. As soon as I saw the output file from the wget command I knew what was wrong.
The way the FOS Linux calls it is in this line:
https://github.com/FOGProject/fos/blob/8d310f51d7d945c5dc1685eb6698d1aed8634dc7/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog#L8With real values:
curl -Lks -o /tmp/hinfo.txt --data “sysuuid=bob&mac=d6:29:3b:0e:fc:16” “http://192.168.112.116/fog/service/hostinfo.php” -A ‘’With the variables
curl -Lks -o /tmp/hinfo.txt --data “sysuuid=${sysuuid}&mac=${mac}” “${web}/service/hostinfo.php” -A ‘’It did return what was expected into hinfo.txt.
I had to spin up a new FOG server because the centos and ubuntu servers were reconfgured for nfsv4, So now I need to build a new windows VM and capture that image onto the new FOG server to test how well the deploy script runs. I’m confident we will be able to access the other tags too.
# cat hinfo.txt [[ -z $mac ]] && export mac='d6:29:3b:0e:fc:16' [[ -z $ftp ]] && export ftp='192.168.112.116' [[ -z $osid ]] && export osid='9' [[ -z $storage ]] && export storage='192.168.112.116:/images/' [[ -z $storageip ]] && export storageip='192.168.112.116' [[ -z $img ]] && export img='Baseimage1' [[ -z $imgFormat ]] && export imgFormat='5' [[ -z $imgType ]] && export imgType='n' [[ -z $imgPartitionType ]] && export imgPartitionType='all' [[ -z $imgid ]] && export imgid='1' [[ -z $PIGZ_COMP ]] && export PIGZ_COMP='-6' [[ -z $shutdown ]] && export shutdown='0' [[ -z $hostearly ]] && export hostearly='1' [[ -z $pct ]] && export pct='5' [[ -z $ignorepg ]] && export ignorepg='1' [[ -z $winuser ]] && export winuser='' [[ -z $port ]] && export port='' [[ -z $fdrive ]] && export fdrive='' [[ -z $hostname ]] && export hostname='uefibooter' [[ -z $hostdesc ]] && export hostdesc='Created by FOG Reg on January 9, 2021, 12:46 am' [[ -z $hostip ]] && export hostip='' [[ -z $hostimageid ]] && export hostimageid='1' [[ -z $hostbuilding ]] && export hostbuilding='0' [[ -z $hostusead ]] && export hostusead='' [[ -z $hostaddomain ]] && export hostaddomain='' [[ -z $hostaduser ]] && export hostaduser='' [[ -z $hostadpass ]] && export hostadpass='' [[ -z $hostadou ]] && export hostadou='' [[ -z $hostproductkey ]] && export hostproductkey='' [[ -z $imagename ]] && export imagename='Baseimage1' [[ -z $imagedesc ]] && export imagedesc='' [[ -z $imageosid ]] && export imageosid='9' [[ -z $imagepath ]] && export imagepath='Baseimage1' [[ -z $primaryuser ]] && export primaryuser='JonDoe' [[ -z $othertag ]] && export othertag='MyTag1' [[ -z $othertag1 ]] && export othertag1='MyTag2' [[ -z $sysman ]] && export sysman='QEMU' [[ -z $sysproduct ]] && export sysproduct='Standard PC (i440FX + PIIX, 1996)' [[ -z $sysserial ]] && export sysserial='Not Specified' [[ -z $mbman ]] && export mbman='' [[ -z $mbserial ]] && export mbserial='' [[ -z $mbasset ]] && export mbasset='' [[ -z $mbproductname ]] && export mbproductname='' [[ -z $caseman ]] && export caseman='QEMU' [[ -z $caseserial ]] && export caseserial='Not Specified' [[ -z $caseasset ]] && export caseasset='Not Specified' [[ -z $type ]] && export type='down'