#!/bin/bash ############################################################ ### ÀÛ¼ºÀÚ : ±Ç±â¼º(Ä«ÆóÀÎ nonots@hanmail.net) ### ÀÛ¼ºÃ³ : ¹Ù´ÙÀ¥È£½ºÆà °³¹ß½Ç (http://www.bada.cc) ### ÃÖÃÊ ÀÛ¼ºÀÏ : 2008-08-07 ¿­³ª°Ô ¹«´õ¿î ¿©¸§ ¿ÀÈÄ ### ÃÖ±Ù ¼öÁ¤ÀÏ : 2008-08-30 ############################################################ #### »ç¿ëµÇ´Â ȯ°æº¯¼ö ¼³Á¤°ª # »ç¿ëÀÚ Ãß°¡ USERADD_BIN="/usr/sbin/useradd" PASSWD_BIN="/usr/bin/passwd" ONLYMAIL_ID_HOME="/home/onlymail" # ¾ÆÆÄÄ¡ ¼³Á¤ HTTPD_CONF="/usr/local/apache/conf/member.conf" #HTTPD_CONF="/usr/local/apache/conf/httpd.conf" HTTPD_START="/etc/init.d/httpd" #HTTPD_START="/usr/local/apache/bin/apachectl" # Mysql ¸í·É¾î ¹× ¼³Á¤ MYSQL_BIN="/usr/local/mysql/bin/mysql" MYSQLADMIN_BIN="/usr/local/mysql/bin/mysqladmin" MYSQL_ROOT_PWD="" #MYSQL_ROOT_PWD="qkektjdrhd@" # Á÷Á¢ ÀÔ·ÂÇϼ¼¿ä.. # quota ¼³Á¤ EDQUOTA_BIN="/usr/sbin/edquota" SETQUOTA_BIN="/usr/sbin/setquota" #### »ç¿ëµÇ´Â ȯ°æº¯¼ö ¼³Á¤°ª ³¡ function show_head(){ echo -e " ################################# $1 ################################# \n"; } function show_enter(){ echo -n -e "\n\n $1 ... ¿£Å͸¦ Ä¡¼¼¿ä !! "; read } function show_var(){ show_head "»ç¿ëµÇ´Â ȯ°æº¯¼ö ¼³Á¤°ª" cat < ServerAdmin pcdoumi@bada.cc DocumentRoot /home/userid/public_html ServerName userid.bada.cc ServerAlias userid.co.kr www.userid.co.kr CBandLimit 1Gi CBandPeriod 1D CBandExceededURL http://www.bada.cc/message/traffic.htm #ThrottlePolicy Volume 1000mb 1d ErrorLog logs/userid.bada.cc-error_log CustomLog logs/userid.bada.cc-access_log combined "; echo -e "\n ### À¥¼­¹ö Àç½ÃÀÛÆÄÀÏ : $HTTPD_START\n"; echo -n -e "\n ¼±Åà : 1) À¥¼³Á¤ÆÄÀÏ ¼öÁ¤(vim), 2)À¥¼­¹ö Àç½ÃÀÛ, x) Á¾·á ? "; read asel case "$asel" in 1) vim + $HTTPD_CONF ;; 2) $HTTPD_START restart show_enter ;; x) return ;; "") return ;; esac done } # mysql DB DBUser Ãß°¡ function setMysql(){ clear show_head "MYSQL DB ¹× DB »ç¿ëÀÚ ÀÛ¾÷"; if [[ $MYSQL_ROOT_PWD = "" ]] ; then echo -n " \$MYSQL_ROOT_PWD °ªÀÌ ¾ø½À´Ï´Ù. mysql root ºñ¹øÀ» ÀÔ·ÂÇϼ¼¿ä ? " read R_PWD if [[ $R_PWD != "" ]]; then MYSQL_ROOT_PWD=$R_PWD else show_enter "mysql ·çÆ® ºñ¹øÁ¤º¸°¡ ¾ø½À´Ï´Ù." return fi fi while : do echo -e "\n ¸Þ´º : 1) DB Ãß°¡, 2) DB »èÁ¦, 3) DB »ç¿ëÀÚ Ãß°¡, 4) DB »ç¿ëÀÚ »èÁ¦, x) Á¾·á \n" echo -n -e " ¼±Åà ? "; read asel case "$asel" in 1) db_add ;; 2) db_del ;; 3) db_add_user ;; 4) db_del_user ;; x) return ;; "") return ;; esac done } # DB »ç¿ëÀÚ »èÁ¦ function db_del_user(){ echo -n -e " >> »èÁ¦ÇÒ DB »ç¿ëÀÚ ¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä. ex) userid ? " read DEL_DB_ID if [[ $DEL_DB_ID = "" ]]; then echo " ¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä "; return fi echo -n -e " >> $DEL_DB_ID ¾ÆÀ̵𸦠»èÁ¦ÇϽðڽÀ´Ï±î? (Y/n) "; read DEL_ID_YN if [[ $DEL_ID_YN != "n" ]]; then echo "$MYSQL_BIN -p$MYSQL_ROOT_PWD -e \"use mysql; delete from user where user = '$DEL_DB_ID' \""; $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "use mysql; delete from user where user = '$DEL_DB_ID'"; if [ $? = 0 ] ; then $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "flush privileges" echo " $DEL_DB_ID »ç¿ëÀÚ »èÁ¦ ¼º°ø"; else echo " $DEL_DB_ID »ç¿ëÀÚ »èÁ¦ ½ÇÆÐ !!! "; fi fi } # DB »ç¿ëÀÚ Ãß°¡ function db_add_user(){ echo -e "\n »ç¿ëÇÒ DB°¡ ¹Ì¸® »ý¼ºµÇ¾î ÀÖ¾î¾ß ÇÕ´Ï´Ù.\n" echo -n -e " >> Ãß°¡ÇÒ DB »ç¿ëÀÚ ¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä. ex) userid ? " read NEW_DB_ID echo -n -e " >> $NEW_DB_ID »ç¿ëÀÚ°¡ »ç¿ëÇÒ DB ¸íÀ» ÀÔ·ÂÇϼ¼¿ä. ex) userid_db ? " read NEW_DB_IDDB echo -n -e " >> $NEW_DB_ID »ç¿ëÀÚ°¡ »ç¿ëÇÒ DB ºñ¹Ð¹øÈ£ ÀÔ·ÂÇϼ¼¿ä. ex) dbpwd123 ? " read NEW_DB_PWD if [[ "$NEW_DB_ID" = "" ]]; then echo " ¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä "; return elif [[ "$NEW_DB_IDDB" = "" ]]; then echo " »ç¿ëÇÒ DB ¸íÀ» ÀÔ·ÂÇϼ¼¿ä "; return elif [[ "$NEW_DB_PWD" = "" ]]; then echo " »ç¿ëÇÒ ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇϼ¼¿ä "; return fi ExEDB=`$MYSQL_BIN -p$MYSQL_ROOT_PWD -e "show databases" | grep "$NEW_DB_IDDB"` if [[ "$ExEDB" = "" ]] ; then show_enter "$NEW_DB_IDDB ¶ó´Â DB°¡ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù. ¸ÕÀú DB ¸¦ »ý¼ºÇϼ¼¿ä" return; fi echo -n -e " >> ¾ÆÀ̵ð: $NEW_DB_ID, DBÀ̸§: $NEW_DB_IDDB, ºñ¹Ð¹øÈ£: $NEW_DB_PWD, ¸Â½À´Ï±î? (Y/n) "; read NEW_DB_YN if [[ "$NEW_DB_YN" != "n" ]]; then echo "grant all on $NEW_DB_IDDB.* to $NEW_DB_ID@localhost identified by '$NEW_DB_PWD'"; $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "grant all on $NEW_DB_IDDB.* to $NEW_DB_ID@localhost identified by '$NEW_DB_PWD'" if [ $? = 0 ] ; then $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "flush privileges" echo "DB »ç¿ëÀÚ ÀÔ·Â ¼º°ø"; else echo " DB »ç¿ëÀÚ Ãß°¡ ½ÇÆÐ !!! "; fi fi } # DB Ãß°¡ function db_add(){ echo -n -e " >> Ãß°¡ÇÒ DBÀ̸§À» ÀÔ·ÂÇϼ¼¿ä. ex) userid_db ? " read NEW_DB_NAME if [ "$NEW_DB_NAME" != "" ]; then EEDB=`$MYSQL_BIN -p$MYSQL_ROOT_PWD -e "use mysql;select db from db where db = '$NEW_DB_NAME'"` if [[ "$EEDB" != "" ]] ; then echo " $NEW_DB_NAME ´Â ÀÌ¹Ì ÀÖ´Â DB ÀÔ´Ï´Ù. ´Ù½Ã ÀÔ·ÂÇϼ¼¿ä. "; return; else $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "create database $NEW_DB_NAME" if [[ $? = 0 ]]; then echo " create database $NEW_DB_NAME" echo " $NEW_DB_NAME À̸§À¸·Î »õ DB °¡ »ý¼ºµÇ¾ú½À´Ï´Ù."; else echo " »ý¼º ½ÇÆÐ" fi fi fi } # DB »èÁ¦ function db_del(){ echo -n -e " >> »èÁ¦ÇÒ DBÀ̸§À» ÀÔ·ÂÇϼ¼¿ä. ex) userid_db ? " read DEL_DB_NAME if [[ "$DEL_DB_NAME" != "" && "$DEL_DB_NAME" != "mysql" ]]; then $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "use mysql; delete from db where db = '$DEL_DB_NAME'" $MYSQL_BIN -p$MYSQL_ROOT_PWD -e "drop database $DEL_DB_NAME" if [[ $? = 0 ]]; then echo " drop database $DEL_DB_NAME" echo " $DEL_DB_NAME »èÁ¦¿Ï·á."; else echo " »èÁ¦½ÇÆÐ"; fi else echo " DB ¸í ÀÔ·Â ¿¡·¯"; fi } # add shell user °èÁ¤ »ç¿ëÀÚ Ãß°¡ function setUser(){ clear show_head "¸®´ª½º »ç¿ëÀÚ °èÁ¤ Ãß°¡" echo " ## °èÁ¤Ãß°¡¿¡ »ç¿ëµÇ´Â ±âº»°ªÀÔ´Ï´Ù. ±âº»°ªÀÌ ¾Æ´Ñ º°µµ °ªÀ» »ç¿ëÇÏ·Á¸é useradd ¸í·É¾î ¿É¼ÇÀ» Áְųª, /etc/default/useradd ÆÄÀÏÀÇ ³»¿ëÀ» ¼öÁ¤ÈÄ »ç¿ëÇÏ½Ã¸é µË´Ï´Ù. [[ÀÏ¹Ý ¾ÆÀ̵ð]] " /usr/sbin/useradd -D | sed -e 's/^/\t/' echo " [[¸ÞÀÏÀü¿ë Á¦ÇÑ ¾ÆÀ̵ð]] Ȩµð·ºÅ丮 : $ONLYMAIL_ID_HOME ½© : /bin/false "; while : do echo -n -e " >> Ãß°¡ÇÒ »ç¿ëÀÚ ¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä. (x:ÁßÁö) ? " read newid if [[ "$newid" = "" || "$newid" = "x" ]] ; then show_enter "»ç¿ëÀÚ °èÁ¤ Ãß°¡ ÀÛ¾÷Áß´Ü"; return fi echo ""; if egrep "^$newid:" /etc/passwd ; then show_enter "$newid ´Â ÀÌ¹Ì ÀÖ´Â ¾ÆÀ̵ð ÀÔ´Ï´Ù." ; return fi echo -n -e " >> ¾ÆÀ̵ð Á¾·ù¼±Åà : 1) ÀϹݾÆÀ̵ð, 2) ¸ÞÀÏ¿ë Á¦ÇÑ ¾ÆÀ̵ð, x)ÁßÁö ? " read idsel case $idsel in 1) addoption=''; ;; 2) addoption=" -d $ONLYMAIL_ID_HOME/$newid -s /bin/false "; ;; *) return ;; esac if $USERADD_BIN $newid $addoption ; then echo " $USERADD_BIN $newid $addoption " $PASSWD_BIN $newid eval "chmod 705 ~$newid" show_enter "$newid ¾ÆÀ̵ð Ãß°¡ ¿Ï·á." ; echo ""; echo -n " µð½ºÅ© QUOTA ¼³Á¤À» ÇϽðڽÀ´Ï±î? (Y/n) " read quotayn if [[ $quotayn = "n" || $quotayn = "N" ]]; then return else setQuota $newid fi fi done } # disk quota µð½ºÅ© ÄõÅÍ ¼³Á¤ function setQuota(){ #setquota -u pcdoumi 50000 50000 0 0 -a if [[ $1 = "" ]] ; then clear show_head "¸®´ª½º QUOTA µð½ºÅ© ¿ë·® Ãß°¡" echo -n -e " >> QUOTA¸¦ ¼³Á¤ÇÒ °èÁ¤ ¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä. (x:ÁßÁö) ? " read newid if [[ "$newid" = "" || "$newid" = "x" ]] ; then show_enter "»ç¿ëÀÚ ÄõÅͼ³Á¤ ÀÛ¾÷Áß´Ü" return fi else newid=$1 fi if ! egrep "^$newid:" /etc/passwd > /dev/null 2>&1 ; then show_enter "$newid ´Â ¾ø´Â ¾ÆÀ̵ð ÀÔ´Ï´Ù. »ç¿ëÀÚ Ãß°¡¸¦ ¸ÕÀúÇϼ¼¿ä." return else echo -e "\n### $newid ¾ÆÀ̵ðÀÇ ÇöÀç QUOTA ¼³Á¤»óÅ : repquota -auv"; repquota -auv | egrep "$newid " echo "" fi echo -n " >> $newid : ÄõÅÍ¿ë·® ¼±Åà : 1)100M, 2)300M, 3)500M, 4)1G, 5)2G, 6)4G, 7)Á÷Á¢ÀÔ·Â x)ÁßÁö ? " read qnum case $qnum in 1) qsize=100000 ;; 2) qsize=300000 ;; 3) qsize=500000 ;; 4) qsize=1000000 ;; 5) qsize=2000000 ;; 6) qsize=5000000 ;; x|X) return ;; *) echo -n " >> ÄõÅÍÅ©±â (KB ´ÜÀ§, 300M ´Â 300000 À¸·Î ÀÔ·Â) ? " read qsize if [[ $qsize -gt 1000000000 || $qsize -lt 1000 || $qsize = 0 ]]; then show_enter "ÄõÅÍÅ©±â ¹üÀ§°¡ ÀÌ»óÇÔ, ÀÛ¾÷ Áß´Ü"; return fi ;; esac echo " $SETQUOTA_BIN -u $newid $qsize $qsize 0 0 "; if $SETQUOTA_BIN -u $newid $qsize $qsize 0 0 -a > /dev/null 2>&1 ; then show_enter " $newid : $qsize ÄõÅÍ ¼³Á¤ ¼º°ø "; return; fi } function main_page(){ cat <> "; read selnum } while : do clear main_page case "$selnum" in 1) setUser ;; 2) setMysql ;; 3) setApache ;; 4) setQuota ;; 5) setUser; setMysql ;; 6) setUser; setMysql; setApache ;; h|H) show_help ;; v|V) show_var ;; *) exit 0 ;; esac done