Skip to content

Instantly share code, notes, and snippets.

View bahamat's full-sized avatar
☁️

Brianna Bennett bahamat

☁️
View GitHub Profile
@bahamat
bahamat / make-bootable-image.sh
Created March 8, 2023 21:10 — forked from oetiker/make-bootable-image.sh
How to create a bootable disk image that works with bios and uefi
#!/bin/sh
# apt install gdisk syslinux syslinux-efi mtools
IMG=boot-image.img
SIZE=300
KERNEL=vmlinz
INITRAMFS=initrd.img
MD="mmd -i ${IMG}@@1M"
CP="mcopy -i ${IMG}@@1M"
RN="mren -i ${IMG}@@1M"
dd if=/dev/zero bs=1M count=$SIZE of=$IMG
@bahamat
bahamat / sync-authorized-keys.sh
Created October 27, 2020 17:25
Configure Triton CNs to use the same ssh keys as the headnode.
#!/bin/bash -x
node_config=/usbkey/extra/joysetup/node.config
if ! grep -q root_authorized_keys_file "$node_config" ; then
echo "root_authorized_keys_file='root.authorized_keys'" >> "$node_config"
fi
sdc-oneachnode -X -c -g /usbkey/config.inc/root.authorized_keys -d /opt/smartdc/config/
sdc-oneachnode -c 'svcadm restart smartdc/config'
@bahamat
bahamat / smtptest
Last active October 8, 2021 23:47
Using curl to send mail via SMTP
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Copyright 2014 Brian Bennett
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
@bahamat
bahamat / time-machine.sh
Last active April 30, 2024 19:06
DNS-SD Bonjour service discovery for Time Machine volumes
#!/bin/bash -x
if [[ -z $1 ]]; then
printf 'Must supply a path\n'
exit 1
fi
# We want to advertise a consistent volume UUID that will survive reprovisions.
zone_uuid=$(zonename)
bonjour_name="$(hostname -s).local"
@bahamat
bahamat / zpool_2x2_to_3x.txt
Created April 5, 2020 05:26
Convert a zpool from mirror/stripe (raid 10) to 3-way mirror
# zpool create tank mirror /var/tmp/f1 /var/tmp/f2 mirror /var/tmp/f3 /var/tmp/f4
# zpool list tank
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
tank 1.88G 1.36M 1.87G - - 0% 0% 1.00x ONLINE -
# zpool status tank
pool: tank
state: ONLINE
scan: none requested
config:
@bahamat
bahamat / zone_count.prom
Last active March 17, 2020 03:06
CMON plugin to get gz zone count metrics
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Copyright 2020 Joyent, Inc.
printf '# HELP plugin_zone_count Zone count by state\n'
printf '# TYPE plugin_zone_count gauge\n'
@bahamat
bahamat / sdc-ssh
Created March 9, 2020 18:33
sdc-ssh: SSH to CN by hostname or uuid for Triton headnode
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2020 Joyent, Inc.
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
@bahamat
bahamat / anycast
Last active August 2, 2020 16:47
Anycast Example using Quagga on SmartOS
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# This is the SMF start method for anycast.
# Put it in /opt/custom/smf/anycast
set -o xtrace
@bahamat
bahamat / mph-example.sh
Created February 17, 2020 16:24
Manta MPU multi-part upload example
#!/bin/bash
# MPU parts need to be minimum 5MB, except the last part.
split -b 5m file part.
# Create MPU transaction
mpu_id=$(mmpu create ~~/stor/file)
# Upload each part
part0=$(mmpu upload -f part.aa "$mpu_id" 0)
part1=$(mmpu upload -f part.ab "$mpu_id" 1)
@bahamat
bahamat / chroot_example.sh
Last active March 19, 2020 00:07
chroot in lx brand zone
#!/bin/bash
# MIT License.
# This isn't meant to be run as a script exactly, but github has better syntax hilighting if I pretend.
chr=${PWD}/testroot
mkdir -p $chr/{bin,lib,lib64,native,var}
cd $chr
cp -v /bin/{bash,touch,ls,rm} $chr/bin