📄 install
字号:
#!/bin/sh################### Start of $RCSfile: Install,v $ #################### $Source: /home/alb/afbackup/afbackup-3.3.8.1/RCS/Install,v $# $Id: Install,v 1.4 2004/07/08 20:34:42 alb Exp alb $# $Date: 2004/07/08 20:34:42 $# $Author: alb $######### description #######################################################################################################################if [ _"$1" = _--testonly ] ; then shift adminprefix=/tmp for f in services inetd.conf passwd group ; do ( test -f $adminprefix/$f || cp /etc/$f $adminprefix ; chmod u+w $adminprefix/$f ) >/dev/null 2>&1 donefi#### some basic settingsOSNAME=`uname -s|sed 's/[^a-zA-Z1-9]//g'`umask 22servicename="afbackup"varstosave="servinstdir username userid groupid defdev servvarinstdir clntinstdir clntvarinstdir port use_des des_header des_include des_lib des_libdir disable_threads orduserrestore runclientconfig runserverconfig servicename activate_mserver mservicename mport add_mservice use_zlib zlib_include zlib_libdir usegcc chown_server_var libdesbug_enabled do_install optimizer_flags servnamalias"#### read the cache file overriding defaultsif [ -r Install.cache ] ; then grep '^[ ]*set[ ]' Install.cache >/dev/null if [ $? -eq 0 ] ; then # the old csh-syntax CACHE=`sed 's/^[ ]*set[ ][ ]*//g' Install.cache | sed 's/=(/="/g;s/)$/"/g'` else CACHE=`cat Install.cache` fi eval "$CACHE"fi#### set defaults as not obtained from the cache fileif [ _"$servinstdir" = _ ] ; then servinstdir="/usr/local/afbackup"fiif [ _"$clntinstdir" = _ ] ; then clntinstdir="/usr/local/afbackup"fiif [ _"$port" = _ ] ; then port=2988fiif [ _"$mport" = _ ] ; then mport=`expr $port + 1`fiif [ _"$servnamalias" = _ ] ; then servnamalias="Yes"fiif [ _"$orduserrestore" = _ ] ; then orduserrestore="No"fiif [ _"$use_des" = _ ] ; then use_des="No"fiif [ _"$des_header" = _ ] ; then des_header="des.h"fiif [ _"$des_include" = _ ] ; then des_include="../libdes"fiif [ _"$des_lib" = _ ] ; then des_lib="-ldes"fiif [ _"$libdesbug_enabled" = _ ] ; then libdesbug_enabled="No"fiif [ _"$use_zlib" = _ ] ; then use_zlib="No"fiif [ _"$zlib_include" = _ ] ; then zlib_include="/usr/local/include"fiif [ _"$zlib_libdir" = _ ] ; then if [ _"$zlib_include" = _ ] ; then zlib_libdir="/usr/local/lib" fifiif [ _"$servvarinstdir" = _ ] ; then servvarinstdir="/var/logs/backup"fiif [ _"$clntvarinstdir" = _ ] ; then clntvarinstdir="/var/logs/backup"fiif [ _"$activate_mserver" = _ ] ; then activate_mserver="Yes"fiif [ _"$add_mservice" = _ ] ; then add_mservice="Yes"fiif [ _"$mservicename" = _ ] ; then mservicename="afmbackup"fiif [ _"$chown_server_var" = _ ] ; then chown_server_var="Yes"fiif [ _"$disable_threads" = _ ] ; then disable_threads="No"fiif [ _"$optimizer_flags" = _ ] ; then optimizer_flags="-O2"fiif [ _"$do_install" = _ ] ; then do_install="Yes"fiif [ _"$runclientconfig" = _ ] ; then runclientconfig="Yes"fiif [ _"$runserverconfig" = _ ] ; then runserverconfig="Yes"fi############################################################################ Utilities###########################################################################matches(){ echo "$1" | egrep -i "$2" >/dev/null}tolowercase(){ sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'}###########################################################################yes_no(){ while true ; do echo " " echo_n 'Your choice (Yes/No) ['"$1"']: ' read yesno if [ _"$yesno" = _ ] ; then yesno="$1" fi if matches "$yesno" '^(ye?s?|no?)$' ; then break else echo ' ' echo 'This is not a valid choice. Please try again.' fi done if matches "$yesno" '^ye?s?$' ; then yesno="yes" else yesno="no" fi test $yesno = yes}issymlink(){ return `/bin/ls -l1 "$1" |grep '^l' | wc -l`}save_cache_vars(){ echo_n "Saving cache, please wait ..." /bin/rm -f Install.cache touch Install.cache for var in $varstosave ; do set | grep '^'"$var"= >/dev/null if [ $? -eq 0 ] ; then eval valuestr='$'"$var" echo "$var""='$valuestr'" >> Install.cache fi done echo dummy | awk '{printf "\r \r"}'}## with exit status as argument#do_exit(){ save_cache_vars exit $1}## which as sh function#find_program(){ for dir in `echo $PATH | tr : " "` ; do if [ -x "$dir"/"$1" ] ; then echo "$dir"/"$1" return 0 fi done return 1}## get xinetd entry stanza#get_xinetd_entry(){ sed -n '/^\([ ]\)\?service[ ][ ]*'"$1"'\([ ].*\)\?/,/^[ ]*[}][ ]*/ p' "$2"}## get xinetd param value#get_xinetd_param(){ sed -n '/^\([ ]\)\?service[ ][ ]*'"$1"'\([ ].*\)\?/,/^[ ]*[}][ ]*/ p' "$3"|grep '^[ ]*'"$2"'[ ]*=[ ]*'|sed 's/^[^=]*=[ ]*//g'}## remove named xinetd entry from data stream#strip_xinetd_entry(){ sed '/^\([ ]\)\?service[ ][ ]*'"$1"'\([ ].*\)\?/,/^[ ]*[}][ ]*/ d' "$2"}## combine empty lines to one empty line#comb_empty_lines(){ awk 'BEGIN{s = 0;}{if(NF = 0){if(s = 0)print; s = 1}else{s = 0; print}}'}# return signal number by signal name## seems csh is the only thing to print the signals without any scrolls#SIGNALLIST=`csh -f -c 'kill -l' | grep -v '^[ ]$' | awk '{ for(i = 1; i <= NF; i++) print $i }' | fgrep -vx NULL | sed 's/^SIG//g'`signalbyname(){ echo "$SIGNALLIST" | egrep -n '^(SIG)?'"$1" | sed 's/:.*$//g'}####### add afbackup entry to /etc/services interactivelyadd_backup_service(){ servnamvar="$1" eval servnam='"$'"$servnamvar"'"' protnam="$2" if [ _"$3" != _ ] ; then portnumvar="$3" eval portnum='"$'"$portnumvar"'"' fi echo ' ' echo 'An entry for the backup service is necessary in the system' echo "file $adminprefix/services." # add_service: while true ; do cont=no servicesline=`egrep '^[ ]*('"$servnam"'|[^ ][^ ]*[ ][ ]*[^ ].*[ ]'"$servnam"')([ ].*)?$' $adminprefix/services` serviceslinen=`echo $servicesline | wc -w` if [ $serviceslinen -gt 0 ] ; then while true ; do echo "There exists an entry for this service in $adminprefix/services." echo "It looks like this:" echo ' ' echo "$servicesline" echo ' ' echo 'Should we remove this entry and create a new one, or add another ?' echo '(If no is chosen, the existing entry will be used)' echo ' ' echo_n 'Your choice (Yes/No/Add) [No]: ' read c echo ' ' if [ _"$c" = _ ] ; then c="no" fi if matches "$c" '^(ye?s?|no?|ad?d?)$' ; then break else echo "Invalid choice. Please try again." echo ' ' fi done if matches "$c" '^ad?d?' ; then # newservname: while true ; do echo " " echo_n "Enter a name for the new service: " read c if matches "$c" '^[a-zA-Z0-9_-]*$' ; then break fi echo " " echo "A service name should contain only A-Z, a-z, 0-9, _ or -" echo "Please try again." done servnam="$c" continue fi if matches "$c" '^ye?s?$' ; then panic=0 cp -p $adminprefix/services $adminprefix/services.$$ CPST=$? saved_files="$saved_files $adminprefix/services.$$" if [ ! -f $adminprefix/services.$$ -o $CPST -ne 0 ] ; then echo "Panic: cannot make backup copy of $adminprefix/services." echo "I'll not go on to add the entry. You have to do it yourself." panic=1 else NEWSRVF=`egrep -v '^[ ]*('"$servnam"'|[^ ][^ ]*[ ][ ]*[^ ].*[ ]'"$servnam"')([ ].*)?$' "$adminprefix"/services` cp -p "$adminprefix"/services "$adminprefix"/services.tmp.$$ \ && echo "$NEWSRVF" > "$adminprefix"/services.tmp.$$ \ && /bin/mv "$adminprefix"/services.tmp.$$ "$adminprefix"/services if [ $? -ne 0 ] ; then echo "Error: removing entry from the system file failed." panic=1 fi fi if [ $panic -ne 0 ] ; then echo "The following line must be removed from $adminprefix/services" echo ' ' egrep '^[ ]*('"$servnam"'|[^ ][^ ]*[ ][ ]*[^ ].*[ ]'"$servnam"')([ ].*)?$' "$adminprefix"/services echo " " echo "Please hit enter when you are done with it." read a fi continue fi if [ `matches "$c" '^no?$'` ] ; then portnum=`echo "$servicesline"|awk '{print $2}'|cut -d/ -f1|awk '{print $1}'` fi else while [ `grep -i "$portnum"/"$protnam" "$adminprefix"/services|grep -v $servnam|wc -l` -gt 0 ] ; do portnum=`expr $portnum + 1` done # portserviceselection: while true ; do if [ $portnum = 2988 ] ; then hint=' (hex 0xbac)' else hint='' fi echo ' ' echo "Should we add an entry to $adminprefix/services for this" echo 'service ? Default port number is '"$portnum$hint"'. If' echo 'you do not want to add an entry, just enter no. If you' echo 'would like to use a different port number, enter it. If' echo 'you want a service name different from '"$servnam"',' echo 'enter it (all lowercase letters, numbers or -, please).' echo 'If everything is ok, enter yes.' while true ; do echo " " echo_n 'Your choice (Yes/No/port/servicename) [Yes]: ' read c if [ _"$c" = _ ] ; then c='Yes' fi if matches "$c" '^(ye?s?|no?|[0-9][0-9]*|[a-z][a-z0-9-]*)$' ; then break fi echo ' ' echo 'This is not a valid choice. Please try again.' done if matches "$c" '^[0-9][0-9]*$' ; then portnum="$c" echo " " echo "Ok, port number changed to $c." if [ `grep -c '^[ ]*[a-z][a-z0-9-]*[ ][ ]*'"$c/"'[tT][Cc][Pp]' $adminprefix/services` -gt 0 ] ; then echo "Warning: Port number $c is already used in $adminprefix/services." fi continue fi matches "$c" '^(ye?s?|no?)$' M=$? if test $M -ne 0 && matches "$c" '^[a-z][a-z0-9-]*$' ; then servnam="$c" echo " " echo "Ok, service name changed to $c." if [ `egrep '^[ ]*('"$c"'[ ][ ]*[1-9][0-9]*/[tT][Cc][Pp]|[^ ][^ ]*[ ][ ]*[1-9][0-9]*/[tT][Cc][Pp].*[ ]'"$c"')([ ].*)?$' $adminprefix/services|wc -l` -gt 0 ] ; then echo "Hm, service name $c is already used in $adminprefix/services." cont=yes break fi continue fi if matches "$c" '^no?$' ; then : else servicesline=`egrep '^[ ]*[a-z][a-z0-9-]*[ ][ ]*'"$portnum/"'[tT][Cc][Pp]([ ].*)?$' $adminprefix/services | egrep -v '^(.*[ ])?'"$servnam"'([ ].*)?$'` lineadded="no" if [ `echo $servicesline | wc -w` -gt 0 ] ; then echo ' ' echo "Warning: The port number $portnum is already used in $adminprefix/services," echo "but without an entry for the name $servnam. It looks like this:" echo ' ' echo "$servicesline" echo ' ' echo "Should the existing entry be extended with $servnam as an alias name ?" if yes_no $servnamalias ; then servnamalias=Yes cp -p $adminprefix/services $adminprefix/services.$$ CPST=$? saved_files="$saved_files $adminprefix/services.$$" if [ ! -f $adminprefix/services.$$ -o $CPST -ne 0 ] ; then echo "Panic: cannot make backup copy of $adminprefix/services." echo "I'll not go on to add the entry. Please do it yourself" echo "and press Return, when done." read v else servlineentry=`egrep '^[ ]*[a-z][a-z0-9-]*[ ][ ]*'"$portnum/"'[tT][Cc][Pp]([ ].*)?$' $adminprefix/services | egrep -v '^(.*[ ])?'"$servnam"'([ ].*)?$'` servlineno=`egrep -n '^[ ]*[a-z][a-z0-9-]*[ ][ ]*'"$portnum/"'[tT][Cc][Pp]([ ].*)?$' "$adminprefix"/services | sed 's/:.*$//g'` comment=`echo "$servlineentry"|grep '#'|sed 's/^[^#]*#/ #/g'` thebeef=`echo "$servlineentry"|sed 's/[ ]*#.*//g'` cp -p "$adminprefix"/services $adminprefix/services.$$.2 awk '{if(NR == '"$servlineno"') printf "%s '"$servnam"'%s\n","'"$thebeef"'","'"$comment"'"; else print $0}' $adminprefix/services.$$ > $adminprefix/services.$$.2 NDIFF1=`diff $adminprefix/services.$$ $adminprefix/services.$$.2 | grep '^< ' | wc -l` NDIFF2=`diff $adminprefix/services.$$ $adminprefix/services.$$.2 | grep '^> ' | wc -l` if [ $NDIFF1 = 1 -a $NDIFF2 = 1 ] ; then /bin/mv $adminprefix/services.$$.2 $adminprefix/services else /bin/rm -f $adminprefix/services.$$.2 echo "Error: Could not modify $adminprefix/services correctly." echo "Please do it manually and press Return afterwards." read v fi fi lineadded="yes" else continue fi fi if [ $lineadded = no ] ; then echo "$servnam $portnum/$protnam" >> $adminprefix/services fi fi break done fi if [ _"$cont" != _yes ] ; then break fi done eval "$servnamvar"='"'"$servnam"'"' eval "$portnumvar"='"'"$portnum"'"'}################### add entry to /etc/inetd.conf fileadd_inetd_entry(){ servnam="$1" waitforexit="$2" prognam="$3" protnam=tcp waityesno="no" if [ $waitforexit = "wait" ] ; then waityesno="yes" fi echo 'An entry for this service is necessary in the system' echo "file $inetdfile." while true ; do # add_inetdentry: if [ $use_xinetd -ne 0 ] ; then inetdentry=`get_xinetd_entry $servnam $inetdfile` else inetdentry=`egrep '^[ ]*'"$servnam"'([ ].*)?$' $inetdfile` fi inetdentryn=`echo $inetdentry|wc -w` if [ $inetdentryn -gt 0 ] ; then echo "There exists an entry in $inetdfile." echo "It looks like this:" echo ' ' if [ $use_xinetd -ne 0 ] ; then get_xinetd_entry $servnam $inetdfile else echo "$inetdentry" fi echo ' ' def="No" if [ $use_xinetd -eq 0 ] ; then I=1 N=`echo "$inetdentry" | wc -w` while [ $I -le $N ] ; do eval i"$I"='"'`echo "$inetdentry" | awk '{print $'"$I"'}'`'"' I=`expr $I + 1` done if matches "$i6""/" ^"$servinstdir""/" ; then : else echo 'The directory path in this entry seems to be wrong (It' echo 'should be '"$servinstdir"'/... )' def="Yes" fi if matches "$i6" /"$prognam"'$' && matches "$i7" /"$prognam"'$' ; then : else echo "The program name in this entry is wrong (it must be $prognam)." def="Yes" fi if matches "$i7""/" '^'"$servinstdir""/" ; then : else echo 'The program path in this entry is wrong ('"it must be $servinstdir/$prognam"').' def="Yes" fi if [ _"$i5" != _"$username" ] ; then echo 'The username in this entry is wrong (should be '$username').' def="Yes" fi i3=`echo "$i3" | tolowercase` if [ "$i3" != "$protnam" -o "$i4" != "$waitforexit" -o "$i2" != stream ] ; then echo 'The protocol in this entry is wrong (we are allowing' if [ "$waitforexit" = "nowait" ] ; then echo 'several server processes).' else echo 'only one server process)' fi def="Yes" fi else # xinetd server=`get_xinetd_param "$servnam" server "$inetdfile"` if matches "$server""/" '^'"$servinstdir""/" ; then : else echo 'The directory path in this entry seems to be wrong (It' echo 'should be '"$servinstdir"'/... )' def="Yes" fi server_args=`get_xinetd_param "$servnam" server_args "$inetdfile"` I=1 N=`echo "$server_args" | wc -w` while [ $I -le $N ] ; do eval server_args"$I"='"'`echo "$server_args" | awk '{print $'"$I"'}'`'"' I=`expr $I + 1` done if matches "$server" /"$prognam"'$' && matches "$server_args1" /"$prognam"'$' ; then : else echo "The program name in this entry is wrong (it must be $prognam)." def="Yes"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -