diff options
| author | mikka <miklos.martin@gmail.com> | 2012-09-11 22:04:56 +0200 | 
|---|---|---|
| committer | mikka <miklos.martin@gmail.com> | 2012-09-11 22:04:56 +0200 | 
| commit | 08f4d8b9ce43bae69a2d712456cc6bde68b4f0d1 (patch) | |
| tree | 576ad805526a50e9969461a8f272011e82833f28 /plugins/nginx | |
| parent | 91303246ecb4f103a1a3e21dfd9bcb65d1d5e832 (diff) | |
| download | zsh-08f4d8b9ce43bae69a2d712456cc6bde68b4f0d1.tar.gz zsh-08f4d8b9ce43bae69a2d712456cc6bde68b4f0d1.tar.bz2 zsh-08f4d8b9ce43bae69a2d712456cc6bde68b4f0d1.zip | |
fixed nginx vhost template, made variables local, imroved parameter validation
Diffstat (limited to 'plugins/nginx')
| -rw-r--r-- | plugins/nginx/nginx.plugin.zsh | 49 | ||||
| -rw-r--r-- | plugins/nginx/templates/symfony2 | 2 | 
2 files changed, 21 insertions, 30 deletions
| diff --git a/plugins/nginx/nginx.plugin.zsh b/plugins/nginx/nginx.plugin.zsh index 6dd90c6d5..4d2c4122d 100644 --- a/plugins/nginx/nginx.plugin.zsh +++ b/plugins/nginx/nginx.plugin.zsh @@ -81,45 +81,36 @@ _nginx_vhost () {  # Parsing arguments  vhost () { -    user=$USER; -    template=$NGINX_VHOST_TEMPLATE -    tpl="non_existing_template" -    enable=1 -    write_hosts=0 -    args="" +    local user=$USER; +    local template=$NGINX_VHOST_TEMPLATE +    local tpl="non_existing_template" +    local enable=1 +    local write_hosts=0      while getopts ":lu:t:nwh" option      do        case $option in          l ) ls $NGINX_DIR/sites-enabled; return ;; -        u ) user=$OPTARG; args="$args -u $OPTARG" ;; -        t ) tpl=$OPTARG; args="$args -t $OPTARG" ;; -        n ) enable=0; args="$args -n" ;; -        w ) write_hosts=1; args="$args -w" ;; +        u ) user=$OPTARG ;; +        t ) tpl=$OPTARG ;; +        n ) enable=0 ;; +        w ) write_hosts=1 ;;          h ) _vhost_usage; return ;;        esac      done -    vhost=${@: -1} -    vhostNotGiven=0 -     -    if [ ! $vhost ]; then -        vhostNotGiven=1 -    else -        if [ $(echo $args | grep -o $vhost) ]; then -            vhostNotGiven=1 -        fi -    fi -     -    if [ $vhostNotGiven -eq 1 ]; then +    shift $[ $OPTIND - 1 ] +    local vhost=$1 +   +    if [ -z "$vhost" ]; then          echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m"          return      fi      if [ -e $ZSH/plugins/nginx/templates/$tpl ]; then -        template=$ZSH/plugins/nginx/templates/$tpl +        local template=$ZSH/plugins/nginx/templates/$tpl      elif [ -e $tpl ]; then -        template=$tpl +        local template=$tpl      fi      _vhost_generate $vhost $user @@ -149,7 +140,7 @@ _vhost_usage () {  # Generate config file  _vhost_generate () { -    user=$(cat /etc/passwd | grep $2 | awk -F : '{print $1 }') +    local user=$(cat /etc/passwd | grep $2 | awk -F : '{print $1 }')      if [ ! $user ]; then        echo "User \033[31m$2\033[0m doesn't have an account on \033[33m$HOST\033[0m" @@ -158,10 +149,10 @@ _vhost_generate () {      echo "Generating \033[32m$1\033[0m vhost for \033[33m$user\033[0m user" -    user_id=$(cat /etc/passwd | grep $2 | awk -F : '{print $3 }') -    pool_port=1$user_id +    local user_id=$(cat /etc/passwd | grep $2 | awk -F : '{print $3 }') +    local pool_port=1$user_id -    conf=$(sed -e 's/{vhost}/'$1'/g' -e 's/{user}/'$user'/g' -e 's/{pool_port}/'$pool_port'/g' $template ) +    local conf=$(sed -e 's/{vhost}/'$1'/g' -e 's/{user}/'$user'/g' -e 's/{pool_port}/'$pool_port'/g' $template )      echo $conf > $1.tmp      $sudo mv $1.tmp $NGINX_DIR/sites-available/$1 @@ -188,7 +179,7 @@ _write_hosts () {  	$sudo mv $temp /etc/hosts; -	"\033[32m$1\033[0m vhost has been successfully written in /etc/hosts" +	echo "\033[32m$1\033[0m vhost has been successfully written in /etc/hosts"  }  alias ngt="$sudo nginx -t" diff --git a/plugins/nginx/templates/symfony2 b/plugins/nginx/templates/symfony2 index 4d5754ca1..c2eeaec0a 100644 --- a/plugins/nginx/templates/symfony2 +++ b/plugins/nginx/templates/symfony2 @@ -9,7 +9,7 @@ server {  	access_log /var/log/nginx/{vhost}.access.log;      location / { -        try_files $uri $uri/ /app_dev.php; +        try_files $uri $uri/ /app_dev.php$uri /app_dev.php$is_args$args;      }      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:{pool_port} | 
