bash functions and aliases
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

733 lines
22KB

  1. #!/bin/bash
  2. # FUNCTIONS
  3. if [ "$(id -u)" != "0" ]; then
  4. IS_SUDOERS=$(groups | grep sudo)
  5. if [ -n "$(command -v sudo)" ] && [ -n "$IS_SUDOERS" ]; then
  6. NEED_SUDO="$(command -v sudo)"
  7. else
  8. NEED_SUDO=""
  9. fi
  10. fi
  11. command_exists() {
  12. command -v "$@" >/dev/null 2>&1
  13. }
  14. _run() {
  15. if [ -n "$2" ]; then
  16. echo -ne "${TPUT_ECHO}${2}${TPUT_RESET}\t"
  17. fi
  18. if ! { "$1"; }; then
  19. if [ -n "$2" ]; then
  20. echo -e "${TPUT_FAIL}[KO]${TPUT_RESET}"
  21. fi
  22. else
  23. if [ -n "$2" ]; then
  24. echo -e "[${TPUT_OK}OK${TPUT_RESET}]"
  25. fi
  26. fi
  27. }
  28. apt_install() {
  29. DEBIAN_FRONTEND=noninteractive apt-get install --option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold "$@" --assume-yes /dev/null 2>&1
  30. }
  31. transfer_vtbox_net() {
  32. { curl --progress-bar --upload-file "$1" "https://transfer.vtbox.net/$(basename $1)" && echo ""; } | tee -a $HOME/.transfer.log && echo ""
  33. }
  34. compress_pigz() {
  35. tar -I pigz -cvf "$1.tar.gz" "$1"
  36. }
  37. decompress_pigz() {
  38. tar -I pigz -xvf "$1"
  39. }
  40. update_git_mybashrc() {
  41. if [ -d "$HOME/.mybashrc/.git" ]; then
  42. git -C "$HOME/.mybashrc" pull -q
  43. $HOME/.mybashrc/setup.sh >/dev/null 2>&1
  44. fi
  45. }
  46. EE_MYSQL_OPTIMIZATION() {
  47. if [ -f "$HOME/.my.cnf" ]; then
  48. /usr/bin/mysqlcheck -Aos --auto-repair
  49. elif [ -f /etc/psa/.psa.shadow ]; then
  50. MYSQL_PWD="$(cat /etc/psa/.psa.shadow)" /usr/bin/mysqlcheck -Aos -uadmin --auto-repair
  51. else
  52. echo "$HOME/.my.cnf or /etc/psa/.psa.shadow doesn't exist"
  53. fi
  54. }
  55. encrypt_gpg() {
  56. gpg -c "$1"
  57. }
  58. decrypt_gpg() {
  59. gpg --output "${1%.gpg}" -d "$1"
  60. }
  61. LIST_BY_SIZE() {
  62. du -sh ./* | sort -h
  63. }
  64. EE_DOCKER_SETUP() {
  65. if [ ! -d "$HOME/.ee" ]; then
  66. mkdir $HOME/.ee
  67. fi
  68. curl -fsSL get.docker.com -o $HOME/.ee/get-docker.sh
  69. chmod +x $HOME/.ee/get-docker.sh
  70. $HOME/.ee/get-docker.sh
  71. }
  72. SET_TINC_UP() {
  73. sudo tincd -n "$1"
  74. }
  75. SET_TINC_DOWN() {
  76. sudo tincd -n "$1" -k
  77. }
  78. DD_BENCHMARK_DISK() {
  79. dd if=/dev/zero bs=1024 count=1000000 of=file_1GB
  80. dd if=file_1GB of=/dev/null bs=1024
  81. rm file_1GB
  82. }
  83. ffmpeg_start_time() {
  84. if [ "$#" = "0" ]; then
  85. echo "ffmpeg-cut-start <start-time> <input> <duration(optional)>"
  86. echo ""
  87. echo "example : ffmpeg-cut-start 00:34:24.85 file.mp4 300"
  88. else
  89. if [ -n "$3" ]; then
  90. bash -c "ffmpeg -ss '$1' -y -i '$2' -t '$3' -c copy -movflags +faststart '${2%.mp4}-output.mp4';"
  91. else
  92. bash -c "ffmpeg -ss '$1' -y -i '$2' -c copy -movflags +faststart '${2%.mp4}-output.mp4';"
  93. fi
  94. fi
  95. }
  96. RANDOM_GIT_COMMIT() {
  97. [ -z "$(command -v w3m)" ] && {
  98. apt-get install -y w3m
  99. }
  100. git add .
  101. git commit -m "$(w3m whatthecommit.com | head -1)"
  102. }
  103. GIT_COMMIT() {
  104. git add .
  105. git commit -am "$1"
  106. }
  107. _find_duplicates() {
  108. if [ "$#" = "0" ]; then
  109. echo "duplicate-find <path> [--force]"
  110. echo "use --force to delete files"
  111. else
  112. if ! command_exists rdfind; then
  113. apt-get install rdfind -y
  114. fi
  115. if [ "$2" = "--force" ]; then
  116. rdfind -ignoreempty false "$1"
  117. else
  118. rdfind -dryrun true -ignoreempty false "$1"
  119. fi
  120. fi
  121. }
  122. MAINTENANCE_APT() {
  123. # Colors
  124. # Colors
  125. CSI='\033['
  126. CEND="${CSI}0m"
  127. CGREEN="${CSI}1;32m"
  128. if [ "$(id -u)" = "0" ] || [ -n "$IS_SUDOERS" ]; then
  129. export DEBIAN_FRONTEND=noninteractive
  130. echo -e "${CGREEN}#############################################${CEND}"
  131. echo -e ' APT UPDATE '
  132. echo -e "${CGREEN}#############################################${CEND}"
  133. if ! {
  134. $NEED_SUDO apt-get update --allow-releaseinfo-change
  135. }; then
  136. $NEED_SUDO apt-get update
  137. fi
  138. echo -e "${CGREEN}#############################################${CEND}"
  139. echo -e ' APT FULL-UPGRADE '
  140. echo -e "${CGREEN}#############################################${CEND}"
  141. $NEED_SUDO apt-get --option=Dpkg::options::=--force-confmiss --option=Dpkg::options::=--force-confold --option=Dpkg::options::=--force-unsafe-io -y dist-upgrade
  142. echo -e "${CGREEN}#############################################${CEND}"
  143. echo -e ' APT-GET AUTOREMOVE '
  144. echo -e "${CGREEN}#############################################${CEND}"
  145. $NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y --purge autoremove
  146. echo -e "${CGREEN}#############################################${CEND}"
  147. echo -e ' APT AUTOCLEAN '
  148. echo -e "${CGREEN}#############################################${CEND}"
  149. $NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y autoclean
  150. $NEED_SUDO apt-get -y clean
  151. ## clean packages in deinstall state
  152. DEINSTALLED=$($NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1)
  153. if [ -n "$DEINSTALLED" ]; then
  154. echo -e "${CGREEN}#############################################${CEND}"
  155. echo -e ' CLEAN DEINSTALLED PACKAGES '
  156. echo -e "${CGREEN}#############################################${CEND}"
  157. $NEED_SUDO dpkg --get-selections | grep deinstall | cut -f1 | xargs dpkg --purge
  158. fi
  159. if [ "$1" = "--docker" ]; then
  160. if command_exists docker; then
  161. list_images=$(docker images --filter "dangling=true" -q --no-trunc)
  162. list_volumes=$(docker volume ls -qf dangling=true)
  163. if [ -n "$list_images" ]; then
  164. echo -e "${CGREEN}#############################################${CEND}"
  165. echo -e ' DOCKER IMAGES CLEANUP '
  166. echo -e "${CGREEN}#############################################${CEND}"
  167. docker rmi "$list_images"
  168. fi
  169. if [ -n "$list_volumes" ]; then
  170. echo -e "${CGREEN}#############################################${CEND}"
  171. echo -e ' DOCKER VOLUMES CLEANUP '
  172. echo -e "${CGREEN}#############################################${CEND}"
  173. docker volume rm "$list_volumes"
  174. fi
  175. fi
  176. fi
  177. OLD_LOGS=$($NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz")
  178. if [ -n "$OLD_LOGS" ]; then
  179. echo -e "${CGREEN}#############################################${CEND}"
  180. echo -e ' CLEANUP OLD LOGS '
  181. echo -e "${CGREEN}#############################################${CEND}"
  182. $NEED_SUDO find /var/log/ -type f -mtime +30 -iname "*.gz" -exec rm '{}' \;
  183. fi
  184. echo -e "${CGREEN}#############################################${CEND}"
  185. echo -e ' EE-BASHRC UPDATE '
  186. echo -e "${CGREEN}#############################################${CEND}"
  187. update_git_mybashrc
  188. else
  189. echo "you need to be root or sudoers to launch the maintenance"
  190. fi
  191. }
  192. EE_NGINX_COMPILE() {
  193. if [ ! -d $HOME/.scripts ]; then
  194. mkdir $HOME/.scripts
  195. fi
  196. wget -qO $HOME/.scripts/nginx-build.sh https://raw.githubusercontent.com/VirtuBox/nginx-ee/master/nginx-build.sh
  197. chmod +x $HOME/.scripts/nginx-build.sh
  198. $HOME/.scripts/nginx-build.sh "$@"
  199. }
  200. EE_SHOW_LOG() {
  201. if ! command_exists ccze; then
  202. apt install ccze -y
  203. fi
  204. if echo "$1" | grep -q ".gz"; then
  205. zcat "$1" | ccze -A -p syslog -C
  206. else
  207. tail -n 500 "$1" | ccze -A -p syslog -C
  208. fi
  209. }
  210. _PYTHON_VIRTUALENV() {
  211. python3 -m venv "$1"
  212. source "$1/bin/activate"
  213. }
  214. CHEAT_CHECK() {
  215. {
  216. CHECK_CHT=$(command -v cht.sh)
  217. [ -z "$CHECK_CHT" ] && {
  218. wget -O /usr/local/bin/cht.sh https://cht.sh/:cht.sh
  219. chmod +x /usr/local/bin/cht.sh
  220. }
  221. ND_CHECK_CHT="$(command -v cht.sh)"
  222. $ND_CHECK_CHT "$@"
  223. }
  224. }
  225. EE_SHOW_FPM() {
  226. top -bn1 | grep -c "php-fpm"
  227. }
  228. MAGENTO_UPGRADE() {
  229. if [ -x bin/magento ]; then
  230. bin/magento maintenance:enable
  231. bin/magento cache:flush
  232. bin/magento setup:upgrade
  233. rm -Rf "./generated/metadata/*" "./generated/code/*" "./var/cache/*" "./var/page_cache/*"
  234. bin/magento setup:di:compile
  235. /usr/bin/composer dump-autoload -o --apcu
  236. rm -Rf "./pub/static/frontend/*" "./pub/static/adminhtml/*" "./var/view_preprocessed/*" "./pub/static/_cache/*" "./pub/static/_requirejs/*"
  237. bin/magento setup:static-content:deploy fr_FR
  238. bin/magento setup:static-content:deploy en_US --theme="Magento/backend"
  239. bin/magento cache:enable
  240. bin/magento maintenance:disable
  241. else
  242. echo "you are not in a magento root folder"
  243. fi
  244. }
  245. _WP_PERMISSIONS() {
  246. if [ -f ./wp-config.php ] || [ -f ../wp-config.php ]; then
  247. find . -type d -exec chmod 750 {} \;
  248. find . -type f -exec chmod 640 {} \;
  249. else
  250. echo "not a wordpress directory"
  251. fi
  252. }
  253. _PERM_FILES() {
  254. find . -type f -exec chmod "$1" {} \;
  255. }
  256. _PERM_FOLDER() {
  257. find . -type d -exec chmod "$1" {} \;
  258. }
  259. _NGINX_EE() {
  260. wget -qO /tmp/nginx-ee vtb.cx/nginx-ee
  261. chmod +x /tmp/nginx-ee
  262. /tmp/nginx-ee "$@"
  263. }
  264. _INSTALL_NODEJS() {
  265. if [ -n "$1" ]; then
  266. wget -O nodejs.sh https://deb.nodesource.com/setup_"$1".x
  267. else
  268. wget -O nodejs.sh https://deb.nodesource.com/setup_10.x
  269. fi
  270. chmod +x nodejs.sh
  271. ./nodejs.sh
  272. rm nodejs.sh
  273. $NEED_SUDO apt-get install -y nodejs
  274. }
  275. _UPDATE_NPM() {
  276. $NEED_SUDO npm install -g npm
  277. }
  278. _PPA_INSTALL() {
  279. if [ "$#" -eq 0 ]; then
  280. echo "Usage : IPPA <ppa-name>"
  281. echo " PPA : "
  282. echo " - ubuntu backports : --jonathonf"
  283. echo " - virtubox backports : --backports"
  284. echo " - ondrej php : --php"
  285. echo " - ondrej nginx : --nginx"
  286. echo " - WordOps nginx : --nginx-wo"
  287. echo " - ondrej apache : --apache"
  288. echo " - redis-server : --redis"
  289. echo " - ffmpeg4 : --ffmpeg"
  290. echo " - gcc8 : --gcc"
  291. echo " - tinc : --tinc"
  292. echo " - goaccess : --goaccess"
  293. else
  294. PPA=""
  295. while [ "$#" -gt 0 ]; do
  296. case "$1" in
  297. --jonathonf)
  298. PPA="$PPA ppa:jonathonf/backports"
  299. ;;
  300. --backports)
  301. PPA="$PPA ppa:virtubox/backports"
  302. ;;
  303. --php)
  304. PPA="$PPA ppa:ondrej/php"
  305. ;;
  306. --nginx)
  307. PPA="$PPA ppa:ondrej/nginx-mainline"
  308. ;;
  309. --nginx-wo)
  310. PPA="$PPA ppa:virtubox/nginx-wo"
  311. ;;
  312. --apache)
  313. PPA="$PPA ppa:ondrej/apache2"
  314. ;;
  315. --redis)
  316. PPA="$PPA ppa:chris-lea/redis-server"
  317. ;;
  318. --ffmpeg)
  319. PPA="$PPA ppa:jonathonf/ffmpeg-4"
  320. ;;
  321. --gcc)
  322. PPA="$PPA ppa:jonathonf/gcc"
  323. ;;
  324. --tinc)
  325. PPA="$PPA ppa:virtubox/tinc"
  326. ;;
  327. --goaccess)
  328. PPA="$PPA ppa:alex-p/goaccess"
  329. ;;
  330. *) ;;
  331. esac
  332. shift
  333. done
  334. if [ -n "$PPA" ]; then
  335. for UPPA in $PPA; do
  336. $NEED_SUDO add-apt-repository "$UPPA" -y
  337. done
  338. fi
  339. fi
  340. }
  341. _INSTALL_NANORC() {
  342. if [ ! -d /usr/share/nano-syntax-highlighting ]; then
  343. git clone --depth 1 https://github.com/scopatz/nanorc.git /usr/share/nano-syntax-highlighting -q
  344. fi
  345. if ! grep -q "/usr/share/nano-syntax-highlighting" /etc/nanorc; then
  346. echo "include /usr/share/nano-syntax-highlighting/*.nanorc" >>/etc/nanorc
  347. fi
  348. }
  349. _SYSINFO() {
  350. # Reading out system information...
  351. # Reading CPU model
  352. cname=$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')
  353. # Reading amount of CPU cores
  354. cores=$(awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo)
  355. # Reading CPU frequency in MHz
  356. freq=$(awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')
  357. # Reading total memory in MB
  358. tram=$(free -m | awk 'NR==2 {print $2}')
  359. # Reading Swap in MB
  360. vram=$(free -m | awk 'NR==4 {print $2}')
  361. # Reading system uptime
  362. up=$(uptime | awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }' | sed 's/^[ \t]*//;s/[ \t]*$//')
  363. # Reading operating system and version (simple, didn't filter the strings at the end...)
  364. opsy=$(cat /etc/issue.net | awk 'NR==1 {print}') # Operating System & Version
  365. arch=$(uname -m) # Architecture
  366. lbit=$(getconf LONG_BIT) # Architecture in Bit
  367. hn=$(hostname -f) # Hostname
  368. kern=$(uname -r)
  369. echo ""
  370. # Output of results
  371. echo "System Info"
  372. echo "Server : $hn"
  373. echo "-----------"
  374. echo "Processor : $cname"
  375. echo "CPU Cores : $cores"
  376. echo "Frequency : $freq MHz"
  377. echo "Memory : $tram MB"
  378. echo "Swap : $vram MB"
  379. echo "Uptime : $up"
  380. echo "-----------"
  381. echo "OS : $opsy"
  382. echo "Arch : $arch ($lbit Bit)"
  383. echo "Kernel : $kern"
  384. echo ""
  385. }
  386. _SITESPEED() {
  387. if [ "$#" = "0" ]; then
  388. echo "Usage : sitespeed <url>"
  389. else
  390. curl -s -w \
  391. '\nLookup time:\t\t%{time_namelookup}\nConnect time:\t\t%{time_connect}\nSSL handshake time:\t%{time_appconnect}\nPre-Transfer time:\t%{time_pretransfer}\nRedirect time:\t\t%{time_redirect}\nStart transfer time:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null "$@"
  392. fi
  393. }
  394. _SETUP_TOOLS() {
  395. DEBIAN_FRONTEND=noninteractive $NEED_SUDO apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install haveged curl git unzip zip htop nload nmon ntp gnupg gnupg2 wget pigz tree ccze
  396. }
  397. _RSYSLOG_UFW() {
  398. [ -f /etc/rsyslog.d/20-ufw.conf ] && {
  399. sed -i 's/\#\& stop/\& stop/' /etc/rsyslog.d/20-ufw.conf
  400. service rsyslog restart
  401. }
  402. }
  403. _START_SSH_AGENT() {
  404. rm -f /root/.ssh/ssh_auth_sock
  405. ssh-agent -a /root/.ssh/ssh_auth_sock
  406. export SSH_AUTH_SOCK="/root/.ssh/ssh_auth_sock"
  407. ssh-add -l >/dev/null || ssh-add
  408. }
  409. _APT_REPO_UBUNTU() {
  410. wget -O /etc/apt/sources.list https://vtb.cx/$(lsb_release -sc)-list
  411. }
  412. _APT_BIONIC_KERNEL() {
  413. if [ "$(lsb_release -sc)" = "bionic" ]; then
  414. apt update && apt install --install-recommends linux-generic-hwe-18.04 --assume-yes
  415. fi
  416. }
  417. _FTP_ADD() {
  418. if [ "$#" = "0" ] || [ "$#" = "1" ]; then
  419. echo "Usage : ftpadd <user> <domain>"
  420. else
  421. if ! command_exists pwgen; then
  422. apt_install pwgen
  423. fi
  424. ftpaccountpass=$(_PWGEN)
  425. if [ -d /var/www/"$2"/htdocs ]; then
  426. $NEED_SUDO useradd -d "/var/www/$2/htdocs" -M -s /bin/false -G www-data "$1"
  427. echo "$1:$ftpaccountpass" | $NEED_SUDO chpasswd -m
  428. chmod -R g+rw "/var/www/$2/htdocs"
  429. echo -e "\n\n [/var/www/$2/htdocs]" | tee -a "$HOME/.ftpaccounts"
  430. echo -e "user : $1" | tee -a "$HOME/.ftpaccounts"
  431. echo "password : $ftpaccountpass" | tee -a "$HOME/.ftpaccounts"
  432. else
  433. echo "site directory doesn't exist"
  434. fi
  435. fi
  436. }
  437. _UFW_MINIMAL() {
  438. ufw logging low
  439. ufw default allow outgoing
  440. ufw default deny incoming
  441. ufw limit 22
  442. ufw limit 10022
  443. ufw allow 53
  444. ufw allow http
  445. ufw allow https
  446. ufw allow 68
  447. ufw allow 655
  448. ufw allow 873
  449. ufw allow 123
  450. ufw allow 22222
  451. ufw allow from 144.76.159.118 to any port 35621
  452. ufw allow from 144.76.159.118 to any port 35622
  453. ufw allow from 144.76.159.118 to any port 35623
  454. ufw allow from 159.69.0.216 to any port 10050
  455. }
  456. _SSH_SECURE() {
  457. CURRENT_SSH_PORT=$(grep "Port" /etc/ssh/sshd_config | awk -F " " '{print $2}')
  458. wget https://raw.githubusercontent.com/VirtuBox/ubuntu-nginx-web-server/master/etc/ssh/sshd_config -O /etc/ssh/sshd_config
  459. if [ -n "$1" ]; then
  460. sed -i "s/Port 22/Port $1/" /etc/ssh/sshd_config
  461. else
  462. sed -i "s/Port 22/Port $CURRENT_SSH_PORT/" /etc/ssh/sshd_config
  463. fi
  464. }
  465. _PWGEN() {
  466. if ! command_exists pwgen; then
  467. apt_install pwgen
  468. fi
  469. pwgen -s 24 1
  470. }
  471. _FD() {
  472. if [ -z "$(command -v fd)" ]; then
  473. echo "downloading fd ..."
  474. wget -qO https://github.com/sharkdp/fd/releases/download/v7.3.0/fd-musl_7.3.0_amd64.deb -O /tmp/fd.deb >/dev/null
  475. echo "installing fd ..."
  476. dpkg -i /tmp/fd.deb && rm /tmp/db.deb >/dev/null
  477. fi
  478. fd "$@"
  479. }
  480. _LXC_LOGIN() {
  481. lxc exec "$@" /usr/bin/env bash
  482. }
  483. _LXC_LAUNCH() {
  484. local RANDOM
  485. RANDOM=$(date +%s | sha256sum | base64 | head -c 4)
  486. if [ "$#" = "0" ]; then
  487. lxc launch ubuntu-daily:18.04 "ctn-$RANDOM"
  488. else
  489. lxc launch ubuntu-daily:18.04 "$1"
  490. fi
  491. }
  492. _BACKPORT_PACKAGE() {
  493. if [ "$#" = "0" ]; then
  494. echo "Usage :"
  495. echo "bppackage <ppa (optional)> <.dsc url> "
  496. echo "exemple : bppackage ppa:virtubox/backports http://url.dsc"
  497. fi
  498. local RANDOM
  499. RANDOM=$(date +%s | sha256sum | base64 | head -c 4)
  500. if [ "$PWD" = "/root" ]; then
  501. mkdir -p "backport-$RANDOM"
  502. cd "backport-$RANDOM" || exit 1
  503. fi
  504. if [ "$#" = "1" ]; then
  505. backportpackage -r -w . -d bionic -u ppa:virtubox/backports -kE3CC41E7F354756B94A7DF4322EB296C97BAD476 "$1"
  506. elif [ "$#" = "2" ]; then
  507. backportpackage -r -w . -d bionic -u "$1" -kE3CC41E7F354756B94A7DF4322EB296C97BAD476 "$2"
  508. fi
  509. }
  510. _WO_FULL_UPGRADE() {
  511. [ ! -f "$HOME/.gitconfig" ] && {
  512. sudo bash -c 'echo -e "[user]\n\tname = $USER\n\temail = root@wops.cc" > $HOME/.gitconfig'
  513. }
  514. rm -f wo
  515. wget -qO wo https://raw.githubusercontent.com/WordOps/WordOps/updating-configuration/install && sudo bash wo -b updating-configuration
  516. }
  517. _SPEEDTEST() {
  518. if ! command_exists speedtest; then
  519. DEB_DISTRO=$(lsb_release -sc)
  520. apt-get install gnupg1 apt-transport-https dirmngr -y
  521. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 379CE192D401AB61
  522. echo "deb https://ookla.bintray.com/debian $DEB_DISTRO main" | sudo tee /etc/apt/sources.list.d/speedtest.list
  523. apt-get update
  524. apt-get install speedtest -y
  525. fi
  526. speedtest
  527. }
  528. _INSTALL_WPCLI() {
  529. curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  530. chmod +x wp-cli.phar
  531. $NEED_SUDO mv wp-cli.phar /usr/local/bin/wp
  532. wget -O /etc/bash_completion.d/wp-completion.bash https://raw.githubusercontent.com/wp-cli/wp-cli/master/utils/wp-completion.bash
  533. }
  534. _SETUP_CONTROLLER() {
  535. if [ "$#" -eq 0 ]; then
  536. echo "Usage : SSETUP <ppa-name>"
  537. echo " PPA : "
  538. echo " - nanorc : --nanorc"
  539. echo " - wpcli : --wpcli"
  540. else
  541. INSTALL=""
  542. while [ "$#" -gt 0 ]; do
  543. case "$1" in
  544. --nanorc)
  545. INSTALL="$INSTALL _INSTALL_NANORC"
  546. ;;
  547. --wpcli)
  548. INSTALL="$INSTALL _INSTALL_WPCLI"
  549. ;;
  550. *) ;;
  551. esac
  552. shift
  553. done
  554. if [ -n "$INSTALL" ]; then
  555. for APP in $INSTALL; do
  556. $NEED_SUDO $APP
  557. done
  558. fi
  559. fi
  560. }
  561. _ZABBIX_UPDATE() {
  562. local distro
  563. distro="$(lsb_release -si)"
  564. wget -O /tmp/zabbix.deb https://repo.zabbix.com/zabbix/4.4/"${distro,,}"/pool/main/z/zabbix-release/zabbix-release_4.4-1+"$(lsb_release -sc)"_all.deb
  565. dpkg -i /tmp/zabbix.deb
  566. rm -f /tmp/zabbix.deb
  567. }
  568. # enable color support of ls and also add handy aliases
  569. # some more ls aliases
  570. #alias wp='/usr/bin/wp --allow-root'
  571. alias .....="cd ../../../.."
  572. alias ....="cd ../../.."
  573. alias ...="cd ../.."
  574. alias ..="cd .."
  575. alias allservices='service --status-all'
  576. alias apt-bionic-kernel=_APT_BIONIC_KERNEL
  577. alias apt-repo-ubuntu=_APT_REPO_UBUNTU
  578. alias aptremove='apt-get autoremove -y --purge'
  579. alias arsync_hard='rsync -rLptgoD --human-readable --progress'
  580. alias arsync='rsync -avz -h --progress'
  581. alias bppackage=_BACKPORT_PACKAGE
  582. alias cheat=CHEAT_CHECK
  583. alias commit=GIT_COMMIT
  584. alias dd-benchmark=DD_BENCHMARK_DISK
  585. alias dir='dir --color=auto'
  586. alias docker-setup=EE_DOCKER_SETUP
  587. alias duplicate-finder=_find_duplicates
  588. alias ee-bashrc-update=update_git_mybashrc
  589. alias ee-ls=LIST_BY_SIZE
  590. alias ee-mysql-optimize=EE_MYSQL_OPTIMIZATION
  591. alias ee-syslog='tail -n 250 /var/log/syslog | ccze -A'
  592. alias egrep='egrep --color=auto'
  593. alias ffmpeg-cut-start=ffmpeg_start_time
  594. alias ftpadd=_FTP_ADD
  595. alias fgrep='fgrep --color=auto'
  596. alias gg="ping google.fr"
  597. alias gpg-crypt=encrypt_gpg
  598. alias gpg-decrypt=decrypt_gpg
  599. alias gpigz=compress_pigz
  600. alias grep='grep --color=auto'
  601. alias gunpigz=decompress_pigz
  602. alias install-nanorc=_INSTALL_NANORC
  603. alias IPPA=_PPA_INSTALL
  604. alias l='ls -CF'
  605. alias la='ls -A'
  606. alias ld='du -sh ./* | sort -h'
  607. alias lh="stat -c '%A %a %n' ./*"
  608. alias ll='ls -alhF'
  609. alias ls='ls --color=auto'
  610. alias lxclogin=_LXC_LOGIN
  611. alias lxclaunch=_LXC_LAUNCH
  612. alias magento-upgrade=MAGENTO_UPGRADE
  613. alias maintenance=MAINTENANCE_APT
  614. alias nano='nano -E'
  615. alias netdata-fix=_FIX_NETDATA
  616. alias nginx-ee=_NGINX_EE
  617. alias npm-update=_UPDATE_NPM
  618. alias passwdgen=_PWGEN
  619. alias pip='python3 -m pip'
  620. alias random-commit=RANDOM_GIT_COMMIT
  621. alias rsyslog-ufw=_RSYSLOG_UFW
  622. alias setdirperm=_PERM_FOLDER
  623. alias setfileperm=_PERM_FILES
  624. alias setup-nodejs=_INSTALL_NODEJS
  625. alias setup-tools=_SETUP_TOOLS
  626. alias show-fpm-process=EE_SHOW_FPM
  627. alias showlog=EE_SHOW_LOG
  628. alias sitespeed=_SITESPEED
  629. alias ssh-secure=_SSH_SECURE
  630. alias start-ssh=_START_SSH_AGENT
  631. alias sysinfo=_SYSINFO
  632. alias tinc-down=SET_TINC_DOWN
  633. alias tinc-up=SET_TINC_UP
  634. alias transfer=transfer_vtbox_net
  635. alias ufw-minimal=_UFW_MINIMAL
  636. alias vb-virtualenv=_PYTHON_VIRTUALENV
  637. alias vdir='vdir --color=auto'
  638. alias wo-virtualenv=_PYTHON_VIRTUALENV
  639. alias wp-fix-perms=_WP_PERMISSIONS
  640. alias upgrade-wo-full=_WO_FULL_UPGRADE
  641. alias speedtestnet="_run _SPEEDTEST 'Installing speedtest'"
  642. alias SSETUP=_SETUP_CONTROLLER
  643. alias journalctfail='journalctl -b -p err -S "yesterday"'
  644. alias zabbix-update=_ZABBIX_UPDATE