Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various installer issues. #4096

Merged
merged 2 commits into from
Oct 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 62 additions & 58 deletions snipeit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ progress () {
done
}

#Used for Debian and Ubuntu
vhenvfile () {
find /etc/apache2/mods-enabled -maxdepth 1 -name 'rewrite.load' >/dev/null 2>&1
apachefile=/etc/apache2/sites-available/$name.conf
Expand All @@ -74,16 +75,16 @@ vhenvfile () {
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=$mysqluserpw
APP_URL=http://$fqdn
APP_KEY=$random32
EOF
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'$(cat /etc/timezone)',' $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 's,^\(APP_KEY=\).*,\1'$$random32',' $webdir/$name/.env
}

perms () {
Expand Down Expand Up @@ -173,7 +174,7 @@ echo ""

#Do you want to set your own passwords, or have me generate random ones?
until [[ $ans == "yes" ]] || [[ $ans == "no" ]]; do
echo -n " Q. Do you want me to automatically create the snipe database user password? (y/n) "
echo -n " Q. Do you want to automatically create the database user password? (y/n) "
read setpw

case $setpw in
Expand Down Expand Up @@ -306,7 +307,7 @@ case $distro in
webdir=/var/www/html
#Allow us to get the mysql engine
echo ""
echo "## Adding IUS, epel-release and mariaDB repos.";
echo "## Adding IUS, epel-release and mariaDB repositories.";
mariadbRepo=/etc/yum.repos.d/MariaDB.repo
touch "$mariadbRepo"
{
Expand All @@ -322,25 +323,23 @@ case $distro in
log "wget -P "$tmp/" https://centos6.iuscommunity.org/ius-release.rpm"
log "rpm -Uvh "$tmp/ius-release*.rpm""

#Install PHP and other needed stuff.
echo "## Installing PHP and other needed stuff";
PACKAGES="httpd MariaDB-server git unzip php56u php56u-mysqlnd php56u-bcmath php56u-cli php56u-common php56u-embedded php56u-gd php56u-mbstring php56u-mcrypt php56u-ldap"
#Install PHP and other needed stuff
echo "## Installing PHP 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
if isinstalled "$p"; then
echo " ## $p already installed"
else
echo -n " ## installing $p ... "
echo -n " ## Installing $p ... "
log "yum -y install $p"
echo "";
fi
done;

echo -e "\n## Downloading Snipe-IT from github and putting it in the web directory.";
echo -e "\n## Cloning Snipe-IT from github to the web directory.";

log "wget -P $tmp/ https://github.com/snipe/snipe-it/archive/$file"
unzip -qo $tmp/$file -d $tmp/
cp -R $tmp/$fileName $webdir/$name
log "git clone https://github.com/snipe/snipe-it $webdir/$name"

# Make mariaDB start on boot and restart the daemon
echo "## Starting the mariaDB server.";
Expand Down Expand Up @@ -387,17 +386,16 @@ case $distro in
tzone=$(grep ZONE /etc/sysconfig/clock | tr -d '"' | sed 's/ZONE=//g');
echo "## Configuring .env file."

cat > $webdir/$name/.env <<-EOF
#Created By Snipe-it Installer
APP_TIMEZONE=$tzone
DB_HOST=localhost
DB_DATABASE=snipeit
DB_USERNAME=snipeit
DB_PASSWORD=$mysqluserpw
APP_URL=http://$fqdn
APP_KEY=$random32
DB_DUMP_PATH='/usr/bin'
EOF
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 's,^\(APP_KEY=\).*,\1'$$random32',' $webdir/$name/.env

echo "## Configure composer"
cd $webdir/$name
Expand All @@ -417,35 +415,39 @@ case $distro in
fi

service httpd restart
php artisan key:generate
php artisan passport:install

echo "## Generating the application key."
php artisan key:generate --force

echo "## Artisan Migrate."
php artisan migrate --force

elif [[ "$version" =~ ^7 ]]; then
##################################### Install for Centos/Redhat 7 ##############################################

webdir=/var/www/html

#Allow us to get the mysql engine
echo -e "\n## Add IUS, epel-release and mariaDB repos.";
echo -e "\n## Adding IUS, epel-release and mariaDB repositories.";
log "yum -y install wget epel-release"
log "wget -P $tmp/ https://centos7.iuscommunity.org/ius-release.rpm"
log "rpm -Uvh $tmp/ius-release*.rpm"

#Install PHP and other needed stuff.
echo "## Installing PHP and other needed stuff";
PACKAGES="httpd mariadb-server git unzip php56u php56u-mysqlnd php56u-bcmath php56u-cli php56u-common php56u-embedded php56u-gd php56u-mbstring php56u-mcrypt php56u-ldap"
#Install PHP and other requirements
echo "## Installing PHP 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
if isinstalled "$p"; then
echo " ## $p already installed"
else
echo -n " ## installing $p ... "
echo -n " ## Installing $p ... "
log "yum -y install $p"
echo "";
fi
done;

echo -e "\n## Downloading Snipe-IT from github and put it in the web directory.";
echo -e "\n## Cloning Snipe-IT from github to the web directory.";

log "git clone https://github.com/snipe/snipe-it $webdir/$name"

Expand Down Expand Up @@ -500,44 +502,46 @@ case $distro in
tzone=$(timedatectl | gawk -F'[: ]' ' $9 ~ /zone/ {print $11}');
echo "## Configuring .env file."

cat > $webdir/$name/.env <<-EOF
#Created By Snipe-it Installer
APP_TIMEZONE=$tzone
DB_HOST=localhost
DB_DATABASE=snipeit
DB_USERNAME=snipeit
DB_PASSWORD=$mysqluserpw
APP_URL=http://$fqdn
APP_KEY=$random32
DB_DUMP_PATH='/usr/bin'
EOF

# Change permissions on directories
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 's,^\(APP_KEY=\).*,\1'$$random32',' $webdir/$name/.env

#Install / configure composer
cd $webdir/$name

curl -sS https://getcomposer.org/installer | php
php composer.phar install --no-dev --prefer-source

#Set permissions
perms
chown -R apache:apache $webdir/$name
# Make SeLinux happy
chcon -R -h -t httpd_sys_script_rw_t $webdir/$name/

#Check if SELinux is enforcing
if [ "$(getenforce)" == "Enforcing" ]; then
#Add SELinux and firewall exception/rules.
#Add SELinux and firewall exception/rules
#Required for ldap integration
setsebool -P httpd_can_connect_ldap on
#Sets SELinux context type so that scripts running in the web server process are allowed read/write access
chcon -R -h -t httpd_sys_script_rw_t $webdir/$name/
fi

systemctl restart httpd.service
php artisan key:generate
php artisan passport:install

echo "## Generating the application key."
php artisan key:generate --force

echo "## Artisan Migrate."
php artisan migrate --force

echo "## Creating scheduler cron."
(crontab -l ; echo "* * * * * /usr/bin/php $webdir/$name/artisan schedule:run >> /dev/null 2>&1") | crontab -

else
echo "Unable to Handle Centos Version #. Version Found: " $version
Expand All @@ -546,7 +550,7 @@ case $distro in
esac

echo ""
echo " ***If you want mail capabilities, edit $webdir/$name/.env and edit based on .env.example***"
echo " ***If you want mail capabilities, edit $webdir/$name/.env***"
echo ""
echo " ***Open http://$fqdn to login to Snipe-IT.***"
echo ""
Expand Down