Skip to content

Instantly share code, notes, and snippets.

@polster
polster / rbenv-brew-setup.sh
Created May 12, 2017 12:17
Ruby: Install Ruby Version with rbenv and homebrew on macOS
# Install
brew install rbenv ruby-build
# List available ruby versions
rbenv -l
# Install the required ruby version
rbenv install 2.4.1
rbenv global 2.4.1
@polster
polster / iptables-config.sh
Last active April 24, 2024 13:16
iptables: Sample Configuration
#!/bin/sh
# Abort script when command exits with error
set -e
# Print each command before it is executed (only for debugging)
#set -x
########################################################################
# Config
@polster
polster / ssh-copy.sh
Created March 9, 2017 09:16
SSH: Key distribution
# On systems without ssh-copy-id:
cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key copied"'
# Or:
ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<hostname>
@polster
polster / httpd-vhost-php-minimal.conf
Created March 2, 2017 07:45
Apache: Minimal vhost sample for serving a PHP app
<VirtualHost 172.4.16.23:80>
DocumentRoot /opt/httpd/vhosts/wp.example.com/htdocs
ServerName wp.example.com
ServerAlias community-new.hintest.ch
ErrorLog /opt/httpd/logs/error.wp.example.com.srv-web01.log
CustomLog /opt/httpd/logs/access.wp.example.com.srv-web01.log combined
# Inherit Rewrite Rules from httpd.conf
RewriteEngine On
RewriteOptions InheritBefore
@polster
polster / virtualbox-shared-folder.sh
Created March 1, 2017 14:27
Virtualbox: How to add share a local folder with the Linux Guest
# Ensure the local folder to be shared with the guest has been configured in VirtualBox (Menu > Devices > Shared Folders)
# Create local mount point, assuming the shared folder's name corresponds to Downloads
mkdir -p Shares/VBox/Downloads
# Mount by specifying the right user/group id plus mount filesystem type
sudo mount -o uid=1000,gid=1000 -t vboxsf Downloads ~/Shares/VBox/Downloads/
@polster
polster / docker-dns-fixing.sh
Last active February 28, 2017 14:47
Docker: How to fix Docker DNS problems
# Login to your Docker host
# Print the Docker host's configured DNS servers
nmcli dev show | grep 'IP4.DNS'
# Run the following command in order to check if DNS resolution within the container is working (using one of the DNS servers)
docker run --dns <dns host or ip> busybox nslookup google.com
# In case there are no errors and resolution works, we may apply a system wide fix (adjust the DNS entries as needed):
echo "{
@polster
polster / macos-terminal-gatekeeper.sh
Created January 30, 2017 07:54
macOS: Allow Gatekeeper untrusted apps
# Check if a specific app has been quarantined by Gatekeeper
➜ ~ xattr Applications/Eclipse.app
com.apple.quarantine
# Remove the app from the quarantine
➜ ~ sudo xattr -r -d com.apple.quarantine Applications/Eclipse.app
@polster
polster / configure-nrpe.yml
Created January 12, 2017 22:53
Ansible: Replace key value in config file
- name: "NRPE config: Update hosts allowed to call the NRPE agent"
replace:
dest: "{{ ansible_nagios_nrpe_config_file }}"
replace: 'allowed_hosts={{ ansible_nagios_nrpe_source_hosts }}'
regexp: 'allowed_hosts=\s*([^\n\r]*)'
notify:
- Restart NRPE agent
- Run NRPE check
- Assert NRPE check was successful
@polster
polster / defaults-main.yml
Last active January 1, 2017 00:12
Ansible: Trigger certain installation or setup tasks over a self managed version file (sample)
# Ansible role's default vars
---
# The NRPE version
ansible_nagios_nrpe_version: "3.0.1"
# Allows to force a re-installation
ansible_nagios_nrpe_reinstall_force: false
@polster
polster / ssl-ca-signed-certs.sh
Created December 26, 2016 13:53
SSL Certs: Root CA with client and server certs signing sample
# Create root CA
openssl genrsa -aes256 -out ca-key.pem 4096
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
# Create Server key and CSR
openssl genrsa -out server-key.pem 4096
openssl req -subj "/CN=docker-node01-dev" -sha256 -new -key server-key.pem -out server.csr
# Create trusted Server Certificate
echo subjectAltName = DNS:docker-node01-dev,IP:192.168.9.70,IP:127.0.0.1 > extfile.cnf