userspace:opsi-info
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| userspace:opsi-info [2013/09/03 18:39] – created islam | userspace:opsi-info [2021/08/23 10:37] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| 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: | ||
| + | < | ||
| + | replacing the version number can be useful if you use the version as parameter in your setup script, for example | ||
| + | < | ||
| + | |||
| + | This means, updating Firefox would just require you to place the new setup exe file inside " | ||
| + | then setting the the new version with opsi-info.sh | ||
| + | |||
| + | - optionally set " | ||
| + | |||
| Download Link here: http:// | Download Link here: http:// | ||
| + | |||
| + | ############################ | ||
| + | |||
| + | opsi-info : view / edit opsi package information | ||
| + | |||
| + | usage: | ||
| + | |||
| + | opsi-info [arguments] | ||
| + | |||
| + | arguments: | ||
| + | |||
| + | -h : | ||
| + | |||
| + | -prod [product-id] : | ||
| + | |||
| + | -ver [decimal] : | ||
| + | |||
| + | -pver [integer] : | ||
| + | |||
| + | |||
| + | example: <code Bash> | ||
| + | |||
| + | sets new version " | ||
| + | |||
| + | |||
| + | ############################ | ||
| + | |||
| + | **opsi-info.sh** | ||
| + | |||
| + | <code Bash> | ||
| + | #!/bin/bash | ||
| + | |||
| + | ############### | ||
| + | # opsi-info | ||
| + | # read / edit opsi-package info | ||
| + | # By Islam Adel | ||
| + | |||
| + | ############### | ||
| + | |||
| + | #usage: opsi-info -h (help file) | ||
| + | |||
| + | ############### | ||
| + | #change log: | ||
| + | # 2013-09-02 view, | ||
| + | # 2013-09-03 view, | ||
| + | # 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 " | ||
| + | |||
| + | # General-Info to find installed product on client: | ||
| + | |||
| + | # installed info: | ||
| + | # in / | ||
| + | # | ||
| + | # function: | ||
| + | # Find string " | ||
| + | # | ||
| + | # Set for setup | ||
| + | # change from " | ||
| + | # to: " | ||
| + | |||
| + | # | ||
| + | #target: - read/edit opsi package information | ||
| + | # - list all package-ids | ||
| + | # - error verification / reporting | ||
| + | # - read / edit package version | ||
| + | # - backup all relevant files | ||
| + | # - fix conflict if product version = package version | ||
| + | |||
| + | #to-do: auto detect depot files | ||
| + | |||
| + | #input: arguments 1. option, 2. product_id, 3. value | ||
| + | |||
| + | # option: -ver (product version) | ||
| + | |||
| + | |||
| + | ###################### | ||
| + | # global variables | ||
| + | ver=" | ||
| + | #set loop delimiter as " | ||
| + | IFS=$' | ||
| + | |||
| + | # | ||
| + | NOW=" | ||
| + | |||
| + | ###################### | ||
| + | # user variables | ||
| + | # opsi=" | ||
| + | # opsi=" | ||
| + | opsi=" | ||
| + | |||
| + | ###################### | ||
| + | #functions | ||
| + | |||
| + | #error message | ||
| + | error() { | ||
| + | echo " | ||
| + | echo | ||
| + | # echo "use -h argument for help" | ||
| + | # echo | ||
| + | #exit | ||
| + | } | ||
| + | |||
| + | #display hel | ||
| + | f_printUsage() { | ||
| + | echo " | ||
| + | echo | ||
| + | echo " | ||
| + | echo | ||
| + | echo " | ||
| + | echo | ||
| + | echo " | ||
| + | echo | ||
| + | echo " | ||
| + | echo "-prod [product-id] : | ||
| + | #echo "-ver | --version : | ||
| + | echo "-ver [decimal] : | ||
| + | #echo "-pver | --pkgversion : | ||
| + | echo "-pver [integer] : | ||
| + | echo | ||
| + | echo | ||
| + | echo " | ||
| + | echo " | ||
| + | echo | ||
| + | exit | ||
| + | } | ||
| + | |||
| + | # read all passed arguments | ||
| + | f_GetArgs() { | ||
| + | |||
| + | #echo "all args=[${@}]" | ||
| + | #echo " | ||
| + | #echo " | ||
| + | #echo " | ||
| + | #echo " | ||
| + | #echo " | ||
| + | |||
| + | i=0 | ||
| + | argv=() | ||
| + | for arg in " | ||
| + | argv[$i]=" | ||
| + | i=$((i + 1)) | ||
| + | #debug# echo $i=$arg | ||
| + | done | ||
| + | |||
| + | # Handle OPTIONS and build directory array | ||
| + | |||
| + | # | ||
| + | # | ||
| + | #run_jobs=0 | ||
| + | # | ||
| + | # | ||
| + | |||
| + | i=0 | ||
| + | dir_index=0 | ||
| + | while test $i -lt $# ; do | ||
| + | |||
| + | arg=" | ||
| + | |||
| + | case " | ||
| + | |||
| + | # | ||
| + | |||
| + | -h|--help) | ||
| + | |||
| + | #-j|--jobs) i=$((i + 1)); n_threads=${argv[$i]};; | ||
| + | |||
| + | # | ||
| + | |||
| + | # | ||
| + | #verify decimal value before setting | ||
| + | --version|-ver) i=$((i + 1)); if [ " | ||
| + | #verify integer value before setting | ||
| + | --pkgversion|-pver) i=$((i + 1)); if [ " | ||
| + | | ||
| + | --product|-prod) i=$((i + 1)); product=" | ||
| + | |||
| + | *) if ! test -d " | ||
| + | error " | ||
| + | else | ||
| + | source_dirs[$dir_index]=" | ||
| + | dir_index=$((dir_index + 1)) | ||
| + | fi;; | ||
| + | |||
| + | esac | ||
| + | |||
| + | i=$((i + 1)) | ||
| + | |||
| + | done | ||
| + | |||
| + | } | ||
| + | |||
| + | # input file | ||
| + | f_Depot() { | ||
| + | #autodetect depot file | ||
| + | if [ " | ||
| + | #local_test | ||
| + | if [ " | ||
| + | |||
| + | dep=0 | ||
| + | for d in $(ls " | ||
| + | # add depot number | ||
| + | dep=$((dep + 1)) | ||
| + | dep_[$i]=" | ||
| + | #echo " | ||
| + | #prompt to choose depot number if multiple found | ||
| + | depot_name=" | ||
| + | depot=" | ||
| + | #echo $depot_name | ||
| + | #echo $depot | ||
| + | if [ " | ||
| + | echo "[ $dep ] depots have been found" | ||
| + | echo " | ||
| + | #add this feature later, to choose depot number | ||
| + | fi | ||
| + | done | ||
| + | |||
| + | if [ ! " | ||
| + | |||
| + | depot_bak_dir=" | ||
| + | depot_bak_file=" | ||
| + | #create backup folder if not exist | ||
| + | if [ ! -d " | ||
| + | |||
| + | #tmp files | ||
| + | depot_tmp1=" | ||
| + | # remove existing tmp file | ||
| + | if [ -f $depot_tmp1 ]; then rm -f $depot_tmp1; | ||
| + | depot_tmp2=" | ||
| + | if [ -f $depot_tmp2 ]; then rm -f $depot_tmp2; | ||
| + | } | ||
| + | |||
| + | #find clients with installed product and set for setup | ||
| + | f_UpdateClients() { | ||
| + | # Find string " | ||
| + | |||
| + | # first find clients, display names and prompt | ||
| + | # use: grep -l " | ||
| + | |||
| + | echo | ||
| + | echo " | ||
| + | echo | ||
| + | |||
| + | # Set number of clients found with product already installed | ||
| + | updclient=0 | ||
| + | #Path of clients Folder | ||
| + | clientspath="/ | ||
| + | #backup path for clients | ||
| + | client_bak_dir="/ | ||
| + | #create backup folder if not exist | ||
| + | if [ ! -d " | ||
| + | |||
| + | # find all clients with product already installed and not set to setup | ||
| + | for c in $(grep -l " | ||
| + | # print client names with product already installed, trim .ini extension | ||
| + | # print client name only - trim .ini extension, trim dir path | ||
| + | #echo ${c%.ini} | ||
| + | echo " | ||
| + | # Add number of clients and check later if results >0 | ||
| + | updclient=$((updclient + 1)) | ||
| + | done | ||
| + | |||
| + | #If results found, begin interaction | ||
| + | if [ " | ||
| + | # 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 " | ||
| + | # use last path accepted | ||
| + | "" | ||
| + | # yes I want to set product for setup on clients | ||
| + | #echo | ||
| + | echo " | ||
| + | echo | ||
| + | for c in $(grep -l " | ||
| + | # print client names with product already installed, trim .ini extension | ||
| + | #echo ${c%.ini} | ||
| + | # Add number of clients and check later if results >0 | ||
| + | # | ||
| + | |||
| + | # backup client files first | ||
| + | #cp -f " | ||
| + | # backup original file to backup dir, trimming source file name only adding date.bak as suffix | ||
| + | cp -f " | ||
| + | # begin replacing string into tmp file | ||
| + | cat " | ||
| + | # replace tmp file with original file | ||
| + | mv -f " | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 " | ||
| + | |||
| + | #verify edit | ||
| + | if grep -q " | ||
| + | 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 | ||
| + | |||
| + | } | ||
| + | |||
| + | #version info in install script | ||
| + | f_Install() { | ||
| + | if [ " | ||
| + | # | ||
| + | if [ " | ||
| + | setup_file=" | ||
| + | |||
| + | setup_bak_dir=" | ||
| + | setup_bak_file=" | ||
| + | #create backup folder if not exist | ||
| + | |||
| + | if [ ! -d " | ||
| + | |||
| + | #Set $ProductVersion$ | ||
| + | if [ -f " | ||
| + | #echo " | ||
| + | #change version info in setup-script | ||
| + | #echo " | ||
| + | #cat " | ||
| + | #echo " | ||
| + | #backup | ||
| + | cp -f " | ||
| + | cat " | ||
| + | mv -f " | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 " | ||
| + | |||
| + | #verify edit | ||
| + | if grep -q "Set \$ProductVersion\$ | ||
| + | then | ||
| + | # code if found | ||
| + | echo "OK: ProductVersion replaced in $setup_file" | ||
| + | else | ||
| + | # code if not found | ||
| + | error " | ||
| + | fi | ||
| + | |||
| + | |||
| + | fi | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | # products info | ||
| + | f_Product() { | ||
| + | |||
| + | if [ " | ||
| + | #local test | ||
| + | if [ " | ||
| + | |||
| + | #echo " | ||
| + | #echo " | ||
| + | #read pkg_ver | ||
| + | #set old packageversion if new is not defined | ||
| + | if [ ! " | ||
| + | #set old product version if new is not defined | ||
| + | if [ ! " | ||
| + | |||
| + | # | ||
| + | #identify type .localboot or .netboot #later feature | ||
| + | product_file_old=" | ||
| + | product_file_new=" | ||
| + | # echo | ||
| + | # echo old_version=" | ||
| + | # echo new_version=" | ||
| + | # echo old_pkg_version=" | ||
| + | # echo new_pkg_version=" | ||
| + | |||
| + | product_bak_dir=" | ||
| + | product_bak_file=" | ||
| + | #create backup folder if not exist | ||
| + | if [ ! -d $product_bak_dir ]; then mkdir -p $product_bak_dir; | ||
| + | |||
| + | |||
| + | #check if product file exists | ||
| + | if [ -f " | ||
| + | #### rename product file | ||
| + | #backup file? #later | ||
| + | cp -f " | ||
| + | |||
| + | mv -f " | ||
| + | #check if renamed file exists? # | ||
| + | |||
| + | #### change file version in content | ||
| + | case " | ||
| + | 1) # change product version | ||
| + | cat " | ||
| + | mv -f " | ||
| + | # verify change, #later | ||
| + | # cat " | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 " | ||
| + | |||
| + | #### change file version in setup script | ||
| + | f_Install | ||
| + | ### update installed clients | ||
| + | f_UpdateClients | ||
| + | ;; | ||
| + | 3) # change package version / sed ====> first match for version: only / first occurence | ||
| + | cat " | ||
| + | # all occurences | ||
| + | #cat " | ||
| + | mv -f " | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 " | ||
| + | ;; | ||
| + | 4) #change prod. version first, then pkg version | ||
| + | cat " | ||
| + | cat " | ||
| + | #mv -f " | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 " | ||
| + | #### change file version in setup script | ||
| + | f_Install | ||
| + | ### update installed clients | ||
| + | f_UpdateClients | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | if [ -f " | ||
| + | |||
| + | else | ||
| + | error " | ||
| + | #restore backed up file | ||
| + | mv -f $depot_bak_file $depot | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 $depot | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | |||
| + | ###################### | ||
| + | #script start | ||
| + | echo | ||
| + | echo "#################################" | ||
| + | echo "# | ||
| + | echo "# opsi-info version: $ver #" | ||
| + | echo "# | ||
| + | echo "# use -h for help #" | ||
| + | echo "# | ||
| + | echo "#################################" | ||
| + | echo | ||
| + | |||
| + | # read arguments | ||
| + | f_GetArgs $@ | ||
| + | |||
| + | f_Depot | ||
| + | #display values | ||
| + | #echo "using depot file :" | ||
| + | #echo " | ||
| + | #echo ver = $new_version | ||
| + | #echo product = $product | ||
| + | |||
| + | #read depot file | ||
| + | |||
| + | # sed '/ | ||
| + | # replace line starting with " | ||
| + | # replace new lines by ";" | ||
| + | # replace " | ||
| + | # replace ";;" | ||
| + | # replace ";" | ||
| + | #cat $depot | sed '/ | ||
| + | |||
| + | #create tmp file and change structure for search | ||
| + | cat $depot | sed '/ | ||
| + | |||
| + | # find line with product name and replace string (version value) till ";" | ||
| + | found=0 | ||
| + | change=0 | ||
| + | for v in $(cat $depot_tmp1 | grep " | ||
| + | found=$((found + 1)) | ||
| + | if [ " | ||
| + | # must find 1 instance only - replace only one product | ||
| + | # read current version | ||
| + | #last working: old_version=$(echo $v | sed ' | ||
| + | old_version=$(echo " | ||
| + | old_pkg_version=$(echo " | ||
| + | |||
| + | # echo old_version=" | ||
| + | # echo new_version=" | ||
| + | # echo old_pkg_version=" | ||
| + | # echo new_pkg_version=" | ||
| + | # echo v=" | ||
| + | |||
| + | #edit only if new_version is defined | ||
| + | if [ " | ||
| + | change=$((change + 1)) | ||
| + | # replace old version with new, retain whole string | ||
| + | n=$(echo " | ||
| + | #echo n=" | ||
| + | #exit | ||
| + | echo " | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | |||
| + | #edit only if new_pkg_version is defined | ||
| + | if [ " | ||
| + | change=$((change + 3)) | ||
| + | # replace old version with new, retain whole string | ||
| + | p=$(echo " | ||
| + | echo " | ||
| + | else | ||
| + | echo " | ||
| + | fi | ||
| + | else | ||
| + | error "[ $found ] matches found for: $product " | ||
| + | fi | ||
| + | done | ||
| + | |||
| + | #case for changes | ||
| + | case " | ||
| + | # 0) echo "# nothing to change";; | ||
| + | 1) #echo "# change version only" | ||
| + | # backup original depot file | ||
| + | cp -f $depot $depot_bak_file | ||
| + | # replace version info and retain original file structure | ||
| + | sed ' | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 $depot | ||
| + | f_Product | ||
| + | ;; | ||
| + | 3) #echo "# change pkg version only" | ||
| + | # backup original depot file | ||
| + | cp -f $depot $depot_bak_file | ||
| + | sed ' | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 $depot | ||
| + | # change further files | ||
| + | f_Product | ||
| + | ;; | ||
| + | 4) #echo "# change pver + ver" | ||
| + | p=$(echo " | ||
| + | # backup original depot file | ||
| + | cp -f $depot $depot_bak_file | ||
| + | # replace version info and retain original file structure | ||
| + | sed ' | ||
| + | # set file rights | ||
| + | chown opsiconfd: | ||
| + | chmod 660 $depot | ||
| + | # change further files | ||
| + | f_Product | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # errors only if product / arguments specified | ||
| + | #echo $i | ||
| + | if [ " | ||
| + | if [ " | ||
| + | else | ||
| + | error "no arguments specified" | ||
| + | echo "use -h argument for help" | ||
| + | fi | ||
| + | |||
| + | # file end | ||
| + | echo | ||
| + | echo "###############################" | ||
| + | echo | ||
| + | echo " | ||
| + | # remove existing tmp file | ||
| + | if [ -f $depot_tmp1 ]; then rm -f $depot_tmp1; | ||
| + | if [ -f $depot_tmp2 ]; then rm -f $depot_tmp2; | ||
| + | echo | ||
| + | #read -p "" | ||
| + | #exit | ||
| + | |||
| + | </ | ||
userspace/opsi-info.1378226375.txt.gz · Last modified: (external edit)
