Skip to content

Instantly share code, notes, and snippets.

View mshafiee's full-sized avatar

Mohammad Shafiee mshafiee

View GitHub Profile
@mshafiee
mshafiee / create-certificate-stack.sh
Created February 13, 2023 20:59
This is a bash script that creates a CloudFormation stack for a public certificate with DNS validation, based on input parameters provided as command line flags.
#!/bin/bash
# This is a bash script that creates a CloudFormation stack for a public certificate with DNS validation,
# based on input parameters provided as command line flags.
# The script starts by defining the print_help function that displays the usage information for the script,
# along with the available command line flags.
# Next, the script uses the getopts command to parse the command line flags and store their values in variables
# (stack_name, csv_file, and domain_name). If any of the required flags are missing, the script will display
# an error message and exit.
# The script then reads the contents of the CSV file into a bash array (subject_alternative_names), which
# will be used to specify the SubjectAlternativeNames for the certificate.
@mshafiee
mshafiee / resetBranch.sh
Created February 4, 2023 15:14
This bash script will check if a branch named BRANCH_NAME exists in the Git repository. If it exists, it will checkout to that branch and reset the branch to the previous commit, discarding all previous commits except the last one. It will then rename the latest commit to COMMIT_NAME and push the rewritten branch to the remote repository. Finall…
#!/bin/bash
# This bash script will check if a branch named BRANCH_NAME exists in the Git repository.
# If it exists, it will checkout to that branch and reset the branch to the previous commit,
# discarding all previous commits except the last one. It will then rename the latest
# commit to COMMIT_NAME and push the rewritten branch to the remote repository.
# Finally, it will display a message indicating that the branch has been rewritten
# and the last commit has been renamed.
if [ $# -ne 2 ]; then
# This script is a command line tool that reads German conjugations of the verb "sein" (to be)
# in the present tense using Festival TTS engine on Linux. The script declares an array of strings,
# each string containing a conjugation of the verb "sein" for a different personal pronoun.
# Then, it uses an infinite while loop to iterate over the array, reading each conjugation 60 times
# with a sleep of 1 second in between each reading. The script uses the echo "$i" | festival --tts -voice de
# command to read the current string in the array, where -voice de option is added to the festival --tts command,
# which causes the TTS engine to use a German voice. The script is useful for language learners who want to
# practice the conjugations of the verb "sein" in the present tense on Linux.
# How to install festival:
# sudo apt-get install festival
@mshafiee
mshafiee / sysctl.conf
Last active June 27, 2022 09:50
Customized sysctl for high network loads
###################################################################
# Protected links
#
# Protects against creating or following links under certain conditions
# Debian kernels have both set to 1 (restricted)
# See https://www.kernel.org/doc/Documentation/sysctl/fs.txt
#fs.protected_hardlinks=0
#fs.protected_symlinks=0
net.ipv4.ip_forward=1
#net.ipv4.ip_local_reserved_ports=30000-32767
@mshafiee
mshafiee / haproxy.cfg
Last active June 13, 2022 10:34
Sample of HAProxy active-active peers rate limiting by counting a custom header
global
localpeer haproxy-1
defaults
timeout connect 5s
timeout client 1m
timeout server 1m
peers haproxy-peers
@mshafiee
mshafiee / bash.sh
Created May 12, 2022 11:57
bash cheatsheets
#!/bin/bash
##############################################################################
# SHORTCUTS and HISTORY
##############################################################################
CTRL+A # move to beginning of line
CTRL+B # moves backward one character
CTRL+C # halts the current command
CTRL+D # deletes one character backward or logs out of current session, similar to exit
CTRL+E # moves to end of line
@mshafiee
mshafiee / clean.sh
Created May 12, 2022 11:39
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
#!/bin/sh
#Check the Drive Space Used by Cached Files
du -sh /var/cache/apt/archives
#Clean all the log file
#for logs in `find /var/log -type f`; do > $logs; done
logs=`find /var/log -type f`
for i in $logs
@mshafiee
mshafiee / install-latest-docker.sh
Created May 12, 2022 11:26
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
@mshafiee
mshafiee / join-ubuntu-to-ad-dc.sh
Last active May 11, 2022 12:00
Join Ubuntu 20.04.4 to Active Directory Domain
#!/bin/bash
JDC_ORG_UNIT=""
JDC_ORG_ENV=""
JDC_DOMAIN_NAME=mydomain.com
JDC_AD_DC1_IP=192.168.240.11
JDC_AD_DC2_IP=192.168.240.12
JDC_AD_DC1_NAME=dc1-inf-ad-ds1.mydomain.com
JDC_AD_DC2_NAME=dc1-inf-ad-ds2.mydomain.com
JDC_HOST_NAME=$(hostname | awk -F'.' '{print $1}').$JDC_DOMAIN_NAME
JDC_GROUP_PREFIX="os"
@mshafiee
mshafiee / netplan-set-custom-dns.sh
Created May 8, 2022 13:36
Ubuntu 20.04.4 - Scripting Netplan for custom DNS address
sudo snap install yq
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bk_`date +%Y%m%d%H%M`
cat /etc/netplan/00-installer-config.yaml | yq -e '.network.ethernets.ens160.nameservers.addresses[0]="192.168.10.11" | .network.ethernets.ens160.nameservers.addresses[1]="192.168.10.12"' | sudo tee /etc/netplan/00-installer-config.yaml
sudo netplan apply