自己第一次写的青涩脚本
- #!/bin/bash
- set -x #这个我调试脚本用的,没其他含义,可以删除
- allow=YES
- deny=NO
- Sname=vsftpd
- VFconf="/etc/vsftpd/vsftpd.conf"
- VFstart="/etc/init.d/vsftpd"
- VUser="/etc/vsftpd/vuser"
- VUCdirectory="/etc/vsftpd/vuconf"
- VFpam="/etc/pam.d/vsftpdd"
- VFDirectory="/var/www/html"
- DB4=db4
- DB4UTILS="db4-utils"
- DB4DEVEL="db4-devel"
- sys_tem="/lib64"
- http=apache
- #----------主配置文件--------------
- MAIN_CONFIG()
- {
- if [ -d $sys_tem ];then
- echo "you system is 64bit"
- systems=$sys_tem
- else
- echo "you system is 32bit"
- systems=/lib
- fi
- # touch $VFpam
- sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' $VFconf
- sed -i 's/#chown_uploads=YES/chown_uploads=NO/g' $VFconf
- sed -i 's/#xferlog_file/xferlog_file/g' $VFconf
- sed -i 's/#async_abor_enable=YES/async_abor_enable=YES/g' $VFconf
- sed -i 's/#ascii_upload_enable=YES/ascii_upload_enable=YES/g' $VFconf
- sed -i 's/#ascii_download_enable=YES/ascii_download_enable=YES/g' $VFconf
- sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/g' $VFconf
- sed -i 's/pam_service_name=vsftpd/pam_service_name=vsftpdd/g' $VFconf
- {
- echo "guest_enable=$allow"
- echo "guest_username=$http"
- echo "user_config_dir=$VUCdirectory"
- echo "virtual_use_local_privs=$allow"
- } >> $VFconf
- touch $VFpam
- {
- echo "auth sufficient $systems/security/pam_userdb.so db=$VUser"
- echo "account sufficient $systems/security/pam_userdb.so db=$VUser"
- } > $VFpam
- }
- #------------用户配置-----------------------
- USER_CONFIG ()
- {
- Uname=$1
- userhome="local_root="
- userworld="anon_world_readable_only="
- userupload="anon_upload_enable="
- usermkdir="anon_mkdir_write_enable="
- userothen="anon_mkdir_write_enable="
- userwrite="write_enable="
- echo "现在开始配置用户....."
- if [ -d $VUCdirectory ];then
- echo "............"
- else
- mkdir $VUCdirectory
- fi
- echo "你需要配置的用户是:"
- echo "$Uname"
- touch "$VUCdirectory/$Uname" && echo "用户配置文件创建成功.................................."
- {
- echo "$userhome$VFDirectory"
- echo "$userwrite$allow"
- echo "$userworld$deny"
- echo "$userupload$allow"
- echo "$usermkdir$allow"
- echo "$userothen$allow"
- } > $VUCdirectory/$Uname
- chown -R $http:$http $VFDirectory
- chmod -R 755 $VFDirectory
- }
- #----------------增加用户---------------------
- ADD_USER()
- {
- echo "start add user"
- rpm -q $DB4
- if [ $? -eq 0 ];then
- echo "............."
- else
- echo "need download $DB4..."
- yum install -y $DB4
- fi
- rpm -q $DB4UTILS
- if [ $? -eq 0 ];then
- echo "............."
- else
- echo "need download $DB4UTILS..."
- yum install -y $DB4UTILS
- fi
- rpm -q $DB4DEVEL
- if [ $? -eq 0 ];then
- echo "------------"
- else
- echo "need download $DB4DEVEL..."
- yum install -y $DB4DEVEL
- fi
- if [ -f $VUser ];then
- echo "..................."
- else
- touch $VUser
- fi
- username=$1
- userpasswd=$2
- {
- echo "$username"
- echo "$userpasswd"
- } >> $VUser
- db_load -T -t hash -f $VUser $VUser.db
- rm -rf $VUser
- }
- #-----------------安装服务---------------------
- INSTALL_SERVER()
- {
- rpm -q $Sname
- if [ $? -eq 0 ];then
- echo "--------------------"
- else
- yum install -y $Sname
- fi
- echo -n "add user? "
- echo "y is add"
- echo "n and q is quit"
- echo -n "Please select:"
- read stall
- case $stall in
- y|Y)
- echo "ENTER USERNAME"
- read name1
- echo "ENTER PASSWD"
- read passwd1
- ADD_USER $name1 $passwd1
- USER_CONFIG $name1
- MAIN_CONFIG
- ;;
- n|q|N|Q)
- echo "EXIT。"
- exit 0
- ;;
- esac
- }
- #------------------------------------------------
- echo "start install $Sname:"
- INSTALL_SERVER
- $VFstart restart
- exit 0