tadd various script - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 38d06afe7d688d5746958735d24f282f0348c02f
(DIR) parent 93a9c760af519f2f373191025c0062e4dad863ce
(HTM) Author: z3bra <willyatmailoodotorg>
Date: Mon, 21 Sep 2015 23:48:39 +0200
add various script
Diffstat:
A autoup | 13 +++++++++++++
A cross-gcc | 224 +++++++++++++++++++++++++++++++
A cross-pcc | 210 +++++++++++++++++++++++++++++++
A ftpcrawl | 31 +++++++++++++++++++++++++++++++
A maillist | 26 ++++++++++++++++++++++++++
A maximize | 53 ++++++++++++++++++++++++++++++
A nx-termcast | 29 +++++++++++++++++++++++++++++
A rot13 | 3 +++
A takeoffdir | 6 ++++++
A toxrdb | 8 ++++++++
10 files changed, 603 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/autoup b/autoup
t@@ -0,0 +1,13 @@
+#!/bin/sh
+
+SSHUSER=z3bra
+SSHKEY=$HOME/.ssh/autoupload
+SERVER=raw.z3bra.org
+WEBROOT=/var/www/http/raw.z3bra.org
+WEBDIR=dev/random
+
+test -z "$1" && exit 1 || FILENAME=$(basename $1)
+scp -i "$SSHKEY" "$1" "${SSHUSER}@${SERVER}:${WEBROOT}/${WEBDIR}/$FILENAME"
+echo "http://$SERVER/$WEBDIR/$FILENAME" | xsel -i
+$HOME/bin/popup "$FILENAME uploaded!"
+rm $1
(DIR) diff --git a/cross-gcc b/cross-gcc
t@@ -0,0 +1,224 @@
+#!/bin/sh -ex
+#
+# Couple of useful links:
+# + http://wiki.osdev.org/GCC_Cross-Compiler
+# + http://wiki.osdev.org/Cross-Compiler_Successful_Builds
+# + https://git.framasoft.org/Ypnose/solyste/blob/master/scripts/create-crossenv
+# + http://kegel.com/crosstool/
+# + https://github.com/GregorR/musl-cross/tree/master/patches
+#
+# 0. download gcc, binutils, gmp, mpc, mpfr
+# 1. extract them
+# 2. patch everything that require patching
+# 3. prepare gcc (move gmp, mpc, mpfr in)
+# 4. install linux headers
+# 5. build binutils
+# 6. build musl
+# 7. build gcc
+# 8. add pkg-config wrapper
+
+# cross compiler environment
+MARCH=$(uname -m)
+TARGET=${TARGET:-${MARCH}-linux-musl}
+PREFIX=${PREFIX:-${HOME}/cross/gcc-${MARCH}}
+BLDDIR=${BLDDIR:-${HOME}/cross/build}
+SRCDIR=${SRCDIR:-${HOME}/cross/source}
+PATCHD=${PATCHD:-${HOME}/cross/patches}
+
+# compilation variables
+CFLAGS="-Os -fomit-frame-pointer -pipe"
+CXXFLAGS="${CFLAGS}"
+CPPFLAGS="${CFLAGS}"
+LDFLAGS="-Wl,--as-needed"
+MAKEFLAGS="-j4"
+
+# versions
+GCCV=${GCCV:-4.8.5}
+BINV=${BINV:-2.25}
+GMPV=${GMPV:-5.1.3}
+MPCV=${MPCV:-1.0.3}
+MPFRV=${MPFRV:-3.1.3}
+MUSLV=${MUSLV:-1.1.10}
+KERNV=${KERNV:-4.1.4}
+
+
+# random but useful vars
+PATH="${PREFIX}/bin:${PATH}"
+GNUMIRROR=ftp://ftp.gnu.org/gnu
+MUSLMIRROR=http://www.musl-libc.org/releases
+LINUXMIRROR=https://www.kernel.org/pub/linux/kernel/v4.x
+
+# Preparing sources
+mkdir -p "${SRCDIR}" "${BLDDIR}" "${PREFIX}"
+cd "${SRCDIR}"
+
+#
+# ┏━┓
+# ┃┃┃
+# ┗━┛╹
+# Get all GNU tarballs
+grab_sources() {
+curl -O -# "${GNUMIRROR}/gcc/gcc-${GCCV}/gcc-${GCCV}.tar.gz"
+curl -O -# "${GNUMIRROR}/binutils/binutils-${BINV}.tar.gz"
+curl -O -# "${GNUMIRROR}/mpc/mpc-${MPCV}.tar.gz"
+curl -O -# "${GNUMIRROR}/gmp/gmp-${GMPV}.tar.gz"
+curl -O -# "${GNUMIRROR}/mpfr/mpfr-${MPFRV}.tar.gz"
+curl -O -# "${MUSLMIRROR}/musl-${MUSLV}.tar.gz"
+curl -O -# "${LINUXMIRROR}/linux-${KERNV}.tar.xz"
+}
+
+#
+# ╺┓
+# ┃
+# ╺┻╸╹
+# Extract everything
+extract_source() {
+tar xz < gcc-${GCCV}.tar.gz
+tar xz < binutils-${BINV}.tar.gz
+tar xz < mpc-${MPCV}.tar.gz
+tar xz < gmp-${GMPV}.tar.gz
+tar xz < mpfr-${MPFRV}.tar.gz
+tar xz < musl-${MUSLV}.tar.gz
+tar xJ < linux-${KERNV}.tar.xz
+}
+
+#
+# ┏━┓
+# ┏━┛
+# ┗━╸╹
+# Patch all source trees.
+# This will take all patches in $PATCHD matching the programs
+# (eg: gcc-4.8.4-*.diff to patch gcc in version 4.8.4)
+patch_sources() {
+for DIR in $(find "${SRCDIR}" -maxdepth 1 -type d); do
+ cd "${DIR}"
+ cat "${PATCHD}/$(basename ${DIR})"-*.diff | patch -Np1
+done
+}
+
+#
+# ┏━┓
+# ╺━┫
+# ┗━┛╹
+# Prepare the gcc dir
+prepare_gcc() {
+mv "${SRCDIR}/gmp-${GMPV}" "${SRCDIR}/gcc-${GCCV}/gmp"
+mv "${SRCDIR}/mpc-${MPCV}" "${SRCDIR}/gcc-${GCCV}/mpc"
+mv "${SRCDIR}/mpfr-${MPFRV}" "${SRCDIR}/gcc-${GCCV}/mpfr"
+}
+
+#
+# ╻ ╻
+# ┗━┫
+# ╹╹
+# Get linux headers
+install_headers() {
+cd "${SRCDIR}/linux-${KERNV}"
+make ARCH=$(uname -m) headers_check
+make ARCH=$(uname -m) INSTALL_HDR_PATH=${PREFIX}/${TARGET} headers_install
+rm -r "${SRCDIR}/linux-${KERNV}"
+}
+
+#
+# ┏━╸
+# ┗━┓
+# ┗━┛╹
+# Build binutils and install them to ${PREFIX}
+install_binutils() {
+mkdir -p "${BLDDIR}/binutils"
+cd "${BLDDIR}/binutils"
+${SRCDIR}/binutils-${BINV}/configure --target=${TARGET} \
+ --prefix=${PREFIX} \
+ --with-sysroot=${PREFIX}/${TARGET} \
+ --disable-nls \
+ --disable-shared \
+ --disable-multilib
+make configure-host
+make LDFLAGS="${LDFLAGS} -all-static -static"
+make install
+rm -rf "${BLDDIR}/binutils"
+rm -rf "${SRCDIR}/binutils-${BINV}"
+}
+
+#
+# ┏━┓
+# ┣━┓
+# ┗━┛╹
+# Build the musl libc
+install_musl() {
+cd "${SRCDIR}/musl-${MUSLV}"
+./configure --prefix=${PREFIX}/${TARGET} \
+ --target=${TARGET} \
+ --disable-gcc-wrapper \
+ --disable-debug \
+ --disable-shared \
+ --disable-warning
+make LDFLAGS="${LDFLAGS}"
+make install
+rm -rf "${SRCDIR}/musl-${MUSLV}"
+}
+
+#
+# ┏━┓
+# ┃
+# ╹╹
+# Build gcc linked against musl
+install_gcc() {
+mkdir -p "${BLDDIR}/gcc"
+cd "${BLDDIR}/gcc"
+${SRCDIR}/gcc-${GCCV}/configure --target=${TARGET} \
+ --prefix=${PREFIX} \
+ --with-sysroot=${PREFIX}/${TARGET} \
+ --with-native-system-header-dir=/include \
+ --disable-nls \
+ --disable-shared \
+ --disable-multilib \
+ --disable-libmudflap \
+ --enable-languages=c
+make LDFLAGS="${LDFLAGS} -static" all-gcc all-target-libgcc
+make install-gcc install-target-libgcc
+rm -rf "${BLDDIR}/gcc"
+rm -rf "${SRCDIR}/gcc-${GCCV}"
+}
+
+#
+# ┏━┓
+# ┣━┫
+# ┗━┛╹
+# Add pkg-config wrapper
+install_pkgconfig() {
+cat << EOF > "${PREFIX}/bin/${TARGET}-pkg-config"
+#!/bin/sh
+export PKG_CONFIG_SYSROOT_DIR=${PREFIX}/${TARGET}
+export PKG_CONFIG_LIBDIR=${PREFIX}/${TARGET}/usr/lib/pkgconfig
+export PKG_CONFIG_PATH=\$PKG_CONFIG_LIBDIR
+
+exec pkg-config --static "\$@"
+EOF
+chmod 755 "${PREFIX}/bin/${TARGET}-pkg-config"
+}
+
+grab_sources
+extract_source
+patch_sources
+prepare_gcc
+install_headers
+install_binutils
+install_musl
+install_gcc
+install_pkgconfig
+
+rm -rf "${SRCDIR}"
+rm -rf "${BLDDIR}"
+rm -rf "${PREFIX}/share"
+rm -f "${PREFIX}/lib/libiberty.a"
+
+cat << EOF | tee ${PREFIX}/README
+TRIPLET : $TARGET
+PREFIX : $PREFIX
+
+GCC : $GCCV
+BINUTILS: $BINV
+MUSL : $MUSLV
+KERNEL : $KERNV
+EOF
(DIR) diff --git a/cross-pcc b/cross-pcc
t@@ -0,0 +1,210 @@
+#!/bin/sh -ex
+#
+# Couple of useful links:
+# + http://pcc.ludd.ltu.se/cross-compiler/
+# + http://wiki.osdev.org/Cross-Compiler_Successful_Builds
+# + https://git.framasoft.org/Ypnose/solyste/blob/master/scripts/create-crossenv
+# + http://kegel.com/crosstool/
+# + https://github.com/GregorR/musl-cross/tree/master/patches
+#
+# 0. download and extract sources
+# 1. patch everything that require patching
+# 2. install linux headers
+# 3. build binutils
+# 4. build musl
+# 5. build pcc with gcc
+# 6. add pkg-config wrapper
+
+# cross compiler environment
+MARCH=$(uname -m)
+TRIPLE=${TRIPLE:-${MARCH}-linux-musl}
+PREFIX=${PREFIX:-${HOME}/cross/pcc-${MARCH}}
+BLDDIR=${BLDDIR:-${HOME}/cross/build}
+SRCDIR=${SRCDIR:-${HOME}/cross/source}
+PATCHD=${PATCHD:-${HOME}/cross/patches}
+
+# compilation variables
+PATH="${PREFIX}/bin:${PATH}"
+CFLAGS="-Os -fomit-frame-pointer -pipe"
+CXXFLAGS="${CFLAGS}"
+CPPFLAGS="${CFLAGS}"
+LDFLAGS="-Wl,--as-needed"
+MAKEFLAGS="-j8"
+
+# versions
+PCCV=${PCCV:-1.1.0}
+BINV=${BINV:-2.25}
+MUSLV=${MUSLV:-1.1.10}
+KERNV=${KERNV:-4.1.4}
+
+
+# source mirrors
+PCCMIRROR=ftp://pcc.ludd.ltu.se/pub/pcc-releases
+GNUMIRROR=ftp://ftp.gnu.org/gnu
+MUSLMIRROR=http://www.musl-libc.org/releases
+LINUXMIRROR=https://www.kernel.org/pub/linux/kernel/v4.x
+
+# Preparing sources
+mkdir -p "${SRCDIR}" "${BLDDIR}" "${PREFIX}"
+cd "${SRCDIR}"
+
+#
+# ┏━┓
+# ┃┃┃
+# ┗━┛╹
+# Get all GNU tarballs
+grab_sources() {
+curl -# "${PCCMIRROR}/pcc-${PCCV}.tgz" | tar xz
+curl -# "${PCCMIRROR}/pcc-libs-${PCCV}.tgz" | tar xz
+curl -# "${GNUMIRROR}/binutils/binutils-${BINV}.tar.gz" | tar xz
+curl -# "${MUSLMIRROR}/musl-${MUSLV}.tar.gz" | tar xz
+curl -# "${LINUXMIRROR}/linux-${KERNV}.tar.xz" | tar xJ
+}
+
+#
+# ╺┓
+# ┃
+# ╺┻╸╹
+# Patch all source trees.
+# This will take all patches in $PATCHD matching the programs
+patch_sources() {
+for DIR in $(find "${SRCDIR}" -maxdepth 1 -type d); do
+ cd "${DIR}"
+ cat "${PATCHD}/$(basename ${DIR})"-*.diff | patch -Np1
+done
+}
+
+#
+# ┏━┓
+# ┏━┛
+# ┗━╸╹
+# Get linux headers
+install_headers() {
+cd "${SRCDIR}/linux-${KERNV}"
+make ARCH=$(uname -m) headers_check
+make ARCH=$(uname -m) INSTALL_HDR_PATH=${PREFIX}/${TRIPLE} headers_install
+rm -r "${SRCDIR}/linux-${KERNV}"
+}
+
+#
+# ┏━┓
+# ╺━┫
+# ┗━┛╹
+# Build binutils and install them to ${PREFIX}
+install_binutils() {
+mkdir -p "${BLDDIR}/binutils"
+cd "${BLDDIR}/binutils"
+${SRCDIR}/binutils-${BINV}/configure --target=${TRIPLE} \
+ --prefix=${PREFIX} \
+ --with-sysroot=${PREFIX}/${TRIPLE} \
+ --disable-nls \
+ --disable-shared \
+ --disable-multilib
+make configure-host
+make LDFLAGS="${LDFLAGS} -all-static -static"
+make install
+rm -rf "${BLDDIR}/binutils"
+rm -rf "${SRCDIR}/binutils-${BINV}"
+}
+
+#
+# ╻ ╻
+# ┗━┫
+# ╹╹
+# Build the musl libc
+install_musl() {
+cd "${SRCDIR}/musl-${MUSLV}"
+./configure --prefix=${PREFIX}/${TRIPLE} \
+ --target=${TRIPLE} \
+ --disable-gcc-wrapper \
+ --disable-debug \
+ --disable-shared \
+ --disable-warning
+make LDFLAGS="${LDFLAGS}"
+make install
+rm -rf "${SRCDIR}/musl-${MUSLV}"
+}
+
+#
+# ┏━╸
+# ┗━┓
+# ┗━┛╹
+# Build pcc linked against musl
+install_pcc() {
+mkdir -p "${BLDDIR}/pcc"
+mkdir -p "${BLDDIR}/pcc-libs"
+cd "${BLDDIR}/pcc"
+${SRCDIR}/pcc-${PCCV}/configure --target=${TRIPLE} \
+ --with-libdir=${PREFIX}/${TRIPLE}/lib \
+ --with-incdir=${PREFIX}/${TRIPLE}/include \
+ --prefix=${PREFIX}
+
+make LDFLAGS="${LDFLAGS} -static" \
+ PCCLIBDIR=${PREFIX}/${TRIPLE}/pcc/lib \
+ PCCINCDIR=${PREFIX}/${TRIPLE}/pcc/include
+make PCCLIBDIR=${PREFIX}/${TRIPLE}/pcc/lib \
+ PCCINCDIR=${PREFIX}/${TRIPLE}/pcc/include \
+ install
+rm -rf "${BLDDIR}/pcc"
+rm -rf "${SRCDIR}/pcc-${PCCV}"
+}
+
+#
+# ┏━┓
+# ┣━┓
+# ┗━┛╹
+# Build pcc libraries against musl
+install_pcc_libs() {
+cd "${BLDDIR}/pcc-libs"
+${SRCDIR}/pcc-libs-${PCCV}/configure --target=${TRIPLE} \
+ --prefix=${PREFIX}
+
+make PCCLIBDIR=${PREFIX}/${TRIPLE}/pcc/lib \
+ PCCINCDIR=${PREFIX}/${TRIPLE}/pcc/include
+make PCCLIBDIR=${PREFIX}/${TRIPLE}/pcc/lib \
+ PCCINCDIR=${PREFIX}/${TRIPLE}/pcc/include \
+ install
+rm -rf "${BLDDIR}/pcc-libs"
+rm -rf "${SRCDIR}/pcc-libs-${PCCV}"
+}
+
+#
+# ┏━┓
+# ┃
+# ╹╹
+# Add pkg-config wrapper
+install_pkgconfig() {
+cat << EOF > "${PREFIX}/bin/${TRIPLE}-pkg-config"
+#!/bin/sh
+export PKG_CONFIG_SYSROOT_DIR=${PREFIX}/${TRIPLE}
+export PKG_CONFIG_LIBDIR=${PREFIX}/${TRIPLE}/usr/lib/pkgconfig
+export PKG_CONFIG_PATH=\$PKG_CONFIG_LIBDIR
+
+exec pkg-config --static "\$@"
+EOF
+chmod 755 "${PREFIX}/bin/${TRIPLE}-pkg-config"
+}
+
+grab_sources
+patch_sources
+install_headers
+install_binutils
+install_musl
+install_pcc
+install_pcc_libs
+install_pkgconfig
+
+# clean environment
+rm -rf "${SRCDIR}"
+rm -rf "${BLDDIR}"
+rm -rf "${PREFIX}/share"
+rm -f "${PREFIX}/lib/libiberty.a"
+
+cat << EOF | tee ${PREFIX}/README
+TRIPLET : $TRIPLE
+PREFIX : $PREFIX
+PCC : $PCCV
+BINUTILS: $BINV
+MUSL : $MUSLV
+KERNEL : $KERNV
+EOF
(DIR) diff --git a/ftpcrawl b/ftpcrawl
t@@ -0,0 +1,31 @@
+#!/bin/sh
+
+ENGINES=${ENGINES:-"filemare ftplike"}
+
+extract_link() {
+ ENGINE=$1
+ ARCHIVE=$2
+ case $1 in
+ filemare) URL="http://filemare.com/en/search/${ARCHIVE}"
+ SED='s^.*/en/browse/\([^>'\''"]*\).*$ftp://\1p;d'
+ ;;
+ ftplike) URL="http://ftplike.com/index.aspx?m=EXACT&t=Files&q=${ARCHIVE}"
+ SED='s|^.*\(ftp://[^ '\''"><]*\).*$|\1|p;d'
+ ;;
+ *) return 1
+ esac
+
+ curl -s "$URL" | sed "$SED"
+}
+
+crawl() {
+ ARCHIVE=$1
+ for ENGINE in $ENGINES; do
+ extract_link $ENGINE $ARCHIVE
+ done | shuf
+}
+
+for ARG in $@; do
+ crawl $ARG
+done
+
(DIR) diff --git a/maillist b/maillist
t@@ -0,0 +1,26 @@
+#!/bin/sh
+
+INBOX=$HOME/var/mail/inbox
+MBASE=$HOME/var/mail
+LISTS='crux lobsters'
+
+crawl() {
+ case $1 in
+ crux)
+ REGEX='^(to|cc):.*crux@lists.crux.nu'
+ ;;
+ lobsters)
+ REGEX='^to:.*lobsters-[a-zA-Z0-9]*@lobste.rs'
+ ;;
+ esac
+
+ find $INBOX -type f -exec grep -liP "$REGEX" {} +
+}
+
+for ML in $LISTS; do
+ crawl "$ML" | while read FILE; do
+ printf '[1;37m%s[0m: %s\n' "$ML" "$(sed 's/^Subject: //p;d' $FILE)"
+ NEW=$(echo "$(basename $FILE)" | sed 's/\(:[12],[DFPR]*\)S\([T]*\)/\1\2/')
+ mv $FILE $MBASE/lists/$ML/new/$NEW
+ done
+done
(DIR) diff --git a/maximize b/maximize
t@@ -0,0 +1,53 @@
+#!/bin/sh
+
+usage() {
+ echo "usage: $(basename $0) [-hv] wid" >&2
+ exit 1
+}
+
+while getopts hv OPT; do
+ case $OPT in
+ h) MAX=horz ;;
+ v) MAX=vert ;;
+ *) usage ;;
+ esac
+done
+shift $((OPTIND -1))
+
+test -n "$1" && WID=$1 || usage
+
+MAX=${MAX:-full}
+EXPANDIR=/tmp/.expan.d
+BW=$(wattr b $WID)
+SW=$(( $(wattr w `lsw -r`) - 2*$BW))
+SH=$(( $(wattr h `lsw -r`) - 2*$BW))
+
+test -d $EXPANDIR || mkdir -p $EXPANDIR
+
+is_maxed() {
+ case $MAX in
+ vert) test $(wattr h $WID) -eq $SH && return 0 ;;
+ horz) test $(wattr w $WID) -eq $SW && return 0 ;;
+ full) test "$(wattr wh $WID)" = "$SW $SH" && return 0 ;;
+ esac
+
+ return 1
+}
+
+expand_win() {
+ wattr xywhi $WID > $EXPANDIR/$WID
+ case $MAX in
+ vert) GEOMETRY=$(printf '%d 0 %d %d' $(wattr xw $WID) "$SH") ;;
+ horz) GEOMETRY=$(printf '0 %d %d %d' $(wattr y $WID) "$SW" $(wattr h $WID)) ;;
+ full) GEOMETRY=$(printf '0 0 %d %d' "$SW" "$SH") ;;
+ esac
+ wtp ${GEOMETRY} ${WID}
+}
+
+collapse_win() {
+ test -f $EXPANDIR/$WID || return
+ wtp $(grep $WID $EXPANDIR/$WID)
+ rm $EXPANDIR/$WID
+}
+
+is_maxed && collapse_win || expand_win ;
(DIR) diff --git a/nx-termcast b/nx-termcast
t@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# start recording a script, and upload it in base64 to sprunge
+# usage: nx-termcast [url]
+
+nx_upload() {
+ # feel free to override, if you know what you're doing
+ curl -sLT${1:--} https://p.iotek.org
+}
+
+nx_record() {
+ script --timing=timing typescript
+ # make a motherfucking tarbomb
+ tar cz . | base64 | nx_upload
+}
+
+nx_replay() {
+ curl -s "$*" | base64 -d | tar xz
+ scriptreplay timing typescript
+}
+
+# that's to prevent the motherfucking tarbombs
+cd $(mktemp -d)
+
+# give the impression of a clean session
+clear
+
+# either record or play, your choice
+test -n "$1" && nx_replay "$*" || nx_record
(DIR) diff --git a/rot13 b/rot13
t@@ -0,0 +1,3 @@
+#!/bin/sh
+
+tr 'A-Za-z' 'N-ZA-Mn-za-m'
(DIR) diff --git a/takeoffdir b/takeoffdir
t@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# file either created or modified
+wendy -m 136 -f ~/var/takeoff -v | while read ev file; do
+ $HOME/bin/autoup "$file"
+done
(DIR) diff --git a/toxrdb b/toxrdb
t@@ -0,0 +1,7 @@
+#!/bin/sh
+
+cpt=0
+while read hexcode; do
+ printf '*color%d: %s\n' "$cpt" "$hexcode"
+ cpt=$(expr $cpt + 1)
+done | column -t
+\ No newline at end of file