Skip to content

Instantly share code, notes, and snippets.

View anonymouse64's full-sized avatar
๐ŸŽ
Think Different

Ian Johnson anonymouse64

๐ŸŽ
Think Different
View GitHub Profile
@anonymouse64
anonymouse64 / check-ld-cache-good.sh
Created November 25, 2019 18:12
Script to ensure ld.so.cache is usable and updated
#!/bin/sh -e
# save the original LD_LIBRARY_PATH, and unset it to check the cache
ORIGINAL_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
LD_LIBRARY_PATH=""
export LD_LIBRARY_PATH
# FINAL_BINARY should be set and exported to what the "real" final executable
# that's run is so we can check that
# an alternative would be to always run the "real" final executable immediately
@anonymouse64
anonymouse64 / install.sh
Created November 25, 2019 18:13
Chromium snap install hook to create private, correct /etc/ld.so.cache
#!/bin/bash -ex
# make sure our fake ld.so.cache exists
if [ ! -f "$SNAP_DATA/etc/ld.so.cache" ]; then
echo "snap private ld.so.cache doesn't exist!"
exit 1
fi
# copying the conf dir from real /etc into $SNAP_DATA
mkdir -p "$SNAP_DATA/etc/ld.so.conf.d"
@anonymouse64
anonymouse64 / gnome-calculator-file-trace.json
Created November 28, 2019 04:45
JSON of all files accessed by gnome-calculator snap
This file has been truncated, but you can view the full file.
{
"ExecvePaths": {
"AllFiles": [
"/snap/gnome-calculator/current",
"/snap/gnome-calculator/x1",
"/snap/gnome-calculator/x1/data-dir",
"/snap/gnome-calculator/x1/data-dir/icons",
"/snap/gnome-calculator/x1/data-dir/icons/Adwaita",
"/snap/gnome-calculator/x1/data-dir/icons/Adwaita/16x16/devices",
"/snap/gnome-calculator/x1/data-dir/icons/Adwaita/16x16/emblems",
config: {}
networks:
- config:
ipv4.address: auto
ipv6.address: auto
description: ""
name: lxdbr0
type: ""
storage_pools:
- config: {}
@anonymouse64
anonymouse64 / example.go
Created July 16, 2020 18:42
go-check MockCommand mocking of a fully verifying argument script
func mockRealSystemdMountInBash(c *C, expArgs [][]string) *testutil.MockCmd {
stateCallFile := filepath.Join(c.MkDir(), "systemd-mount-state-call")
template := fmt.Sprintf(`
STATE_FILE=%s
if [ ! -f "$STATE_FILE" ]; then
CALL_NUM=0
else
CALL_NUM=$(cat "$STATE_FILE")
fi
@anonymouse64
anonymouse64 / hashmap.go
Created July 31, 2020 14:26
Hash a map and a bool in Go deterministically
func hashMapAndBool(b bool, m map[string]string) string {
h := sha256.New()
// hashing maps is not deterministic because it is not sorted, so we have
// to manually hash each key value into another hash after sorting
// first we hash the string representation of the bool
h.Write([]byte(fmt.Sprintf("%v", b)))
keys := make([]string, len(m))
i := 0
@anonymouse64
anonymouse64 / sign-system-user-assertion.sh
Created September 25, 2020 10:28
simplistic shell script for creating system-user assertions for use with snapd/ubuntu core
#!/bin/bash
set -e
# first argument is the name of the key to sign the assertion with
if [ "$#" != 1 ]; then
echo "usage: ./sign-system-user-assertion <key-name>"
exit 1
fi
@anonymouse64
anonymouse64 / kernel_cmdline.go
Created November 18, 2020 02:30
pointless overly complicated and overly engineered kernel cmdline parsing utilities using SplitFunc supporting quotes (but not nested quotes!) in Go
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2020 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
@anonymouse64
anonymouse64 / self-signed-root-account-key-assertion.go
Created February 11, 2021 14:42
Generate a self signed root account-key assertion for snapd
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2021 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
@anonymouse64
anonymouse64 / leaf-account-key-testkeys-assertion.go
Last active February 12, 2021 14:59
Generate a leaf, non-self-signed account-key assertion with associated private key for use with snapd
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2021 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,