From be3f9aff0beb76898d59cdc583ea49d287b6884f Mon Sep 17 00:00:00 2001 From: efelon Date: Tue, 2 Apr 2019 23:11:19 +0200 Subject: [PATCH] Refactor folder structure and adding first seqs --- README.md | 4 + seqs/gitea.sh | 134 ++++++++++++++++++++++ seqs/librenms.sh | 152 +++++++++++++++++++++++++ sequencer.sh => sequencer/sequencer.sh | 0 stepTemplate.sh | 2 +- 5 files changed, 291 insertions(+), 1 deletion(-) create mode 100755 seqs/gitea.sh create mode 100755 seqs/librenms.sh rename sequencer.sh => sequencer/sequencer.sh (100%) diff --git a/README.md b/README.md index bda69df..feea913 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,7 @@ Main sequencer script to be included at the end of a step definition script. [...] . ./sequencer.sh + +## seqs/ + +Contains sequences (seqs) for different tools, servers or occasions. diff --git a/seqs/gitea.sh b/seqs/gitea.sh new file mode 100755 index 0000000..bc0a9c4 --- /dev/null +++ b/seqs/gitea.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +# +## Installation of git service Gitea + +toolName="gitea" +giteaDownload="https://dl.gitea.io/gitea/1.7.5/gitea-1.7.5-linux-arm-7" +giteaService="https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service" +giteaServiceLoc="/etc/systemd/system/gitea.service" + +function step_1 { + echo -e "Updating apt\n" + apt update +} + +function step_2 { + echo -e "Downloading $toolName to user home: $giteaDownload\n" + cd + wget -O gitea $giteaDownload + saveReturn $? + endReturn +} + +function step_3 { + echo -e "Adding user for $toolName (git:git)" + adduser \ + --system \ + --shell /bin/bash \ + --gecos 'Git Version Control' \ + --group \ + --disabled-password \ + --home /home/git \ + git + saveReturn $? + endReturn +} + +function step_4 { + echo -e "Create required directory structure" + mkdir -p /var/lib/gitea/{custom,data,log} + chown -R git: /var/lib/gitea/ + chmod -R 750 /var/lib/gitea/ + mkdir /etc/gitea + chown root:git /etc/gitea + chmod 770 /etc/gitea + echo "Copying gitea to global location and making it executable" + chmod +x ~/gitea + cp ~/gitea /usr/local/bin/gitea + saveReturn $? + endReturn +} + +function step_5 { + echo -e "Creating systemd service" + wget -O $giteaServiceLoc $giteaService + echo -en "Uncomment needed services (enter to continue): " + read + vi $giteaServiceLoc +} + +function step_6 { + echo -e "Starting $toolName service" + systemctl enable gitea + systemctl start gitea + echo "Before proceeding to installation you may need to create a database first with step 10" + echo + echo "Goto http://[yourip]:3000/install and complete installation" + echo + echo "Afterwards please execute step 20 to secure configuration" +} + + + +function step_10 { + local mysqlDatabase + local mysqlUser + local mysqlPass + + echo "Setup mysql database" + echo "Existing mysql databases:" + mysql -u root -e 'SHOW DATABASES;' + + echo -en "Enter database name: " + read mysqlDatabase + endCheckEmpty mysqlDatabase "database name" + mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' + saveReturn $? + endReturn + + echo "Existing mysql user:" + mysql -u root -e 'SELECT User, Host FROM mysql.user;' + echo -en "Enter mysql user name: " + read mysqlUser + endCheckEmpty mysqlDatabase "user name" + + echo -en "Enter mysql user password: " + read mysqlPass + endCheckEmpty mysqlPass "password" + mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' + saveReturn $? + endReturn + + mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' + saveReturn $? + endReturn + + mysql -u root -e 'FLUSH PRIVILEGES;' +} + +function step_20 { + echo -e "Secure settings after installation" + chmod 750 /etc/gitea + chmod 644 /etc/gitea/app.ini +} + +help() { + echo " $toolName Documentation" + echo " 1: Updating apt" + echo " 2: Downloading $toolName to user home: $giteaDownload" + echo " 3: Adding user for $toolName (git:git)" + echo " 4: Create required directory structure" + echo " 5: Creating systemd service" + echo " 6: Starting $toolName service" + echo + echo " 10: Setup mysql database" + echo + echo " 20: Secure settings after installation" + echo +} + + +# +## Path to sequencer +. ../sequencer/sequencer.sh diff --git a/seqs/librenms.sh b/seqs/librenms.sh new file mode 100755 index 0000000..00c7841 --- /dev/null +++ b/seqs/librenms.sh @@ -0,0 +1,152 @@ +#!/bin/bash + +# +## Installation and maintenance for LibreNMS +## Using buster repositories for php 7.3 installation + +librePhpDeps="composer php-cli-prompt php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-json-schema php-psr-log php-symfony-console php-symfony-filesystem php-symfony-finder php-symfony-polyfill-mbstring php-symfony-process" +librePackages="fping git graphviz imagemagick mtr-tiny nmap python-memcache python-mysqldb rrdtool snmp snmpd whoisi nagios-plugins" + + +function step_1 { + echo -e "Updating apt\n" + #apt update +} + +function step_2 { + echo -e "Installing: $librePackages\n" + apt install $librePackages + saveReturn $? + endReturn +} + +function step_3 { + echo -e "Installing -t buster PHP related packages\n$librePhpDeps\n" + apt -t buster install $librePhpDeps + saveReturn $? + endReturn +} + +function step_4 { + echo -e "Adding librenms user" + useradd librenms -d /opt/librenms -M -r + saveReturn $? + usermod -a -G librenms www-data + saveReturn $? + endReturn +} + +function step_5 { + echo -e "Installing librenms using composer" + cd /opt + composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master + saveReturn $? + endReturn +} + +function step_10 { + local mysqlDatabase + local mysqlUser + local mysqlPass + + echo "Setup mysql database" + echo "Existing mysql databases:" + mysql -u root -e 'SHOW DATABASES;' + + echo -en "Enter database name: " + read mysqlDatabase + endCheckEmpty mysqlDatabase "database name" + mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8 COLLATE utf8_unicode_ci;' + saveReturn $? + endReturn + + echo "Existing mysql user:" + mysql -u root -e 'SELECT User, Host FROM mysql.user;' + echo -en "Enter mysql user name: " + read mysqlUser + endCheckEmpty mysqlDatabase "user name" + + echo -en "Enter mysql user password: " + read mysqlPass + endCheckEmpty mysqlPass "password" + mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' + saveReturn $? + endReturn + + mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' + saveReturn $? + endReturn + + mysql -u root -e 'FLUSH PRIVILEGES;' +} + +function step_11 { + echo "MariaDB configuration" + echo "Edit or create /etc/mysql/mariadb.conf.d/90-myconfig.cnf and add:" + echo + echo "------------------------" + echo "[mysqld]" + echo "innodb_file_per_table=1" + echo "lower_case_table_names=0" + echo "------------------------" + echo + echo "Restart mysql afterwards:" + echo "service mysql restart" +} + +function step_12 { + echo "PHP fpm/cli configuration" + echo "Ensure date.timezone is set in php.ini to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid examples are: \"America/New_York\", \"Europe/Berlin\", \"Etc/UTC\"." + echo + echo "vi /etc/php/7.3/fpm/conf.d/90-custom_pi.ini" + echo "vi /etc/php/7.3/cli/php.ini" + echo + echo "-------------------------------------------" + echo "date.timezone = Europe/Berlin" + echo "-------------------------------------------" + echo + echo "Restart php-fpm afterwards:" + echo "service php7.3-fpm restart" +} + +function step_40 { + echo "Switch Librenms installation to monthly stable" + echo + echo "Add following to /opt/librenms/config.php" + echo + echo "--------------------------------------" + echo "\$config['update_channel'] = 'release';" + echo "--------------------------------------" + echo + echo "Execute following command afterwards:" + echo "cd /opt/librenms && git fetch --tags && git checkout \$(git describe --tags \$(git rev-list --tags --max-count=1))" +} + +function step_42 { + echo "Fix librenms permission" + chown -R librenms:librenms /opt/librenms + + setfacl -d -m g::rwx /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd + + chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd +} + +help() { + echo " Step Documentation" + echo " 1: Updating apt" + echo -e " 2: Install packages:\n\t$librePackages" + echo -e " 3: Installing -t buster PHP related packages:\n\t$librePhpDeps" + echo " 4: Adding librenms user" + echo " 5: Installing librenms using composer" + echo + echo " 10: Setup mysql database" + echo " 11: MariaDB configuration" + echo " 12: PHP fpm/cli configuration" + echo + echo " 40: Switch Librenms installation to monthly stable" + echo " 42: Fix librenms permission" +} + +# +## Path to sequencer +. ../sequencer/sequencer.sh diff --git a/sequencer.sh b/sequencer/sequencer.sh similarity index 100% rename from sequencer.sh rename to sequencer/sequencer.sh diff --git a/stepTemplate.sh b/stepTemplate.sh index a7a5806..6977f0f 100755 --- a/stepTemplate.sh +++ b/stepTemplate.sh @@ -46,4 +46,4 @@ help() { # ## Path to local sequencer.sh script -. ./sequencer.sh +. ./sequencer/sequencer.sh