|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2012 Citrix Systems, Inc. Licensed under the |
| 3 | +# Apache License, Version 2.0 (the "License"); you may not use this |
| 4 | +# file except in compliance with the License. Citrix Systems, Inc. |
| 5 | +# reserves all rights not expressly granted by the License. |
| 6 | +# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +# |
| 13 | +# Automatically generated by addcopyright.py at 04/03/2012 |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +# Usage |
| 20 | +# save_password -v <user VM IP> -p <password> |
| 21 | + |
| 22 | +source /root/func.sh |
| 23 | + |
| 24 | +lock="passwdlock" |
| 25 | +#default timeout value is 30 mins as password reset command is not synchronized on agent side any more, |
| 26 | +#and multiple commands can be sent to the same VR at a time |
| 27 | +locked=$(getLockFile $lock 1800) |
| 28 | +if [ "$locked" != "1" ] |
| 29 | +then |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +PASSWD_FILE=/var/cache/cloud/passwords |
| 34 | + |
| 35 | +while getopts 'v:p:' OPTION |
| 36 | +do |
| 37 | + case $OPTION in |
| 38 | + v) VM_IP="$OPTARG" |
| 39 | + ;; |
| 40 | + p) |
| 41 | + ENCODEDPASSWORD="$OPTARG" |
| 42 | + PASSWORD=$(echo $ENCODEDPASSWORD | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]') |
| 43 | + ;; |
| 44 | + ?) echo "Incorrect usage" |
| 45 | + unlock_exit 1 $lock $locked |
| 46 | + ;; |
| 47 | + esac |
| 48 | +done |
| 49 | + |
| 50 | +[ -f $PASSWD_FILE ] || touch $PASSWD_FILE |
| 51 | + |
| 52 | +sed -i /$VM_IP/d $PASSWD_FILE |
| 53 | + |
| 54 | +ps aux | grep serve_password.sh |grep -v grep 2>&1 > /dev/null |
| 55 | +if [ $? -eq 0 ] |
| 56 | +then |
| 57 | + echo "$VM_IP=$PASSWORD" >> $PASSWD_FILE |
| 58 | +else |
| 59 | + echo "$VM_IP=saved_password" >> $PASSWD_FILE |
| 60 | +fi |
| 61 | + |
| 62 | +unlock_exit $? $lock $locked |
0 commit comments