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.

815 lines
25KB

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