Skip to content

Instantly share code, notes, and snippets.

View sjorge's full-sized avatar

Jorge Schrauwen sjorge

View GitHub Profile
@sjorge
sjorge / syncthing-backup.md
Last active July 31, 2023 14:16
using syncthing for backups

introduction

I wanted to replace rsync for my current host backups.

I had 2 hosts (1 laptop and 1 desktop) that would get there changes polled from a backup server. (polled = cronjob ran every hours) Ofcourse those boxes are not always on and a frenzy of cron mails happen every now and then.

I replaced everything with syncthing, they have clients available for linux, illumos, openbsd and mac. With the config below (client::folder master = yes, server::folder master = no) we prevent the server from accidentally overriding a file on the client. The client knows the server's IPv4 and/or IPv6 address so we do not need global or local discovery nor UPnP.

Currently I am stuck trying to retrieve the version of the chip, which seems to be needed to configure it slightly different later on. FreeBSD function https://github.com/freebsd/freebsd/blob/f6abce8e79ecc1992d2d0b2e53f8e92ab3102671/sys/dev/usb/serial/uchcom.c#L479, which calls a different function to read data into a buffer from the device.

A similar function is also present for writing, based on ftdi and pl2303 I managed to get the write function to work (I think, it returns USB_SUCCESS). However I cannot get the read function to work, It returns USB_FAILURE with CR set to Endpoint returned stall PID

static int
uchcom_cmd_vendor_write0(uchcom_state_t *uch,
@sjorge
sjorge / persist-syscfg
Created December 1, 2014 16:38
SmartOS File Server
#!/usr/bin/bash
# Originally based on http://wiki.smartos.org/display/DOC/Allowing+user+CRUD+in+the+global+zone
# Author: hugo@freenode
enable_stmf=1
enable_smb=1
enable_nfs=1
save_us=( /etc/passwd /etc/shadow /etc/group /etc/ouser_attr /etc/user_attr \
/etc/security/policy.conf /etc/security/auth_attr /etc/security/exec_attr \
@sjorge
sjorge / auto_home
Last active January 11, 2020 16:23
#!/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 2019 Joyent, Inc.
# Inspired by
# http://znogger.blogspot.com/2010/05/solaris-automatic-creation-of-home-dirs.html
#!/usr/bin/bash
## CONFIG
# Lookup USBKEY: disklist -r
AUTO_REBOOT=1
MIRROR=us-east.manta.joyent.com
USBKEY=c1t0d0
## INIT
CURRENT_REFERENCE=$(curl -s -k https://${MIRROR}/Joyent_Dev/public/builds/smartos/ | grep release | tail -n 1 | json name)
@sjorge
sjorge / 1_salt_grains_mdata.patch
Last active July 9, 2019 11:24
salt.grains.mdata
--- /opt/tools/lib/python2.7/site-packages/salt/grains/mdata.py Tue Jul 9 11:24:40 2019
+++ /opt/tools/lib/python2.7/site-packages/salt/grains/mdata.py.fix Tue Jul 9 11:24:07 2019
@@ -63,6 +63,8 @@
return grains
for mdata_grain in __salt__['cmd.run'](mdata_list, ignore_retcode=True).splitlines():
+ if mdata_grain.startswith("ERROR:"):
+ continue
mdata_value = __salt__['cmd.run']('{0} {1}'.format(mdata_get, mdata_grain), ignore_retcode=True)
@sjorge
sjorge / 1_grain.yaml
Last active July 9, 2019 07:37
salt.grains.smartos fixes
pkgin_repositories:
- https://pkgsrc.joyent.com/packages/SmartOS/2018Q1/tools/All
- http://pkg.blackdot.be/packages/2018Q1/tools/All
pkgsrcpath:
https://pkgsrc.joyent.com/packages/SmartOS/2018Q1/tools/All
pkgsrcversion:
2018Q1
@sjorge
sjorge / zone-bootstrap.sh
Created March 10, 2017 07:19
SaltStack Boostrapper for SmartOS
#!/bin/bash
####
## Acheron SaltStack Bootstrap
## ---------------------------
####
### configuration
SALT_VERSION=2016.11
SALT_MASTER=salt-master.example.org
LOGFILE=/var/log/bootstrap.log
[16:05:04] <sjorge> There is a mistake in https://mgerdts.github.io/2018/03/14/omnios-bhyve-guest.html, the zfs clone command has omios instead of omnios
[16:05:49] <mgerdts> that's what I get for not logging my terminal when I may create a blog post. :)
[16:05:52] <mgerdts> thanks, will fix
[16:51:30] <sjorge> I got it all up and running now, I got a few more remarks
[16:51:33] <sjorge> bhyvectl --destroy --vm=o1
[16:51:41] <sjorge> Is needed to free o1
[16:51:45] <mgerdts> ah yes
[16:51:49] <sjorge> missing manifest.json example, perhaps link https://raw.githubusercontent.com/joyent/manifest-creator/master/create-kvm-manifest
[16:54:19] <sjorge> https://gist.github.com/sjorge/0dfd42584249e2827a38bfff4ceacf76 <- not sure this is by design or not
/*
* HD Set Parm
* ----------------------------
* Based on setapm and setaam from:
* http://solaris.kuehnke.de/archives/23-Set-APM-and-AAM-feature-configuration \
* -attributes-for-disks-on-Solaris.html
*/
#include <stdio.h>
#include <stdlib.h>