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

    Change Image ID Number

    Scheduled Pinned Locked Moved Solved
    FOG Problems
    3
    44
    12.7k
    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.
    • Wayne WorkmanW
      Wayne Workman @RobTitian16
      last edited by Wayne Workman

      @RobTitian16 Try to double quote the variables in there like this:

      if [[ "$snmysqlhost" != "" ]]; then

      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!
      Daily Clean Installation Results:
      https://fogtesting.fogproject.us/
      FOG Reporting:
      https://fog-external-reporting-results.fogproject.us/

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

        @Wayne-Workman It seemed to work without double quoting the variables - I just had to put spaces, like:

        if [[ $snmysqlhost != “” ]] then

        1 Reply Last reply Reply Quote 0
        • Tom ElliottT
          Tom Elliott
          last edited by

          https://github.com/NodeBB/NodeBB/issues/5126

          Created issue about the spaces being stripped out.

          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 2
          • Wayne WorkmanW
            Wayne Workman @Tom Elliott
            last edited by

            @Tom-Elliott said in Change Image ID Number:

            @RobTitian16, @Wayne-Workman is correct.

            On all the of the “if lines” you must have a space after [[ and before ]]

            Tom, you’re correct. And this whole mis-understanding and errors with the script are due to a nodeBB bug. It was stripping out the spaces between the brackets. I’ve checked the script’s original text that I posted by clicking the “edit” button on the post, there are spaces there but the forums isn’t displaying the spaces, so when @RobTitian16 copy/pasted he got a copy without the needed spaces.

            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!
            Daily Clean Installation Results:
            https://fogtesting.fogproject.us/
            FOG Reporting:
            https://fog-external-reporting-results.fogproject.us/

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

              @Wayne-Workman Thanks for the assistance with this - it’s much appreciated!
              It might be an idea to put this on the wiki once all is done as it would be quite helpful to others, I’m sure 🙂

              1 Reply Last reply Reply Quote 1
              • Wayne WorkmanW
                Wayne Workman
                last edited by

                #wiki worthy

                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!
                Daily Clean Installation Results:
                https://fogtesting.fogproject.us/
                FOG Reporting:
                https://fog-external-reporting-results.fogproject.us/

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

                  @Wayne-Workman Just an update on this: I tried running the script again after adding an image (the FOG web gui said it was image 31), but the script didn’t appear to run at all - there was no output as before. As a workaround, I had to set the image ID manually, but is this a known issue with the script?

                  Tom ElliottT 1 Reply Last reply Reply Quote 0
                  • Tom ElliottT
                    Tom Elliott @RobTitian16
                    last edited by

                    @RobTitian16 The scripts limitations as they currently stand will only operate if ID 1 is available to be used.

                    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

                    RobTitian16R 1 Reply Last reply Reply Quote 0
                    • Wayne WorkmanW
                      Wayne Workman
                      last edited by

                      Tom’s right. I have several ideas on how to make it better but I’ve just not worked on it.

                      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!
                      Daily Clean Installation Results:
                      https://fogtesting.fogproject.us/
                      FOG Reporting:
                      https://fog-external-reporting-results.fogproject.us/

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

                        @Tom-Elliott Ah that makes sense. Thanks for clarifying!

                        1 Reply Last reply Reply Quote 0
                        • Wayne WorkmanW
                          Wayne Workman
                          last edited by Wayne Workman

                          New script that works no matter what, plus resets the auto-number too.

                          Keep in mind the nodeBB bug that removes spaces after [[ and before ]].

                          Where you see double left brackets, a space must come after them. Where you see double right brackets, a space must come before them. You’ll need to add these spaces to the script if they are not there.

                          #!/bin/bash
                          
                          #----- MySQL Credentials -----#
                          snmysqluser=""
                          snmysqlpass=""
                          snmysqlhost=""
                          # If user and pass is blank, leave just a set of double quotes like ""
                          # if the db is local, set the host to just double quotes "" or "127.0.0.1" or "localhost"
                          
                          
                          #----- Begin Program -----#
                          
                          selectAllImageIDs="SELECT imageID FROM images ORDER BY imageID"
                          selectLowestImageID="SELECT imageID FROM images ORDER BY imageID ASC LIMIT 1"
                          selectHighestImageID="SELECT imageID FROM images ORDER BY imageID DESC LIMIT 1"
                          
                          options="-sN"
                          if [[ $snmysqlhost != "" ]]; then
                                  options="$options -h$snmysqlhost"
                          fi
                          if [[ $snmysqluser != "" ]]; then
                                  options="$options -u$snmysqluser"
                          fi
                          if [[ $snmysqlpass != "" ]]; then
                                  options="$options -p$snmysqlpass"
                          fi
                          options="$options -D fog -e"
                          
                          
                          #Information gathering.
                          lowestID=$(mysql $options "$selectLowestImageID")
                          highestID=$(mysql $options "$selectHighestImageID")
                          newAutoIncrement=$((highestID + 1))
                          
                          
                          ####### Basic logic flow ########
                          
                          #If there is an image id of 1, move it to the new auto increment number.
                          #After re-numbering is complete, the new auto increment number will not be taken.
                          #Then reset the auto-increment to the new auto increment number, which is the first free number.
                          
                          
                          
                          #Move any images that have an ID of 1 to the next free number.
                          if [[ "$lowestID" -eq "1" ]]; then
                              echo "-------------------"
                              echo "Attempting to change Image ID $lowestID to $newAutoIncrement"
                              mysql $options "UPDATE images SET imageID = $newAutoIncrement WHERE imageID = $lowestID"
                              mysql $options "UPDATE imageGroupAssoc SET igaImageID = $newAutoIncrement WHERE igaImageID = $lowestID"
                              mysql $options "UPDATE hosts SET hostImage = $newAutoIncrement WHERE hostImage = $lowestID"
                              echo "Attempt completed"
                          fi
                          
                          
                          #Re-number all images sequentially.
                          count=1
                          mysql $options "$selectAllImageIDs" | while read imageID; do
                              echo "-------------------"
                              echo "Attempting to change Image ID $imageID to $count"
                              mysql $options "UPDATE images SET imageID = $count WHERE imageID = $imageID"
                              mysql $options "UPDATE imageGroupAssoc SET igaImageID = $count WHERE igaImageID = $imageID"
                              mysql $options "UPDATE hosts SET hostImage = $count WHERE hostImage = $imageID"
                              echo "Attempt completed"
                              count=$((count + 1))
                          done
                          
                          
                          #set new auto-increment.
                          echo "-------------------"
                          highestID=$(mysql $options "$selectHighestImageID")
                          newAutoIncrement=$((highestID + 1))
                          echo "Attempting to change the auto_increment for the images table to $newAutoIncrement"
                          mysql $options "ALTER TABLE images AUTO_INCREMENT = $newAutoIncrement"
                          echo "Attempt completed"
                          
                          

                          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!
                          Daily Clean Installation Results:
                          https://fogtesting.fogproject.us/
                          FOG Reporting:
                          https://fog-external-reporting-results.fogproject.us/

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

                            @Wayne-Workman Perfect - thanks for this!

                            1 Reply Last reply Reply Quote 0
                            • 1
                            • 2
                            • 3
                            • 1 / 3
                            • First post
                              Last post

                            258

                            Online

                            12.0k

                            Users

                            17.3k

                            Topics

                            155.2k

                            Posts
                            Copyright © 2012-2024 FOG Project