From 732876299f4dccb4caa3a915879d2b5945bbdd42 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 2 Apr 2014 11:15:54 +0200 Subject: filehooker is now elchOS --- elchos/root-image/krebs/lib/_punani_db | 57 +++++++++++++ elchos/root-image/krebs/lib/color | 7 ++ elchos/root-image/krebs/lib/core | 80 +++++++++++++++++ elchos/root-image/krebs/lib/filehooker | 152 +++++++++++++++++++++++++++++++++ elchos/root-image/krebs/lib/iso | 7 ++ elchos/root-image/krebs/lib/krebs | 16 ++++ elchos/root-image/krebs/lib/network | 100 ++++++++++++++++++++++ elchos/root-image/krebs/lib/punani | 99 +++++++++++++++++++++ elchos/root-image/krebs/lib/retiolum | 99 +++++++++++++++++++++ elchos/root-image/krebs/lib/tahoe | 34 ++++++++ elchos/root-image/krebs/lib/tor | 19 +++++ elchos/root-image/krebs/lib/vim | 40 +++++++++ 12 files changed, 710 insertions(+) create mode 100644 elchos/root-image/krebs/lib/_punani_db create mode 100644 elchos/root-image/krebs/lib/color create mode 100644 elchos/root-image/krebs/lib/core create mode 100644 elchos/root-image/krebs/lib/filehooker create mode 100644 elchos/root-image/krebs/lib/iso create mode 100644 elchos/root-image/krebs/lib/krebs create mode 100644 elchos/root-image/krebs/lib/network create mode 100644 elchos/root-image/krebs/lib/punani create mode 100644 elchos/root-image/krebs/lib/retiolum create mode 100644 elchos/root-image/krebs/lib/tahoe create mode 100644 elchos/root-image/krebs/lib/tor create mode 100644 elchos/root-image/krebs/lib/vim (limited to 'elchos/root-image/krebs/lib') diff --git a/elchos/root-image/krebs/lib/_punani_db b/elchos/root-image/krebs/lib/_punani_db new file mode 100644 index 00000000..e5bf15b1 --- /dev/null +++ b/elchos/root-image/krebs/lib/_punani_db @@ -0,0 +1,57 @@ +_punanidb_pacman_= +_punanidb_yum_= +_punanidb_aptget_= + +_punanidb_pacman_git=git +_punanidb_yum_git=git +_punanidb_aptget_git=git-core + +_punanidb_pacman_python2=python2 +_punanidb_yum_python2=python +_punanidb_aptget_python2=python + +_punanidb_pacman_python3=python +_punanidb_aptget_python3=python3 + +_punanidb_pacman_pip2=python2-pip +_punanidb_aptget_pip2=python-pip + +_punanidb_pacman_virtualenv=python-virtualenv +_punanidb_aptget_virtualenv=python-virtualenv + +_punanidb_pacman_gpp=g++ +_punanidb_aptget_gpp=gcc + +_punanidb_pacman_python2_dev=python2 +_punanidb_aptget_python2_dev=python-dev + +_punanidb_pacman_hostname=inetutils +_punanidb_aptget_hostname=hostname + +_punanidb_pacman_hostname=inetutils +_punanidb_aptget_hostname=hostname + +_punanidb_pacman_make=make +_punanidb_yum_make=make +_punanidb_aptget_make=make + +_punanidb_pacman_tinc=tinc +_punanidb_yum_tinc=tinc +_punanidb_aptget_tinc=tinc + +_punanidb_pacman_zsh=zsh +_punanidb_yum_zsh=zsh +_punanidb_aptget_zsh=zsh + +_punanidb_pacman_tor=tor +_punanidb_yum_tor=tor +_punanidb_aptget_tor=tor + +_punanidb_pacman_nano=nano +_punanidb_yum_nano=nano +_punanidb_aptget_nano=nano + +_punanidb_pacman_vim=vim +_punanidb_yum_vim=vim-enhanced +_punanidb_aptget_vim=vim + diff --git a/elchos/root-image/krebs/lib/color b/elchos/root-image/krebs/lib/color new file mode 100644 index 00000000..cec2044e --- /dev/null +++ b/elchos/root-image/krebs/lib/color @@ -0,0 +1,7 @@ +# superseed logging with color +green='\e[0;32m' +red='\e[0;31m' +nc='\e[0m' +msg() { printf "$*\n" >&2; } +info() { msg "$green$*$nc"; } +error() { msg "$green$*$nc"; } diff --git a/elchos/root-image/krebs/lib/core b/elchos/root-image/krebs/lib/core new file mode 100644 index 00000000..0c321525 --- /dev/null +++ b/elchos/root-image/krebs/lib/core @@ -0,0 +1,80 @@ +# logging +msg() { echo "$*" >&2; } +info() { msg "** $*"; } +error() { msg "!! $*"; } +## usage: die [REASON...] +die() { + test $# -gt 0 && error "$*" + error 'Bailing out.' + exit 1 +} +exists(){ + type "$1" >/dev/null 2>/dev/null; +} + +is_root(){ + test $(id -u) -eq 0 +} + +defer(){ + #close enough + trapstr="$1;${trapstr:-exit}" + trap "$trapstr" INT TERM EXIT KILL +} + +esudo(){ + # weaksauce esudo (expect sudo) + if ! is_root; then + # for the record: + # exec sudo -E "$0" "$@" + error "You are not root enough for this script" + exit 23 # go to hell + fi +} + +get_hostname(){ + # finds the current hostname + # if ENV HOSTN is set echo $HOSTN + # We try the following: + # $HOSTN + # $HOSTNAME + # hostname + # uci system.hostname + # /etc/hostname + # if everything fails, it returns 1 and prints 'unknown' + + if [ -n "${HOSTN:-}" ] ; then printf "${HOSTN:-}" + elif [ -n "${HOSTNAME:-}" ] ;then printf "$HOSTNAME" + elif exists hostname ; then printf "$(hostname)" + elif exists uci ; then printf "$(uci get system.@system[0].hostname)" + elif [ -e /etc/hostname ] ;then printf "$(cat /etc/hostname)" + else printf "unknown"; return 1 + fi + return 0 +} + +line_to_dot(){ + while read line; do printf .; done; +} + +get_os(){ + # TODO: find all the release files + #if grep -q 'Linux' /etc/*release 2>/dev/null || grep -qe 'Linux' /etc/issue 2>/dev/null; then + if grep -q 'Linux' /etc/lsb-release 2>/dev/null || grep -q 'Linux' /etc/issue 2>/dev/null; then + echo 'linux' + elif test -e /etc/preferred-apps/google.xml; then + echo 'android' + elif test -e /etc/openwrt_release; then + echo 'openwrt' + elif uname -s | grep -qi 'darwin'; then + echo 'osx' + else + warn "Cannot determine your operating system, falling back to Linux" + echo 'linux' + fi +} + +# user management +has_user(){ + egrep "^$1:" /etc/passwd >/dev/null +} diff --git a/elchos/root-image/krebs/lib/filehooker b/elchos/root-image/krebs/lib/filehooker new file mode 100644 index 00000000..b3bef435 --- /dev/null +++ b/elchos/root-image/krebs/lib/filehooker @@ -0,0 +1,152 @@ +#@include core +. /krebs/lib/core +#@include network +. /krebs/lib/network +ncdc_user=${ncdc_user:-hooker} +ncdc_bin=${ncdc_bin:-/usr/bin/ncdc} + + +ncdc_config(){ + # maybe we want to use the running ncdc process and communicate via tmux send-keys ? + txt="$(cat)" +# printf "%s" "$txt" + ! sudo -u $ncdc_user /usr/bin/tmux has-session -t dcpp && echo "ncdc session must be running" && exit 1 + sudo -u $ncdc_user /usr/bin/tmux send-keys -t dcpp:ncdc "$txt" C-m +} + +ncdc_configure_netshare(){ + : "${1?provide path to share}" + rnd=`hexdump -n 2 -e '/2 "%u"' /dev/urandom` + rnd_name="${2:-share_$rnd}" + info "removing old share $rnd_name" + (echo "/unshare $rnd_name" ) | ncdc_config + info "adding share $rnd_name ($1)" + (echo "/share $rnd_name $1") | ncdc_config +} + +ncdc_configure_nick(){ + nick=${1?nick must be provided} + info "configuring DC Nick: $nick" + echo "/nick $nick" | ncdc_config +} +ncdc_configure_hub(){ + rnd=`hexdump -n 2 -e '/2 "%u"' /dev/urandom` + hub=${1?adcs://localhost:2781} + hubname="${2:-hub_$rnd}" + info "setting active as true" + (echo "/set active true") | ncdc_config + info "configuring DC Hub: $hub, activating autconnect" + (echo "/open ${hubname} ${hub}" ; + echo "/hset autoconnect true") | ncdc_config +} + +ncdc_download(){ +install_dir="$(dirname "${ncdc_bin}")" +info "installing ncdc to $install_dir" +curl http://dev.yorhel.nl/download/ncdc-linux-x86_64-1.19.tar.gz | tar xz -C "$install_dir" +} +ncdc_install(){ +useradd -m $ncdc_user ||: +} + +ncdc_autostart(){ +# only systemd +# punani install tmux +cat > /etc/systemd/system/ncdc@.service </dev/null + sleep 1 + (printf "o\nn\np\n\n\n\nw\n\n") |fdisk $disk >/dev/null ||: + #partprobe $disk + mkfs.btrfs -f ${disk}1 >/dev/null + uuid="$(blkid ${disk}1 -o value | head -n 1)" + mountpoint="/media/vag${count}" + mkdir -p "$mountpoint" + echo "UUID=$uuid $mountpoint btrfs rw,relatime,space_cache 0 0" >> /etc/fstab + echo "$mountpoint" + : $((count++)) + else + info "skipping $disk" + fi + done +} +install_tor_announce(){ +# systemd only +info "writing tor_announce.service" +cat > /etc/systemd/system/tor_announce.service<