Bash script template

 Uncategorized  Comments Off on Bash script template
Oct 282022
 
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
    set -o xtrace
fi

if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
    echo 'Usage: ./script.sh arg-one arg-two

This is an awesome bash script to make your life better.

'
    exit
fi

cd "$(dirname "$0")"

main() {
    echo do awesome stuff
}

main "$@"

More info and source: https://sharats.me/posts/shell-script-best-practices/

 Posted by at 12:11

Hash file in windows

 Uncategorized  Comments Off on Hash file in windows
Oct 062022
 

cmd:

certutil -hashfile z:\desktop\lsr.exe SHA512

or powershell:

Get-FileHash -Path z:\desktop\lsr.exe -Algorithm SHA512

 Posted by at 09:48

Indent HTML using tidy

 Uncategorized  Comments Off on Indent HTML using tidy
Jun 202022
 

for my own reference:

tidy -indent --indent-spaces 2 --quiet --tidy-mark no --wrap 0 --drop-empty-elements no base.html > newbase.html
 Posted by at 09:32

Debian VM as GW routing through VPN (tun) with nftables

 Uncategorized  Comments Off on Debian VM as GW routing through VPN (tun) with nftables
Apr 072022
 

My LAN interfaces are ens3/ens8/ens9.

VPN tunnel set up using openvpn, gets dev tun0.

NFTables config file /etc/nftables.conf (do not forget to enable the nftables services):

flush ruleset
table inet filter {
  chain input {
    type filter hook input priority 0; policy drop;
    ct state {established, related} accept
    ct state invalid drop
    iifname lo accept
    iifname ens3 accept
    iifname ens8 accept
    iifname ens9 accept
    ip protocol icmp accept
    tcp dport 22 accept comment "SSH in"
    tcp dport 80 accept comment "HTTP in"
    tcp dport 443 accept comment "HTTPS in"
    reject
  }
  chain forward {
    type filter hook forward priority 0;
    oifname tun0 accept
    iifname tun0 ct state related, established accept
    iifname tun0 drop
  }
  chain output {
    type filter hook output priority 0;
  }
}
table ip nat {
  chain prerouting {
    type nat hook prerouting priority 0;
  }
  chain postrouting {
    type nat hook postrouting priority 0;
    oifname tun0 masquerade
  }
}

Thanks to: https://superuser.com/questions/985800/complete-masquerading-nat-example-using-nftables-on-linux/1225109#1225109

 Posted by at 05:35

mount LVM2_member

 Uncategorized  Comments Off on mount LVM2_member
Sep 042021
 

vgscan

vgchange -ay srv25centos

mount /dev/mapper/srv25centos-root /mnt/srv25

 Posted by at 08:58

Update RHEL/CentOS from local repo (iso/cd)

 Uncategorized  Comments Off on Update RHEL/CentOS from local repo (iso/cd)
Jul 232020
 
sudo -i
mount -o loop /tmp/*77*.iso /mnt
cat > /etc/yum.repos.d/cd.repo
[cd]
name=cd
baseurl=file:///mnt/
enabled=1
gpgcheck=0

#[PRESS enter and CTRL-d]
yum clean all; rm -rf rm -rf /var/cache/yum;  yum makecache fast
yum -y update --skip-broken
yum update
yum erase *devel
yum update kernel redhat-release
umount /mnt
rm -i /etc/yum.repos.d/cd.repo /tmp/*iso
cat /etc/redhat-release
reboot

 Posted by at 07:12

Pihole CORS problems

 Uncategorized  Comments Off on Pihole CORS problems
Jul 192020
 

Fix:

edit

/var/www/html/admin/scripts/pi-hole/php/auth.php

add your host names to

AUTHORIZED_HOSTNAMES

array

 Posted by at 16:27

Move cygwin to different disk, including services

 Uncategorized  Comments Off on Move cygwin to different disk, including services
Jul 142020
 
  1. Stop all services, log out other users, in process explorer, add command line column, stop all in old path
  2. In cygwin, go to /cygdrive, cp -vR c/cygwin* d/
  3. mount -m > /usr/bin/mountCommands.bat # not sure if we really need this
  4. in explorer, rename c:/cygwin to OLD , log off all users if it fails, use lsof alternative if needed
  5. change shortcut on desktop (C:\Users\Public\Desktop)
  6. change start menu items [ "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Cygwin\Cygwin64 Terminal.lnk"]
  7. change NEWLOC/cygwin.bat
  8. Regedit to HLM\system\CurrentControlSet\services\sshd and \cron and \syslog-ng change paths (for all services, do cygrunsrv -L)
  9. cygrunsrv --stop sshd; cygrunsrv --remove sshd; cygrunsrv --install sshd --path /usr/sbin/sshd
  10. Some more magic..?
  11. reboot
 Posted by at 12:25

ubnt / ubiquiti edgerouter passwordless login ssh keys

 Uncategorized  Comments Off on ubnt / ubiquiti edgerouter passwordless login ssh keys
Jul 052020
 
ubnt@er4gw:~$ configure
[edit]
ubnt@er4gw# set system login user ubnt authentication public-keys lb7 type ssh-rsa
[edit]
ubnt@er4gw# set system login user ubnt authentication public-keys lb7 key AAAA****3tfv0vaEUl
ubnt@er4gw# commit
ubnt@er4gw# exit
Warning: configuration changes have not been saved.
ubnt@er4gw:~$ cd .ssh
ubnt@er4gw:~/.ssh$ cat au*
# Automatically generated by Vyatta configuration
# Do not edit, all changes will be lost
ssh-rsa AAAA****3tfv0vaEUl lb7
ubnt@er4gw:~/.ssh$ configure
[edit]
ubnt@er4gw# save
 Posted by at 14:52

Bash remove spaces from file names

 Uncategorized  Comments Off on Bash remove spaces from file names
Jun 042020
 
find . -depth -name '* *' \
| while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done
 Posted by at 09:20

Outlook unblock “unsafe” attachments

 Uncategorized  Comments Off on Outlook unblock “unsafe” attachments
May 152020
 
Regedit, find:

Outlook 2007
[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Security]
Outlook 2010
[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Security]
Outlook 2013
[HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Security]
Outlook 2016, Outlook 2019 and Office 365
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security]

Level1Remove string
Value .cer;.exe;.xxx for the stuff you want to unblock.
 Posted by at 07:18

Extend a LVM-based swap partition

 Uncategorized  Comments Off on Extend a LVM-based swap partition
Apr 172020
 

Sometimes your swap is not large enough

[root@server ~]# free -g
total used free shared buff/cache available
Mem: 23 3 13 0 7 19
Swap: 1 0 1
[root@server ~]# grep swap /etc/fstab
/dev/mapper/vg00-swapvol swap swap defaults 0 0
[root@server ~]# swapoff /dev/mapper/vg00-swapvol
[root@server ~]# lvextend -L10g $_
Size of logical volume vg00/swapvol changed from 2.00 GiB (16 extents) to 10.00 GiB (80 extents).
Logical volume vg00/swapvol successfully resized.
[root@server ~]# mkswap $_
mkswap: /dev/mapper/vg00-swapvol: warning: wiping old swap signature.
Setting up swapspace version 1, size = 10485756 KiB
no label, UUID=xxx
[root@server ~]# swapon $_
[root@server ~]# free -g
total used free shared buff/cache available
Mem: 23 3 13 0 7 19
Swap: 9 0 9
 Posted by at 08:42

Tmux save all output (history) to file

 Uncategorized  Comments Off on Tmux save all output (history) to file
Feb 042020
 
bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -32768 ; save-buffer %1 ; delete-buffer'

Add above in tmux.conf. Then do Prefix+Shift+P

 Posted by at 20:31