Skip to content

Instantly share code, notes, and snippets.

View tsjk's full-sized avatar

Tamas Jantvik tsjk

View GitHub Profile
@tsjk
tsjk / reboot--CG3700EMR-1CMNDS.js
Created February 12, 2016 11:14
Rebooting a NETGEAR Gateway CG3700EMR-1CMNDS using CasperJS. Usage: casperjs reboot--CG3700EMR-1CMNDS.js <routerIP> <adminLogin> <admiPassword>
var casper = require('casper').create();
var utils = require('utils');
casper.start();
casper.setHttpAuth(casper.cli.get(1), casper.cli.get(2));
casper.thenOpen('http://' + casper.cli.get(0)).then(function() {
this.echo(this.getTitle() + ': Logged in.');
});
@tsjk
tsjk / xml_grep.sh
Created March 10, 2016 08:49
Search for nodes in an XML containing an expression and report the xpaths of the findings, using xml-coreutils and coreutils
#!/bin/bash
SEARCH_STRING="${1}"
ROOT_NODE="${2}"
FILE="${3}"
XPATHS=( $(xml-grep --extended-regexp --attributes "${SEARCH_STRING}" "${FILE}" | xml-fmt | xml-find | sed 's@^/root@/'"${ROOT_NODE}"'@' | tac) )
i_="";
NODE_XPATHS=( $(for i in "${XPATHS[@]}"; do if ! echo "${i_}" | egrep -q "${i}"; then echo "${i}"; fi; i_="${i}"; done) )
for i in "${NODE_XPATHS[@]}"; do
k=1;
for j in $(xml-printf '%s' "${FILE}" ":${i}"); do
@tsjk
tsjk / docker-proot-static-build.sh
Last active May 16, 2021 18:15
Build a patched proot (x86_64)
#!/bin/bash
pushd ~/".docker" || exit 1; if [[ ! -d "docker-proot-static-build" ]]; then git clone "https://github.com/proot-me/proot-static-build.git" -b build_environment docker-proot-static-build;
else ( cd ~/".docker/docker-proot-static-build" && git pull ); fi; popd
pushd ~/".docker/docker-proot-static-build" || exit 1; docker build -t proot/proot-buildenv:latest -f Dockerfile.x86_64 . || exit 1; popd
if [[ -n "${1}" ]]; then GIT_SHA="${1}"; shift 1; fi
if [[ -n "${1}" ]]; then exit 254; fi
if [[ -z "${GIT_SHA}" ]]; then
@tsjk
tsjk / archzfs-alarmpi1-compile.sh
Last active January 27, 2022 09:32
Compilation of ARCHZFS on ALARMPI1
#!/bin/bash
### This can be run as:
### bash -i -c "source <(curl -L 'https://gist.githubusercontent.com/tsjk/4b387dd685b9942bcc23497fd3345b99/raw')"
### This script aims to upgrade your kernel packages, and then install ArchZFS the kernel packages installed.
declare -g -i COMPILE_LOCALLY=0
[[ "${1}" != "--compile-locally" ]] || { COMPILE_LOCALLY=1; shift 1; }
[[ -z "${*}" ]] || exit 1
@tsjk
tsjk / PowerCycle.lua
Last active April 16, 2024 11:02
Telldus Lua program for power cycling
-- File: PowerCycle.lua
-- Call with (e.g.): curl -s -X GET 'http://<ip_address>/api/lua/call?script=PowerCycle&function=powerCycle&deviceName=<device_name>&initialDelaySec=<seconds>&delaySec=<seconds>' -H 'Authorization: Bearer <access_token>'
-- File: PowerCycle.lua
local ON = 1
local OFF = 2
local deviceManager = require "telldus.DeviceManager"
local nRetries = 3
local retryDelayMs = 1000
@tsjk
tsjk / DH1080_tcl.so.sh
Last active April 9, 2020 14:41
Static compilation of DH1080_tcl.so on Gentoo (given net-irc/irssi-mod-fish/irssi-mod-fish-9999.ebuild in /usr/local/portage)
#!/bin/bash
[[ -d "/usr/local/portage/net-irc/irssi-mod-fish" ]] && DH1080_TCL_REPO=$(mktemp -d) && \
( cd /usr/local/portage/net-irc/irssi-mod-fish && sudo ebuild irssi-mod-fish-9999.ebuild clean compile ) && \
( sudo chown -R "$(id -nu)": "/tmp/portage/net-irc/irssi-mod-fish-9999" ) && \
( cd "${DH1080_TCL_REPO}" && git clone "https://github.com/orkim/dh1080_tcl.git" ) && \
( cd "/tmp/portage/net-irc/irssi-mod-fish-9999/work/irssi-mod-fish-9999/src" && \
cp -av "${DH1080_TCL_REPO}/dh1080_tcl"/* ./ && rm -rf "${DH1080_TCL_REPO}" && \
sed -i -E 's@^TCLINC=.*@TCLINC=\/usr\/include@' make_linux* && \
./make_linux64.sh && cp -av DH1080.so DH1080_tcl.so ~/ ) && \
( cd /usr/local/portage/net-irc/irssi-mod-fish && sudo ebuild irssi-mod-fish-9999.ebuild clean ) && \
@tsjk
tsjk / 79_usbmode
Last active August 9, 2020 13:40
/lib/preinit/79_usbmode - For pre-init USB mode switch on OpenWRT
#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
# To be included in ROM image, together with at least usb-modeswitch,
# kmod-usb-storage and a /etc/usb-mode.preinit.json.
#
# Tested on OpenWRT v19.07.3
log_usbmode() {
@tsjk
tsjk / openwrt-v19.07.9-ar71xx-tiny-config.diff
Last active April 13, 2022 20:02
Generated OpenWRT v19.07.9 diffconfig for TP-Link TL-MR3420 V2 - with USB storage support for extroot on an f2fs-formatted USB-stick
# Usage: ( VERSION="19.07.9" && ARCH="ar71xx" && TYPE="tiny" && cd "${OPENWRT_BUILD_DIR}" && \
# wget -O './.config' "https://downloads.openwrt.org/releases/${VERSION}/targets/${ARCH}/${TYPE}/config.buildinfo" && \
# cat "${THIS_FILE}" >> ./.config && make defconfig )
CONFIG_TARGET_ar71xx=y
CONFIG_TARGET_ar71xx_tiny=y
CONFIG_TARGET_ar71xx_tiny_DEVICE_tl-mr3420-v2=y
CONFIG_ALL_KMODS=y
CONFIG_ALL_NONSHARED=y
CONFIG_DEVEL=y
CONFIG_AUTOREMOVE=y
@tsjk
tsjk / imgbuilder-19.07.9-ar71xx-tiny.sh
Last active April 13, 2022 20:05
OpenWRT v19.07.9 extroot image for the TP-Link TL-MR3420 V2 - the easy way
#!/bin/bash
BASENAME=$(basename "${0}"); DIRNAME=$(dirname "${0}"); DIRNAME=$(realpath "${DIRNAME}");
VERSION=$(grep -oP '(?<=imgbuilder-)[0-9\.]+(?=-)' <<< "${BASENAME}")
ARCH=$(sed -E 's@^imgbuilder-[0-9\.]+-@@' <<< "${BASENAME}" | grep -oP '^[^-]+')
TYPE=$(sed -E 's@^imgbuilder-[0-9\.]+-@@; s@'"${ARCH}"'-@@' <<< "${BASENAME}" | grep -oP '^[^\.]+')
[[ -n "${VERSION}" && -n "${ARCH}" && -n "${TYPE}" ]] || exit 255
[[ ! -x "${DIRNAME}/imgbuilder-get-base-path.sh" ]] || source "${DIRNAME}/imgbuilder-get-base-path.sh"
[[ -n "${OPENWRT_IMG_BUILDER_BASE_PATH}" ]] || OPENWRT_IMG_BUILDER_BASE_PATH="${DIRNAME}/openwrt-imagebuilder-${ARCH}-${TYPE}"
@tsjk
tsjk / sdparm-disable_sleep.sh
Last active January 9, 2024 20:17
Disabling of sleep on external disk using sdparm so that they do not disconnect in middle of transactions (e.g. WD_My_Book_25ED)
#!/bin/bash
# Usage: sdparm-disable_sleep.sh <device>
[[ -n "${1}" && -b "${1}" ]] \
&& sdparm --flexible --page=po -l -a "${1}" \
&& { sdparm --set=STANDBY_Z=0 -S "${1}" \
&& sdparm --set=SZCT=$((45*60*100)) -S "${1}" \
&& sdparm --flexible --page=po -l -a "${1}"; }