diff --git a/usr/local/sbin/eeupdate b/usr/local/sbin/eeupdate new file mode 100644 index 00000000..aefa5a8b --- /dev/null +++ b/usr/local/sbin/eeupdate @@ -0,0 +1,126 @@ +#!/bin/bash + + + +# Make Variables Available For Later Use +INSTALLLOG=/var/log/easyengine/install.log + +# Capture Errors +OwnError() +{ + echo -e "[ `date` ] \033[31m$@\e[0m" | tee -ai $INSTALLLOG + exit 101 +} + +EEUPDATE() +{ + # Clone EasyEngine (ee) Stable Repository + git clone -b stable git://github.com/rtCamp/easyengine.git /tmp/easyengine &>> $INSTALLLOG || OwnError "Unable To Clone Easy Engine" + + # EasyEngine (ee) /etc Files + cp -a /tmp/easyengine/etc/bash_completion.d/ee /etc/bash_completion.d/ &>> $INSTALLLOG || OwnError "Unable To Copy EE Auto Complete File" + cp -a /tmp/easyengine/etc/easyengine/ee.conf /etc/easyengine/ &>> $INSTALLLOG || OwnError "Unable To Copy ee.conf File" + + # EE /usr/share/easyengine Files + cp -a /tmp/easyengine/etc/nginx/* /usr/share/easyengine/nginx/ &>> $INSTALLLOG || OwnError "Unable To Copy Configuration Files " + cp -a /tmp/easyengine/usr/share/easyengine/* /usr/share/easyengine/ &>> $INSTALLLOG || OwnError "Unable To Copy Configuration Files " + + # EE Command + cp -a /tmp/easyengine/usr/local/sbin/* /usr/local/sbin/ &>> $INSTALLLOG || OwnError "Unable To Copy EasyEngine Command" + + # EE Man Pages + cp -a /tmp/easyengine/man/ee.8 /usr/share/man/man8/ &>> $INSTALLLOG || OwnError "Unable To Copy EasyEngine Man Pages" + + # Change Permission For EE + chmod 750 /usr/local/sbin/easyengine /usr/local/sbin/eeupdate || OwnError "Unable To Change EasyEngine Command Permission" + + # Create Symbolic Link If Not Exist + if [ ! -L /usr/local/sbin/ee ] + then + ln -s /usr/local/sbin/easyengine /usr/local/sbin/ee + fi + + # Adjust FastCGI Cache Size 20% Of /var/run + VARRUNSIZE=$(df --block-size=M /var/run | awk '{print $4}' | tail -n1 |cut -d'M' -f1) + FCSIZE=$(expr $VARRUNSIZE \* 25 / 100) + + # Change Size + sed -i "s/500m/$FCSIZE\m/" /usr/share/easyengine/nginx/conf.d/fastcgi.conf || OwnError "Unable To Change Fastcgi Cache Size" + + # Git Config Settings + EEGITNAME=$(git config user.name) + EEGITEMAIL=$(git config user.email) + + if [ -z "$EEGITNAME" ] || [ -z "$EEGITEMAIL" ] + then + echo + echo -e "\033[34mEasyEngine (ee) Required Your Name & Email Address To Track Changes You Made Under The Git\e[0m" | tee -ai $INSTALLLOG + echo -e "\033[34mEasyEngine (ee) Will Be Able To Send You Daily Reports & Alerts In Upcoming Version\e[0m" | tee -ai $INSTALLLOG + echo -e "\033[34mEasyEngine (ee) Will NEVER Send Your Information Across\e[0m" | tee -ai $INSTALLLOG + fi + # Check Git User Is Empty Or Not + if [ -z "$EEGITNAME" ] + then + read -p "Enter Your Name [$(whoami)]: " EEGITNAME + # If Enter Is Pressed + if [[ $EEGITNAME = "" ]] + then + EEGITNAME=$(whoami) + fi + git config --global user.name "$EEGITNAME" &>> $INSTALLLOG + fi + + # Check Git User Is Empty Or Not + if [ -z "$EEGITEMAIL" ] + then + read -p "Enter Your Email [$(whoami)@$(hostname -f)]: " EEGITEMAIL + # If Enter Is Pressed + if [[ $EEGITEMAIL = "" ]] + then + EEGITEMAIL=$(whoami)@$(hostname -f) + fi + git config --global user.email $EEGITEMAIL &>> $INSTALLLOG + fi +} + + +EE101() +{ + # Let Copy Some Missing Files + (sed "/allow/,+2d" /usr/share/easyengine/nginx/common/acl.conf; grep -v ^# /etc/nginx/common/allowed_ip.conf ) > /etc/nginx/common/acl.conf + cp -v /usr/share/easyengine/nginx/common/locations.conf /etc/nginx/common + +} + + + +# Update EasyEngine (ee) +EECURRENTVERSION=$(ee version | awk '{print($3)}') +EELATESTVERSION=$(curl -sL https://api.github.com/repos/rtCamp/easyengine/releases | grep tag_name | awk '{print($2)}' | cut -d'"' -f2 | cut -c2-) +echo EECURRENTVERSION = $EECURRENTVERSION EELATESTVERSION = $EELATESTVERSION &>> $INSTALLLOG + +if [[ $EECURRENTVERSION < $EELATESTVERSION ]] +then + stty echo + read -p "Would You Like To Update EasyEngine To $EELATESTVERSION (y/n): " EEUPDATE + + # Check User Choice + if [ "$EEUPDATE" = "y" ] || [ "$EEUPDATE" = "Y" ] + then + # Lets Start Update + echo &>> $INSTALLLOG + echo &>> $INSTALLLOG + echo -e "\033[34mEasyEngine (ee) Update Started [$(date)]\e[0m" | tee -ai $INSTALLLOG + + # Update EasyEngine (ee) + EEUPDATE + + if [[ $EECURRENTVERSION = 1.0.1 ]] + then + EE101 + fi + fi + +else + echo "EasyEngine Already Updated To The Latest Version" +fi