mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 22:37:28 -08:00
installer automation? (#5433)
* cli * less spaces! * rename functions * move progress spinner variables into progress () * $hosts was used in one place * missed this one * make testing snipeit.sh easier
This commit is contained in:
parent
d6d498bc8f
commit
6ad3d40216
68
Vagrantfile
vendored
Normal file
68
Vagrantfile
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
SNIPEIT_SH_URL= "https://raw.githubusercontent.com/snipe/snipe-it/master/snipeit.sh"
|
||||
NETWORK_BRIDGE= "en0: Wi-Fi (AirPort)"
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.define "xenial" do |xenial|
|
||||
xenial.vm.box = "ubuntu/xenial64"
|
||||
xenial.vm.hostname = 'xenial'
|
||||
xenial.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
xenial.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
xenial.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "trusty" do |trusty|
|
||||
trusty.vm.box = "ubuntu/trusty32"
|
||||
trusty.vm.hostname = 'trusty'
|
||||
trusty.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
trusty.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
trusty.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "centos7" do |centos7|
|
||||
centos7.vm.box = "centos/7"
|
||||
centos7.vm.hostname = 'centos7'
|
||||
centos7.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
centos7.vm.provision :shell, :inline => "sudo yum -y update"
|
||||
centos7.vm.provision :shell, :inline => "yum install -y wget"
|
||||
centos7.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
centos7.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "centos6" do |centos6|
|
||||
centos6.vm.box = "centos/6"
|
||||
centos6.vm.hostname = 'centos6'
|
||||
centos6.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
centos6.vm.provision :shell, :inline => "sudo yum -y update"
|
||||
centos6.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
centos6.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "jessie" do |jessie|
|
||||
jessie.vm.box = "debian/jessie64"
|
||||
jessie.vm.hostname = 'debian8'
|
||||
jessie.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
jessie.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
jessie.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "stretch" do |stretch|
|
||||
stretch.vm.box = "debian/stretch64"
|
||||
stretch.vm.hostname = 'debian9'
|
||||
stretch.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
stretch.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
stretch.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
|
||||
config.vm.define "fedora25" do |fedora25|
|
||||
fedora25.vm.box = "fedora/25-cloud-base"
|
||||
fedora25.vm.hostname = 'fedora25'
|
||||
fedora25.vm.network "public_network", bridge: NETWORK_BRIDGE
|
||||
fedora25.vm.provision :shell, :inline => "dnf -y update"
|
||||
fedora25.vm.provision :shell, :inline => "dnf -y install wget"
|
||||
fedora25.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
|
||||
fedora25.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
|
||||
end
|
||||
end
|
148
snipeit.sh
Normal file → Executable file
148
snipeit.sh
Normal file → Executable file
|
@ -1,4 +1,11 @@
|
|||
#!/bin/bash
|
||||
#/ Usage: sniepit [-vh]
|
||||
#/
|
||||
#/ Install Snipe-IT open source asset management.
|
||||
#/
|
||||
#/ OPTIONS:
|
||||
#/ -v | --verbose Enable verbose output.
|
||||
#/ -h | --help Show this message.
|
||||
|
||||
######################################################
|
||||
# Snipe-It Install Script #
|
||||
|
@ -13,6 +20,43 @@
|
|||
# credit where it's due. Thanks! #
|
||||
######################################################
|
||||
|
||||
# Parse arguments
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
show_help=true
|
||||
shift
|
||||
;;
|
||||
-v|--verbose)
|
||||
set -x
|
||||
verbose=true
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo "Error: invalid argument: '$1'" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
print_usage () {
|
||||
grep '^#/' <"$0" | cut -c 4-
|
||||
exit ${1:-1}
|
||||
}
|
||||
|
||||
if [ -n "$show_help" ]; then
|
||||
print_usage
|
||||
else
|
||||
for x in "$@"; do
|
||||
if [ "$x" = "--help" ] || [ "$x" = "-h" ]; then
|
||||
print_usage
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# ensure running as root
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
#Debian doesnt have sudo if root has a password.
|
||||
|
@ -27,17 +71,15 @@ fi
|
|||
clear
|
||||
|
||||
name="snipeit"
|
||||
verbose="false"
|
||||
hostname="$(hostname)"
|
||||
fqdn="$(hostname --fqdn)"
|
||||
hosts=/etc/hosts
|
||||
|
||||
progress () {
|
||||
spin[0]="-"
|
||||
spin[1]="\\"
|
||||
spin[2]="|"
|
||||
spin[3]="/"
|
||||
|
||||
progress () {
|
||||
echo -n " "
|
||||
while kill -0 "$pid" > /dev/null 2>&1; do
|
||||
for i in "${spin[@]}"; do
|
||||
|
@ -49,21 +91,21 @@ progress () {
|
|||
}
|
||||
|
||||
log () {
|
||||
if [ "$verbose" = true ]; then
|
||||
eval "$@"
|
||||
if [ -n "$verbose" ]; then
|
||||
eval "$@" |& tee -a /var/log/snipeit-install.log
|
||||
else
|
||||
eval "$@" |& tee -a /var/log/snipeit-install.log >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
installpackages () {
|
||||
install_packages () {
|
||||
case $distro in
|
||||
ubuntu|debian)
|
||||
for p in $PACKAGES; do
|
||||
if dpkg -s "$p" >/dev/null 2>&1; then
|
||||
echo " * $p already installed"
|
||||
else
|
||||
echo " * Installing $p ... "
|
||||
echo " * Installing $p"
|
||||
log "DEBIAN_FRONTEND=noninteractive apt-get install -y $p"
|
||||
fi
|
||||
done;
|
||||
|
@ -73,7 +115,7 @@ installpackages () {
|
|||
if yum list installed "$p" >/dev/null 2>&1; then
|
||||
echo " * $p already installed"
|
||||
else
|
||||
echo " * Installing $p ... "
|
||||
echo " * Installing $p"
|
||||
log "yum -y install $p"
|
||||
fi
|
||||
done;
|
||||
|
@ -83,7 +125,7 @@ installpackages () {
|
|||
if dnf list installed "$p" >/dev/null 2>&1; then
|
||||
echo " * $p already installed"
|
||||
else
|
||||
echo " * Installing $p ... "
|
||||
echo " * Installing $p"
|
||||
log "dnf -y install $p"
|
||||
fi
|
||||
done;
|
||||
|
@ -91,7 +133,7 @@ installpackages () {
|
|||
esac
|
||||
}
|
||||
|
||||
createvh () {
|
||||
create_virtualhost () {
|
||||
{
|
||||
echo "<VirtualHost *:80>"
|
||||
echo " <Directory $webdir/$name/public>"
|
||||
|
@ -106,7 +148,7 @@ createvh () {
|
|||
} >> "$apachefile"
|
||||
}
|
||||
|
||||
installsnipeit () {
|
||||
install_snipeit () {
|
||||
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';"
|
||||
|
@ -148,7 +190,7 @@ installsnipeit () {
|
|||
(crontab -l ; echo "* * * * * /usr/bin/php $webdir/$name/artisan schedule:run >> /dev/null 2>&1") | crontab -
|
||||
}
|
||||
|
||||
openfirewalld () {
|
||||
set_firewall () {
|
||||
if [ "$(firewall-cmd --state)" == "running" ]; then
|
||||
echo "* Configuring firewall to allow HTTP traffic only."
|
||||
log "firewall-cmd --zone=public --add-port=http/tcp --permanent"
|
||||
|
@ -156,7 +198,7 @@ openfirewalld () {
|
|||
fi
|
||||
}
|
||||
|
||||
configureselinux () {
|
||||
set_selinux () {
|
||||
#Check if SELinux is enforcing
|
||||
if [ "$(getenforce)" == "Enforcing" ]; then
|
||||
echo "* Configuring SELinux."
|
||||
|
@ -167,15 +209,15 @@ configureselinux () {
|
|||
fi
|
||||
}
|
||||
|
||||
sethostfile () {
|
||||
set_hosts () {
|
||||
echo "* Setting up hosts file."
|
||||
echo >> $hosts "127.0.0.1 $hostname $fqdn"
|
||||
echo >> /etc/hosts "127.0.0.1 $hostname $fqdn"
|
||||
}
|
||||
|
||||
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)"
|
||||
distro="$(lsb_release -is)"
|
||||
version="$(lsb_release -rs)"
|
||||
codename="$(lsb_release -cs)"
|
||||
elif [ -f /etc/os-release ]; then
|
||||
distro="$(. /etc/os-release && echo $ID)"
|
||||
version="$(. /etc/os-release && echo $VERSION_ID)"
|
||||
|
@ -275,23 +317,22 @@ case $distro in
|
|||
|
||||
echo "* Installing Apache httpd, PHP, MariaDB and other requirements."
|
||||
PACKAGES="mariadb-server mariadb-client apache2 libapache2-mod-php php php-mcrypt php-curl php-mysql php-gd php-ldap php-zip php-mbstring php-xml php-bcmath curl git unzip"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
log "a2enmod rewrite"
|
||||
log "a2ensite $name.conf"
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
echo "* Restarting Apache httpd."
|
||||
log "service apache2 restart"
|
||||
|
||||
elif [[ "$version" =~ ^8 ]]; then
|
||||
##################################### Install for Debian 8 ##############################################
|
||||
webdir=/var/www
|
||||
|
@ -315,23 +356,22 @@ case $distro in
|
|||
|
||||
echo "* Installing Apache httpd, PHP, MariaDB and other requirements."
|
||||
PACKAGES="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"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
log "a2enmod rewrite"
|
||||
log "a2ensite $name.conf"
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
echo "* Restarting Apache httpd."
|
||||
log "service apache2 restart"
|
||||
|
||||
else
|
||||
echo "Unsupported Debian version. Version found: $version"
|
||||
exit 1
|
||||
|
@ -357,16 +397,16 @@ case $distro in
|
|||
|
||||
echo "* Installing Apache httpd, PHP, MariaDB and other requirements."
|
||||
PACKAGES="mariadb-server mariadb-client apache2 libapache2-mod-php php php-mcrypt php-curl php-mysql php-gd php-ldap php-zip php-mbstring php-xml php-bcmath curl git unzip"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
log "phpenmod mcrypt"
|
||||
log "phpenmod mbstring"
|
||||
log "a2enmod rewrite"
|
||||
log "a2ensite $name.conf"
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Starting MariaDB."
|
||||
log "service mysql start"
|
||||
|
@ -374,11 +414,10 @@ case $distro in
|
|||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
echo "* Restarting Apache httpd."
|
||||
log "service apache2 restart"
|
||||
|
||||
elif [[ "$version" =~ 14 ]]; then
|
||||
##################################### Install for Ubuntu 14 ##############################################
|
||||
webdir=/var/www
|
||||
|
@ -400,16 +439,16 @@ case $distro in
|
|||
|
||||
echo "* Installing Apache httpd, PHP, MariaDB and other requirements."
|
||||
PACKAGES="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"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
log "phpenmod mcrypt"
|
||||
log "phpenmod mbstring"
|
||||
log "a2enmod rewrite"
|
||||
log "a2ensite $name.conf"
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Starting MariaDB."
|
||||
log "service mysql start"
|
||||
|
@ -417,11 +456,10 @@ case $distro in
|
|||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
echo "* Restarting Apache httpd."
|
||||
log "service apache2 restart"
|
||||
|
||||
else
|
||||
echo "Unsupported Ubuntu version. Version found: $version"
|
||||
exit 1
|
||||
|
@ -453,21 +491,21 @@ case $distro in
|
|||
|
||||
echo "* 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 php71u-process"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
|
||||
echo "* Setting MariaDB to start on boot and starting MariaDB."
|
||||
log "chkconfig mysql on"
|
||||
log "/sbin/service mysql start"
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
if /sbin/service iptables status >/dev/null 2>&1; then
|
||||
echo "* Configuring iptables."
|
||||
|
@ -479,7 +517,6 @@ case $distro in
|
|||
echo "* Setting Apache httpd to start on boot and starting service."
|
||||
log "chkconfig httpd on"
|
||||
log "/sbin/service httpd start"
|
||||
|
||||
elif [[ "$version" =~ ^7 ]]; then
|
||||
##################################### Install for CentOS/Redhat 7 ##############################################
|
||||
webdir=/var/www/html
|
||||
|
@ -494,12 +531,12 @@ case $distro in
|
|||
|
||||
echo "* 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 php71u-process"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Setting MariaDB to start on boot and starting MariaDB."
|
||||
log "systemctl enable mariadb.service"
|
||||
|
@ -508,16 +545,15 @@ case $distro in
|
|||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
openfirewalld
|
||||
set_firewall
|
||||
|
||||
configureselinux
|
||||
set_selinux
|
||||
|
||||
echo "* Setting Apache httpd to start on boot and starting service."
|
||||
log "systemctl enable httpd.service"
|
||||
log "systemctl restart httpd.service"
|
||||
|
||||
else
|
||||
echo "Unsupported CentOS version. Version found: $version"
|
||||
exit 1
|
||||
|
@ -532,12 +568,12 @@ case $distro in
|
|||
|
||||
echo "* Installing Apache httpd, PHP, MariaDB and other requirements."
|
||||
PACKAGES="httpd mariadb-server git unzip php php-mysqlnd php-bcmath php-cli php-common php-embedded php-gd php-mbstring php-mcrypt php-ldap php-json php-simplexml"
|
||||
installpackages
|
||||
install_packages
|
||||
|
||||
echo "* Configuring Apache."
|
||||
createvh
|
||||
create_virtualhost
|
||||
|
||||
sethostfile
|
||||
set_hosts
|
||||
|
||||
echo "* Setting MariaDB to start on boot and starting MariaDB."
|
||||
log "systemctl enable mariadb.service"
|
||||
|
@ -546,11 +582,11 @@ case $distro in
|
|||
echo "* Securing MariaDB."
|
||||
/usr/bin/mysql_secure_installation
|
||||
|
||||
installsnipeit
|
||||
install_snipeit
|
||||
|
||||
openfirewalld
|
||||
set_firewall
|
||||
|
||||
configureselinux
|
||||
set_selinux
|
||||
|
||||
echo "* Setting Apache httpd to start on boot and starting service."
|
||||
log "systemctl enable httpd.service"
|
||||
|
|
Loading…
Reference in a new issue