A free open source IT asset/license management system
Support Debian 8 installs. Shellchecked. More cleanup. (#4174)
tiagom6248277606debe
diff --git a/snipeit.sh b/snipeit.shindex 78ab2cc925..b54575e2e5 100755--- a/snipeit.sh+++ b/snipeit.sh@@ -39,14 +39,12 @@ spin[3]="/"# Debian/Ubuntu friendly f(x)sprogress () {- while kill -0 $pid > /dev/null 2>&1- do- for i in "${spin[@]}"- do- echo -ne "\b$i"- sleep .1- done+ while kill -0 "$pid" > /dev/null 2>&1; do+ for i in "${spin[@]}"; do+ echo -ne "\b$i"+ sleep .1done+ done}setvhdebian () {@@ -100,30 +98,27 @@ installsnipeit () {log "git clone https://github.com/snipe/snipe-it $webdir/$name"echo "* Configuring .env file."- cp $webdir/$name/.env.example $webdir/$name/.env+ cp "$webdir/$name/.env.example" "$webdir/$name/.env"- sed -i '1 i\#Created By Snipe-it Installer' $webdir/$name/.env- sed -i 's,^\(APP_TIMEZONE=\).*,\1'$tzone',' $webdir/$name/.env- sed -i 's,^\(DB_HOST=\).*,\1'localhost',' $webdir/$name/.env- sed -i 's,^\(DB_DATABASE=\).*,\1'snipeit',' $webdir/$name/.env- sed -i 's,^\(DB_USERNAME=\).*,\1'snipeit',' $webdir/$name/.env- sed -i 's,^\(DB_PASSWORD=\).*,\1'$mysqluserpw',' $webdir/$name/.env- sed -i 's,^\(APP_URL=\).*,\1'http://$fqdn',' $webdir/$name/.env+ sed -i '1 i\#Created By Snipe-it Installer' "$webdir/$name/.env"+ sed -i 's,^\(APP_TIMEZONE=\).*,\1'$tzone',' "$webdir/$name/.env"+ sed -i 's,^\(DB_HOST=\).*,\1'localhost',' "$webdir/$name/.env"+ sed -i 's,^\(DB_DATABASE=\).*,\1'snipeit',' "$webdir/$name/.env"+ sed -i 's,^\(DB_USERNAME=\).*,\1'snipeit',' "$webdir/$name/.env"+ sed -i 's,^\(DB_PASSWORD=\).*,\1'$mysqluserpw',' "$webdir/$name/.env"+ sed -i 's,^\(APP_URL=\).*,\1'http://$fqdn',' "$webdir/$name/.env"echo "* Installing and running composer."- cd $webdir/$name/+ cd "$webdir/$name/"curl -sS https://getcomposer.org/installer | phpphp composer.phar install --no-dev --prefer-sourceecho "* Setting permissions."- chmod_dirs=( "$webdir/$name/storage" )- chmod_dirs+=( "$webdir/$name/storage/private_uploads" )- chmod_dirs+=( "$webdir/$name/public/uploads" )- for chmod_dir in "${chmod_dirs[@]}"- do+ for chmod_dir in "$webdir/$name/storage" "$webdir/$name/storage/private_uploads" "$webdir/$name/public/uploads"; dochmod -R 755 "$chmod_dir"done- chown -R $ownergroup $webdir/$name++ chown -R "$ownergroup" "$webdir/$name"echo "* Generating the application key."log "php artisan key:generate --force"@@ -135,8 +130,7 @@ installsnipeit () {(crontab -l ; echo "* * * * * /usr/bin/php $webdir/$name/artisan schedule:run >> /dev/null 2>&1") | crontab -}-#CentOS Friendly f(x)s-function isinstalled {+isinstalled () {if yum list installed "$@" >/dev/null 2>&1; thentrueelse@@ -144,8 +138,8 @@ function isinstalled {fi}-if [ -f /etc/lsb-release ]; then- distro="$(lsb_release -s -i )"+if [[ -f /etc/lsb-release || -f /etc/debian_version ]]; then+ distro="$(lsb_release -s -i)"version="$(lsb_release -s -r)"codename="$(lsb_release -c -s)"elif [ -f /etc/os-release ]; then@@ -176,15 +170,15 @@ echo ""shopt -s nocasematchcase $distro in*Ubuntu*)- echo " The installer has detected Ubuntu version $version as the OS."+ echo " The installer has detected $distro version $version codename $codename."distro=ubuntu;;*Debian*)- echo " The installer has detected Debian version $version as the OS."+ echo " The installer has detected $distro version $version codename $codename."distro=debian;;*centos*|*redhat*|*ol*|*rhel*)- echo " The installer has detected $distro version $version as the OS."+ echo " The installer has detected $distro version $version."distro=centos;;*)@@ -195,7 +189,7 @@ esacshopt -u nocasematchecho -n " Q. What is the FQDN of your server? ($fqdn): "-read fqdn+read -r fqdnif [ -z "$fqdn" ]; thenfqdn="$(hostname --fqdn)"fi@@ -205,7 +199,7 @@ echo ""ans=defaultuntil [[ $ans == "yes" ]] || [[ $ans == "no" ]]; doecho -n " Q. Do you want to automatically create the database user password? (y/n) "-read setpw+read -r setpwcase $setpw in[yY] | [yY][Ee][Ss] )@@ -215,7 +209,7 @@ case $setpw in;;[nN] | [n|N][O|o] )echo -n " Q. What do you want your snipeit user password to be?"- read -s mysqluserpw+ read -rs mysqluserpwecho ""ans="no";;@@ -267,9 +261,54 @@ case $distro inecho "* Restarting Apache httpd."log "service apache2 restart"+ elif [[ "$version" =~ ^8 ]]; then+ webdir=/var/www+ ownergroup=www-data:www-data+ tzone=$(cat /etc/timezone)++ echo "* Adding MariaDB and ppa:ondrej/php repositories."+ log "apt-get install -y software-properties-common"+ log "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db"+ log "add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.1/debian $codename main'"+ #PHP7 repository+ log "apt-get install -y apt-transport-https"+ log "wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg"+ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list++ echo "* Updating with apt-get update."+ log "apt-get update" & pid=$!+ progress++ echo "* Upgrading packages with apt-get upgrade."+ log "apt-get -y upgrade" & pid=$!+ progress++ echo "* Installing Apache httpd, PHP, MariaDB and other requirements."+ log "DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server mariadb-client php7.1 php7.1-mcrypt php7.1-curl php7.1-mysql php7.1-gd php7.1-ldap php7.1-zip php7.1-mbstring php7.1-xml php7.1-bcmath curl git unzip" & pid=$!+ progress++ a2enmod rewrite++ echo "* Creating the new virtual host in Apache."+ setvhdebian++ echo >> $hosts "127.0.0.1 $hostname $fqdn"++ echo "* Securing MariaDB."+ /usr/bin/mysql_secure_installation++ echo "* Creating MariaDB Database/User."+ echo "* Please Input your MariaDB root password:"+ mysql -u root -p --execute="CREATE DATABASE snipeit;GRANT ALL PRIVILEGES ON snipeit.* TO snipeit@localhost IDENTIFIED BY '$mysqluserpw';"++ installsnipeit++ echo "* Restarting Apache httpd."+ log "service apache2 restart"+else- echo "Unsupported Debian version. Version found: " $version- return 1+ echo "Unsupported Debian version. Version found: $version"+ exit 1fi;;ubuntu)@@ -280,6 +319,7 @@ case $distro intzone=$(cat /etc/timezone)echo "* Adding MariaDB repository."+ log "apt-get install software-properties-common"log "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8"log "add-apt-repository 'deb [arch=amd64,i386] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu $codename main'"@@ -326,6 +366,7 @@ case $distro intzone=$(cat /etc/timezone)echo "* Adding MariaDB and ppa:ondrej/php repositories."+ log "apt-get install software-properties-common"log "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db"log "add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu $codename main'"#PHP7 repository@@ -368,8 +409,8 @@ case $distro inlog "service apache2 restart"else- echo "Unsupported Ubuntu version. Version found: " $version- return 1+ echo "Unsupported Ubuntu version. Version found: $version"+ exit 1fi;;centos)@@ -398,7 +439,7 @@ case $distro inecho "* Installing Apache httpd, PHP, MariaDB and other requirements."PACKAGES="httpd mariadb-server git unzip php71u php71u-mysqlnd php71u-bcmath php71u-cli php71u-common php71u-embedded php71u-gd php71u-mbstring php71u-mcrypt php71u-ldap php71u-json php71u-simplexml"- for p in $PACKAGES;do+ for p in $PACKAGES; doif isinstalled "$p"; thenecho " * $p already installed"else@@ -418,15 +459,13 @@ case $distro inecho "* Please Input your MariaDB root password: "mysql -u root -p --execute="CREATE DATABASE snipeit;GRANT ALL PRIVILEGES ON snipeit.* TO snipeit@localhost IDENTIFIED BY '$mysqluserpw';"- #Create the new virtual host in Apache and enable rewriteecho "* Creating the new virtual host in Apache."setvhcentosecho "* Setting up hosts file."echo >> $hosts "127.0.0.1 $hostname $fqdn"- /sbin/service iptables status >/dev/null 2>&1- if [ $? = 0 ]; then+ if /sbin/service iptables status >/dev/null 2>&1; thenecho "* Configuring iptables."iptables -I INPUT 1 -p tcp -m tcp --dport 80 -j ACCEPTiptables -I INPUT 1 -p tcp -m tcp --dport 443 -j ACCEPT@@ -453,7 +492,7 @@ case $distro inecho "* Installing Apache httpd, PHP, MariaDB and other requirements."PACKAGES="httpd mariadb-server git unzip php71u php71u-mysqlnd php71u-bcmath php71u-cli php71u-common php71u-embedded php71u-gd php71u-mbstring php71u-mcrypt php71u-ldap php71u-json php71u-simplexml"- for p in $PACKAGES;do+ for p in $PACKAGES; doif isinstalled "$p"; thenecho " * $p already installed"else@@ -498,53 +537,53 @@ case $distro inlog "systemctl restart httpd.service"else- echo "Unsupported CentOS version. Version found: " $version- return 1+ echo "Unsupported CentOS version. Version found: $version"+ exit 1fiesacsetupmail=defaultuntil [[ $setupmail == "yes" ]] || [[ $setupmail == "no" ]]; doecho -n " Q. Do you want to configure mail server settings? (y/n) "-read setupmail+read -r setupmailcase $setupmail in[yY] | [yY][Ee][Ss] )echo -n " Outgoing mailserver address:"- read mailhost- sed -i 's,^\(MAIL_HOST=\).*,\1'$mailhost',' $webdir/$name/.env+ read -r mailhost+ sed -i 's,^\(MAIL_HOST=\).*,\1'$mailhost',' "$webdir/$name/.env"echo -n " Server port number:"- read mailport- sed -i 's,^\(MAIL_PORT=\).*,\1'$mailport',' $webdir/$name/.env+ read -r mailport+ sed -i 's,^\(MAIL_PORT=\).*,\1'$mailport',' "$webdir/$name/.env"echo -n " Username:"- read mailusername- sed -i 's,^\(MAIL_USERNAME=\).*,\1'$mailusername',' $webdir/$name/.env+ read -r mailusername+ sed -i 's,^\(MAIL_USERNAME=\).*,\1'$mailusername',' "$webdir/$name/.env"echo -n " Password:"- read mailpassword- sed -i 's,^\(MAIL_PASSWORD=\).*,\1'$mailpassword',' $webdir/$name/.env+ read -rs mailpassword+ sed -i 's,^\(MAIL_PASSWORD=\).*,\1'$mailpassword',' "$webdir/$name/.env"echo -n " Encryption(null/TLS/SSL):"- read mailencryption- sed -i 's,^\(MAIL_ENCRYPTION=\).*,\1'$mailencryption',' $webdir/$name/.env+ read -r mailencryption+ sed -i 's,^\(MAIL_ENCRYPTION=\).*,\1'$mailencryption',' "$webdir/$name/.env"echo -n " From address:"- read mailfromaddr- sed -i 's,^\(MAIL_FROM_ADDR=\).*,\1'$mailfromaddr',' $webdir/$name/.env+ read -r mailfromaddr+ sed -i 's,^\(MAIL_FROM_ADDR=\).*,\1'$mailfromaddr',' "$webdir/$name/.env"echo -n " From name:"- read mailfromname- sed -i 's,^\(MAIL_FROM_NAME=\).*,\1'$mailfromname',' $webdir/$name/.env+ read -r mailfromname+ sed -i 's,^\(MAIL_FROM_NAME=\).*,\1'$mailfromname',' "$webdir/$name/.env"echo -n " Reply to address:"- read mailreplytoaddr- sed -i 's,^\(MAIL_REPLYTO_ADDR=\).*,\1'$mailreplytoaddr',' $webdir/$name/.env+ read -r mailreplytoaddr+ sed -i 's,^\(MAIL_REPLYTO_ADDR=\).*,\1'$mailreplytoaddr',' "$webdir/$name/.env"echo -n " Reply to name:"- read mailreplytoname- sed -i 's,^\(MAIL_REPLYTO_NAME=\).*,\1'$mailreplytoname',' $webdir/$name/.env+ read -r mailreplytoname+ sed -i 's,^\(MAIL_REPLYTO_NAME=\).*,\1'$mailreplytoname',' "$webdir/$name/.env"setupmail="yes";;[nN] | [n|N][O|o] )