Skip to content

Instantly share code, notes, and snippets.

@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 / cmon.sh
Last active April 25, 2024 18:43
Shell script to pull CMON metrics from Joyent Triton (https://www.joyent.com/triton)
#!/bin/bash
# shellcheck disable=SC2154
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
export PATH=/opt/pkg/bin:/opt/local/bin:/opt/custom/bin:$PATH
@bahamat
bahamat / shell_config.md
Last active March 15, 2023 02:42
How are various shells configured, and in which order?

ash & dash

login interactive files
N N
N Y $ENV
Y N /etc/profile, ~/.profile
Y Y /etc/profile, ~/.profile, $ENV

bash

@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 / no_compute_resources_available.md
Last active December 5, 2021 07:14
Diagnosing "No Compute Resources Available" messages in Triton.

No Compute Resources Available

This error is somewhat ambiguious because there is seemingly no indication which resource is exhausted.

Triton chooses compute nodes with a subcomponent called sdc-designation (also refered to as , DAPI). The full DAPI log for a provision job is embedded in the CNAPI log file and can be extracted with the workflow job uuid.

Note: The script below is no longer necessary because cnapi now includes /opt/smartdc/cnapi/bin/alloc-reasons.sh which does the same thing.

#!/bin/bash
@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 / triton-update-all
Last active January 31, 2021 16:52
Script to update/upgrade all components of SDC/Triton
[root@headnode (barovia) ~]# cat /opt/custom/bin/update-all
#!/bin/bash
set -o errexit
set -o xtrace
imgadm vacuum -f
sdcadm update --all --just-images -y
sdcadm self-update --allow-major-update --latest
@bahamat
bahamat / gist:c154b59ea1c5710e141c
Last active December 20, 2020 01:06 — forked from bdha/gist:c456cf6e5484ea5ad256
haskell ghc on smartos
@bahamat
bahamat / gist:7c4abade72d674e34281
Last active December 20, 2020 01:05
Magical quoting with printf %q
$ echo quote what? ; read quoteme ; printf %q "$quoteme" ; echo
quote what?
The horse said "$)#*@(!!%" when he stubbed his hoof.
The\ horse\ said\ \"\$\)#\*@\(\!\!%\"\ when\ he\ stubbed\ his\ hoof.
$
@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'