├── .editorconfig ├── LICENSE ├── README.md ├── apps ├── ioncube │ ├── README.md │ └── ioncube.sh ├── phpmyadmin │ ├── README.md │ └── update.sh └── unbound │ ├── README.md │ ├── dns.conf │ ├── unbound.sh │ └── update-root-hints.sh ├── backup └── mysqldump │ ├── README.md │ └── mysqldump.sh ├── cryptocurrency ├── xmrig │ ├── README.md │ ├── install.sh │ └── update-source.sh └── xmrigCC │ ├── README.md │ ├── install.sh │ ├── update-xmrigcc.sh │ └── xmrigcc.service ├── easyengine └── secure-22222 │ ├── 22222.sh │ └── README.md ├── mail └── imapsync │ ├── README.md │ ├── credentials.csv │ └── imapsync-from-csv.sh └── wp-cli └── https-migrate ├── README.md └── migrate.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = false -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 VirtuBox 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bash-scripts collection 2 | 3 | A collection of bash scripts 4 | 5 | ## App 6 | 7 | * [phpmyadmin update](https://github.com/VirtuBox/bash-scripts/tree/master/apps/phpmyadmin) : update phpmyadmin to the latest release with EasyEngine 8 | * [ioncube installer](https://github.com/VirtuBox/bash-scripts/tree/master/apps/ioncube) : install ioncube loader on ubuntu 9 | 10 | ## Backup 11 | 12 | * [mysqldump](https://github.com/VirtuBox/bash-scripts/blob/master/backup/mysqldump/) : dump each MySQL database or to perform a full dump. Work on almost all linux servers and support Plesk. 13 | 14 | ## Mail 15 | 16 | * [imapsync from csv](https://github.com/VirtuBox/bash-scripts/blob/master/mail/imapsync/) : migrate emails between two imap servers by reading users credentials in a csv file using imapsync 17 | 18 | ## Cryptocurrency 19 | 20 | * [xmrigCC compilation](https://github.com/VirtuBox/bash-scripts/tree/master/cryptocurrency/xmrigCC) : compile xmrig from source on Ubuntu 16.04/18.04 LTS 21 | * [xmrig compilation](https://github.com/VirtuBox/bash-scripts/tree/master/cryptocurrency/xmrig) : compile xmrig from source on Ubuntu 16.04/18.04 LTS 22 | 23 | ## WP-CLI 24 | 25 | * [https migration](https://github.com/VirtuBox/bash-scripts/tree/master/wp-cli/https-migrate) : bash script to migrate from http to https using WP-CLI 26 | -------------------------------------------------------------------------------- /apps/ioncube/README.md: -------------------------------------------------------------------------------- 1 | # Ioncube loader installer 2 | 3 | ## Install ioncube loader for php5.6, php7.0, php7.1 or php7.2 on Ubuntu 4 | 5 | * tested on Ubuntu 16.04 LTS & 18.04 LTS 6 | 7 | ### Usage 8 | 9 | ```bash 10 | bash <(wget -qO - vtb.cx/ioncube) 11 | ``` 12 | 13 | Example for php7.0 : 14 | 15 | ```bash 16 | bash <(wget -qO - vtb.cx/ioncube) 7.0 17 | ``` 18 | 19 | If php version is not set as argument, the script will automatically install ioncube for the newest php version installed 20 | 21 | -------------------------------------------------------------------------------- /apps/ioncube/ioncube.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # check if a command exist 4 | command_exists() { 5 | command -v "$@" >/dev/null 2>&1 6 | } 7 | 8 | if ! command_exists curl; then 9 | "curl isn't installed and is required" 10 | exit 1 11 | fi 12 | 13 | cd /tmp || exit 1 14 | rm -rf /tmp/ioncube 15 | 16 | if [ -n "$1" ]; then 17 | if [ -x "/usr/bin/php$1" ]; then 18 | PHP_VER="$1" 19 | else 20 | echo "php$1 isn't installed" 21 | exit 1 22 | fi 23 | else 24 | if [ -x "/usr/bin/php" ]; then 25 | PHP_VER=$(readlink -f /etc/alternatives/php | awk -F "/usr/bin/php" '{print $2}') 26 | fi 27 | fi 28 | 29 | EXTENSION_DIR=$(/usr/bin/php${PHP_VER} -i | grep extension_dir | grep /usr/lib | awk -F "=> " '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') 30 | 31 | curl -sSL https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz | tar -xzf - -C /tmp 32 | cd /tmp/ioncube || exit 1 33 | cp ioncube_loader_lin_${PHP_VER}.so "${EXTENSION_DIR}/" -f 34 | 35 | if [ ! -f "${EXTENSION_DIR}/ioncube_loader_lin_${PHP_VER}.so" ]; then 36 | exit 1 37 | fi 38 | 39 | if ! grep -q "ioncube" -r /etc/php/${PHP_VER}/mods-available; then 40 | echo -e "; configuration for php ioncube loader\n; priority=00\nzend_extension=ioncube_loader_lin_${PHP_VER}.so" >/etc/php/${PHP_VER}/mods-available/ioncube-loader.ini 41 | fi 42 | if ! grep -q "ioncube" -R /etc/php/${PHP_VER}/fpm/conf.d; then 43 | phpenmod -v "$PHP_VER" ioncube-loader 44 | fi 45 | if ! grep -q "ioncube" -R /etc/php/${PHP_VER}/cli/conf.d; then 46 | phpenmod -v "$PHP_VER" ioncube-loader 47 | fi 48 | 49 | service php${PHP_VER}-fpm restart 50 | cd || exit 1 51 | rm -rf /tmp/ioncube 52 | -------------------------------------------------------------------------------- /apps/phpmyadmin/README.md: -------------------------------------------------------------------------------- 1 | # update phpmyadmin with EasyEngine 2 | 3 | ```bash 4 | bash <(wget -O - https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/apps/phpmyadmin/update.sh) 5 | ``` 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /apps/phpmyadmin/update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PHPMYADMIN_VERSION="4.9.0.1" 3 | 4 | if [ "$(id -u)" != "0" ]; then 5 | echo "Error: You must be root to run this script, please use the root user to install the software." 6 | echo "" 7 | echo "Use 'sudo su - root' to login as root" 8 | exit 1 9 | fi 10 | 11 | cd /var/www/22222/htdocs/db/ || exit 1 12 | wget -O phpmyadmin.zip https://files.phpmyadmin.net/phpMyAdmin/$PHPMYADMIN_VERSION/phpMyAdmin-$PHPMYADMIN_VERSION-all-languages.zip 13 | 14 | unzip phpmyadmin.zip && rm phpmyadmin.zip 15 | mv pma/config.inc.php . 16 | cp -rf phpMyAdmin-$PHPMYADMIN_VERSION-all-languages/* pma/ 17 | mv config.inc.php pma/ 18 | rm -rf phpMyAdmin-$PHPMYADMIN_VERSION-all-languages 19 | 20 | sudo chown -R www-data:www-data pma 21 | -------------------------------------------------------------------------------- /apps/unbound/README.md: -------------------------------------------------------------------------------- 1 | # Unbound Install Script 2 | 3 | ```bash 4 | bash <(wget -O - raw.githubusercontent.com/VirtuBox/bash-scripts/master/apps/unbound/unbound.sh) 5 | ``` 6 | -------------------------------------------------------------------------------- /apps/unbound/dns.conf: -------------------------------------------------------------------------------- 1 | server: 2 | verbosity: 1 3 | use-syslog: no 4 | logfile: "/var/log/unbound.log" 5 | log-time-ascii: yes 6 | 7 | num-threads: 2 8 | 9 | # Parametres par defaut qu'on laisse pour s'en souvenir 10 | interface: 127.0.0.1 11 | interface: ::1 12 | do-ip4: yes 13 | do-ip6: yes 14 | do-udp: yes 15 | do-tcp: yes 16 | 17 | root-hints: "/var/lib/unbound/root.hints" 18 | 19 | harden-referral-path: yes 20 | use-caps-for-id: yes 21 | hide-identity: yes 22 | hide-version: yes 23 | harden-glue: yes 24 | harden-dnssec-stripped: yes 25 | 26 | # the time to live (TTL) value lower bound, in seconds. Default 0. 27 | # If more than an hour could easily give trouble due to stale data. 28 | # WARNING : against protocol rule but efficient against stupidly too low TTLs 29 | 30 | cache-min-ttl: 3600 31 | 32 | # the time to live (TTL) value cap for RRsets and messages in the 33 | # cache. Items are not cached for longer. In seconds. 34 | cache-max-ttl: 86400 35 | 36 | prefetch: yes 37 | 38 | # If nonzero, unwanted replies are not only reported in statistics, but also 39 | # a running total is kept per thread. If it reaches the threshold, a warning 40 | # is printed and a defensive action is taken, the cache is cleared to flush 41 | # potential poison out of it. A suggested value is 10000000, the default is 42 | # 0 (turned off). We think 10K is a good value. 43 | unwanted-reply-threshold: 10000 44 | 45 | # Should additional section of secure message also be kept clean of unsecure 46 | # data. Useful to shield the users of this validator from potential bogus 47 | # data in the additional section. All unsigned data in the additional section 48 | # is removed from secure messages. 49 | 50 | val-clean-additional: yes 51 | 52 | # Log validation failures 53 | val-log-level: 2 54 | 55 | statistics-interval: 0 56 | extended-statistics: yes 57 | statistics-cumulative: yes 58 | 59 | # Qname minimization, harden-below-nxdomain is recommanded, see manpage for 60 | # details & https://unbound.net/pipermail/unbound-users/2015-December/004129.html and RFC 8020 61 | harden-below-nxdomain: yes 62 | qname-minimisation: yes 63 | 64 | private-address: 10.0.0.0/8 65 | private-address: 172.16.0.0/12 66 | private-address: 192.168.0.0/16 67 | private-address: 169.254.0.0/16 68 | private-address: fd00::/8 69 | private-address: fe80::/10 -------------------------------------------------------------------------------- /apps/unbound/unbound.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | apt-get update && apt-get install unbound -y 4 | 5 | wget https://www.internic.net/domain/named.cache -O /var/lib/unbound/root.hints 6 | 7 | chown unbound: /var/lib/unbound/root.hints 8 | chmod 644 /var/lib/unbound/root.hints 9 | 10 | wget -O /etc/unbound/unbound.conf.d/dns.conf https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/apps/unbound/dns.conf 11 | 12 | 13 | touch /var/log/unbound.log 14 | chown unbound: /var/log/unbound.log 15 | 16 | service unbound restart 17 | -------------------------------------------------------------------------------- /apps/unbound/update-root-hints.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Source : https://www.shaftinc.fr/arretez-google-dns.html 4 | 5 | TmpName=$(mktemp) 6 | TmpDiff=$(mktemp) 7 | TmpErr=$(mktemp) 8 | REPORT_EMAIL="admin" 9 | URL="https://www.internic.net/domain/named.cache" 10 | 11 | wget -nv $URL -O $TmpName 2> $TmpErr 12 | 13 | # On intercepte toute erreur 14 | # et on stoppe le script dans ce cas 15 | # On continue sinon 16 | 17 | if [ "$?" -ne 0 ];then 18 | printf "\nScript was stopped at this point. A manual action may be required.\n" >> $TmpErr 19 | mail -s "[DNS - $(uname -n)] Root hints file download failed" $REPORT_EMAIL < $TmpErr 20 | rm $TmpErr 21 | rm $TmpDiff 22 | rm $TmpName 23 | exit 0 24 | else 25 | rm $TmpErr 26 | shaTMP=$(sha512sum $TmpName | awk '{print $1}') 27 | shaHINTS=$(sha512sum /var/lib/unbound/root.hints | awk '{print $1}') 28 | 29 | if [ $shaTMP = $shaHINTS ]; then 30 | # Si le fichier récupéré est identique à celui 31 | # utilisé par Unbound, on fait... rien 32 | rm $TmpName 33 | exit 0 34 | else 35 | printf "A new root hints file was spotted on InterNIC server.\nFile downloaded and old root.hints file replaced.\nHere is the diff:\n\n" > $TmpDiff 36 | diff $TmpName /var/lib/unbound/root.hints >> $TmpDiff 37 | printf "\n\n" >> $TmpDiff 38 | mv -f $TmpName /var/lib/unbound/root.hints 39 | chown unbound: /var/lib/unbound/root.hints 40 | chmod 644 /var/lib/unbound/root.hints 41 | sleep 5 42 | service unbound restart 43 | printf "Unbound status is $(service unbound status | grep Active | awk '{print $2 " " $3}')\n" >> $TmpDiff 44 | mail -s "[DNS - $(uname -n)] Update in Root Hints" $REPORT_EMAIL < $TmpDiff 45 | rm $TmpDiff 46 | fi 47 | fi 48 | exit 0 -------------------------------------------------------------------------------- /backup/mysqldump/README.md: -------------------------------------------------------------------------------- 1 | # MySQLDump Backup Script 2 | 3 | ## Download the script 4 | 5 | ```bash 6 | wget https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/backup/mysqldump/mysqldump.sh -O mysqldump.sh 7 | chmod +x mysqldump.sh 8 | ``` 9 | 10 | ## Optional 11 | 12 | Install pigz for multithreaded compression 13 | 14 | ```bash 15 | sudo apt update && apt install pigz -y 16 | ``` 17 | 18 | ## Add cronjob 19 | 20 | ```bash 21 | crontab -e 22 | 23 | # every 6 hours 24 | 0 */6 * * * /root/mysqldump.sh > /dev/null 2>&1 25 | 26 | # every 12 hours 27 | 0 */12 * * * /root/mysqldump.sh > /dev/null 2>&1 28 | 29 | # every 24 hours 30 | @daily /root/mysqldump.sh > /dev/null 2>&1 31 | 32 | ``` 33 | -------------------------------------------------------------------------------- /backup/mysqldump/mysqldump.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ------------------------------------------------------------------------- 3 | # Modified First By: Mitesh Shah 4 | # Then Modified By : VirtuBox 5 | # Copyright (c) 2007 Vivek Gite 6 | # This script is licensed under GNU GPL version 2.0 or above 7 | # ------------------------------------------------------------------------- 8 | # This script is part of nixCraft shell script collection (NSSC) 9 | # Visit http://bash.cyberciti.biz/ for more information. 10 | # ------------------------------------------------------------------------- 11 | 12 | ### Enable Log = 1 ### 13 | LOGS=1 14 | 15 | ### Default Time Format ### 16 | TIME_FORMAT='%d-%b-%Y-%H%M%S' 17 | 18 | ### Setup Dump And Log Directory ### 19 | MYSQLDUMPPATH=/var/www/mysqldump 20 | MYSQLFULLDUMPPATH="$MYSQLDUMPPATH/full" 21 | MYSQLDUMPLOG=/var/log/mysqldump.log 22 | EXTRA_PARAMS="" 23 | 24 | ### Remove Backup older than X days ### 25 | DAYSOLD=3 26 | 27 | ### Backup all-databases in a single file ### 28 | ALLDB=0 29 | SINGLE_DB=1 30 | 31 | if [ -d /etc/psa ]; then 32 | readonly MYSQL_PWD=$(cat /etc/psa/.psa.shadow) 33 | MSQL_USER="-uadmin" 34 | else 35 | MSQL_USER="" 36 | fi 37 | 38 | ### Add help menu 39 | _help() { 40 | echo "Backup MySQL databases using mysqldump" 41 | echo "Usage: ./mysqldump.sh [mode][options] ..." 42 | echo " Options:" 43 | echo " -e, --extra ..... add options to mysqldump command" 44 | echo " -p, --path ....... set MySQL dump path" 45 | echo " --log ..... set mysqldump.sh log path" 46 | echo " Modes:" 47 | echo " --full ..... enable all-databases dump in a single file" 48 | echo " --only-full ..... enable all-databases dump and disable individual dump" 49 | echo " Other options:" 50 | echo " -h, --help, help ... displays this help information" 51 | echo "" 52 | return 0 53 | } 54 | 55 | # check if a command exist 56 | command_exists() { 57 | command -v "$@" >/dev/null 2>&1 58 | } 59 | 60 | ##################################### 61 | ### ----[ No Editing below ]------### 62 | ##################################### 63 | 64 | # script arguments parsing 65 | 66 | while [ "$#" -gt 0 ]; do 67 | case "$1" in 68 | -e | --extra) 69 | EXTRA_PARAMS=$2 70 | shift 71 | ;; 72 | -p | --path) 73 | MYSQLDUMPPATH=$2 74 | shift 75 | ;; 76 | --log) 77 | MYSQLDUMPLOG=$2 78 | shift 79 | ;; 80 | -f | --full) 81 | ALLDB=1 82 | ;; 83 | --only-full) 84 | ALLDB=1 85 | SINGLE_DB=0 86 | ;; 87 | -h | --help | help) 88 | _help 89 | ;; 90 | *) # positional args 91 | ;; 92 | esac 93 | shift 94 | done 95 | 96 | ### Check if /usr/bin/pigz is executable 97 | ### if yes, use pigz instead of gzip to compress with multithreading support 98 | 99 | ### Make Sure Bins Exists ### 100 | verify_bins() { 101 | 102 | if command_exists pigz; then 103 | COMPRESS=$(command -v pigz) 104 | NCPU=$(nproc) 105 | GZIP_ARG="-9 -p$NCPU" 106 | else 107 | COMPRESS=$(command -v gzip) 108 | GZIP_ARG="-1" 109 | fi 110 | 111 | if ! command_exists gzip; then 112 | echo "gzip isn't available." 113 | exit 0 114 | fi 115 | if ! command_exists mysql; then 116 | echo "mysql isn't available." 117 | exit 0 118 | else 119 | MYSQL=$(command -v mysql) 120 | fi 121 | if ! command_exists mysqldump; then 122 | echo "mysqldump isn't available" 123 | exit 0 124 | else 125 | MYSQLDUMP=$(command -v mysqldump) 126 | fi 127 | if ! command_exists mysqladmin; then 128 | echo "mysqladmin isn't available" 129 | exit 0 130 | else 131 | MYSQLADMIN=$(command -v mysqladmin) 132 | fi 133 | } 134 | 135 | ### Check if .my.cnf exit or if Plesk is installed 136 | if [ ! -f ~/.my.cnf ] && [ ! -f /etc/mysql/conf.d/my.cnf ] && [ ! -d /etc/psa ]; then 137 | echo "Error: ~/.my.cnf not found" 138 | exit 0 139 | fi 140 | 141 | ### Make Sure We Can Connect To The Server ### 142 | verify_mysql_connection() { 143 | if ! { 144 | $MYSQLADMIN $MSQL_USER ping | grep -q 'alive' >/dev/null 145 | }; then 146 | echo "Error: Cannot connect to MySQL Server. Make sure username and password are set correctly in $0" 147 | exit 0 148 | fi 149 | } 150 | 151 | ### Make A Backup ### 152 | backup_mysql() { 153 | local DBS 154 | DBS="$($MYSQL $MSQL_USER -Bse 'show databases')" 155 | local db="" 156 | 157 | [ ! -d "$MYSQLDUMPLOG" ] && mkdir -p "$MYSQLDUMPLOG" 158 | [ ! -d "$MYSQLDUMPPATH" ] && mkdir -p "$MYSQLDUMPPATH" 159 | 160 | # find backup older than $DAYOLD and remove them 161 | find "$MYSQLDUMPPATH" -type f -mtime +$DAYSOLD -exec rm -f {} \; >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 & 162 | 163 | [ $LOGS -eq 1 ] && echo "" >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 164 | [ $LOGS -eq 1 ] && echo "*** Dumping MySQL Database At $(date) ***" >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 165 | [ $LOGS -eq 1 ] && echo "Database >> " >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 166 | 167 | for db in $DBS; do 168 | local TIME 169 | TIME=$(date +"$TIME_FORMAT") 170 | local FILE 171 | FILE="$MYSQLDUMPPATH/$db/$db.$TIME.gz" 172 | [ $LOGS -eq 1 ] && echo -e \\t "$db" >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 173 | 174 | if [ "$db" = "mysql" ] || [ "$db" = "performance_schema" ] || [ "$db" = "slow_query_log" ] || [ "$db" = "information_schema" ] || [ "$db" = "phpmyadmin" ]; then 175 | echo "mysql settings tables" >>"$MYSQLDUMPLOG/mysqldump.log" 176 | else 177 | [ ! -d "$MYSQLDUMPPATH/$db" ] && mkdir -p "$MYSQLDUMPPATH/$db" 178 | $MYSQLDUMP $MSQL_USER --single-transaction "$db" $EXTRA_PARAMS | $COMPRESS $GZIP_ARG >"$FILE" || echo -e \\t \\t "MySQLDump Failed $db" 179 | fi 180 | done 181 | wait 182 | [ $LOGS -eq 1 ] && echo "*** Backup Finished At $(date) [ files wrote to $MYSQLDUMPPATH] ***" >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 183 | } 184 | 185 | ## Backup all databases 186 | backup_mysql_all_database() { 187 | 188 | [ $LOGS -eq 1 ] && echo "" >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 189 | [ $LOGS -eq 1 ] && echo "*** Dumping MySQL all-database At $(date) ***" >>"$MYSQLDUMPLOG/mysqldump.log" 2>&1 190 | 191 | local TIME 192 | TIME=$(date +"$TIME_FORMAT") 193 | [ ! -d $MYSQLFULLDUMPPATH ] && mkdir -p $MYSQLFULLDUMPPATH 194 | local FILE="$MYSQLFULLDUMPPATH/all-database.$TIME.gz" 195 | $MYSQLDUMP $MSQL_USER --all-databases --single-transaction --events | $COMPRESS $GZIP_ARG >"$FILE" || echo -e \\t \\t "MySQLDump Failed all-databases" & 196 | [ $LOGS -eq 1 ] && echo "*** Backup Finished At $(date) [ files wrote to $MYSQLFULLDUMPPATH] ***" >>"$MYSQLDUMPLOG/mysqldumpl.log" 2>&1 197 | wait 198 | } 199 | 200 | ### Main #### 201 | verify_bins 202 | verify_mysql_connection 203 | if [ "$SINGLE_DB" = "1" ]; then 204 | backup_mysql 205 | fi 206 | if [ "$ALLDB" = "1" ]; then 207 | backup_mysql_all_database 208 | fi 209 | -------------------------------------------------------------------------------- /cryptocurrency/xmrig/README.md: -------------------------------------------------------------------------------- 1 | ## Bash script to compile xmrig on Ubuntu 16.04 LTS with gcc7 2 | 3 | Run the script with : 4 | ``` 5 | bash <(wget -O - https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/cryptocurrency/xmrig/install.sh) 6 | ``` 7 | 8 | 9 | -------------------------------------------------------------------------------- /cryptocurrency/xmrig/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | release=v2.6.2 4 | 5 | # xmrig install script for Ubuntu 16.04 LTS 6 | # 7 | # 1) download the script 8 | # 2) make the script executable with : chmod +x install.sh 9 | # 3) execute it : ./install.sh 10 | # 4) edit default config.json file (pool address, wallet address) 11 | # 5) start xmrig : sudo systemctl start xmrig.service 12 | # 13 | 14 | # install prerequisites 15 | 16 | sudo apt-get update 17 | sudo apt-get install git build-essential cmake libuv1-dev libmicrohttpd-dev libssl-dev -y 18 | 19 | # install gcc-7 20 | 21 | sudo add-apt-repository ppa:jonathonf/gcc-7.1 -y 22 | sudo apt-get update 23 | sudo apt-get install gcc-7 g++-7 -y 24 | 25 | # download xmrig 26 | 27 | cd /etc || exit 28 | sudo git clone https://github.com/xmrig/xmrig.git 29 | 30 | # set current user as owner 31 | sudo chown -R $USER:$USER xmrig 32 | 33 | # build xmrig 34 | cd xmrig || exit 35 | git checkout $release 36 | mkdir build 37 | cd build || exit 38 | cmake .. -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 39 | make -j "$(nproc)" 40 | 41 | # create xmrig systemd service 42 | 43 | cat <xmrig.service 44 | [Unit] 45 | Description=xmrig Daemon 46 | 47 | [Service] 48 | ExecStart=/etc/xmrig/build/xmrig 49 | StandardOutput=null 50 | 51 | [Install] 52 | WantedBy=multi-user.target 53 | Alias=xmrig.service 54 | EOF 55 | 56 | # move xmrig.service to systemd 57 | 58 | sudo mv xmrig.service /lib/systemd/system/xmrig.service 59 | 60 | # enable HugePage 61 | echo 'vm.nr_hugepages=128' | sudo tee -a /etc/sysctl.conf 62 | sudo sysctl -p 63 | 64 | # enable xmrig service 65 | sudo systemctl enable xmrig.service 66 | -------------------------------------------------------------------------------- /cryptocurrency/xmrig/update-source.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | release=v2.6.0-beta2 4 | 5 | # stop xmrig 6 | sudo systemctl stop xmrig 7 | 8 | cd /etc/xmrig || exit 9 | 10 | # get the last release 11 | git fetch 12 | git checkout $release 13 | 14 | # compile xmrig 15 | cmake . -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 16 | make -j "$(nproc)" 17 | 18 | # restart xmrig 19 | service xmrig start 20 | -------------------------------------------------------------------------------- /cryptocurrency/xmrigCC/README.md: -------------------------------------------------------------------------------- 1 | # Script to install or update XMRIGCC Ubuntu 16.04/18.04 LTS with Gcc7/G++7 2 | 3 | ## Compile xmrigcc from source and setup xmrigcc.service 4 | 5 | ```bash 6 | bash <(wget -O - https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/cryptocurrency/xmrigCC/install.sh) 7 | ``` 8 | 9 | ## Update xmrigcc (compiled from source or static build ) 10 | 11 | ```bash 12 | bash <(wget --no-cache -O - https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/cryptocurrency/xmrigCC/update-xmrigcc.sh) 13 | ``` 14 | -------------------------------------------------------------------------------- /cryptocurrency/xmrigCC/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # xmrigCC install script for Ubuntu 16.04 LTS 4 | # 5 | # 1) download the script 6 | # 2) make the script executable with : chmod +x install.sh 7 | # 3) execute it : ./install.sh 8 | # 4) edit default config.json file (pool address, wallet address) 9 | # 5) start xmrigCC : sudo systemctl start xmrigcc.service 10 | # 11 | 12 | # install prerequisites 13 | 14 | sudo apt-get update 15 | sudo apt-get install git build-essential cmake libuv1-dev libmicrohttpd-dev libssl-dev -y 16 | 17 | ################################## 18 | # Install gcc7 or gcc8 from PPA 19 | ################################## 20 | # gcc7 for nginx stable on Ubuntu 16.04 LTS 21 | # gcc8 for nginx mainline on Ubuntu 16.04 LTS & 18.04 LTS 22 | 23 | # Checking lsb_release package 24 | if [ ! -x /usr/bin/lsb_release ]; then 25 | sudo apt-get -y install lsb-release | sudo tee -a /tmp/nginx-ee.log 2>&1 26 | fi 27 | 28 | # install gcc-7 29 | distro_version=$(lsb_release -sc) 30 | 31 | 32 | if [ "$distro_version" == "bionic" ] && [ ! -f /etc/apt/sources.list.d/jonathonf-ubuntu-gcc-bionic.list ]; then 33 | apt-get install software-properties-common -y 34 | add-apt-repository -y ppa:jonathonf/gcc 35 | elif [ "$distro_version" == "xenial" ] && [ ! -f /etc/apt/sources.list.d/jonathonf-ubuntu-gcc-xenial.list ]; then 36 | apt-get install software-properties-common -y 37 | add-apt-repository -y ppa:jonathonf/gcc 38 | fi 39 | apt-get update 40 | apt-get full-upgrade 41 | apt-get install gcc-7 g++-7 -y 42 | export CC="/usr/bin/gcc-7" 43 | export CXX="/usr/bin/gc++-7" 44 | 45 | # install libboost if needed 46 | 47 | if [ ! -d /etc/boost ]; then 48 | cd /etc || exit 49 | wget https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2 50 | tar xvfj boost_1_67_0.tar.bz2 && rm -rf boost_1_67_0.tar.bz2 51 | mv boost_1_67_0 boost 52 | cd boost || exit 53 | ./bootstrap.sh --with-libraries=system 54 | ./b2 55 | fi 56 | 57 | # download xmrigCC 58 | cd /etc || exit 59 | sudo git clone https://github.com/Bendr0id/xmrigCC.git 60 | sudo chown -R $USER:$USER xmrigCC 61 | 62 | # build xmrigCC 63 | cd xmrigCC || exit 64 | cmake . -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 -DBOOST_ROOT=/etc/boost 65 | make -j "$(nproc)" 66 | 67 | # create xmrigCC systemd service 68 | 69 | sudo wget -O /lib/systemd/system/xmrigcc.service https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/cryptocurrency/xmrigCC/xmrigcc.service 70 | 71 | # enable xmrigCC service 72 | sudo systemctl enable xmrigcc.service 73 | 74 | # enable HugePage 75 | echo 'vm.nr_hugepages=128' | sudo tee -a /etc/sysctl.conf 76 | sudo sysctl -p 77 | 78 | # copy default config.json file 79 | cp src/config.json . 80 | cp src/config_cc.json . 81 | -------------------------------------------------------------------------------- /cryptocurrency/xmrigCC/update-xmrigcc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################## 4 | # Variables 5 | ################################## 6 | 7 | release="1.9.3" 8 | static_build="https://github.com/Bendr0id/xmrigCC/releases/download/1.9.3/xmrigCC-1.9.3-with_tls-gcc7-linux-static-miner_only-x64.tar.gz" 9 | 10 | ################################## 11 | # Stopping service 12 | ################################## 13 | 14 | [ -f /etc/systemd/system/xmrigdash.service ] && { 15 | sudo service xmrigdash stop 16 | echo "xmrigdash stopped [OK]" 17 | } 18 | 19 | # stop xmrigcc 20 | [ -f /etc/systemd/system/xmrigcc.service ] && { 21 | sudo service xmrigcc stop 22 | echo "xmrigcc stopped [OK]" 23 | } 24 | 25 | if [ -d /etc/xmrigCC/.git ]; then 26 | git -C /etc/xmrigCC fetch 27 | 28 | ################################## 29 | # Install gcc7 or gcc8 from PPA 30 | ################################## 31 | 32 | # Checking lsb_release package 33 | if [ -z "$(command -v lsb_release)" ]; then 34 | sudo apt-get -y install lsb-release | sudo tee -a /tmp/nginx-ee.log 2>&1 35 | fi 36 | 37 | # install gcc-7 38 | 39 | if [ ! -f /etc/apt/sources.list.d/jonathonf-ubuntu-gcc-"$(lsb_release -sc)".list ]; then 40 | apt-get install software-properties-common -y 41 | add-apt-repository -y ppa:jonathonf/gcc 42 | apt-get update 43 | fi 44 | if [ ! -x /usr/bin/gcc-7 ]; then 45 | apt-get install gcc-7 g++-7 -y 46 | fi 47 | export CC="/usr/bin/gcc-7" 48 | export CXX="/usr/bin/gc++-7" 49 | 50 | if [ ! -d /etc/boost ]; then 51 | cd /etc || exit 1 52 | curl -sL https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2 | /bin/tar xjf - -C /etc 53 | rm -f boost_1_67_0.tar.bz2 54 | mv boost_1_67_0 boost 55 | cd /etc/boost || exit 1 56 | ./bootstrap.sh --with-libraries=system 57 | ./b2 --toolset=gcc-7 58 | fi 59 | 60 | cd /etc/xmrigCC || exit 1 61 | 62 | # get the last release 63 | git checkout $release 64 | 65 | # compile xmrigcc 66 | make clean 67 | cmake . -DCMAKE_C_COMPILER=gcc-7 -DCMAKE_CXX_COMPILER=g++-7 -DBOOST_ROOT=/etc/boost 68 | make -j"$(nproc)" 69 | 70 | else 71 | 72 | cd /etc/xmrigCC || exit 1 73 | 74 | wget -O xmrigcc.tar.gz "$static_build" 75 | 76 | mv config.json c 77 | /bin/tar -xzf xmrigcc.tar.gz 78 | 79 | rm -f xmrigcc.tar.gz 80 | rm -f config.json 81 | mv c config.json 82 | 83 | fi 84 | 85 | 86 | # restart xmrigcc 87 | sudo service xmrigcc start 88 | echo "xmrigcc started [OK]" 89 | 90 | if [ -f /etc/systemd/system/xmrigdash.service ]; then 91 | sudo service xmrigdash start 92 | echo "xmrigdash started [OK]" 93 | fi 94 | -------------------------------------------------------------------------------- /cryptocurrency/xmrigCC/xmrigcc.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=xmrigCC Daemon 3 | After=syslog.target network.target remote-fs.target nss-lookup.target 4 | 5 | [Service] 6 | ExecStart=/usr/bin/nice -n 19 /etc/xmrigCC/xmrigDaemon 7 | ExecStop=/bin/kill -s QUIT $MAINPID 8 | StandardOutput=null 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | Alias=xmrigcc.service 13 | -------------------------------------------------------------------------------- /easyengine/secure-22222/22222.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # install acme.sh if needed 4 | echo "" 5 | echo "checking if acme.sh is already installed" 6 | echo "" 7 | if [ ! -f ~/.acme.sh/acme.sh ]; then 8 | echo "" 9 | echo "installing acme.sh" 10 | echo "" 11 | wget -O - https://get.acme.sh | sh 12 | fi 13 | 14 | echo "" 15 | echo "checking if dig is available" 16 | echo "" 17 | if [ ! -x /usr/bin/dig ]; then 18 | apt-get install bind9-host -y >>/dev/null 19 | fi 20 | 21 | NET_INTERFACES_WAN=$(ip -4 route get 8.8.8.8 | grep -oP "dev [^[:space:]]+ " | cut -d ' ' -f 2) 22 | MY_IP=$(ip -4 address show ${NET_INTERFACES_WAN} | grep 'inet' | sed 's/.*inet \([0-9\.]\+\).*/\1/') 23 | MY_HOSTNAME=$(/bin/hostname -f) 24 | MY_HOSTNAME_IP=$(/usr/bin/dig +short @8.8.8.8 "$MY_HOSTNAME") 25 | 26 | if [[ "$MY_IP" = "$MY_HOSTNAME_IP" ]]; then 27 | 28 | [ ! -f /etc/systemd/system/multi-user.target.wants/nginx.service ] && { 29 | 30 | sudo systemctl enable nginx.service 31 | } 32 | 33 | sudo apt install socat -y 34 | 35 | [ ! -f $HOME/.acme.sh/${MY_HOSTNAME}_ecc/fullchain.cer ] && { 36 | 37 | $HOME/.acme.sh/acme.sh --issue -d $MY_HOSTNAME --keylength ec-384 --standalone --pre-hook "service nginx stop " --post-hook "service nginx start" 38 | } 39 | 40 | if [ -d /etc/letsencrypt/live/$MY_HOSTNAME ]; then 41 | rm -rf /etc/letsencrypt/live/$MY_HOSTNAME/* 42 | else 43 | mkdir -p /etc/letsencrypt/live/$MY_HOSTNAME 44 | fi 45 | [ -f $HOME/.acme.sh/${MY_HOSTNAME}_ecc/fullchain.cer ] && { 46 | # install the cert and reload nginx 47 | $HOME/.acme.sh/acme.sh --install-cert -d ${MY_HOSTNAME} --ecc \ 48 | --cert-file /etc/letsencrypt/live/${MY_HOSTNAME}/cert.pem \ 49 | --key-file /etc/letsencrypt/live/${MY_HOSTNAME}/key.pem \ 50 | --fullchain-file /etc/letsencrypt/live/${MY_HOSTNAME}/fullchain.pem \ 51 | --reloadcmd "systemctl enable nginx.service && service nginx restart" 52 | } 53 | 54 | if [ -f /etc/letsencrypt/live/${MY_HOSTNAME}/fullchain.pem ] && [ -f /etc/letsencrypt/live/${MY_HOSTNAME}/key.pem ]; then 55 | 56 | sed -i "s/ssl_certificate \/var\/www\/22222\/cert\/22222.crt;/ssl_certificate \/etc\/letsencrypt\/live\/${MY_HOSTNAME}\/fullchain.pem;/" /etc/nginx/sites-available/22222 57 | sed -i "s/ssl_certificate_key \/var\/www\/22222\/cert\/22222.key;/ssl_certificate_key \/etc\/letsencrypt\/live\/${MY_HOSTNAME}\/key.pem;/" /etc/nginx/sites-available/22222 58 | fi 59 | service nginx reload 60 | 61 | fi 62 | -------------------------------------------------------------------------------- /easyengine/secure-22222/README.md: -------------------------------------------------------------------------------- 1 | # Script to secure easyengine backend with acme.sh 2 | -------------------------------------------------------------------------------- /mail/imapsync/README.md: -------------------------------------------------------------------------------- 1 | # Script to migrate emails between two servers using imapsync - user credentials read from csv 2 | 3 | ## Download the script and csv example 4 | 5 | ```bash 6 | wget https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/mail/imapsync/imapsync-from-csv.sh -O imapsync-from-csv.sh 7 | wget https://raw.githubusercontent.com/VirtuBox/bash-scripts/master/mail/imapsync/credentials.csv -O credentials.csv 8 | chmod +x imapsync-from-csv.sh 9 | ``` 10 | 11 | ## Run the script 12 | 13 | Put your users crendentials in the csv file, and run imapsync-from-csv.sh this way : 14 | 15 | ```bash 16 | ./imapsync-from-csv.sh imap-server-1.tld imap-server-2.tld 17 | ``` 18 | -------------------------------------------------------------------------------- /mail/imapsync/credentials.csv: -------------------------------------------------------------------------------- 1 | user@domain.tld|password_imap_1|password_imap_2 2 | user2@domain.tld| password_imap_1|password_imap_2 3 | -------------------------------------------------------------------------------- /mail/imapsync/imapsync-from-csv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | input="credentials.csv" 4 | while IFS='|' read -r f1 f2 f3; do 5 | imapsync \ 6 | --host1 "$1" \ 7 | --user1 "$f1" \ 8 | --ssl1 \ 9 | --authmech1 LOGIN \ 10 | --password1 "$f2" \ 11 | --host2 "$2" \ 12 | --ssl2 \ 13 | --user2 "$f1" \ 14 | --password2 "$f3" \ 15 | --authmech2 LOGIN \ 16 | --automap 17 | done <"$input" 18 | -------------------------------------------------------------------------------- /wp-cli/https-migrate/README.md: -------------------------------------------------------------------------------- 1 | # Bash script to migrate WordPress site from http to https using WP-CLI 2 | 3 | ```bash 4 | cd /path/to/wordpress 5 | 6 | bash <(wget -O - raw.githubusercontent.com/VirtuBox/bash-scripts/master/wp-cli/https-migrate/migrate.sh) 7 | ``` 8 | -------------------------------------------------------------------------------- /wp-cli/https-migrate/migrate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # check if wp-cli is installed 4 | # if not, download it 5 | if [ -z "$(command -v wp)" ]; then 6 | wget -O wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 7 | chmod +x wp 8 | WPCLI="./wp" 9 | else 10 | WPCLI="wp" 11 | fi 12 | 13 | # check if wp is-installed 14 | WP_CHECK=$($WPCLI core is-installed) 15 | if [ -z "$WP_CHECK" ]; then 16 | 17 | SITE_URL=$($WPCLI option get siteurl) 18 | SITE_DOMAIN=$($WPCLI option get siteurl | awk -F "//" '{print $2}') 19 | 20 | # replace site url with https 21 | $WPCLI search-replace \ 22 | "$SITE_URL" \ 23 | "https://$SITE_DOMAIN" \ 24 | --skip-columns=guid --skip-tables=wp_users 25 | 26 | # replace encoded site url with https 27 | $WPCLI search-replace \ 28 | "http:\/\/$SITE_DOMAIN" \ 29 | "https:\/\/$SITE_DOMAIN" \ 30 | --skip-columns=guid --skip-tables=wp_users 31 | 32 | else 33 | echo "no wordpress instance found" 34 | exit 1 35 | fi --------------------------------------------------------------------------------