Skip to content

Instantly share code, notes, and snippets.

@viktordw
viktordw / .cpanel.yml
Created August 16, 2021 11:53
primer cPanel deploy fajla.
---
deployment:
tasks:
- DEPLOYPATH="/home/$USER/public_html"
- TEMPDIR="/home/$USER/tmp/public_html"
- REPOPATH="/home/${USER}/repositories"
- rm -r $TEMPDIR; mkdir $TEMPDIR
- cp -Tar ${DEPLOYPATH}/.well-known ${TEMPDIR}/.well-known
- cp -Tar ${DEPLOYPATH}/cgi-bin ${TEMPDIR}/cgi-bin
- cp -Tar ${DEPLOYPATH}/index.phtml ${TEMPDIR}/index.phtml
@viktordw
viktordw / get_shell_name.sh
Created August 17, 2021 14:00
Get shell executable name
# https://stackoverflow.com/questions/23011370/how-to-recognize-whether-bash-or-dash-is-being-used-within-a-script
getTrueShellExeName() {
local trueExe nextTarget 2>/dev/null # ignore error in shells without `local`
# Determine the shell executable filename.
trueExe=$(ps -o comm= $$) || return 1
# Strip a leading "-", as added e.g. by OSX for login shells.
[ "${trueExe#-}" = "$trueExe" ] || trueExe=${trueExe#-}
# Determine full executable path.
[ "${trueExe#/}" != "$trueExe" ] || trueExe=$([ -n "$ZSH_VERSION" ] && which -p "$trueExe" || which "$trueExe")
@viktordw
viktordw / simple_args_parsing.sh
Created November 17, 2021 12:14 — forked from jehiah/simple_args_parsing.sh
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"
@viktordw
viktordw / gist:c9e4adfac8d5dcff6004a724f257bc36
Created December 25, 2021 11:18 — forked from reikind/gist:4072830
Example bash getopts
#!/bin/bash
usage() {
cat << EOT
usage $0 [-hgw]
$0 -m MESSAGE
OPTIONS
@viktordw
viktordw / pager.sh
Created February 10, 2022 15:07
Less pager
#!/bin/bash
text=$(curl -s 'https://baconipsum.com/api/?type=meat-and-filler')
pager() {
# if stdout is not to a TTY, copy directly w/o paging
[ -t 1 ] || { cat; return; }
if [ -n "$PAGER" ]; then
"$PAGER"
@viktordw
viktordw / uset-wp-install.sh
Last active February 24, 2022 15:01
WordPress installation script - taken from https://github.com/sitemapxml/USet
#!/bin/bash
# WordPress install script
# This is a snippet from USet. It is not functional on its own.
# Project URL: https://github.com/sitemapxml/USet
# config.txt
# Wordpress settings
conf_wp_wget_locale='https://wordpress.org/latest.tar.gz'
conf_wp_aditional_php_extensions='php-xmlrpc php-exif'
@viktordw
viktordw / ip-check.sh
Created August 12, 2022 13:11
Check public IP address of server
#!/bin/bash
# NOTE: route command is part of dnsutils package on Debian, and net-tools on Ubuntu
# Based on following Stack Overflow answer:
# https://stackoverflow.com/questions/14594151/methods-to-detect-public-ip-address-in-bash/22209864#22209864
MAINIF=$( route -n | grep '^0\.0\.0\.0' | head -n 1 | awk '{print $NF}' )
IP=$( ifconfig $MAINIF | awk -v row=2 'FNR == 'row' {print $2}' )
echo $IP
@viktordw
viktordw / checkmk-install.sh
Created August 12, 2022 13:55
Install checkmk monitoring server
#!/bin/bash
# https://checkmk.com/download
if [ -n `command -v ufw` ]; then
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
fi
@viktordw
viktordw / disable-comments.sh
Created August 30, 2022 07:59 — forked from jplhomer/disable-comments.sh
Disable all comments/pings in WordPress with WP-CLI
$ wp post list --format=ids | xargs wp post update --comment_status=closed
# Output:
# Success: Updated post 2514.
# Success: Updated post 2511.
# Success: Updated post 2504.
# Success: Updated post 2499.
# Success: Updated post 2441.
# etc...
declare -a DIRS
savedir() {
local i
for ((i=1;i<=9;i++)); do
test "$1" = "${DIRS[$i]}" && return
done
for ((i=9;i>1;i--)); do
DIRS[$i]="${DIRS[((i-1))]}"
done