This shows you the differences between two versions of the page.
userspace:opsi_productadd [2012/10/17 16:25] sschu |
userspace:opsi_productadd [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | This is a shell-script setting a package to be set up, if another package is already installed\\ | ||
- | I use this script to either set " | ||
- | or to install a software like adobeflash, if a host has already Mozilla Firefox | ||
- | |||
- | ==== opsi-productadd ==== | ||
- | < | ||
- | #!/bin/bash | ||
- | # insert proper values for your opsi-server here | ||
- | # Feel free to modify, as long as you let us participate on your changes... | ||
- | # Licensed under GPL | ||
- | # Copyright Sven Schumacher, 2011 | ||
- | # NO WARRANTY | ||
- | |||
- | defaultuser=" | ||
- | BASENAME=`basename $0` | ||
- | OPSIDEPOT=`cat / | ||
- | # | ||
- | CUT_OF_DOMAIN=`dnsdomainname` | ||
- | # if backend file is used for softwareaudits, | ||
- | OPSI_SOFTWARE_INVENTORY_DIR="/ | ||
- | # if backend mysql is used for softwareaudits nothing needs to be changed | ||
- | |||
- | # NO MORE CHANGES BELOW THIS LINE NEEDED | ||
- | |||
- | function usageinfo { | ||
- | echo " | ||
- | |||
- | $BASENAME sets for each found host which has PRODUCT installed the PRODUCTID to be installed | ||
- | Usage (e.g.): | ||
- | $BASENAME Firefox adobeflash | ||
- | |||
- | Options: | ||
- | -q|--quiet | ||
- | -h prints this help | ||
- | --host | ||
- | -u USER the user to be used (default: admin) | ||
- | -p PASSWORD | ||
- | Where | ||
- | PRODUCT | ||
- | PRODUCTID | ||
- | " | ||
- | } | ||
- | user=$defaultuser; | ||
- | #use getopt to parse options | ||
- | TEMP=`getopt -o hqp:u: --long help, | ||
- | -n ' | ||
- | |||
- | if [ $? != 0 ] ; then usageinfo ; exit 1 ; fi | ||
- | |||
- | # Note the quotes around `$TEMP': | ||
- | eval set -- " | ||
- | quiet=" | ||
- | while true ; do | ||
- | case " | ||
- | -q|--quiet) | ||
- | quiet=" | ||
- | shift; | ||
- | ;; | ||
- | -u|--user) | ||
- | user=$2; | ||
- | shift 2; | ||
- | ;; | ||
- | --host) | ||
- | host=$2; | ||
- | shift 2; | ||
- | ;; | ||
- | -p|--password) | ||
- | password=$2; | ||
- | shift 2; | ||
- | ;; | ||
- | -h|--help) | ||
- | usageinfo; | ||
- | shift; | ||
- | exit 1; | ||
- | ;; | ||
- | --) shift; break;; | ||
- | *) echo "We never should get here. Fatal error. AAAARRGS"; | ||
- | esac | ||
- | done; | ||
- | if [ $# != 2 ]; then | ||
- | echo " | ||
- | usageinfo | ||
- | exit 1; | ||
- | fi | ||
- | #if you don't want to enter the password in commandline, | ||
- | if [ -z " | ||
- | read -s -p "Enter password for user $user (will not be displayed):" | ||
- | echo | ||
- | password=$REPLY | ||
- | fi | ||
- | product=$1; | ||
- | productid=$2; | ||
- | |||
- | cd $OPSI_SOFTWARE_INVENTORY_DIR | ||
- | if [ ! -d " | ||
- | echo "No such package: $productid"; | ||
- | exit 1; | ||
- | fi | ||
- | if [ -z " | ||
- | # to be replaced by mysql query | ||
- | # use the following line if software-audit has backend " | ||
- | hostlist=`(mysql -N --password=opsi -u opsi opsi << | ||
- | SELECT clientid FROM SOFTWARE_CONFIG WHERE name LIKE " | ||
- | -ENDE | ||
- | )|sed " s/ | ||
- | # if your software-audit has backend file use this line instead | ||
- | # hostlist=`fgrep -r $product *.sw |awk -F: '{ print $1; }' | ||
- | else | ||
- | hostlist=$host | ||
- | fi | ||
- | for I in $hostlist; do | ||
- | if [[ $quiet = " | ||
- | echo " | ||
- | fi | ||
- | opsi-admin -u $user -p $password method setProductActionRequest $productid $I.$CUT_OF_DOMAIN setup; | ||
- | done | ||
- | </ | ||
- | |||