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

    Rolling FOG out to US Site

    Scheduled Pinned Locked Moved Solved
    General
    5
    97
    44.8k
    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.
    • Tom ElliottT
      Tom Elliott @RobTitian16
      last edited by

      @RobTitian16
      I see a potential typo. Try this?

      #!/bin/bash
      
      . /usr/share/fog/lib/funcs.sh
      
      # Windows 10
      osdiskpart="/dev/sda2";
      
      mkdir /ntfs 2>/dev/null
      
      ntfs-3g -o rw,force "${osdiskpart}" /ntfs 2>/tmp/mntfail
      
      # This last section checks to see if the mntfail file exists and if it does then it means the mount failed
      # so there is no need to continue on with the script. 
      
      mntRet="$?";
      if [ ! "mntRet" = "0" ]; then 
      echo "Failed to mount C:";
      # Display what happened.
      cat /tmp/mntfail;
      # Give the reader a chance to see what the error was 
      sleep 12;
      # Terminate the post install script 
      exit 1;
      fi
      
      # This next section determines the IP of the host system, cuts the last two octects and sets the FOGIP variable to
      # the correct IP address of the FOG server depending on the location (as the subnets are designed by location - i.e.
      # 10.1 is for the UK, 10.2 is for the US, etc.)   
      
      myip='ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' | cut -d "." -f1-2';
      
      case "${myip}" in
      	10.1)
      		sitecode="UK";
      		timezone="Greenwich Mean Time";
      		FOGIP="10.1.0.102"
      		;;
      	10.2)
      		sitecode="US";
      		timezone="Eastern Standard Time";
      		FOGIP="10.2.1.103"
      		;;
      	*)
      		# Default code for the unknowns - we set the FOGIP to the development server in the UK. 
      		sitecode="CompanyName";
      		timezone="Greenwich Mean Time";
      		FOGIP="10.1.0.102"
      		;;
      esac
      
      # Check if the file SetupComplete.cmd exists in the source folder and then copy it to the destination on 
      # the C: drive. 
      
      if [ -f "/images/drivers/Common/SetupComplete.cmd" ]; then
      	cp /images/drivers/Common/SetupComplete.cmd /ntfs/Windows/Setup/Scripts/SetupComplete.cmd;
      fi

      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! Get in contact with me (chat bubble in the top right corner) if you want to join in.

      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

      1 Reply Last reply Reply Quote 0
      • george1421G
        george1421 Moderator @RobTitian16
        last edited by

        @RobTitian16 Sorry I got side tracked yesterday and had no time to respond.

        I might avoid using FOGIP because that variable maybe used already. Since case IS important it may be OK in all upper case.

        This logic makes certain assumptions

        osdiskpart="/dev/sda2";
        
        ntfs-3g -o rw,force "${osdiskpart}" /ntfs 2>/tmp/mntfail
        

        In that paratition 2 on sda will always be where windows lives. This assumption worked great until we started getting NVMe drives in. For NVMe drives the drive name is not /dev/sda but something else and the script breaks.

        Tom came up with a bit of code magic that would compensate for this.

        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 /ntf >/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
                <insert remaining code here>
                ;;
            *)
                echo "Non-Windows Deployment"
                debugPause
                return
                ;;
        esac
        

        This will map the first partition that contains a Windows folder.

        Now as for your setup complete. The cp command assumes you have a SetupComplete.cmd file already and you are just copying it over. This is fine but your script doesn’t contain the dynamic content. If you currently are not using a setup complete file you can create one on the fly using the echo / append commands I posted before.

        Since you created your own IP, let me tweak it a bit.

        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!

        george1421G 1 Reply Last reply Reply Quote 0
        • george1421G
          george1421 Moderator @george1421
          last edited by george1421

          @george1421 well crud I just ran out of time again. I haven’t had a chance to debug this so I don’t know if it actually works. But this at least is the framework of what you need. I’ve attached the actual file since the forum editor sometimes tweaks the posted script.

          #!/bin/bash
          
          . /usr/share/fog/lib/funcs.sh
          
          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 /ntf >/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: $*"
          			# Give the reader a chance to see what the error was 
                      sleep 12;
                      # Terminate the post install script 
                      exit 1;
                  fi
          
                  # This next section determines the IP of the host system, cuts the last two octects and sets the FOGIP variable to
                  # the correct IP address of the FOG server depending on the location (as the subnets are designed by location - i.e.
                  # 10.1 is for the UK, 10.2 is for the US, etc.)   
          
                  myip='ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' | cut -d "." -f1-2';
          
                  case "${myip}" in
          	        10.1)
          		        sitecode="UK";
          		        timezone="Greenwich Mean Time";
          		        FOGIP="10.1.0.102"
          			$sitelocal = "en-GB";
          			$uilang = "en-US";
          		        ;;
          	        10.2)
          		        sitecode="US";
          		        timezone="Eastern Standard Time";
          		        FOGIP="10.2.1.103"
          			$sitelocal = "en-US";
          			$uilang = "en-US";
          		        ;;
          	        *)
          		        # Default code for the unknowns - we set the FOGIP to the development server in the UK. 
          		        sitecode="CompanyName";
          		        timezone="Greenwich Mean Time";
          		        FOGIP="10.1.0.102"
          			$sitelocal = "en-GB";
          			$uilang = "en-US";
          		        ;;
                  esac
          
                  # Check if the file SetupComplete.cmd exists in the source folder and then copy it to the destination on 
                  # the C: drive. 
          
                  if [ -f "/images/drivers/Common/SetupComplete.cmd" ]; then
          	        cp /images/drivers/Common/SetupComplete.cmd /ntfs/Windows/Setup/Scripts/SetupComplete.cmd;
          		# append the msiexec command to the end of the setupComplete.cmd file 
          		echo "msiexec.exe /i FOGService.msi /quiet USETRAY=\"0\" WEBADDRESS=\"${FOGIP}\" " >> /ntfs/Windows/Setup/Scripts/SetupComplete.cmd
          		# just in case we edited the setupcomplete.cmd file in unix lets filter it to make it DOS compatible
          		unix2dos /ntfs/Windows/Setup/Scripts/SetupComplete.cmd
                  fi
          		
          	# now lets use the timezone variable and update the unattend.xml file. You may need to edit the variable to 
          	# point to where your unattend.xml file exists. Remember case IS important. 
          	unattendfile="/ntfs/Windows/Panther/unattend.xml";
          	sed -i -e "s#<TimeZone>\([^<][^<]*\)</TimeZone>#<TimeZone>$timezone</TimeZone>#gi" $unattendfile
          		
          	# now lets deal with the internationalization stuff in the unattend.xml file 
          	sed -i -e "s#<InputLocale>\([^<][^<]*\)</InputLocale>#<InputLocale>$sitelocal</InputLocale>#gi" $unattendfile
          	sed -i -e "s#<SystemLocale>\([^<][^<]*\)</SystemLocale>#<SystemLocale>$sitelocal</SystemLocale>#gi" $unattendfile
          	sed -i -e "s#<UILanguage>\([^<][^<]*\)</UILanguage>#<UILanguage>$uilang</UILanguage>#gi" $unattendfile
          	sed -i -e "s#<UserLocale>\([^<][^<]*\)</UserLocale>#<UserLocale>$sitelocal</UserLocale>#gi" $unattendfile
                  ;;
              *)
                  echo "Non-Windows Deployment"
                  debugPause
                  return
                  ;;
          esac
          

          0_1479303265713_post_inst.sh

          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!

          RobTitian16R 2 Replies Last reply Reply Quote 0
          • RobTitian16R
            RobTitian16 @george1421
            last edited by RobTitian16

            @george1421 Thanks for that. I get a couple of errors at the beginning, and it doesn’t copy over the Setup.cmd file (quite possibly because of said errors).

            Edit: I’ve noticed the errors I received were because I had copied the file across using Windows, so it couldn’t run the script correctly. I’ll try again now.

            george1421G 1 Reply Last reply Reply Quote 0
            • george1421G
              george1421 Moderator @RobTitian16
              last edited by

              @RobTitian16 when you get to the point where you “need” to debug your post install script. I have some helpful hints you can use.

              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
              • RobTitian16R
                RobTitian16 @george1421
                last edited by

                @george1421 I wonder if the syntax of the {print} command is incorrect. I’m getting the following:

                0_1479309990267_Capture2.PNG

                Also, as a note, there were a couple of issues with no spaces in the lines with [[! - one I had added the space (to be like [[ ! ) it was working.

                george1421G 1 Reply Last reply Reply Quote 0
                • george1421G
                  george1421 Moderator @RobTitian16
                  last edited by

                  @RobTitian16 OK I have a few minutes between meetings this am, let me take a look for the print command and for the copy command its possible that you don’t have the complete path created (especially if you never specifically used the setupcomplete.cmd file).

                  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!

                  RobTitian16R 1 Reply Last reply Reply Quote 0
                  • RobTitian16R
                    RobTitian16 @george1421
                    last edited by

                    @george1421 p.s. I’m not using the unattend.xml at the moment so those lines can be ignored.

                    george1421G 2 Replies Last reply Reply Quote 0
                    • george1421G
                      george1421 Moderator @RobTitian16
                      last edited by

                      @RobTitian16 OK is see what happened. I was being lazy and just grabbed your code (which was wrong) when I consolidated the script.

                      the correct code is this

                      myip=`ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' | cut -d "." -f1-2`;
                      

                      Note right after myip= that is a back tick not a single quote.

                      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
                      • Tom ElliottT
                        Tom Elliott
                        last edited by Tom Elliott

                        @george1421

                        myip=`ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' | cut -d "." -f1-2`;
                        

                        I’d recommend as:

                        myip=$(ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' | cut -d "." -f1-2)
                        

                        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! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                        george1421G 1 Reply Last reply Reply Quote 1
                        • george1421G
                          george1421 Moderator @Tom Elliott
                          last edited by

                          @Tom-Elliott said in Rolling FOG out to US Site:

                          I’d recommend as:

                          myip=$(ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' | cut -d "." -f1-2)

                          Sweet, I learned something new today.

                          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
                          • george1421G
                            george1421 Moderator @RobTitian16
                            last edited by Tom Elliott

                            @RobTitian16 You found the other issue I mentioned that the code copied out of the forums sometimes misses spaces that need to be in there.

                            For example this code

                             [[_! -d /ntfs_]] && mkdir -p /ntfs #REPLACE _ WITH SPACES
                            

                            gets converted into

                             [[! -d /ntfs ]] && mkdir -p /ntfs
                            

                            note the missing space after the second left bracket. That is why I included the text file (which I may not have fixed every occurrence when I was quickly hacking it up.)

                            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!

                            RobTitian16R 1 Reply Last reply Reply Quote 0
                            • Q
                              Quazz Moderator
                              last edited by

                              https://www.shellcheck.net/

                              Might be helpful if you’re going to use bash scripts to make sure there’s no mistakes in it.

                              1 Reply Last reply Reply Quote 2
                              • RobTitian16R
                                RobTitian16 @george1421
                                last edited by

                                @george1421 Yep, I remembered it from last time.
                                I did download the file and transfer it to my FOG Server, which is when I had to use dos2linux to convert it as it was giving some unusual errors.
                                Apparently it really doesn’t like:

                                $sitelocal = "en-GB";
                                $uilang = "en-US";
                                

                                As I’m getting this error:

                                0_1479333018583_Capture2.PNG

                                george1421G 1 Reply Last reply Reply Quote 0
                                • george1421G
                                  george1421 Moderator @RobTitian16
                                  last edited by george1421

                                  @RobTitian16 nuts, that’s what happens when you do crud too stuff too fast while doing your real job.

                                  Remove the leading dollar sign “$” from each variable, that should not be there on a set action.

                                  As for the hint part I alluded to before… crud back in a minute.

                                  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!

                                  RobTitian16R george1421G 2 Replies Last reply Reply Quote 0
                                  • RobTitian16R
                                    RobTitian16 @george1421
                                    last edited by

                                    @george1421 haha, I thought that but just wanted to confirm before fiddling 😛

                                    1 Reply Last reply Reply Quote 0
                                    • george1421G
                                      george1421 Moderator @george1421
                                      last edited by

                                      @george1421 OK here is the hint.

                                      1. If you schedule a debug deploy to your target computer.
                                      2. Then pxe boot your target computer. After a few enter key presses you will be dropped to a linux command prompt.
                                      3. From here you can enter fog and single step through the deployment tasks until you get to your postinstall script. If you script bombs out you can then work on editing your post install script. BUT what I recommend is to do step 4 and on.
                                      4. Get the ip address of your target computer using ip addr show
                                      5. Set roo’s password with passwd you can set it to anything you want.
                                      6. Now from a windows or linux computer use putty to connect to your target computer.
                                      7. At the command prompt key in fog to single step through the installation process.

                                      Putty gives you the ability to copy, cut and paste as you edit the post install script.

                                      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!

                                      RobTitian16R 1 Reply Last reply Reply Quote 0
                                      • RobTitian16R
                                        RobTitian16 @george1421
                                        last edited by RobTitian16

                                        @george1421 Thanks!
                                        Not sure why, but it’s still not copying the SetupComplete.cmd… I wonder if it’s because I made it on the FOG Server itself by just typing: “sudo vi SetupComplete.cmd” and then filling in the file with what I needed for the msi installer.

                                        0_1479338512551_Capture2.PNG

                                        george1421G 1 Reply Last reply Reply Quote 0
                                        • george1421G
                                          george1421 Moderator @RobTitian16
                                          last edited by george1421

                                          @RobTitian16 What you need to confirm is does the entire target path exist?

                                          If I had to bet, I would say this path exists on the target computer c:\windows\setup and thats it. If that is the case you need to create the scripts folder in c:\windows\setup folder.

                                          Also remember I said CASE is important. /ntfs/windows/setup/scripts is not the same as /ntfs/Windows/Setup/Scripts as it would be in the windows OS it self, you are still running linux here.

                                          If you single step through a fog deploy like I posted and run into that error, press ctrl-C to blow out of the script. Then you can inspect the /ntfs path to ensure everything is as you would expect it. It helps with debugging greatly.

                                          Don’t give up here, you are doing some pretty complex stuff with FOG, but will end up with a sweet solution when it all comes together.

                                          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!

                                          RobTitian16R 1 Reply Last reply Reply Quote 1
                                          • RobTitian16R
                                            RobTitian16 @george1421
                                            last edited by

                                            @george1421 Thanks, George. Definitely not going to give up here - if anything I’m actually craving more understanding of the coding, etc. which I’ll hopefully gain in time 🙂
                                            So I’d have to create this folder structure inside the image first? Can I not do it through the script whilst it’s in FOS?

                                            george1421G 2 Replies Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 3 / 5
                                            • First post
                                              Last post

                                            192

                                            Online

                                            12.0k

                                            Users

                                            17.3k

                                            Topics

                                            155.2k

                                            Posts
                                            Copyright © 2012-2024 FOG Project