- Timestamp:
- 07/28/09 18:23:40 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/linuxmuster-linbo/branches/testing/linbo/patch_registry.sh
r509 r510 20 20 # this generates a LOT of debugging messages 21 21 DEBUG="-v" 22 file="" 23 tmplog="/tmp/output" 24 tmpctrls="/tmp/controlsets" 25 tmptest="/tmp/keytest" 22 hive="" 23 logfile="/tmp/output" 26 24 27 25 leftchop(){ … … 45 43 } 46 44 47 do_reg() {45 exec_command() { 48 46 local cmd="$1" 49 local logfile="$2" 50 [ -z "$logfile" ] && logfile="$tmplog" 51 chntpw $DEBUG -e "$file" >> $logfile <<. 47 chntpw $DEBUG -e "$hive" >> $logfile <<. 52 48 $(echo -e "$cmd") 53 49 . … … 55 51 56 52 test_key() { 57 local path="$1" 58 local key="$2" 59 local RC=0 60 local cmd="ls ${path}\nq\ny\n" 61 [ -e "$tmptest" ] && rm $tmptest 62 do_reg "$cmd" "$tmptest" 63 grep -q "<${key}>" $tmptest || RC=1 53 local key="$1" 54 local RC=1 55 echo -e "cd $key\nq\ny\n" | chntpw -e "$hive" | grep -q "not found\!" || RC="0" 64 56 return $RC 65 57 } 66 58 67 59 create_key() { 68 local path="$1" 69 local key="$2" 70 local cmd="cd ${path}\nnk ${key}\nq\ny\n" 71 do_reg "$cmd" 72 } 73 74 create_cmd() { 60 local fpath="$1" 61 local tpath="" 62 local bpath="" 63 local cmd="" 64 local i="" 65 local OIFS="$IFS" 66 IFS="\\" 67 for i in $fpath; do 68 bpath="$tpath" 69 if [ -n "$tpath" ]; then tpath="${tpath}\\${i}"; else tpath="$i"; fi 70 if ! test_key "$tpath"; then 71 if [ "$bpath" = "" ]; then 72 cmd="nk ${i}\nq\ny\n" 73 else 74 cmd="cd ${bpath}\nnk ${i}\nq\ny\n" 75 fi 76 exec_command "$cmd" 77 fi 78 done 79 IFS="$OIFS" 80 } 81 82 create_keypath() { 75 83 local key="$1" 76 84 local ctrlset="$2" … … 80 88 ##### 81 89 82 [ -n "$DEBUG" ] && echo " 5 key=$key" | tee -a $tmplog90 [ -n "$DEBUG" ] && echo " 5 key=$key" | tee -a $logfile 83 91 # remove right end and replace it with a backslash 84 92 key=`rightchopend "$key"` 85 93 fullpath="$key" 86 key="$key\\" 87 88 [ -n "$DEBUG" ] && echo "6 fullpath=$fullpath" | tee -a $tmplog 89 90 currentkey=`leftget "$key"` 91 [ -n "$DEBUG" ] && echo "7 currentkey=$currentkey" | tee -a $tmplog 92 93 key=`leftchop "$key"` 94 [ -n "$DEBUG" ] && echo "8 key=$key" | tee -a $tmplog 95 96 base_path="" 97 while [ "$currentkey" != "" ]; do 98 99 [ -z "$base_path" ] && base_path="." 100 101 [ -n "$DEBUG" ] && echo "9 base_path=$base_path" | tee -a $tmplog 94 95 [ -n "$DEBUG" ] && echo " 6 fullpath=$fullpath" | tee -a $logfile 102 96 103 97 # tschmitt: check if currentkey exists in registry, if not create it 104 if ! test_key "$ base_path" "$currentkey"; then105 if [ -n "$ctrlset" ]; then106 # don't create new keys in supplemental controlsets107 [ -n "$DEBUG" ] && echo "### Skipping creation of $currentkey in $ctrlset!" | tee -a $tmplog108 return 1109 fi110 [ -n "$DEBUG" ] && echo "### Creating key $ currentkey" | tee -a $tmplog111 create_key "$ base_path" "$currentkey"98 if ! test_key "$fullpath"; then 99 if [ -n "$ctrlset" ]; then 100 # don't create new keys in supplemental controlsets 101 [ -n "$DEBUG" ] && echo "### Skipping $fullpath" | tee -a $logfile 102 return 1 103 fi 104 [ -n "$DEBUG" ] && echo "### Creating key $fullpath" | tee -a $logfile 105 create_key "$fullpath" 112 106 fi 113 114 if [ "$base_path" = "." ]; then 115 base_path="${currentkey}" 116 else 117 base_path="${base_path}\\${currentkey}" 118 fi 119 120 currentkey=`leftget "$key"` 121 [ -n "$DEBUG" ] && echo "10 currentkey=$currentkey" | tee -a $tmplog 122 123 key=`leftchop "$key"` 124 [ -n "$DEBUG" ] && echo "11 key=$key" | tee -a $tmplog 125 126 done 127 128 base_command="cd ${fullpath}\n" 129 } 130 131 create_val() { 107 } 108 109 # returns success if old value is equal to new value 110 test_value(){ 111 local fpath="$1" 112 local newval="$2" 113 local curval="$(echo -e "cat ${fpath}\nq\ny\n" | chntpw -e "$hive" | grep -Fi "$newval")" 114 if [ -n "$curval" ]; then 115 [ -n "$DEBUG" ] && echo "### $parameter is already set to $curval. Skipping." | tee -a $logfile 116 return 0 117 else 118 [ -n "$DEBUG" ] && echo "### $parameter is not equal to $newval. Patching." | tee -a $logfile 119 return 1 120 fi 121 } 122 123 create_command() { 132 124 #### 133 125 # parse value changes 134 126 #### 135 [ -n "$DEBUG" ] && echo " 12 change=$change" | tee -a $tmplog127 [ -n "$DEBUG" ] && echo " 7 change=$change" | tee -a $logfile 136 128 137 129 if [ "$change" = "" ]; then … … 139 131 fi 140 132 141 command=" ${base_command}"142 [ -n "$DEBUG" ] && echo " 13 command=$command" | tee -a $tmplog133 command="cd ${fullpath}\n" 134 [ -n "$DEBUG" ] && echo " 8 command=$command" | tee -a $logfile 143 135 144 136 parameter=`leftgetvalue "$change"` 145 [ -n "$DEBUG" ] && echo " 14 parameter=$parameter" | tee -a $tmplog137 [ -n "$DEBUG" ] && echo " 9 parameter=$parameter" | tee -a $logfile 146 138 147 139 parameter="$(echo "$parameter" | sed 's,\",,g')" 148 [ -n "$DEBUG" ] && echo "1 5 parameter=$parameter" | tee -a $tmplog140 [ -n "$DEBUG" ] && echo "10 parameter=$parameter" | tee -a $logfile 149 141 150 142 value=`rightgetvalue "$change"` 151 [ -n "$DEBUG" ] && echo "1 6 value=$value" | tee -a $tmplog143 [ -n "$DEBUG" ] && echo "11 value=$value" | tee -a $logfile 152 144 153 145 value="$(echo "$value" | sed 's,\",,g')" 154 [ -n "$DEBUG" ] && echo "1 7 value=$value" | tee -a $tmplog155 146 [ -n "$DEBUG" ] && echo "12 value=$value" | tee -a $logfile 147 156 148 value="$(echo "$value" | sed 's,$,,g')" 157 [ -n "$DEBUG" ] && echo "1 8 value=$value" | tee -a $tmplog149 [ -n "$DEBUG" ] && echo "13 value=$value" | tee -a $logfile 158 150 159 151 # our standard type for strings is REG_SZ … … 166 158 esac 167 159 if [ -n "$DEBUG" ]; then 168 echo "19 type=$type" | tee -a $tmplog 169 echo "20 value=$value" | tee -a $tmplog 160 echo "14 type=$type" | tee -a $logfile 161 echo "15 value=$value" | tee -a $logfile 162 fi 163 164 # return if value is already set -> nothing to do 165 if [ -n "$value" ]; then 166 test_value "${fullpath}\\${parameter}" "$value" && return 1 170 167 fi 171 168 172 169 command="${command}dv ${parameter}\n" 170 [ -n "$DEBUG" ] && echo "16 command=$command" | tee -a $logfile 171 173 172 command="${command}nv ${type} ${parameter}\n" 174 [ -n "$DEBUG" ] && echo " 21 command=$command" | tee -a $tmplog173 [ -n "$DEBUG" ] && echo "17 command=$command" | tee -a $logfile 175 174 176 175 command="${command}ed ${parameter}\n" 177 [ -n "$DEBUG" ] && echo "22 command=$command" | tee -a $tmplog 178 176 [ -n "$DEBUG" ] && echo "18 command=$command" | tee -a $logfile 177 178 # out final command 179 179 command="${command}$value\nq\ny\n" 180 [ -n "$DEBUG" ] && echo "23 command=$command" | tee -a $tmplog 181 182 # out final command 183 [ -n "$DEBUG" ] && echo "24 final command=$command" | tee -a $tmplog 180 [ -n "$DEBUG" ] && echo "19 final command=$command" | tee -a $logfile 184 181 } 185 182 186 183 while read -r key; do 187 [ -n "$DEBUG" ] && echo "$key $((count++))" | tee -a $ tmplog188 189 # select file for patching184 [ -n "$DEBUG" ] && echo "$key $((count++))" | tee -a $logfile 185 186 # select hive for patching 190 187 case "$key" in 191 188 \[HKEY_LOCAL_MACHINE*) 192 189 key="$(leftchop "$key")" 193 [ -n "$DEBUG" ] && echo " 1 key=$key" | tee -a $tmplog190 [ -n "$DEBUG" ] && echo " 1 key=$key" | tee -a $logfile 194 191 195 192 case `leftget "$key"` in 196 193 [Ss][Yy][Ss][Tt][Ee][Mm]*) 197 file="$(ls -1d $2/[Ww][Ii][Nn][Dd][Oo][Ww][Ss]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Yy][Ss][Tt][Ee][Mm] 2>/dev/null | tail -1)"198 [ -z "$ file" ] && file="$(ls -1d $2/[Ww][Ii][Nn][Nn][Tt]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Yy][Ss][Tt][Ee][Mm] 2>/dev/null | tail -1)"199 # strip file194 hive="$(ls -1d $2/[Ww][Ii][Nn][Dd][Oo][Ww][Ss]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Yy][Ss][Tt][Ee][Mm] 2>/dev/null | tail -1)" 195 [ -z "$hive" ] && hive="$(ls -1d $2/[Ww][Ii][Nn][Nn][Tt]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Yy][Ss][Tt][Ee][Mm] 2>/dev/null | tail -1)" 196 # strip hive 200 197 key=`leftchop "$key"` 201 [ -n "$DEBUG" ] && echo " 2 key=$key" | tee -a $tmplog198 [ -n "$DEBUG" ] && echo " 2 key=$key" | tee -a $logfile 202 199 203 200 # change "CurrentControlSet" to "ControlSet001" 204 201 key="$(echo "$key" | sed 's,CurrentControlSet,ControlSet001,')" 205 [ -n "$DEBUG" ] && echo " 3 key=$key" | tee -a $tmplog202 [ -n "$DEBUG" ] && echo " 3 key=$key" | tee -a $logfile 206 203 ;; 207 204 [Ss][Oo][Ff][Tt][Ww][Aa][Rr][Ee]*) 208 file="$(ls -1d $2/[Ww][Ii][Nn][Dd][Oo][Ww][Ss]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Oo][Ff][Tt][Ww][Aa][Rr][Ee] 2>/dev/null | tail -1)"209 [ -z "$ file" ] && file="$(ls -1d $2/[Ww][Ii][Nn][Nn][Tt]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Oo][Ff][Tt][Ww][Aa][Rr][Ee] 2>/dev/null | tail -1)"210 # strip file205 hive="$(ls -1d $2/[Ww][Ii][Nn][Dd][Oo][Ww][Ss]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Oo][Ff][Tt][Ww][Aa][Rr][Ee] 2>/dev/null | tail -1)" 206 [ -z "$hive" ] && hive="$(ls -1d $2/[Ww][Ii][Nn][Nn][Tt]/[Ss][Yy][Ss][Tt][Ee][Mm]32/[Cc][Oo][Nn][Ff][Ii][Gg]/[Ss][Oo][Ff][Tt][Ww][Aa][Rr][Ee] 2>/dev/null | tail -1)" 207 # strip hive 211 208 key=`leftchop "$key"` 212 [ -n "$DEBUG" ] && echo " 4 key=$key" | tee -a $tmplog209 [ -n "$DEBUG" ] && echo " 4 key=$key" | tee -a $logfile 213 210 ;; 214 211 esac 215 212 216 create_ cmd"$key"213 create_keypath "$key" 217 214 218 215 while read -r change; do 219 216 220 create_val || break 221 222 do_reg "$command" 223 224 # tschmitt: patch other controlsets up to 9 217 create_command || break 218 exec_command "$command" 219 220 # tschmitt: patch other controlsets up to 3 225 221 case "$command" in 226 222 *ControlSet001*) 227 if [ ! -s "$tmpctrls" ]; then 228 [ -n "$DEBUG" ] && echo "### Writing $tmpctrls ..." | tee -a $tmplog 229 controlcheck="ls\nq\ny\n" 230 do_reg "$controlcheck" "$tmpctrls" 231 fi 232 n=2 233 while [ $n -lt 10 ]; do 234 ctrlset="ControlSet00$n" 235 [ -n "$DEBUG" ] && echo "### Checking $ctrlset ..." | tee -a $tmplog 236 if grep -q "<$ctrlset>" $tmpctrls; then 237 key_new="$(echo "$key" | sed "s,ControlSet001,$ctrlset,")" 238 [ -n "$DEBUG" ] && echo "### Patching $ctrlset with new key: $key_new" | tee -a $tmplog 239 if create_cmd "$key_new" "$ctrlset"; then 240 create_val && do_reg "$command" 241 fi 242 fi 243 let n+=1 244 done 245 ;; 223 n=2 224 while [ $n -lt 4 ]; do 225 ctrlset="ControlSet00$n" 226 [ -n "$DEBUG" ] && echo "### Checking $ctrlset ..." | tee -a $logfile 227 if test_key "$ctrlset"; then 228 key_new="$(echo "$key" | sed "s,ControlSet001,$ctrlset,")" 229 [ -n "$DEBUG" ] && echo "### Patching $ctrlset with new key: $key_new" | tee -a $logfile 230 if create_keypath "$key_new" "$ctrlset"; then 231 create_command && exec_command "$command" 232 fi 233 fi 234 let n+=1 235 done 236 ;; 246 237 esac 247 238 … … 252 243 done < "$1" # while read -r key 253 244 254 # merge logfiles255 cat $tmplog >> $tmpctrls256 mv $tmpctrls $tmplog257
Note: See TracChangeset
for help on using the changeset viewer.
