Browse Source

Better way to call all args except last atgs

old-stable
Mitesh Shah 11 years ago
parent
commit
a4e77db88e
  1. 33
      src/lib/ee_lib_git.sh
  2. 61
      src/lib/ee_lib_service.sh

33
src/lib/ee_lib_git.sh

@ -2,26 +2,23 @@
function ee_lib_git()
{
for ee_git_dir in $@; do
if [ $ee_git_dir != ${@: -1} ]; then
for ee_git_dir in ${@:1:$(($#-1))}; do
# Change directory
cd $ee_git_dir || ee_lib_error "Unable to change directory $ee_git_dir, exit status = " $?
# Change directory
cd $ee_git_dir || ee_lib_error "Unable to change directory $ee_git_dir, exit status = " $?
# Check .git
if [ ! -d .git ]; then
ee_lib_echo "Initialize Git on ${ee_git_dir}..."
git init &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to initialize Git on $ee_git_dir, exit status = " $?
fi
# Check .git
if [ ! -d .git ]; then
ee_lib_echo "Initialize Git on ${ee_git_dir}"
git init &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to initialize Git on $ee_git_dir, exit status = " $?
fi
# Check for untracked files
if [ $(git status -s | wc -l) -ne 0 ]; then
# Add files in Git version control
ee_lib_echo "Committing changes inside $EE_GIT_DIR, please wait..."
git add --all && git commit -am ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to Git commit on $ee_git_dir, exit status = " $?
fi
# Check for untracked files
if [ $(git status -s | wc -l) -ne 0 ]; then
# Add files in Git version control
ee_lib_echo "Git commit on $ee_git_dir, please wait..."
git add --all && git commit -am "${@: -1}" &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to Git commit on $ee_git_dir, exit status = " $?
fi
done
}

61
src/lib/ee_lib_service.sh

@ -6,43 +6,32 @@
function ee_lib_service()
{
for ee_service_name in $@; do
if [ $ee_service_name != ${@: -1} ]; then
# Display message
ee_lib_echo "Executing service $ee_service_name ${@: -1}, please wait..."
# Check nginx and php5-fpm test before start/stop/restart/reload
if [ $ee_service_name = "nginx" ]; then
# Adjust nginx server_names_hash_bucket_size
$ee_service_name -t 2>&1 | grep server_names_hash_bucket_size &>> $EE_COMMAND_LOG
if [ $? -eq 0 ];then
EE_NGINX_CALCULATION=$(echo "l($(ls /etc/nginx/sites-enabled/ | wc -c))/l(2)+2" | bc -l)
EE_NGINX_SET_BUCKET=$(echo "2^$EE_NGINX_CALCULATION" | bc -l 2> /dev/null)
sed -i "s/.*server_names_hash_bucket_size.*/\tserver_names_hash_bucket_size $EE_NGINX_SET_BUCKET;/" /etc/nginx/nginx.conf
fi
# Test and start/stop/restart/reload nginx service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
elif [ $ee_service_name = "php5-fpm" ]; then
# Test and start/stop/restart/reload php5-fpm service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG\
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
else
# start/stop/restart/reload services
service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
for ee_service_name in ${@:1:$(($#-1))}; do
# Display message
ee_lib_echo "Executing service $ee_service_name ${@: -1}, please wait..."
# Check nginx and php5-fpm test before start/stop/restart/reload
if [ $ee_service_name = "nginx" ]; then
# Adjust nginx server_names_hash_bucket_size
$ee_service_name -t 2>&1 | grep server_names_hash_bucket_size &>> $EE_COMMAND_LOG
if [ $? -eq 0 ];then
EE_NGINX_CALCULATION=$(echo "l($(ls /etc/nginx/sites-enabled/ | wc -c))/l(2)+2" | bc -l)
EE_NGINX_SET_BUCKET=$(echo "2^$EE_NGINX_CALCULATION" | bc -l 2> /dev/null)
sed -i "s/.*server_names_hash_bucket_size.*/\tserver_names_hash_bucket_size $EE_NGINX_SET_BUCKET;/" /etc/nginx/nginx.conf
fi
# Test and start/stop/restart/reload nginx service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
elif [ $ee_service_name = "php5-fpm" ]; then
# Test and start/stop/restart/reload php5-fpm service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG\
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
else
# start/stop/restart/reload services
service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
fi
done
}

Loading…
Cancel
Save