Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
userspace:opsi-info [2013/09/03 18:41]
islam
userspace:opsi-info [2013/12/10 19:00] (current)
islam
Line 1: Line 1:
-opsi-info+**opsi-info**
  
 opsi-info.sh opsi-info.sh
  
 shell script to change version information of available opsi packages shell script to change version information of available opsi packages
 +
 +**Features:​**
 +
 +- Display Version and package-version of any opsi product
 +
 +- Edit Version and package-version of any opsi product
 +
 +- Change Product version if defined in setup script (setup.ins)
 +
 +updates this File String in setup.ins:
 +<​code>​Set $ProductVersion$ ​ = "​24.1.1"</​code>​
 +replacing the version number can be useful if you use the version as parameter in your setup script, for example
 +<​code>"​%ScriptPath%\files\Firefox Setup $ProductVersion$esr.exe"​ -ms -ira</​code>​
 +
 +This means, updating Firefox would just require you to place the new setup exe file inside "​%ScriptPath%\files\"​
 +then setting the the new version with opsi-info.sh
 +
 +- optionally set "​setup"​ action for the updated product on all clients with the product already installed
 +
  
 Download Link here: http://​islamadel.com/​en/​downloads?​func=fileinfo&​id=12 Download Link here: http://​islamadel.com/​en/​downloads?​func=fileinfo&​id=12
  
-<code Bash>+############################​
  
 +opsi-info : view / edit opsi package information
 +
 +usage:
 +
 +opsi-info [arguments]
 +
 +arguments:
 +
 +-h :​ display help
 +
 +-prod [product-id] :​ view / edit info for product-id
 +
 +-ver [decimal] :​ set decimal value for product version
 +
 +-pver [integer] :​ set value for package version
 +
 +
 +example: <code Bash>​opsi-info.sh -prod internet_firefox -ver 25.0.1</​code>​
 +
 + sets new version "​25.0.1"​ for product-id "​internet_firefox"​
 +
 +
 +############################​
 +
 +**opsi-info.sh**
 +
 +<code Bash>
 #!/bin/bash #!/bin/bash
  
Line 24: Line 70:
 # 2013-09-02 view,​ edit product version, depot file autodetection # 2013-09-02 view,​ edit product version, depot file autodetection
 # 2013-09-03 view,​ edit package version, backup all edited files # 2013-09-03 view,​ edit package version, backup all edited files
 +# 2013-12-10 added option to update clients with product already installed, set correct file rights for edited files
 +
 +# target: - prompt for software setup on all clients with status "​installed"​
 +
 +# General-Info to find installed product on client:
 +
 +# installed info:
 +# in /​home/​opsiproducts/​client-name.ini
 +#​ internet_firefox = installed:​none
 +# function:
 +# Find string "​internet_firefox = installed:​none"​ all "​*.ini"​ Files in "/​home/​opsiproducts/"​ (replace internet_firefox by product name)
 +#
 +# Set for setup
 +# change from "​internet_firefox = installed:​none"​
 +# to: "​internet_firefox = installed:​setup"​
  
 +#
 #target: - read/edit opsi package information #target: - read/edit opsi package information
 # - list all package-ids # - list all package-ids
Line 41: Line 103:
 ######################​ ######################​
 # global variables # global variables
-ver="​13.09.03"+ver="​13.12.10"
 #set loop delimiter as "​newline"​ #set loop delimiter as "​newline"​
 IFS=$'​\n'​ IFS=$'​\n'​
Line 193: Line 255:
 depot_tmp2="​$depot.2.tmp"​ depot_tmp2="​$depot.2.tmp"​
 if [ -f $depot_tmp2 ]; then rm -f $depot_tmp2;​ fi if [ -f $depot_tmp2 ]; then rm -f $depot_tmp2;​ fi
 +}
 +
 +#find clients with installed product and set for setup
 +f_UpdateClients() {
 + # Find string "​internet_firefox = installed:​none"​ all "​*.ini"​ Files in "/​home/​opsiproducts/"​ (replace internet_firefox by product name)
 +
 + # first find clients, display names and prompt
 + # use: grep -l "​internet_firefox = installed:​none"​ /​var/​lib/​opsi/​config/​clients/​*.ini
 +
 + echo
 + echo "​Searching for clients with [ ${product} ] status: installed .."
 + echo
 +
 + # Set number of clients found with product already installed
 + updclient=0
 + #Path of clients Folder
 + clientspath="/​var/​lib/​opsi/​config/​clients/"​
 + #backup path for clients
 + client_bak_dir="/​var/​lib/​opsi/​config/​clients/​archiv/"​
 + #create backup folder if not exist
 + if [ ! -d "​$client_bak_dir"​ ]; then mkdir -p "​$client_bak_dir";​ fi
 +
 + # find all clients with product already installed and not set to setup
 + for c in $(grep -l "​${product} = installed:​none"​ "​${clientspath}"​*.ini 2>/​dev/​null);​ do
 + # print client names with product already installed, trim .ini extension
 + # print client name only - trim .ini extension, trim dir path
 + #echo ${c%.ini}
 + echo "​$(echo ${c%.ini} | xargs -n1 basename)"​
 + # Add number of clients and check later if results >0
 + updclient=$((updclient + 1))
 + done
 +
 + #If results found, begin interaction
 + if [ "​${updclient}"​ == "​0"​ ]; then
 + # message if search results is 0 
 + echo
 + echo "[ ${product} ] is not installed on any client."​
 + echo
 + else
 + echo
 + echo "[ ${updclient} ] clients found."​
 + echo
 + # Now ask if setup action should be set.
 +
 + ###
 + read -n1 -p  " Set SETUP action for [ ${product} ] on listed clients ? : [ y=Yes | n=No ]: [Default: y ] "
 + case "​${REPLY}"​ in
 + # use last path accepted
 + ""​ | "​y"​ | "​Y"​ | "​yes"​ | "​Yes"​)
 + # yes I want to set product for setup on clients
 + #echo
 + echo "​Setting SETUP action.."​
 + echo
 + for c in $(grep -l "​${product} = installed:​none"​ "​${clientspath}"​*.ini 2>/​dev/​null);​ do
 + # print client names with product already installed, trim .ini extension
 + #echo ${c%.ini}
 + # Add number of clients and check later if results >0
 + #​updclient=$((updclient + 1))
 +
 + # backup client files first
 + #cp -f "​${c}"​ "​${c}_$NOW.bak"​
 + # backup original file to backup dir, trimming source file name only adding date.bak as suffix
 + cp -f "​${c}"​ "​${client_bak_dir}$(echo ${c} | xargs -n1 basename)_$NOW.bak"​
 + # begin replacing string into tmp file
 + cat "​${c}"​ | sed '​s/'​${product}'​ = installed:​none/'​${product}'​ = installed:​setup/​g'​ >"​${c}"​.tmp
 + # replace tmp file with original file
 + mv -f "​${c}"​.tmp "​${c}"​
 + # set file rights
 + chown opsiconfd:​opsifileadmins "​${c}"​
 + chmod 660 "​${c}"​
 +
 + #verify edit
 + if grep -q "​${product} = installed:​setup"​ "​${c}"​
 + then
 +  # code if found
 +  echo "OK: SETUP action set for: $(echo ${c} | xargs -n1 basename)"​
 + else
 +  # code if not found
 +  error "SETUP action NOT set for: $(echo ${c} | xargs -n1 basename)"​
 + fi
 + done
 + ;;
 + # skip file, any other entry
 + *)
 + # Any other answer is now
 + # No changes
 + echo "No clients have been modified."​
 + echo
 + ;;
 + esac
 +
 + fi
 +
 } }
  
Line 219: Line 374:
  cat "​$inst_dir""​$setup_file"​ | sed 's/Set \$ProductVersion\$ ​ = "'​$old_version'"/​Set \$ProductVersion\$ ​ = "'​$new_version'"/​g'​ >"​$inst_dir""​$setup_file"​.tmp  cat "​$inst_dir""​$setup_file"​ | sed 's/Set \$ProductVersion\$ ​ = "'​$old_version'"/​Set \$ProductVersion\$ ​ = "'​$new_version'"/​g'​ >"​$inst_dir""​$setup_file"​.tmp
  mv -f "​$inst_dir""​$setup_file"​.tmp "​$inst_dir""​$setup_file"​  mv -f "​$inst_dir""​$setup_file"​.tmp "​$inst_dir""​$setup_file"​
 + # set file rights
 + chown opsiconfd:​opsifileadmins "​$inst_dir""​$setup_file"​
 + chmod 660 "​$inst_dir""​$setup_file"​
   
  #verify edit   #verify edit
Line 283: Line 441:
  # verify change, #later  # verify change, #later
  # cat "​$product_dir""​$product_file_new"​ | grep version: '​$new_version'​  # cat "​$product_dir""​$product_file_new"​ | grep version: '​$new_version'​
 + # set file rights
 + chown opsiconfd:​opsifileadmins "​$product_dir""​$product_file_new"​
 + chmod 660 "​$product_dir""​$product_file_new"​
 +
  #### change file version in setup script  #### change file version in setup script
  f_Install  f_Install
 + ### update installed clients
 + f_UpdateClients
  ;;  ;;
  3) # change package version / sed ====> first match for version: only / first occurence  3) # change package version / sed ====> first match for version: only / first occurence
Line 291: Line 455:
  #cat "​$product_dir""​$product_file_new"​ | sed '​s/​version:​ '​$old_pkg_version'/​version:​ '​$new_pkg_version'/​g'​ > "​$product_dir""​$product_file_new"​.tmp  #cat "​$product_dir""​$product_file_new"​ | sed '​s/​version:​ '​$old_pkg_version'/​version:​ '​$new_pkg_version'/​g'​ > "​$product_dir""​$product_file_new"​.tmp
  mv -f "​$product_dir""​$product_file_new"​.tmp "​$product_dir""​$product_file_new"​  mv -f "​$product_dir""​$product_file_new"​.tmp "​$product_dir""​$product_file_new"​
 + # set file rights
 + chown opsiconfd:​opsifileadmins "​$product_dir""​$product_file_new"​
 + chmod 660 "​$product_dir""​$product_file_new"​
  ;;  ;;
  4) #change prod. version first, then pkg version  4) #change prod. version first, then pkg version
Line 296: Line 463:
  cat "​$product_dir""​$product_file_new"​.tmp | awk '/​version:​ '​$old_pkg_version'/​{if (M==""​){sub("​version:​ '​$old_pkg_version'","​version:​ '​$new_pkg_version'"​);​M=1}}{print}'​ >"​$product_dir""​$product_file_new"​  cat "​$product_dir""​$product_file_new"​.tmp | awk '/​version:​ '​$old_pkg_version'/​{if (M==""​){sub("​version:​ '​$old_pkg_version'","​version:​ '​$new_pkg_version'"​);​M=1}}{print}'​ >"​$product_dir""​$product_file_new"​
  #mv -f "​$product_dir""​$product_file_new"​.tmp2 "​$product_dir""​$product_file_new"​  #mv -f "​$product_dir""​$product_file_new"​.tmp2 "​$product_dir""​$product_file_new"​
 + # set file rights
 + chown opsiconfd:​opsifileadmins "​$product_dir""​$product_file_new"​
 + chmod 660 "​$product_dir""​$product_file_new"​
  #### change file version in setup script  #### change file version in setup script
  f_Install  f_Install
 + ### update installed clients
 + f_UpdateClients
  ;;  ;;
  esac  esac
Line 307: Line 479:
  #restore backed up file  #restore backed up file
  mv -f $depot_bak_file $depot  mv -f $depot_bak_file $depot
 + # set file rights
 + chown opsiconfd:​opsifileadmins $depot
 + chmod 660 $depot
  fi  fi
 } }
Line 398: Line 573:
  # replace version info and retain original file structure  # replace version info and retain original file structure
  sed '​s/​\'​$v'/​\'​$n'/​g'​ $depot_tmp1 | sed '​s/;;/;/​g'​ | tr ';'​ '​\n'​ >$depot  sed '​s/​\'​$v'/​\'​$n'/​g'​ $depot_tmp1 | sed '​s/;;/;/​g'​ | tr ';'​ '​\n'​ >$depot
 + # set file rights
 + chown opsiconfd:​opsifileadmins $depot
 + chmod 660 $depot
  f_Product  f_Product
  ;;  ;;
Line 404: Line 582:
  cp -f $depot $depot_bak_file  cp -f $depot $depot_bak_file
  sed '​s/​\'​$v'/​\'​$p'/​g'​ $depot_tmp1 | sed '​s/;;/;/​g'​ | tr ';'​ '​\n'​ >$depot  sed '​s/​\'​$v'/​\'​$p'/​g'​ $depot_tmp1 | sed '​s/;;/;/​g'​ | tr ';'​ '​\n'​ >$depot
 + # set file rights
 + chown opsiconfd:​opsifileadmins $depot
 + chmod 660 $depot
  # change further files  # change further files
  f_Product  f_Product
Line 413: Line 594:
  # replace version info and retain original file structure  # replace version info and retain original file structure
  sed '​s/​\'​$v'/​\'​$p'/​g'​ $depot_tmp1 | sed '​s/;;/;/​g'​ | tr ';'​ '​\n'​ >$depot  sed '​s/​\'​$v'/​\'​$p'/​g'​ $depot_tmp1 | sed '​s/;;/;/​g'​ | tr ';'​ '​\n'​ >$depot
 + # set file rights
 + chown opsiconfd:​opsifileadmins $depot
 + chmod 660 $depot
  # change further files  # change further files
  f_Product  f_Product
Line 438: Line 622:
 #read -p ""​ #read -p ""​
 #exit  #exit 
- 
  
  
  
 </​code>​ </​code>​

QR Code
QR Code userspace:opsi-info (generated for current page)