<commit_before>#!/bin/bash

######################################################
#           Snipe-It Install Script                  #
#          Script created by <NAME>             #
#            <EMAIL>                   #
# This script is just to help streamline the         #
# install process for Debian and CentOS              #
# based distributions. I assume you will be          #
# installing as a subdomain on a fresh OS install.   #
# Right now I'm not going to worry about SMTP setup  #
#                                                    #
# Feel free to modify, but please give               #
# credit where it's due. Thanks!                     #
######################################################

# ensure running as root
if [ "$(id -u)" != "0" ]; then
  exec sudo "$0" "$@"
fi
#First things first, let's set some variables and find our distro.
clear

name="snipeit"
hostname="$(hostname)"
fqdn="$(hostname --fqdn)"
ans=default
hosts=/etc/hosts
file=master.zip
tmp=/tmp/$name
fileName=snipe-it-master

spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"

rm -rf ${tmp:?}
mkdir $tmp

# Debian/Ubuntu friendly f(x)s
progress () {
	while kill -0 "$pid" > /dev/null 2>&1
        do
        	for i in "${spin[@]}"
                do
                	if [ -e /proc/"$pid" ]; then
                        echo -ne "\b$i"
                        sleep .1
                        else
                        echo -ne "\n\b\n"
                        fi
                done
        done
}

vhenvfile () {
		find /etc/apache2/mods-enabled -maxdepth 1 -name 'rewrite.load' >/dev/null 2>&1
		apachefile=/etc/apache2/sites-available/$name.conf
		echo "* Create Virtual host for apache."
		{
			echo "<VirtualHost *:80>"
			echo "ServerAdmin webmaster@localhost"
			echo "<Directory $webdir/$name/public>"
			echo "        Require all granted"
			echo "        AllowOverride All"
			echo "   </Directory>"
			echo "    DocumentRoot $webdir/$name/public"
			echo "    ServerName $fqdn"
			echo "        ErrorLog /var/log/apache2/snipeIT.error.log"
			echo "        CustomLog /var/log/apache2/access.log combined"
			echo "</VirtualHost>"
		} >> $apachefile
		echo >> $hosts "127.0.0.1 $hostname $fqdn"
		log "a2ensite $name.conf"

		cat > "$webdir/$name/.env" <<-EOF
		#Created By Snipe-it Installer
		APP_TIMEZONE=$(cat /etc/timezone)
		DB_HOST=localhost
		DB_DATABASE=snipeit
		DB_USERNAME=snipeit
		DB_PASSWORD=$<PASSWORD>
		APP_URL=http://$fqdn
		APP_KEY=$random32
		EOF
}

perms () {
	chmod_dirs=( "$webdir/$name/storage" )
	chmod_dirs+=( "$webdir/$name/storage/private_uploads" )
	chmod_dirs+=( "$webdir/$name/public/uploads" )
	#Change permissions on directories
	for chmod_dir in "${chmod_dirs[@]}"
	do
		chmod -R 755 "$chmod_dir"
	done
}
    
log () {
	eval "$@" |& tee -a /var/log/snipeit-install.log >/dev/null 2>&1
}

#CentOS Friendly f(x)s
function isinstalled {
	if yum list installed "$@" >/dev/null 2>&1; then
		true
	else
		false
	fi
}

if [ -f /etc/lsb-release ]; then
	distro="$(lsb_release -s -i )"
	version="$(lsb_release -s -r)"
elif [ -f /etc/os-release ]; then
	distro="$(. /etc/os-release && echo $ID)"
	version="$(. /etc/os-release && echo $VERSION_ID)"
	#Order is important here.  If /etc/os-release and /etc/centos-release exist, we're on centos 7.
	#If only /etc/centos-release exist, we're on centos6(or earlier).  Centos-release is less parsable,
	#so lets assume that it's version 6 (Plus, who would be doing a new install of anything on centos5 at this point..)
elif [ -f /etc/centos-release ]; then
	distro="Centos"
	version="6"
else
	distro="unsupported"
fi


echo "
	   _____       _                  __________
	  / ___/____  (_)___  ___        /  _/_  __/
	  \__ \/ __ \/ / __ \/ _ \______ / /  / /
	 ___/ / / / / / /_/ /  __/_____// /  / /
	/____/_/ /_/_/ .___/\___/     /___/ /_/
	            /_/
"

echo ""
echo ""
echo "  Welcome to Snipe-IT Inventory Installer for Centos, Debian and Ubuntu!"
echo ""
shopt -s nocasematch
case $distro in
        *Ubuntu*)
                echo "  The installer has detected Ubuntu version $version as the OS."
                distro=ubuntu
                ;;
		*Debian*)
                echo "  The installer has detected Debian version $version as the OS."
                distro=debian
                ;;
        *centos*|*redhat*)
                echo "  The installer has detected $distro version $version as the OS."<commit_msg>Update snipeit.sh (#3620)<commit_after>#!/bin/bash

######################################################
#           Snipe-It Install Script                  #
#          Script created by <NAME>             #
#            <EMAIL>                   #
# This script is just to help streamline the         #
# install process for Debian and CentOS              #
# based distributions. I assume you will be          #
# installing as a subdomain on a fresh OS install.   #
# Right now I'm not going to worry about SMTP setup  #
#                                                    #
# Feel free to modify, but please give               #
# credit where it's due. Thanks!                     #
######################################################

# ensure running as root
if [ "$(id -u)" != "0" ]; then
  exec sudo "$0" "$@"
fi
#First things first, let's set some variables and find our distro.
clear

name="snipeit"
hostname="$(hostname)"
fqdn="$(hostname --fqdn)"
ans=default
hosts=/etc/hosts
file=master.zip
tmp=/tmp/$name
fileName=snipe-it-master

spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"

rm -rf ${tmp:?}
mkdir $tmp

# Debian/Ubuntu friendly f(x)s
progress () {
	while kill -0 "$pid" > /dev/null 2>&1
        do
        	for i in "${spin[@]}"
                do
                	if [ -e /proc/"$pid" ]; then
                        echo -ne "\b$i"
                        sleep .1
                        else
                        echo -ne "\n\b\n"
                        fi
                done
        done
}

vhenvfile () {
		find /etc/apache2/mods-enabled -maxdepth 1 -name 'rewrite.load' >/dev/null 2>&1
		apachefile=/etc/apache2/sites-available/$name.conf
		echo "* Create Virtual host for apache."
		{
			echo "<VirtualHost *:80>"
			echo "ServerAdmin webmaster@localhost"
			echo "<Directory $webdir/$name/public>"
			echo "        Require all granted"
			echo "        AllowOverride All"
			echo "   </Directory>"
			echo "    DocumentRoot $webdir/$name/public"
			echo "    ServerName $fqdn"
			echo "        ErrorLog /var/log/apache2/snipeIT.error.log"
			echo "        CustomLog /var/log/apache2/access.log combined"
			echo "</VirtualHost>"
		} >> $apachefile
		echo >> $hosts "127.0.0.1 $hostname $fqdn"
		log "a2ensite $name.conf"

		cat > "$webdir/$name/.env" <<-EOF
		#Created By Snipe-it Installer
		APP_TIMEZONE=$(cat /etc/timezone)
		DB_HOST=localhost
		DB_DATABASE=snipeit
		DB_USERNAME=snipeit
		DB_PASSWORD=$<PASSWORD>
		APP_URL=http://$fqdn
		APP_KEY=$random32
		EOF
}

perms () {
	chmod_dirs=( "$webdir/$name/storage" )
	chmod_dirs+=( "$webdir/$name/storage/private_uploads" )
	chmod_dirs+=( "$webdir/$name/public/uploads" )
	#Change permissions on directories
	for chmod_dir in "${chmod_dirs[@]}"
	do
		chmod -R 755 "$chmod_dir"
	done
}
    
log () {
	eval "$@" |& tee -a /var/log/snipeit-install.log >/dev/null 2>&1
}

#CentOS Friendly f(x)s
function isinstalled {
	if yum list installed "$@" >/dev/null 2>&1; then
		true
	else
		false
	fi
}

if [ -f /etc/lsb-release ]; then
	distro="$(lsb_release -s -i )"
	version="$(lsb_release -s -r)"
elif [ -f /etc/os-release ]; then
	distro="$(. /etc/os-release && echo $ID)"
	version="$(. /etc/os-release && echo $VERSION_ID)"
	#Order is important here.  If /etc/os-release and /etc/centos-release exist, we're on centos 7.
	#If only /etc/centos-release exist, we're on centos6(or earlier).  Centos-release is less parsable,
	#so lets assume that it's version 6 (Plus, who would be doing a new install of anything on centos5 at this point..)
elif [ -f /etc/centos-release ]; then
	distro="Centos"
	version="6"
else
	distro="unsupported"
fi


echo "
	   _____       _                  __________
	  / ___/____  (_)___  ___        /  _/_  __/
	  \__ \/ __ \/ / __ \/ _ \______ / /  / /
	 ___/ / / / / / /_/ /  __/_____// /  / /
	/____/_/ /_/_/ .___/\___/     /___/ /_/
	            /_/
"

echo ""
echo ""
echo "  Welcome to Snipe-IT Inventory Installer for Centos, Debian and Ubuntu!"
echo ""
shopt -s nocasematch
case $distro in
        *Ubuntu*)
                echo "  The installer has detected Ubuntu version $version as the OS."
                distro=ubuntu
                ;;
		*Debian*)
                echo "  The installer has detected Debian version $version as the OS."
                distro=debian
                ;;
        *centos*|*redhat*|*ol*)
                echo "  The installer has detected $distro version $version as the OS."
{'fraction_non_alphanumeric': 0.15908321101953257, 'fraction_numerical': 0.009484023935869933, 'mean_word_length': 2.0398078242964996, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4277304', 'n_tokens_mistral': 3193, 'n_tokens_neox': 2880, 'n_words': 783}