From 3ef82a908a10979d9a4d14e0674902c85b14a99e Mon Sep 17 00:00:00 2001 From: mikka Date: Sun, 2 Sep 2012 15:43:20 +0200 Subject: [PATCH 1/5] nginx and php-fpm plugins --- plugins/nginx/nginx.plugin.zsh | 195 +++++++++++++++++++++++++++++ plugins/nginx/templates/plain_php | 27 ++++ plugins/nginx/templates/symfony2 | 27 ++++ plugins/php-fpm/php-fpm.plugin.zsh | 75 +++++++++++ plugins/php-fpm/templates/pool | 11 ++ 5 files changed, 335 insertions(+) create mode 100644 plugins/nginx/nginx.plugin.zsh create mode 100644 plugins/nginx/templates/plain_php create mode 100644 plugins/nginx/templates/symfony2 create mode 100644 plugins/php-fpm/php-fpm.plugin.zsh create mode 100644 plugins/php-fpm/templates/pool diff --git a/plugins/nginx/nginx.plugin.zsh b/plugins/nginx/nginx.plugin.zsh new file mode 100644 index 00000000..6dd90c6d --- /dev/null +++ b/plugins/nginx/nginx.plugin.zsh @@ -0,0 +1,195 @@ +: ${NGINX_DIR:=/etc/nginx} +: ${NGINX_VHOST_TEMPLATE:=$ZSH/plugins/nginx/templates/symfony2} + +if [ $use_sudo -eq 1 ]; then + sudo="sudo" +else + sudo="" +fi + +# nginx basic completition + +_nginx_get_en_command_list () { + ls -a $NGINX_DIR/sites-available | awk '/^[a-z][a-z.-]+$/ { print $1 }' +} + +_nginx_get_dis_command_list () { + ls -a $NGINX_DIR/sites-enabled | awk '/^[a-z][a-z.-]+$/ { print $1 }' +} + +_nginx_en () { + compadd `_nginx_get_en_command_list` +} + +_nginx_dis () { + compadd `_nginx_get_dis_command_list` +} + +# Enabling a site +en () { + if [ ! $1 ]; then + echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m"; + return + fi + + if [ ! -e $NGINX_DIR/sites-available/$1 ]; then + echo "\033[31m$1\033[0m doesn't exist"; + return + fi + + if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then + $sudo ln -s $NGINX_DIR/sites-available/$1 $NGINX_DIR/sites-enabled/$1; + if [ -e /etc/nginx/sites-enabled/$1 ]; then + echo "\033[32m$1\033[0m successfully enabled"; + else + echo "An error occured during the enabling of \033[31m$1\033[0m"; + fi + else + echo "\033[31m$1\033[0m is already enabled"; + fi +} +compdef _nginx_en en + +# Disabling a site +dis () { + if [ ! $1 ]; then + echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m"; + return + fi + + if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then + echo "\033[31m$1\033[0m doesn't exist"; + else + $sudo rm -f $NGINX_DIR/sites-enabled/$1; + if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then + echo "\033[32m$1\033[0m successfully disabled"; + else + echo "An error occured during the disabling of \033[31m$1\033[0m"; + fi + fi +} +compdef _nginx_dis dis + +# Completition of vhost +_nginx_get_possible_vhost_list () { + ls -a $HOME/www | awk '/^[^.][a-z0-9._]+$/ { print $1 }' +} + +_nginx_vhost () { + compadd `_nginx_get_possible_vhost_list` +} + +# Parsing arguments +vhost () { + user=$USER; + template=$NGINX_VHOST_TEMPLATE + tpl="non_existing_template" + enable=1 + write_hosts=0 + args="" + + 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" ;; + 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 + 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 + elif [ -e $tpl ]; then + template=$tpl + fi + + _vhost_generate $vhost $user + + if [ $enable -eq 1 ]; then + en $vhost + fi + + if [ $write_hosts -eq 1 ]; then + _write_hosts $vhost + fi +} +compdef _nginx_vhost vhost + +_vhost_usage () { + echo "Usage: vhost [options] [vhost_name]" + echo + echo "Options" + echo " -l Lists enabled vhosts" + echo " -u Sets the user - defaults to the current user ($USER)" + echo " -t Sets the template" + echo " -n Does not enable the generated vhost" + echo " -w Write the vhost to the /etc/hosts file pointing to 127.0.0.1 (writes it at the end of the first line actually)" + echo " -h Get this help message" + return +} + +# Generate config file +_vhost_generate () { + 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" + return + fi + + 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 + + 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 + + if [ -e $NGINX_DIR/sites-available/$1 ]; then + echo "\033[32m$1\033[0m vhost has been successfully created" + else + echo "An error occured during the creating of \033[31m$1\033[0m vhost" + fi +} + +# Write the /etc/hosts file +_write_hosts () { + temp=$HOME/hosts.temp + exec < /etc/hosts + while read line + do + if [ -e $temp ]; then + echo "$line" >> $temp; + else + echo "$line $1" > $temp; + fi + done + + $sudo mv $temp /etc/hosts; + + "\033[32m$1\033[0m vhost has been successfully written in /etc/hosts" +} + +alias ngt="$sudo nginx -t" +alias ngr="$sudo service nginx restart" diff --git a/plugins/nginx/templates/plain_php b/plugins/nginx/templates/plain_php new file mode 100644 index 00000000..f7995f5d --- /dev/null +++ b/plugins/nginx/templates/plain_php @@ -0,0 +1,27 @@ +server { + root /home/{user}/www/{vhost}; + index index.php; + + server_name {vhost}; + + error_log /var/log/nginx/{vhost}.error.log; + access_log /var/log/nginx/{vhost}.access.log; + + location / { + try_files $uri $uri/ $uri/index.php; + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_index index.php; + fastcgi_pass 127.0.0.1:{pool_port}; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param HTTPS off; + } + + location ~ /\.ht { + deny all; + } +} diff --git a/plugins/nginx/templates/symfony2 b/plugins/nginx/templates/symfony2 new file mode 100644 index 00000000..4d5754ca --- /dev/null +++ b/plugins/nginx/templates/symfony2 @@ -0,0 +1,27 @@ +server { + root /home/{user}/www/{vhost}/web; + index app_dev.php; + + server_name {vhost}; + client_max_body_size 10M; + + error_log /var/log/nginx/{vhost}.error.log; + access_log /var/log/nginx/{vhost}.access.log; + + location / { + try_files $uri $uri/ /app_dev.php; + } + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:{pool_port} + location ~ ^/(app|app_dev|check)\.php(/|$) { + fastcgi_pass 127.0.0.1:{pool_port}; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param HTTPS off; + } + + location ~ /\.ht { + deny all; + } +} diff --git a/plugins/php-fpm/php-fpm.plugin.zsh b/plugins/php-fpm/php-fpm.plugin.zsh new file mode 100644 index 00000000..3c095058 --- /dev/null +++ b/plugins/php-fpm/php-fpm.plugin.zsh @@ -0,0 +1,75 @@ +: ${FPM_DIR:=/etc/php5/fpm} + +if [ $use_sudo -eq 1 ]; then + sudo="sudo" +else + sudo="" +fi + +_fpm_get_possible_pool_list () { + cat /etc/passwd | awk -F : '{print $1 }' +} + +_fpm_pool () { + compadd `_fpm_get_possible_pool_list` + +} + +pool () { + while getopts ":lh" option + do + case $option in + l ) ls $FPM_DIR/pool.d; return ;; + h ) _pool_usage; return ;; + * ) _pool_usage; return ;; # Default. + esac + done + + if [ ! $1 ]; then + user=$USER + else + user=$1 + fi + + _pool_generate $user +} +compdef _fpm_pool pool + +_pool_usage () { + echo "Usage: pool [options] [user]" + echo + echo "Options" + echo " -l Lists fpm pools" + echo " -h Get this help message" + return +} + +_pool_generate () { + user=$(cat /etc/passwd | grep $1 | awk -F : '{print $1 }') + + if [ ! $user ]; then + echo "User \033[31m$1\033[0m doesn't have an account on \033[33m$HOST\033[0m" + return + fi + + group=$(groups $user | cut -d " " -f 3) + + echo "Generating pool for \033[33m$user\033[0m user with \033[33m$group\033[0m group" + + user_id=$(cat /etc/passwd | grep $1 | awk -F : '{print $3 }') + pool_port=1$user_id + : ${FPM_POOL_TEMPLATE:=$ZSH/plugins/php-fpm/templates/pool} + + conf=$(sed -e 's/{user}/'$user'/g' -e 's/{group}/'$group'/g' -e 's/{pool_port}/'$pool_port'/g' $FPM_POOL_TEMPLATE ) + + echo $conf > $user.conf + $sudo mv $user.conf $FPM_DIR/pool.d/$user.conf + + if [ -e $FPM_DIR/pool.d/$user.conf ]; then + echo "Pool for \033[32m$user\033[0m user has been successfully created" + else + echo "An error occured during the creating of pool for \033[31m$user\033[0m user" + fi +} + +alias fpmr="$sudo service php5-fpm restart" diff --git a/plugins/php-fpm/templates/pool b/plugins/php-fpm/templates/pool new file mode 100644 index 00000000..80f6693e --- /dev/null +++ b/plugins/php-fpm/templates/pool @@ -0,0 +1,11 @@ +[{user}] +user = {user} +group = {group} + +listen = 127.0.0.1:{pool_port} + +pm = dynamic +pm.max_children = 10 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +pm.max_requests = 100 From 91303246ecb4f103a1a3e21dfd9bcb65d1d5e832 Mon Sep 17 00:00:00 2001 From: mikka Date: Fri, 7 Sep 2012 22:15:43 +0200 Subject: [PATCH 2/5] added lesscss plugin --- plugins/lesscss/lesscss.plugin.zsh | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plugins/lesscss/lesscss.plugin.zsh diff --git a/plugins/lesscss/lesscss.plugin.zsh b/plugins/lesscss/lesscss.plugin.zsh new file mode 100644 index 00000000..6c666adb --- /dev/null +++ b/plugins/lesscss/lesscss.plugin.zsh @@ -0,0 +1,46 @@ +# basics taken from here: +# http://www.ravelrumba.com/blog/watch-compile-less-command-line/comment-page-1/#comment-2464 +# Requires watchr: https://github.com/mynyml/watchr + +watchless () { + compressed=0 + compile="" + + while getopts ":xc:h" option + do + case $option in + x ) compressed=1 ;; + c ) compile=$OPTARG ;; + h ) _watchless_usage; return ;; + esac + done + + if [ $compressed -eq 1 ]; then + x=' -x' + else + x='' + fi + + if [ -n "$compile" ]; then + if [ ! -e $compile ]; then + echo "\033[337;41m\n$compile doesn't exist!\n\033[0m" + return + fi + + name=$(echo $compile | cut -d . -f 1) + + watchr -e 'watch(".*\.less$") { |f| system("lessc '$name'.less > '$name'.css'$x' && echo \"'$name'.less > '$name'.css\" ") }' + else + watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > $(echo #{f[0]} | cut -d\. -f1).css'$x' && echo \"#{f[0]} > $(echo #{f[0]} | cut -d\. -f1).css\" ") }' + fi +} + +_watchless_usage () { + echo "Usage: watchless [options]" + echo + echo "Options" + echo " -x Compiles less files into minified css files" + echo " -c Watch all files but compile only the one given here" + echo " -h Get this help message" + return +} From 08f4d8b9ce43bae69a2d712456cc6bde68b4f0d1 Mon Sep 17 00:00:00 2001 From: mikka Date: Tue, 11 Sep 2012 22:04:56 +0200 Subject: [PATCH 3/5] fixed nginx vhost template, made variables local, imroved parameter validation --- plugins/nginx/nginx.plugin.zsh | 49 +++++++++++++------------------- 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 6dd90c6d..4d2c4122 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 4d5754ca..c2eeaec0 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} From c5d575ccae5ae5f30dd59037210edb8220de2cbe Mon Sep 17 00:00:00 2001 From: mikka Date: Thu, 3 Jan 2013 07:07:40 +0100 Subject: [PATCH 4/5] cleaned up --- plugins/lesscss/lesscss.plugin.zsh | 46 ------- plugins/nginx/nginx.plugin.zsh | 186 ----------------------------- plugins/nginx/templates/plain_php | 27 ----- plugins/nginx/templates/symfony2 | 27 ----- plugins/php-fpm/php-fpm.plugin.zsh | 75 ------------ plugins/php-fpm/templates/pool | 11 -- 6 files changed, 372 deletions(-) delete mode 100644 plugins/lesscss/lesscss.plugin.zsh delete mode 100644 plugins/nginx/nginx.plugin.zsh delete mode 100644 plugins/nginx/templates/plain_php delete mode 100644 plugins/nginx/templates/symfony2 delete mode 100644 plugins/php-fpm/php-fpm.plugin.zsh delete mode 100644 plugins/php-fpm/templates/pool diff --git a/plugins/lesscss/lesscss.plugin.zsh b/plugins/lesscss/lesscss.plugin.zsh deleted file mode 100644 index 6c666adb..00000000 --- a/plugins/lesscss/lesscss.plugin.zsh +++ /dev/null @@ -1,46 +0,0 @@ -# basics taken from here: -# http://www.ravelrumba.com/blog/watch-compile-less-command-line/comment-page-1/#comment-2464 -# Requires watchr: https://github.com/mynyml/watchr - -watchless () { - compressed=0 - compile="" - - while getopts ":xc:h" option - do - case $option in - x ) compressed=1 ;; - c ) compile=$OPTARG ;; - h ) _watchless_usage; return ;; - esac - done - - if [ $compressed -eq 1 ]; then - x=' -x' - else - x='' - fi - - if [ -n "$compile" ]; then - if [ ! -e $compile ]; then - echo "\033[337;41m\n$compile doesn't exist!\n\033[0m" - return - fi - - name=$(echo $compile | cut -d . -f 1) - - watchr -e 'watch(".*\.less$") { |f| system("lessc '$name'.less > '$name'.css'$x' && echo \"'$name'.less > '$name'.css\" ") }' - else - watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > $(echo #{f[0]} | cut -d\. -f1).css'$x' && echo \"#{f[0]} > $(echo #{f[0]} | cut -d\. -f1).css\" ") }' - fi -} - -_watchless_usage () { - echo "Usage: watchless [options]" - echo - echo "Options" - echo " -x Compiles less files into minified css files" - echo " -c Watch all files but compile only the one given here" - echo " -h Get this help message" - return -} diff --git a/plugins/nginx/nginx.plugin.zsh b/plugins/nginx/nginx.plugin.zsh deleted file mode 100644 index 4d2c4122..00000000 --- a/plugins/nginx/nginx.plugin.zsh +++ /dev/null @@ -1,186 +0,0 @@ -: ${NGINX_DIR:=/etc/nginx} -: ${NGINX_VHOST_TEMPLATE:=$ZSH/plugins/nginx/templates/symfony2} - -if [ $use_sudo -eq 1 ]; then - sudo="sudo" -else - sudo="" -fi - -# nginx basic completition - -_nginx_get_en_command_list () { - ls -a $NGINX_DIR/sites-available | awk '/^[a-z][a-z.-]+$/ { print $1 }' -} - -_nginx_get_dis_command_list () { - ls -a $NGINX_DIR/sites-enabled | awk '/^[a-z][a-z.-]+$/ { print $1 }' -} - -_nginx_en () { - compadd `_nginx_get_en_command_list` -} - -_nginx_dis () { - compadd `_nginx_get_dis_command_list` -} - -# Enabling a site -en () { - if [ ! $1 ]; then - echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m"; - return - fi - - if [ ! -e $NGINX_DIR/sites-available/$1 ]; then - echo "\033[31m$1\033[0m doesn't exist"; - return - fi - - if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then - $sudo ln -s $NGINX_DIR/sites-available/$1 $NGINX_DIR/sites-enabled/$1; - if [ -e /etc/nginx/sites-enabled/$1 ]; then - echo "\033[32m$1\033[0m successfully enabled"; - else - echo "An error occured during the enabling of \033[31m$1\033[0m"; - fi - else - echo "\033[31m$1\033[0m is already enabled"; - fi -} -compdef _nginx_en en - -# Disabling a site -dis () { - if [ ! $1 ]; then - echo "\033[337;41m\nThe name of the vhost is required!\n\033[0m"; - return - fi - - if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then - echo "\033[31m$1\033[0m doesn't exist"; - else - $sudo rm -f $NGINX_DIR/sites-enabled/$1; - if [ ! -e $NGINX_DIR/sites-enabled/$1 ]; then - echo "\033[32m$1\033[0m successfully disabled"; - else - echo "An error occured during the disabling of \033[31m$1\033[0m"; - fi - fi -} -compdef _nginx_dis dis - -# Completition of vhost -_nginx_get_possible_vhost_list () { - ls -a $HOME/www | awk '/^[^.][a-z0-9._]+$/ { print $1 }' -} - -_nginx_vhost () { - compadd `_nginx_get_possible_vhost_list` -} - -# Parsing arguments -vhost () { - 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 ;; - t ) tpl=$OPTARG ;; - n ) enable=0 ;; - w ) write_hosts=1 ;; - h ) _vhost_usage; return ;; - esac - done - - 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 - local template=$ZSH/plugins/nginx/templates/$tpl - elif [ -e $tpl ]; then - local template=$tpl - fi - - _vhost_generate $vhost $user - - if [ $enable -eq 1 ]; then - en $vhost - fi - - if [ $write_hosts -eq 1 ]; then - _write_hosts $vhost - fi -} -compdef _nginx_vhost vhost - -_vhost_usage () { - echo "Usage: vhost [options] [vhost_name]" - echo - echo "Options" - echo " -l Lists enabled vhosts" - echo " -u Sets the user - defaults to the current user ($USER)" - echo " -t Sets the template" - echo " -n Does not enable the generated vhost" - echo " -w Write the vhost to the /etc/hosts file pointing to 127.0.0.1 (writes it at the end of the first line actually)" - echo " -h Get this help message" - return -} - -# Generate config file -_vhost_generate () { - 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" - return - fi - - echo "Generating \033[32m$1\033[0m vhost for \033[33m$user\033[0m user" - - local user_id=$(cat /etc/passwd | grep $2 | awk -F : '{print $3 }') - local pool_port=1$user_id - - 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 - - if [ -e $NGINX_DIR/sites-available/$1 ]; then - echo "\033[32m$1\033[0m vhost has been successfully created" - else - echo "An error occured during the creating of \033[31m$1\033[0m vhost" - fi -} - -# Write the /etc/hosts file -_write_hosts () { - temp=$HOME/hosts.temp - exec < /etc/hosts - while read line - do - if [ -e $temp ]; then - echo "$line" >> $temp; - else - echo "$line $1" > $temp; - fi - done - - $sudo mv $temp /etc/hosts; - - echo "\033[32m$1\033[0m vhost has been successfully written in /etc/hosts" -} - -alias ngt="$sudo nginx -t" -alias ngr="$sudo service nginx restart" diff --git a/plugins/nginx/templates/plain_php b/plugins/nginx/templates/plain_php deleted file mode 100644 index f7995f5d..00000000 --- a/plugins/nginx/templates/plain_php +++ /dev/null @@ -1,27 +0,0 @@ -server { - root /home/{user}/www/{vhost}; - index index.php; - - server_name {vhost}; - - error_log /var/log/nginx/{vhost}.error.log; - access_log /var/log/nginx/{vhost}.access.log; - - location / { - try_files $uri $uri/ $uri/index.php; - } - - location ~ \.php$ { - include fastcgi_params; - fastcgi_index index.php; - fastcgi_pass 127.0.0.1:{pool_port}; - fastcgi_split_path_info ^(.+\.php)(/.*)$; - - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS off; - } - - location ~ /\.ht { - deny all; - } -} diff --git a/plugins/nginx/templates/symfony2 b/plugins/nginx/templates/symfony2 deleted file mode 100644 index c2eeaec0..00000000 --- a/plugins/nginx/templates/symfony2 +++ /dev/null @@ -1,27 +0,0 @@ -server { - root /home/{user}/www/{vhost}/web; - index app_dev.php; - - server_name {vhost}; - client_max_body_size 10M; - - error_log /var/log/nginx/{vhost}.error.log; - access_log /var/log/nginx/{vhost}.access.log; - - location / { - 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} - location ~ ^/(app|app_dev|check)\.php(/|$) { - fastcgi_pass 127.0.0.1:{pool_port}; - fastcgi_split_path_info ^(.+\.php)(/.*)$; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS off; - } - - location ~ /\.ht { - deny all; - } -} diff --git a/plugins/php-fpm/php-fpm.plugin.zsh b/plugins/php-fpm/php-fpm.plugin.zsh deleted file mode 100644 index 3c095058..00000000 --- a/plugins/php-fpm/php-fpm.plugin.zsh +++ /dev/null @@ -1,75 +0,0 @@ -: ${FPM_DIR:=/etc/php5/fpm} - -if [ $use_sudo -eq 1 ]; then - sudo="sudo" -else - sudo="" -fi - -_fpm_get_possible_pool_list () { - cat /etc/passwd | awk -F : '{print $1 }' -} - -_fpm_pool () { - compadd `_fpm_get_possible_pool_list` - -} - -pool () { - while getopts ":lh" option - do - case $option in - l ) ls $FPM_DIR/pool.d; return ;; - h ) _pool_usage; return ;; - * ) _pool_usage; return ;; # Default. - esac - done - - if [ ! $1 ]; then - user=$USER - else - user=$1 - fi - - _pool_generate $user -} -compdef _fpm_pool pool - -_pool_usage () { - echo "Usage: pool [options] [user]" - echo - echo "Options" - echo " -l Lists fpm pools" - echo " -h Get this help message" - return -} - -_pool_generate () { - user=$(cat /etc/passwd | grep $1 | awk -F : '{print $1 }') - - if [ ! $user ]; then - echo "User \033[31m$1\033[0m doesn't have an account on \033[33m$HOST\033[0m" - return - fi - - group=$(groups $user | cut -d " " -f 3) - - echo "Generating pool for \033[33m$user\033[0m user with \033[33m$group\033[0m group" - - user_id=$(cat /etc/passwd | grep $1 | awk -F : '{print $3 }') - pool_port=1$user_id - : ${FPM_POOL_TEMPLATE:=$ZSH/plugins/php-fpm/templates/pool} - - conf=$(sed -e 's/{user}/'$user'/g' -e 's/{group}/'$group'/g' -e 's/{pool_port}/'$pool_port'/g' $FPM_POOL_TEMPLATE ) - - echo $conf > $user.conf - $sudo mv $user.conf $FPM_DIR/pool.d/$user.conf - - if [ -e $FPM_DIR/pool.d/$user.conf ]; then - echo "Pool for \033[32m$user\033[0m user has been successfully created" - else - echo "An error occured during the creating of pool for \033[31m$user\033[0m user" - fi -} - -alias fpmr="$sudo service php5-fpm restart" diff --git a/plugins/php-fpm/templates/pool b/plugins/php-fpm/templates/pool deleted file mode 100644 index 80f6693e..00000000 --- a/plugins/php-fpm/templates/pool +++ /dev/null @@ -1,11 +0,0 @@ -[{user}] -user = {user} -group = {group} - -listen = 127.0.0.1:{pool_port} - -pm = dynamic -pm.max_children = 10 -pm.min_spare_servers = 1 -pm.max_spare_servers = 3 -pm.max_requests = 100 From df7cae0f4fdd8221d6cf256cc29c48b1d0d54dbd Mon Sep 17 00:00:00 2001 From: mikka Date: Thu, 3 Jan 2013 07:18:38 +0100 Subject: [PATCH 5/5] moved bower plugin to a separate branch --- plugins/bower/bower.plugin.zsh | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/bower/bower.plugin.zsh diff --git a/plugins/bower/bower.plugin.zsh b/plugins/bower/bower.plugin.zsh new file mode 100644 index 00000000..ed9c0484 --- /dev/null +++ b/plugins/bower/bower.plugin.zsh @@ -0,0 +1,38 @@ +alias bi="bower install" +alias bl="bower list" +alias bs="bower search" + +bower_package_list='' + +_bower () +{ + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '*::options:->options' + + case $state in + (command) + + local -a subcommands + subcommands=(${=$(bower help | grep help | sed -e 's/,//g')}) + _describe -t commands 'bower' subcommands + ;; + + (options) + case $line[1] in + + (install) + if [ -z "$bower_package_list" ];then + bower_package_list=$(bower search | awk 'NR > 2' | cut -d '-' -f 2 | cut -d ' ' -f 2 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g") + fi + compadd "$@" $(echo $bower_package_list) + ;; + esac + ;; + esac +} + +compdef _bower bower