#!/bin/sh # # myini.cgi # # This scriptis more of my shell scripting practice than for real use, # although it should do respective job. # # It will read and parse /www/U/USER/etc/myini.txt and # replace corresponding entries found in /usr/local/lib/php.ini # and write the result into /www/U/USER/htdocs directory. # It'll remove the comments and blank lines, as well. # # This is a pure shell script and uses NO external command ! # So, it should perform better than a scripts with test [ ] and sed. # case "$HOME" in ));;'')echo -e "Content-type: text/plain\n\n" ;;esac main (){ # "main" function, just for easy redirect. U=`whoami` QQ=${HOME:=/www/${U%${U#?}}/$U} INI='/usr/local/lib/php.ini' MYINI="$HOME/etc/myini.txt" INIOUT="$HOME/htdocs/php.ini" getmyini () { # A function to parse and prepare the keyword list (or array, dict, whatever) C=0 KL='' while :;do read R || break case "$R" in ));;'')continue;;'#'*)continue;;';'*)continue;;esac KEY=${R%%=*} while :;do case "$KEY" in ));;*' ')KEY=${KEY%?};;*)break;;esac;done case "$KEY" in ));;'')continue;;esac C=$(($C+1)) KL="$KL${C}_=_${KEY},$R " done } rini () { # Read php.ini and replace lines that match one of keyword # stored in the kyword list, and eliminates blank&comment lines. CL=0 DL=' ' while :;do CL=$(($CL+1)) read R || break # Comment out following line if you don't want blank&comment stripping case "$R" in ));;'')continue;;';'*)continue;;esac CC=0 while :; do CC=$(($CC+1)) E=${KL##*${CC}_=_} K=${E%%,*} L=${E%% $(($CC+1))_=_*} L=${L#*,} FOUND=0 case "$R" in ));; *"$K"*) echo ";;; Following line is from $MYINI ;;;"; echo "$L";FOUND=1 DL="$DL${CC} " ;break ;; esac case "$CC" in ));;$C)break;;esac done case "$FOUND" in ));;0)echo "$R";;esac done # echo '; Additional elements, if any.' CC=0 while :; do case "$CC" in ));;$C)break;;esac CC=$(($CC+1)) case "$DL" in ));;*" $CC "*)continue;; *) E=${KL##*${CC}_=_} L=${E%% $(($CC+1))_=_*} L=${L#*,} echo ";;; Following line 'Added' from $MYINI ;;;"; echo "$L";FOUND=1 ;; esac done } # Parse myini.txt and prepare the replacement list $KL getmyini <"$MYINI" # Treat the php.ini rini <"$INI" >"$INIOUT" echo "processed $INI ($CL lines) !" } main 2>&1 exit