Skip to content

Instantly share code, notes, and snippets.

View gpr's full-sized avatar

Grégory Romé gpr

View GitHub Profile
@gpr
gpr / teleport.sh
Created January 28, 2022 10:46
Setup remote environment shared with Teleport
# /etc/profile.d/teleport.sh
# Set environment in Teleport session
if [ -n "${SSH_TELEPORT_USER}" ]
then
USER_FIRSTNAME=$(echo "${SSH_TELEPORT_USER%%@*}" | cut -d'.' -f1)
USER_LASTNAME=$(echo "${SSH_TELEPORT_USER%%@*}" | cut -d'.' -f2)
export USER_FULLNAME="${USER_FIRSTNAME^} ${USER_LASTNAME^}"
export GIT_AUTHOR_NAME="${USER_FULLNAME}"
export GIT_AUTHOR_EMAIL="${SSH_TELEPORT_USER}"
@gpr
gpr / kubectl-copy-secret.sh
Last active May 17, 2021 08:29
[Copy secrets among different namespaces] #kubernetes #k8s #secrets
#!/bin/bash
#
# Example: ./kubectl-copy-secret.sh s3access default gitlab-runnner
SECRET_NAME=${1:?}
NS_SRC=${2:?}
NS_SRC=${3:?}
kubectl get secret $SECRET_NAME \
--namespace=$NS_SRC \
@gpr
gpr / snippet.yaml
Last active February 15, 2021 08:23
[Node affinity based on hostname] #kubernetes #pods
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node_hostname
@gpr
gpr / kubeconfig-merge.sh
Created November 12, 2020 13:59
[How to merge kubeconfig files?] Merge several configuration to manage them as context #k8s #kubernetes #kubectl
KUBECONFIG=file1:file2:file3 kubectl config view --merge --flatten > config.yaml
@gpr
gpr / CACHEDIR.TAG
Created October 17, 2019 07:48
[Cache Directory Tagging] See https://bford.info/cachedir/spec.html #tools #sysadmin
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag.
# For information about cache directory tags, see:
# http://www.brynosaurus.com/cachedir/
@gpr
gpr / mattermost-bot.sh
Created October 15, 2019 19:57
[Mattermost Bot Usage]
#!/usr/bin/env bash
curl -i -X POST -H 'Content-Type: application/json' -d '{"channel_id":"<channel-id>", "message":"This is a message from a bot", "props":{"attachments": [{"pretext": "Look some text","text": "This is text"}]}}' -H 'Authorization: Bearer <bot-access-token>' <mattermost-url>/api/v4/posts
@gpr
gpr / Systemd_Cheat_Sheet.md
Created August 7, 2019 08:18
[System Cheat Sheet] A collection of Howto about Systemd #systemd #doc
@gpr
gpr / git-log-show-jira-commit.bash
Last active July 30, 2019 11:31
[Show commits that contain a reference to a Jira issue] #jira #git
#!/usr/bin/env bash
#
# usage: git-log-show-jira-commit.bash <JIRA_KEY>
#
JIRA_KEY=${1:?}
REGEX="^.*(${JIRA_KEY}-\d+).*\$"
git log -P --grep="${REGEX}" --pretty=%H | while read line
do
@gpr
gpr / create-console
Created May 25, 2018 21:26
If you need to emulate a connection to a serial console.
$ brew install socat picocom
$ socat -d -d exec:/usr/bin/login,pty,setsid,setpgid,stderr,ctty pty,raw,echo=0
2018/05/25 23:22:38 socat[81257] N forking off child, using pty for reading and writing
2018/05/25 23:22:38 socat[81257] N forked off child process 81258
2018/05/25 23:22:38 socat[81257] N forked off child process 81258
2018/05/25 23:22:38 socat[81257] N PTY is /dev/ttys004
2018/05/25 23:22:38 socat[81257] N starting data transfer loop with FDs [5,5] and [7,7]
2018/05/25 23:22:38 socat[81258] W setpgid(0, 1): Operation not permitted
2018/05/25 23:22:38 socat[81258] W open("/dev/tty", O_NOCTTY, 0640): Device not configured
@gpr
gpr / pyexecvp.py
Created April 27, 2018 11:37
If you need to perform some action with python before executing another program
#!/usr/bin/env python3
import os
os.execvp("bash", ["-l"])