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/.gitignore | 4 + elchos/README.md | 23 ++ elchos/aitab | 3 + elchos/build.sh | 265 +++++++++++++++++++++ .../efiboot/loader/entries/archiso-x86_64-cd.conf | 4 + .../efiboot/loader/entries/archiso-x86_64-usb.conf | 4 + .../loader/entries/uefi-shell-v1-x86_64.conf | 2 + .../loader/entries/uefi-shell-v2-x86_64.conf | 2 + elchos/efiboot/loader/loader.conf | 2 + elchos/isolinux/isolinux.cfg | 6 + elchos/mkinitcpio.conf | 2 + elchos/packages.both | 47 ++++ elchos/packages.i686 | 0 elchos/packages.x86_64 | 3 + elchos/pacman.conf | 92 +++++++ elchos/refresh.sh | 8 + elchos/root-image/etc/collectd.conf | 84 +++++++ elchos/root-image/etc/fstab | 0 elchos/root-image/etc/hostname | 1 + elchos/root-image/etc/locale.conf | 1 + elchos/root-image/etc/pam.d/su | 6 + elchos/root-image/etc/sudoers.d/g_wheel | 1 + .../root-image/etc/systemd/scripts/choose-mirror | 26 ++ .../etc/systemd/system/choose-mirror.service | 10 + .../systemd/system/collectd.service.d/wait.conf | 2 + .../system/dhcpcd.service.d/force-reboot.conf | 2 + .../etc/systemd/system/elch-hostname.service | 11 + .../etc/systemd/system/etc-pacman.d-gnupg.mount | 8 + .../getty@tty1.service.d/run_krebs_secret.conf | 3 + .../hddtemp.service.d/monitor_all_disks.conf | 3 + .../system/ntpdate.service.d/set_hwclock.conf | 2 + .../etc/systemd/system/pacman-init.service | 15 ++ .../etc/systemd/system/start-ncdc@.service | 13 + .../systemd/system/tor-configure-hidden.service | 11 + elchos/root-image/etc/udev/rules.d/81-dhcpcd.rules | 1 + elchos/root-image/krebs/bin/add-reaktor-secret.sh | 24 ++ elchos/root-image/krebs/bin/macid.sh | 2 + elchos/root-image/krebs/bin/reaktor-shell.sh | 4 + elchos/root-image/krebs/bin/refresh-shares.ship | 11 + elchos/root-image/krebs/bin/set-hostname.sh | 5 + elchos/root-image/krebs/bin/start-ncdc.ship | 23 ++ .../root-image/krebs/bin/tor-get-hidden-service.sh | 2 + .../krebs/bin/tor_configure_hidden_service.ship | 16 ++ elchos/root-image/krebs/bin/tor_publish_ssh.ship | 12 + elchos/root-image/krebs/bin/update-search.sh | 5 + elchos/root-image/krebs/bin/vim_sane_defaults.ship | 10 + elchos/root-image/krebs/etc/Reaktor/admin.lst | 0 elchos/root-image/krebs/etc/Reaktor/auth.lst | 0 .../root-image/krebs/etc/Reaktor/commands/ftpget | 58 +++++ .../root-image/krebs/etc/Reaktor/commands/identify | 22 ++ elchos/root-image/krebs/etc/Reaktor/commands/io | 25 ++ elchos/root-image/krebs/etc/Reaktor/commands/ips | 2 + .../krebs/etc/Reaktor/commands/list_downloads | 8 + elchos/root-image/krebs/etc/Reaktor/commands/onion | 3 + .../root-image/krebs/etc/Reaktor/commands/reboot | 3 + .../krebs/etc/Reaktor/commands/refresh_shares | 4 + .../root-image/krebs/etc/Reaktor/commands/shares | 2 + .../krebs/etc/Reaktor/commands/update-search | 3 + elchos/root-image/krebs/etc/Reaktor/config.py | 60 +++++ elchos/root-image/krebs/etc/authorized_keys | 6 + elchos/root-image/krebs/etc/vsftpd.conf | 12 + 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 ++++ elchos/root-image/root/.automated_script.sh | 34 +++ elchos/root-image/root/.zlogin | 1 + elchos/root-image/root/customize_root_image.sh | 82 +++++++ elchos/root-image/usr/bin/ncdc | Bin 0 -> 4242384 bytes elchos/syslinux/archiso.cfg | 11 + elchos/syslinux/archiso_head.cfg | 25 ++ elchos/syslinux/archiso_pxe32.cfg | 32 +++ elchos/syslinux/archiso_pxe64.cfg | 32 +++ elchos/syslinux/archiso_pxe_32_inc.cfg | 3 + elchos/syslinux/archiso_pxe_both_inc.cfg | 4 + elchos/syslinux/archiso_pxe_choose.cfg | 11 + elchos/syslinux/archiso_sys32.cfg | 9 + elchos/syslinux/archiso_sys64.cfg | 9 + elchos/syslinux/archiso_sys_32_inc.cfg | 3 + elchos/syslinux/archiso_sys_both_inc.cfg | 4 + elchos/syslinux/archiso_sys_choose.cfg | 11 + elchos/syslinux/archiso_tail.cfg | 27 +++ elchos/syslinux/splash.png | Bin 0 -> 8810 bytes elchos/syslinux/syslinux.cfg | 5 + 92 files changed, 2002 insertions(+) create mode 100644 elchos/.gitignore create mode 100644 elchos/README.md create mode 100644 elchos/aitab create mode 100755 elchos/build.sh create mode 100644 elchos/efiboot/loader/entries/archiso-x86_64-cd.conf create mode 100644 elchos/efiboot/loader/entries/archiso-x86_64-usb.conf create mode 100644 elchos/efiboot/loader/entries/uefi-shell-v1-x86_64.conf create mode 100644 elchos/efiboot/loader/entries/uefi-shell-v2-x86_64.conf create mode 100644 elchos/efiboot/loader/loader.conf create mode 100644 elchos/isolinux/isolinux.cfg create mode 100644 elchos/mkinitcpio.conf create mode 100644 elchos/packages.both create mode 100644 elchos/packages.i686 create mode 100644 elchos/packages.x86_64 create mode 100644 elchos/pacman.conf create mode 100755 elchos/refresh.sh create mode 100644 elchos/root-image/etc/collectd.conf create mode 100644 elchos/root-image/etc/fstab create mode 100644 elchos/root-image/etc/hostname create mode 100644 elchos/root-image/etc/locale.conf create mode 100644 elchos/root-image/etc/pam.d/su create mode 100644 elchos/root-image/etc/sudoers.d/g_wheel create mode 100755 elchos/root-image/etc/systemd/scripts/choose-mirror create mode 100644 elchos/root-image/etc/systemd/system/choose-mirror.service create mode 100644 elchos/root-image/etc/systemd/system/collectd.service.d/wait.conf create mode 100644 elchos/root-image/etc/systemd/system/dhcpcd.service.d/force-reboot.conf create mode 100644 elchos/root-image/etc/systemd/system/elch-hostname.service create mode 100644 elchos/root-image/etc/systemd/system/etc-pacman.d-gnupg.mount create mode 100644 elchos/root-image/etc/systemd/system/getty@tty1.service.d/run_krebs_secret.conf create mode 100644 elchos/root-image/etc/systemd/system/hddtemp.service.d/monitor_all_disks.conf create mode 100644 elchos/root-image/etc/systemd/system/ntpdate.service.d/set_hwclock.conf create mode 100644 elchos/root-image/etc/systemd/system/pacman-init.service create mode 100644 elchos/root-image/etc/systemd/system/start-ncdc@.service create mode 100644 elchos/root-image/etc/systemd/system/tor-configure-hidden.service create mode 100644 elchos/root-image/etc/udev/rules.d/81-dhcpcd.rules create mode 100755 elchos/root-image/krebs/bin/add-reaktor-secret.sh create mode 100755 elchos/root-image/krebs/bin/macid.sh create mode 100755 elchos/root-image/krebs/bin/reaktor-shell.sh create mode 100755 elchos/root-image/krebs/bin/refresh-shares.ship create mode 100755 elchos/root-image/krebs/bin/set-hostname.sh create mode 100755 elchos/root-image/krebs/bin/start-ncdc.ship create mode 100755 elchos/root-image/krebs/bin/tor-get-hidden-service.sh create mode 100755 elchos/root-image/krebs/bin/tor_configure_hidden_service.ship create mode 100755 elchos/root-image/krebs/bin/tor_publish_ssh.ship create mode 100755 elchos/root-image/krebs/bin/update-search.sh create mode 100755 elchos/root-image/krebs/bin/vim_sane_defaults.ship create mode 100644 elchos/root-image/krebs/etc/Reaktor/admin.lst create mode 100644 elchos/root-image/krebs/etc/Reaktor/auth.lst create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/ftpget create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/identify create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/io create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/ips create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/list_downloads create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/onion create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/reboot create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/shares create mode 100755 elchos/root-image/krebs/etc/Reaktor/commands/update-search create mode 100644 elchos/root-image/krebs/etc/Reaktor/config.py create mode 100644 elchos/root-image/krebs/etc/authorized_keys create mode 100644 elchos/root-image/krebs/etc/vsftpd.conf 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 create mode 100755 elchos/root-image/root/.automated_script.sh create mode 100644 elchos/root-image/root/.zlogin create mode 100755 elchos/root-image/root/customize_root_image.sh create mode 100755 elchos/root-image/usr/bin/ncdc create mode 100644 elchos/syslinux/archiso.cfg create mode 100644 elchos/syslinux/archiso_head.cfg create mode 100644 elchos/syslinux/archiso_pxe32.cfg create mode 100644 elchos/syslinux/archiso_pxe64.cfg create mode 100644 elchos/syslinux/archiso_pxe_32_inc.cfg create mode 100644 elchos/syslinux/archiso_pxe_both_inc.cfg create mode 100644 elchos/syslinux/archiso_pxe_choose.cfg create mode 100644 elchos/syslinux/archiso_sys32.cfg create mode 100644 elchos/syslinux/archiso_sys64.cfg create mode 100644 elchos/syslinux/archiso_sys_32_inc.cfg create mode 100644 elchos/syslinux/archiso_sys_both_inc.cfg create mode 100644 elchos/syslinux/archiso_sys_choose.cfg create mode 100644 elchos/syslinux/archiso_tail.cfg create mode 100644 elchos/syslinux/splash.png create mode 100644 elchos/syslinux/syslinux.cfg (limited to 'elchos') diff --git a/elchos/.gitignore b/elchos/.gitignore new file mode 100644 index 00000000..6b6e109e --- /dev/null +++ b/elchos/.gitignore @@ -0,0 +1,4 @@ +work/ +out/ +arch/ +root-image/usr/bin/ncdc diff --git a/elchos/README.md b/elchos/README.md new file mode 100644 index 00000000..4209db7c --- /dev/null +++ b/elchos/README.md @@ -0,0 +1,23 @@ +# Elch +This builds the elch sharing distribution. + +# Usage + + # create a new iso + ./refresh + # creates: + # out/elchos.iso + +# Requirements +Both development environment and Final Distro are based on a heavily remastered +version of the Arch Linux Install Stick. On Arch you need archiso to build the +distro. + + pacman -Sy archiso + +# Configured URLs +- elchstats.nsupdate.info -> the graphite stats receiver +- elchirc.nsupdate.info -> the irc to be used + irc.freenode.net currently hardcoded + in root-image/krebs/etc/Reaktor/config.py +- elchhub.nsupdate.info -> the dcpp hub to be used diff --git a/elchos/aitab b/elchos/aitab new file mode 100644 index 00000000..b7e9a17a --- /dev/null +++ b/elchos/aitab @@ -0,0 +1,3 @@ +# +root-image / i686 xz ext4 50% +root-image / x86_64 xz ext4 50% diff --git a/elchos/build.sh b/elchos/build.sh new file mode 100755 index 00000000..671b15b5 --- /dev/null +++ b/elchos/build.sh @@ -0,0 +1,265 @@ +#!/bin/bash + +set -e -u + +iso_name=archlinux +iso_label="ARCH_$(date +%Y%m)" +iso_version=$(date +%Y.%m.%d) +install_dir=arch +work_dir=work +out_dir=out + +arch=$(uname -m) +verbose="" +pacman_conf=${work_dir}/pacman.conf +script_path=$(readlink -f ${0%/*}) + +_usage () +{ + echo "usage ${0} [options]" + echo + echo " General options:" + echo " -N Set an iso filename (prefix)" + echo " Default: ${iso_name}" + echo " -V Set an iso version (in filename)" + echo " Default: ${iso_version}" + echo " -L Set an iso label (disk label)" + echo " Default: ${iso_label}" + echo " -D Set an install_dir (directory inside iso)" + echo " Default: ${install_dir}" + echo " -w Set the working directory" + echo " Default: ${work_dir}" + echo " -o Set the output directory" + echo " Default: ${out_dir}" + echo " -v Enable verbose output" + echo " -h This help message" + exit ${1} +} + +# Helper function to run make_*() only one time per architecture. +run_once() { + if [[ ! -e ${work_dir}/build.${1}_${arch} ]]; then + $1 + touch ${work_dir}/build.${1}_${arch} + fi +} + +# Setup custom pacman.conf with current cache directories. +make_pacman_conf() { + local _cache_dirs + _cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g')) + sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${_cache_dirs[@]})|g" ${script_path}/pacman.conf > ${pacman_conf} +} + +# Base installation, plus needed packages (root-image) +make_basefs() { + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" init + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -p "memtest86+ mkinitcpio-nfs-utils nbd" install +} + +# Additional packages (root-image) +make_packages() { + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -p "$(grep -h -v ^# ${script_path}/packages.{both,${arch}})" install +} + +# Copy mkinitcpio archiso hooks and build initramfs (root-image) +make_setup_mkinitcpio() { + local _hook + for _hook in archiso archiso_shutdown archiso_pxe_common archiso_pxe_nbd archiso_pxe_http archiso_pxe_nfs archiso_loop_mnt; do + cp /usr/lib/initcpio/hooks/${_hook} ${work_dir}/${arch}/root-image/usr/lib/initcpio/hooks + cp /usr/lib/initcpio/install/${_hook} ${work_dir}/${arch}/root-image/usr/lib/initcpio/install + done + cp /usr/lib/initcpio/install/archiso_kms ${work_dir}/${arch}/root-image/usr/lib/initcpio/install + cp /usr/lib/initcpio/archiso_shutdown ${work_dir}/${arch}/root-image/usr/lib/initcpio + cp ${script_path}/mkinitcpio.conf ${work_dir}/${arch}/root-image/etc/mkinitcpio-archiso.conf + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -r 'mkinitcpio -c /etc/mkinitcpio-archiso.conf -k /boot/vmlinuz-linux -g /boot/archiso.img' run +} + +# Customize installation (root-image) +make_customize_root_image() { + cp -af ${script_path}/root-image ${work_dir}/${arch} + + # we do not need no new mirrorlist! + #curl -o ${work_dir}/${arch}/root-image/etc/pacman.d/mirrorlist 'https://www.archlinux.org/mirrorlist/?country=all&protocol=http&use_mirror_status=on' + + #we do not need no bloody documentation + #lynx -dump -nolist 'https://wiki.archlinux.org/index.php/Installation_Guide?action=render' >> ${work_dir}/${arch}/root-image/root/install.txt + + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}/${arch}" -C "${pacman_conf}" -D "${install_dir}" -r '/root/customize_root_image.sh' run + rm ${work_dir}/${arch}/root-image/root/customize_root_image.sh +} + +# Prepare kernel/initramfs ${install_dir}/boot/ +make_boot() { + mkdir -p ${work_dir}/iso/${install_dir}/boot/${arch} + cp ${work_dir}/${arch}/root-image/boot/archiso.img ${work_dir}/iso/${install_dir}/boot/${arch}/archiso.img + cp ${work_dir}/${arch}/root-image/boot/vmlinuz-linux ${work_dir}/iso/${install_dir}/boot/${arch}/vmlinuz +} + +# Add other aditional/extra files to ${install_dir}/boot/ +make_boot_extra() { + cp ${work_dir}/${arch}/root-image/boot/memtest86+/memtest.bin ${work_dir}/iso/${install_dir}/boot/memtest + cp ${work_dir}/${arch}/root-image/usr/share/licenses/common/GPL2/license.txt ${work_dir}/iso/${install_dir}/boot/memtest.COPYING +} + +# Prepare /${install_dir}/boot/syslinux +make_syslinux() { + mkdir -p ${work_dir}/iso/${install_dir}/boot/syslinux + for _cfg in ${script_path}/syslinux/*.cfg; do + sed "s|%ARCHISO_LABEL%|${iso_label}|g; + s|%INSTALL_DIR%|${install_dir}|g" ${_cfg} > ${work_dir}/iso/${install_dir}/boot/syslinux/${_cfg##*/} + done + cp ${script_path}/syslinux/splash.png ${work_dir}/iso/${install_dir}/boot/syslinux + cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/*.c32 ${work_dir}/iso/${install_dir}/boot/syslinux + cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/lpxelinux.0 ${work_dir}/iso/${install_dir}/boot/syslinux + cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/memdisk ${work_dir}/iso/${install_dir}/boot/syslinux + mkdir -p ${work_dir}/iso/${install_dir}/boot/syslinux/hdt + gzip -c -9 ${work_dir}/${arch}/root-image/usr/share/hwdata/pci.ids > ${work_dir}/iso/${install_dir}/boot/syslinux/hdt/pciids.gz + gzip -c -9 ${work_dir}/${arch}/root-image/usr/lib/modules/*-ARCH/modules.alias > ${work_dir}/iso/${install_dir}/boot/syslinux/hdt/modalias.gz +} + +# Prepare /isolinux +make_isolinux() { + mkdir -p ${work_dir}/iso/isolinux + sed "s|%INSTALL_DIR%|${install_dir}|g" ${script_path}/isolinux/isolinux.cfg > ${work_dir}/iso/isolinux/isolinux.cfg + cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/isolinux.bin ${work_dir}/iso/isolinux/ + cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/isohdpfx.bin ${work_dir}/iso/isolinux/ + cp ${work_dir}/${arch}/root-image/usr/lib/syslinux/bios/ldlinux.c32 ${work_dir}/iso/isolinux/ +} + +# Prepare /EFI +make_efi() { + mkdir -p ${work_dir}/iso/EFI/boot + cp ${work_dir}/x86_64/root-image/usr/lib/prebootloader/PreLoader.efi ${work_dir}/iso/EFI/boot/bootx64.efi + cp ${work_dir}/x86_64/root-image/usr/lib/prebootloader/HashTool.efi ${work_dir}/iso/EFI/boot/ + + cp ${work_dir}/x86_64/root-image/usr/lib/gummiboot/gummibootx64.efi ${work_dir}/iso/EFI/boot/loader.efi + + mkdir -p ${work_dir}/iso/loader/entries + cp ${script_path}/efiboot/loader/loader.conf ${work_dir}/iso/loader/ + cp ${script_path}/efiboot/loader/entries/uefi-shell-v2-x86_64.conf ${work_dir}/iso/loader/entries/ + cp ${script_path}/efiboot/loader/entries/uefi-shell-v1-x86_64.conf ${work_dir}/iso/loader/entries/ + + sed "s|%ARCHISO_LABEL%|${iso_label}|g; + s|%INSTALL_DIR%|${install_dir}|g" \ + ${script_path}/efiboot/loader/entries/archiso-x86_64-usb.conf > ${work_dir}/iso/loader/entries/archiso-x86_64.conf + + # TODO no uefi shell + # EFI Shell 2.0 for UEFI 2.3+ ( http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=UEFI_Shell ) + # curl -o ${work_dir}/iso/EFI/shellx64_v2.efi https://svn.code.sf.net/p/edk2/code/trunk/edk2/ShellBinPkg/UefiShell/X64/Shell.efi + # EFI Shell 1.0 for non UEFI 2.3+ ( http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Efi-shell ) + # curl -o ${work_dir}/iso/EFI/shellx64_v1.efi https://svn.code.sf.net/p/edk2/code/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi +} + +# Prepare efiboot.img::/EFI for "El Torito" EFI boot mode +make_efiboot() { + mkdir -p ${work_dir}/iso/EFI/archiso + truncate -s 31M ${work_dir}/iso/EFI/archiso/efiboot.img + mkfs.vfat -n ARCHISO_EFI ${work_dir}/iso/EFI/archiso/efiboot.img + + mkdir -p ${work_dir}/efiboot + mount ${work_dir}/iso/EFI/archiso/efiboot.img ${work_dir}/efiboot + + mkdir -p ${work_dir}/efiboot/EFI/archiso + cp ${work_dir}/iso/${install_dir}/boot/x86_64/vmlinuz ${work_dir}/efiboot/EFI/archiso/vmlinuz.efi + cp ${work_dir}/iso/${install_dir}/boot/x86_64/archiso.img ${work_dir}/efiboot/EFI/archiso/archiso.img + + mkdir -p ${work_dir}/efiboot/EFI/boot + cp ${work_dir}/x86_64/root-image/usr/lib/prebootloader/PreLoader.efi ${work_dir}/efiboot/EFI/boot/bootx64.efi + cp ${work_dir}/x86_64/root-image/usr/lib/prebootloader/HashTool.efi ${work_dir}/efiboot/EFI/boot/ + + cp ${work_dir}/x86_64/root-image/usr/lib/gummiboot/gummibootx64.efi ${work_dir}/efiboot/EFI/boot/loader.efi + + mkdir -p ${work_dir}/efiboot/loader/entries + cp ${script_path}/efiboot/loader/loader.conf ${work_dir}/efiboot/loader/ + cp ${script_path}/efiboot/loader/entries/uefi-shell-v2-x86_64.conf ${work_dir}/efiboot/loader/entries/ + cp ${script_path}/efiboot/loader/entries/uefi-shell-v1-x86_64.conf ${work_dir}/efiboot/loader/entries/ + + sed "s|%ARCHISO_LABEL%|${iso_label}|g; + s|%INSTALL_DIR%|${install_dir}|g" \ + ${script_path}/efiboot/loader/entries/archiso-x86_64-cd.conf > ${work_dir}/efiboot/loader/entries/archiso-x86_64.conf + + #cp ${work_dir}/iso/EFI/shellx64_v2.efi ${work_dir}/efiboot/EFI/ + #cp ${work_dir}/iso/EFI/shellx64_v1.efi ${work_dir}/efiboot/EFI/ + + umount ${work_dir}/efiboot +} + +# Copy aitab +make_aitab() { + mkdir -p ${work_dir}/iso/${install_dir} + cp ${script_path}/aitab ${work_dir}/iso/${install_dir}/aitab +} + +# Build all filesystem images specified in aitab (.fs.sfs .sfs) +make_prepare() { + cp -a -l -f ${work_dir}/${arch}/root-image ${work_dir} + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" pkglist + setarch ${arch} mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" prepare + rm -rf ${work_dir}/root-image + # rm -rf ${work_dir}/${arch}/root-image (if low space, this helps) +} + +# Build ISO +make_iso() { + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" checksum + mkarchiso ${verbose} -w "${work_dir}" -D "${install_dir}" -L "${iso_label}" -o "${out_dir}" iso "${iso_name}.iso" +} + +if [[ ${EUID} -ne 0 ]]; then + echo "This script must be run as root." + _usage 1 +fi + +if [[ ${arch} != x86_64 ]]; then + echo "This script needs to be run on x86_64" + _usage 1 +fi + +while getopts 'N:V:L:D:w:o:vh' arg; do + case "${arg}" in + N) iso_name="${OPTARG}" ;; + V) iso_version="${OPTARG}" ;; + L) iso_label="${OPTARG}" ;; + D) install_dir="${OPTARG}" ;; + w) work_dir="${OPTARG}" ;; + o) out_dir="${OPTARG}" ;; + v) verbose="-v" ;; + h) _usage 0 ;; + *) + echo "Invalid argument '${arg}'" + _usage 1 + ;; + esac +done + +mkdir -p ${work_dir} + +run_once make_pacman_conf + +# Do all stuff for each root-image +for arch in x86_64; do + run_once make_basefs + run_once make_packages + run_once make_setup_mkinitcpio + run_once make_customize_root_image +done + +for arch in x86_64; do + run_once make_boot +done + +# Do all stuff for "iso" +run_once make_boot_extra +run_once make_syslinux +run_once make_isolinux +run_once make_efi +run_once make_efiboot + +run_once make_aitab + +for arch in x86_64; do + run_once make_prepare +done + +run_once make_iso diff --git a/elchos/efiboot/loader/entries/archiso-x86_64-cd.conf b/elchos/efiboot/loader/entries/archiso-x86_64-cd.conf new file mode 100644 index 00000000..9892c591 --- /dev/null +++ b/elchos/efiboot/loader/entries/archiso-x86_64-cd.conf @@ -0,0 +1,4 @@ +title Arch Linux archiso x86_64 UEFI CD +linux /EFI/archiso/vmlinuz.efi +initrd /EFI/archiso/archiso.img +options archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% diff --git a/elchos/efiboot/loader/entries/archiso-x86_64-usb.conf b/elchos/efiboot/loader/entries/archiso-x86_64-usb.conf new file mode 100644 index 00000000..f61c5323 --- /dev/null +++ b/elchos/efiboot/loader/entries/archiso-x86_64-usb.conf @@ -0,0 +1,4 @@ +title Arch Linux archiso x86_64 UEFI USB +linux /%INSTALL_DIR%/boot/x86_64/vmlinuz +initrd /%INSTALL_DIR%/boot/x86_64/archiso.img +options archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% diff --git a/elchos/efiboot/loader/entries/uefi-shell-v1-x86_64.conf b/elchos/efiboot/loader/entries/uefi-shell-v1-x86_64.conf new file mode 100644 index 00000000..9597ff2f --- /dev/null +++ b/elchos/efiboot/loader/entries/uefi-shell-v1-x86_64.conf @@ -0,0 +1,2 @@ +title UEFI Shell x86_64 v1 +efi /EFI/shellx64_v1.efi diff --git a/elchos/efiboot/loader/entries/uefi-shell-v2-x86_64.conf b/elchos/efiboot/loader/entries/uefi-shell-v2-x86_64.conf new file mode 100644 index 00000000..0dde77ab --- /dev/null +++ b/elchos/efiboot/loader/entries/uefi-shell-v2-x86_64.conf @@ -0,0 +1,2 @@ +title UEFI Shell x86_64 v2 +efi /EFI/shellx64_v2.efi diff --git a/elchos/efiboot/loader/loader.conf b/elchos/efiboot/loader/loader.conf new file mode 100644 index 00000000..62c4a839 --- /dev/null +++ b/elchos/efiboot/loader/loader.conf @@ -0,0 +1,2 @@ +timeout 3 +default archiso-x86_64 diff --git a/elchos/isolinux/isolinux.cfg b/elchos/isolinux/isolinux.cfg new file mode 100644 index 00000000..10fd2852 --- /dev/null +++ b/elchos/isolinux/isolinux.cfg @@ -0,0 +1,6 @@ +PATH /%INSTALL_DIR%/boot/syslinux/ +DEFAULT loadconfig + +LABEL loadconfig + CONFIG /%INSTALL_DIR%/boot/syslinux/archiso.cfg + APPEND /%INSTALL_DIR%/ diff --git a/elchos/mkinitcpio.conf b/elchos/mkinitcpio.conf new file mode 100644 index 00000000..2f46da49 --- /dev/null +++ b/elchos/mkinitcpio.conf @@ -0,0 +1,2 @@ +HOOKS="base udev memdisk archiso_shutdown archiso archiso_loop_mnt archiso_pxe_common archiso_pxe_nbd archiso_pxe_http archiso_pxe_nfs archiso_kms block pcmcia filesystems keyboard" +COMPRESSION="xz" diff --git a/elchos/packages.both b/elchos/packages.both new file mode 100644 index 00000000..409abe91 --- /dev/null +++ b/elchos/packages.both @@ -0,0 +1,47 @@ +arch-install-scripts +python +hddtemp +mlocate +collectd +sysstat +vsftpd +btrfs-progs +lftp +haveged +crda +dhclient +dialog +dmraid +dnsmasq +dnsutils +dosfstools +ethtool +f2fs-tools +fsarchiver +gnu-netcat +gpm +gptfdisk +grml-zsh-config +hdparm +lftp +linux-atm +mtools +nfs-utils +nilfs-utils +ntfs-3g +ntp +openconnect +openssh +partimage +rfkill +rsync +sudo +tcpdump +wget +wireless_tools +wpa_actiond +zsh +vim +tor +tmux +pacman-mirrorlist diff --git a/elchos/packages.i686 b/elchos/packages.i686 new file mode 100644 index 00000000..e69de29b diff --git a/elchos/packages.x86_64 b/elchos/packages.x86_64 new file mode 100644 index 00000000..407ead28 --- /dev/null +++ b/elchos/packages.x86_64 @@ -0,0 +1,3 @@ +gummiboot +prebootloader +refind-efi diff --git a/elchos/pacman.conf b/elchos/pacman.conf new file mode 100644 index 00000000..45fe03dc --- /dev/null +++ b/elchos/pacman.conf @@ -0,0 +1,92 @@ +# +# /etc/pacman.conf +# +# See the pacman.conf(5) manpage for option and repository directives + +# +# GENERAL OPTIONS +# +[options] +# The following paths are commented out with their default values listed. +# If you wish to use different paths, uncomment and update the paths. +#RootDir = / +#DBPath = /var/lib/pacman/ +#CacheDir = /var/cache/pacman/pkg/ +#LogFile = /var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +HoldPkg = pacman glibc +#XferCommand = /usr/bin/curl -C - -f %u > %o +#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +#UseDelta = 0.7 +Architecture = auto + +# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +#IgnorePkg = +#IgnoreGroup = + +#NoUpgrade = +#NoExtract = + +# Misc options +#UseSyslog +#Color +#TotalDownload +# We cannot check disk space from within a chroot environment +#CheckSpace +#VerbosePkgLists + +# By default, pacman accepts packages signed by keys that its local keyring +# trusts (see pacman-key and its man page), as well as unsigned packages. +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +#RemoteFileSigLevel = Required + +# NOTE: You must run `pacman-key --init` before first using pacman; the local +# keyring can then be populated with the keys of all official Arch Linux +# packagers with `pacman-key --populate archlinux`. + +# +# REPOSITORIES +# - can be defined here or included from another file +# - pacman will search repositories in the order defined here +# - local/custom mirrors can be added here or in separate files +# - repositories listed first will take precedence when packages +# have identical names, regardless of version number +# - URLs will have $repo replaced by the name of the current repo +# - URLs will have $arch replaced by the name of the architecture +# +# Repository entries are of the format: +# [repo-name] +# Server = ServerName +# Include = IncludePath +# +# The header [repo-name] is crucial - it must be present and +# uncommented to enable the repo. +# + +# The testing repositories are disabled by default. To enable, uncomment the +# repo name header and Include lines. You can add preferred servers immediately +# after the header, and they will be used before the default mirrors. + +#[testing] +#Include = /etc/pacman.d/mirrorlist + +[core] +Include = /etc/pacman.d/mirrorlist + +[extra] +Include = /etc/pacman.d/mirrorlist + +#[community-testing] +#Include = /etc/pacman.d/mirrorlist + +[community] +Include = /etc/pacman.d/mirrorlist + +# An example of a custom package repository. See the pacman manpage for +# tips on creating your own repositories. +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs + diff --git a/elchos/refresh.sh b/elchos/refresh.sh new file mode 100755 index 00000000..2ff1d59c --- /dev/null +++ b/elchos/refresh.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu +cd "$(dirname "$(readlink -f "$0")")" +rm -rvf out/ work +./build.sh -N elchos -v +# cp -v out/filehooker* /home/makefu/isos +# TODO internal +# virsh reset vm1 ||: diff --git a/elchos/root-image/etc/collectd.conf b/elchos/root-image/etc/collectd.conf new file mode 100644 index 00000000..30480f2e --- /dev/null +++ b/elchos/root-image/etc/collectd.conf @@ -0,0 +1,84 @@ +#Hostname "elch_" +Interval 10 + +LoadPlugin syslog + + LogLevel info + + +LoadPlugin md +LoadPlugin cpu +LoadPlugin df +LoadPlugin disk +#LoadPlugin ping +LoadPlugin hddtemp +LoadPlugin interface +LoadPlugin load +LoadPlugin memory +LoadPlugin network +LoadPlugin uptime +LoadPlugin users +LoadPlugin write_graphite + + +# Device "/dev/sda1" +# Device "192.168.0.2:/mnt/nfs" + FSType "ext2" + FSType "ext3" + FSType "ext4" + FSType "btrfs" + FSType "ntfs" + FSType "ntfs-3g" + FSType "vfat" + + IgnoreSelected false + + + + Disk "/[vsh]d[abcdefg][12345678]/" + IgnoreSelected false + + + + Host "127.0.0.1" + Port 7634 + #TranslateDevicename false + + + + Interface "lo" + IgnoreSelected true + + + +# + #Host "elchhub.krebsco.de" + #Host "elchstats.krebsco.de" + #Interval 1.0 + #Timeout 0.9 +# TTL 255 +# SourceAddress "1.2.3.4" +# Device "eth0" +# MaxMissed -1 +# + + +# +# Sensor "it8712-isa-0290/temperature-temp1" +# Sensor "it8712-isa-0290/fanspeed-fan3" +# Sensor "it8712-isa-0290/voltage-in8" +# IgnoreSelected false +# + + + + + Host "elchstats.nsupdate.info" + Port "2003" + Prefix "elch." + #Postfix "" + EscapeCharacter "_" + StoreRates false + AlwaysAppendDS false + + diff --git a/elchos/root-image/etc/fstab b/elchos/root-image/etc/fstab new file mode 100644 index 00000000..e69de29b diff --git a/elchos/root-image/etc/hostname b/elchos/root-image/etc/hostname new file mode 100644 index 00000000..ef8963cd --- /dev/null +++ b/elchos/root-image/etc/hostname @@ -0,0 +1 @@ +filebitch diff --git a/elchos/root-image/etc/locale.conf b/elchos/root-image/etc/locale.conf new file mode 100644 index 00000000..01ec548f --- /dev/null +++ b/elchos/root-image/etc/locale.conf @@ -0,0 +1 @@ +LANG=en_US.UTF-8 diff --git a/elchos/root-image/etc/pam.d/su b/elchos/root-image/etc/pam.d/su new file mode 100644 index 00000000..a2910423 --- /dev/null +++ b/elchos/root-image/etc/pam.d/su @@ -0,0 +1,6 @@ +#%PAM-1.0 +auth sufficient pam_rootok.so +auth sufficient pam_wheel.so trust use_uid +auth required pam_unix.so +account required pam_unix.so +session required pam_unix.so diff --git a/elchos/root-image/etc/sudoers.d/g_wheel b/elchos/root-image/etc/sudoers.d/g_wheel new file mode 100644 index 00000000..8c45359f --- /dev/null +++ b/elchos/root-image/etc/sudoers.d/g_wheel @@ -0,0 +1 @@ +%wheel ALL=(ALL) NOPASSWD: ALL diff --git a/elchos/root-image/etc/systemd/scripts/choose-mirror b/elchos/root-image/etc/systemd/scripts/choose-mirror new file mode 100755 index 00000000..0ae08067 --- /dev/null +++ b/elchos/root-image/etc/systemd/scripts/choose-mirror @@ -0,0 +1,26 @@ +#!/bin/bash + +get_cmdline() { + local param + for param in $(< /proc/cmdline); do + case "${param}" in + $1=*) echo "${param##*=}"; + return 0 + ;; + esac + done +} + +mirror=$(get_cmdline mirror) +[[ $mirror = auto ]] && mirror=$(get_cmdline archiso_http_srv) +[[ $mirror ]] || exit 0 + +mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig +cat >/etc/pacman.d/mirrorlist << EOF +# +# Arch Linux repository mirrorlist +# Generated by archiso +# + +Server = ${mirror%%/}/\$repo/os/\$arch +EOF diff --git a/elchos/root-image/etc/systemd/system/choose-mirror.service b/elchos/root-image/etc/systemd/system/choose-mirror.service new file mode 100644 index 00000000..1e4d771d --- /dev/null +++ b/elchos/root-image/etc/systemd/system/choose-mirror.service @@ -0,0 +1,10 @@ +[Unit] +Description=Choose mirror from the kernel command line +ConditionKernelCommandLine=mirror + +[Service] +Type=oneshot +ExecStart=/etc/systemd/scripts/choose-mirror + +[Install] +WantedBy=multi-user.target diff --git a/elchos/root-image/etc/systemd/system/collectd.service.d/wait.conf b/elchos/root-image/etc/systemd/system/collectd.service.d/wait.conf new file mode 100644 index 00000000..05d8b43c --- /dev/null +++ b/elchos/root-image/etc/systemd/system/collectd.service.d/wait.conf @@ -0,0 +1,2 @@ +[Service] +ExecStartPre=/usr/bin/sleep 20 diff --git a/elchos/root-image/etc/systemd/system/dhcpcd.service.d/force-reboot.conf b/elchos/root-image/etc/systemd/system/dhcpcd.service.d/force-reboot.conf new file mode 100644 index 00000000..5b506341 --- /dev/null +++ b/elchos/root-image/etc/systemd/system/dhcpcd.service.d/force-reboot.conf @@ -0,0 +1,2 @@ +[Service] +StartLimitAction=reboot-force diff --git a/elchos/root-image/etc/systemd/system/elch-hostname.service b/elchos/root-image/etc/systemd/system/elch-hostname.service new file mode 100644 index 00000000..bcee7964 --- /dev/null +++ b/elchos/root-image/etc/systemd/system/elch-hostname.service @@ -0,0 +1,11 @@ +[Unit] +Description=change filehooker hostname +Before=network.target nss-lookup.target multi-user.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/krebs/bin/set-hostname.sh + +[Install] +WantedBy=multi-user.target diff --git a/elchos/root-image/etc/systemd/system/etc-pacman.d-gnupg.mount b/elchos/root-image/etc/systemd/system/etc-pacman.d-gnupg.mount new file mode 100644 index 00000000..4eab5513 --- /dev/null +++ b/elchos/root-image/etc/systemd/system/etc-pacman.d-gnupg.mount @@ -0,0 +1,8 @@ +[Unit] +Description=Temporary /etc/pacman.d/gnupg directory + +[Mount] +What=tmpfs +Where=/etc/pacman.d/gnupg +Type=tmpfs +Options=mode=0755 diff --git a/elchos/root-image/etc/systemd/system/getty@tty1.service.d/run_krebs_secret.conf b/elchos/root-image/etc/systemd/system/getty@tty1.service.d/run_krebs_secret.conf new file mode 100644 index 00000000..29e5be5f --- /dev/null +++ b/elchos/root-image/etc/systemd/system/getty@tty1.service.d/run_krebs_secret.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=-/usr/bin/agetty --autologin reaktor --noclear %I 38400 linux diff --git a/elchos/root-image/etc/systemd/system/hddtemp.service.d/monitor_all_disks.conf b/elchos/root-image/etc/systemd/system/hddtemp.service.d/monitor_all_disks.conf new file mode 100644 index 00000000..e6b8fcda --- /dev/null +++ b/elchos/root-image/etc/systemd/system/hddtemp.service.d/monitor_all_disks.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=/bin/bash -c "/usr/bin/hddtemp -dF hddtemp -d /dev/[vsh]d[a-z]" diff --git a/elchos/root-image/etc/systemd/system/ntpdate.service.d/set_hwclock.conf b/elchos/root-image/etc/systemd/system/ntpdate.service.d/set_hwclock.conf new file mode 100644 index 00000000..e57550c8 --- /dev/null +++ b/elchos/root-image/etc/systemd/system/ntpdate.service.d/set_hwclock.conf @@ -0,0 +1,2 @@ +[Service] +ExecStart=/usr/bin/hwclock --systohc --utc -w diff --git a/elchos/root-image/etc/systemd/system/pacman-init.service b/elchos/root-image/etc/systemd/system/pacman-init.service new file mode 100644 index 00000000..23b81445 --- /dev/null +++ b/elchos/root-image/etc/systemd/system/pacman-init.service @@ -0,0 +1,15 @@ +[Unit] +Description=Initializes Pacman keyring +Wants=haveged.service +After=haveged.service +Requires=etc-pacman.d-gnupg.mount +After=etc-pacman.d-gnupg.mount + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/pacman-key --init +ExecStart=/usr/bin/pacman-key --populate archlinux + +[Install] +WantedBy=multi-user.target diff --git a/elchos/root-image/etc/systemd/system/start-ncdc@.service b/elchos/root-image/etc/systemd/system/start-ncdc@.service new file mode 100644 index 00000000..7b5b1b8e --- /dev/null +++ b/elchos/root-image/etc/systemd/system/start-ncdc@.service @@ -0,0 +1,13 @@ +[Unit] +Description=ncdc autoconfig and startup for %i +After=network.target local-fs.target multi-user.target elch-hostname.service + +[Service] +Type=oneshot +RemainAfterExit=yes +#KillMode=none +ExecStart=/usr/bin/tmux new-session -n startup -d "/bin/sh /krebs/bin/start-ncdc.ship" +ExecStop=/usr/bin/sudo -u %i /usr/bin/tmux send-keys -t dcpp:ncdc "/quit" C-m + +[Install] +WantedBy=multi-user.target diff --git a/elchos/root-image/etc/systemd/system/tor-configure-hidden.service b/elchos/root-image/etc/systemd/system/tor-configure-hidden.service new file mode 100644 index 00000000..c9b8f20f --- /dev/null +++ b/elchos/root-image/etc/systemd/system/tor-configure-hidden.service @@ -0,0 +1,11 @@ +[Unit] +Description=Announce Tor Hidden Address +After=network.target nss-lookup.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/krebs/bin/tor_configure_hidden_service.ship + +[Install] +WantedBy=multi-user.target diff --git a/elchos/root-image/etc/udev/rules.d/81-dhcpcd.rules b/elchos/root-image/etc/udev/rules.d/81-dhcpcd.rules new file mode 100644 index 00000000..1c4053c0 --- /dev/null +++ b/elchos/root-image/etc/udev/rules.d/81-dhcpcd.rules @@ -0,0 +1 @@ +ACTION=="add", SUBSYSTEM=="net", ENV{INTERFACE}=="en*|eth*", ENV{SYSTEMD_WANTS}="dhcpcd@$name.service" diff --git a/elchos/root-image/krebs/bin/add-reaktor-secret.sh b/elchos/root-image/krebs/bin/add-reaktor-secret.sh new file mode 100755 index 00000000..92681449 --- /dev/null +++ b/elchos/root-image/krebs/bin/add-reaktor-secret.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -euf +green='\e[0;32m' +red='\e[0;31m' +nc='\e[0m' +black='\e[0;30m' + +printf "${green}Add a Reaktor Secret ${nc}\n" +printf "${red}(no spaces in input plox)${nc}\n" + +nick=${1:-} +while test -z "${nick:-}" ;do + printf "provide Nick Name:\n" + read nick +done + +secret=${2:-} +while test -z "${secret:-}" ;do + printf "provide Secret:$black\n" + read secret +done + +echo "$nick $secret" >> /krebs/painload/Reaktor/admin.lst +printf "${green}done${nc}" diff --git a/elchos/root-image/krebs/bin/macid.sh b/elchos/root-image/krebs/bin/macid.sh new file mode 100755 index 00000000..0fccc84b --- /dev/null +++ b/elchos/root-image/krebs/bin/macid.sh @@ -0,0 +1,2 @@ +#!/bin/sh +ip addr | grep ether | awk '{print $2}' | sort |md5sum | awk '{print $1}' | dd bs=1 count=6 2>/dev/null diff --git a/elchos/root-image/krebs/bin/reaktor-shell.sh b/elchos/root-image/krebs/bin/reaktor-shell.sh new file mode 100755 index 00000000..117c64f6 --- /dev/null +++ b/elchos/root-image/krebs/bin/reaktor-shell.sh @@ -0,0 +1,4 @@ +#!/bin/sh +echo "IP Addresses:" +/krebs/painload/Reaktor/commands/ips || echo "no IPs!" +/krebs/bin/add-reaktor-secret.sh diff --git a/elchos/root-image/krebs/bin/refresh-shares.ship b/elchos/root-image/krebs/bin/refresh-shares.ship new file mode 100755 index 00000000..364d7758 --- /dev/null +++ b/elchos/root-image/krebs/bin/refresh-shares.ship @@ -0,0 +1,11 @@ +#!/bin/sh +#TODO: +#!/usr/bin/env ship +set -euf +#@include filehooker +. /krebs/lib/filehooker +ncdc_user="hooker" + +share_all_partitions +systemctl restart hddtemp.service +exit 0 diff --git a/elchos/root-image/krebs/bin/set-hostname.sh b/elchos/root-image/krebs/bin/set-hostname.sh new file mode 100755 index 00000000..31101a18 --- /dev/null +++ b/elchos/root-image/krebs/bin/set-hostname.sh @@ -0,0 +1,5 @@ +#!/bin/sh +hostn="elch_$(/krebs/bin/macid.sh)" +hostnamectl set-hostname "$hostn" +hostname $hostn +echo "$hostn" > /etc/hostname diff --git a/elchos/root-image/krebs/bin/start-ncdc.ship b/elchos/root-image/krebs/bin/start-ncdc.ship new file mode 100755 index 00000000..1d47bcfb --- /dev/null +++ b/elchos/root-image/krebs/bin/start-ncdc.ship @@ -0,0 +1,23 @@ +#!/usr/bin/env ship +set -euf +#@include filehooker +. /krebs/lib/filehooker +#@include network +ncdc_user="hooker" + +useradd -m $ncdc_user ||: + +sudo -u $ncdc_user /usr/bin/tmux new-session -s dcpp -n ncdc -d ncdc 2>/dev/null || echo "ncdc is already running" + +nick=$(cat /etc/hostname) +echo "using nick $nick" +ncdc_configure_nick "$nick" +sleep 1 +dc_hub="adcs://elchhub.nsupdate.info:2781" +echo "connecting to $dc_hub" +ncdc_configure_hub "$dc_hub" "elch" + + +share_all_partitions + +exit 0 diff --git a/elchos/root-image/krebs/bin/tor-get-hidden-service.sh b/elchos/root-image/krebs/bin/tor-get-hidden-service.sh new file mode 100755 index 00000000..c9946366 --- /dev/null +++ b/elchos/root-image/krebs/bin/tor-get-hidden-service.sh @@ -0,0 +1,2 @@ +#!/bin/sh +cat /var/lib/tor/hidden_service/hostname diff --git a/elchos/root-image/krebs/bin/tor_configure_hidden_service.ship b/elchos/root-image/krebs/bin/tor_configure_hidden_service.ship new file mode 100755 index 00000000..1e026d26 --- /dev/null +++ b/elchos/root-image/krebs/bin/tor_configure_hidden_service.ship @@ -0,0 +1,16 @@ +#!/bin/sh +#@include core +. /krebs/lib/core +#@include network +. /krebs/lib/network +#@include tor +. /krebs/lib/tor + +sleep_time=5 +test -w "$torrc" || ( error "$torrc is not writable!"; exit 1 ) || exit 1 + +configure_hidden_service +test ! -e $hidden_service_dir/hostname && \ + info "hidden service file does not exist, restarting tor" && \ + systemctl restart tor && \ + sleep 1 diff --git a/elchos/root-image/krebs/bin/tor_publish_ssh.ship b/elchos/root-image/krebs/bin/tor_publish_ssh.ship new file mode 100755 index 00000000..2ecee9fb --- /dev/null +++ b/elchos/root-image/krebs/bin/tor_publish_ssh.ship @@ -0,0 +1,12 @@ +#!/usr/bin/env ship +#@include core +. /krebs/lib/core +#@include network +. /krebs/lib/network +#@include tor +. /krebs/lib/tor + +test -w "$torrc" || ( error "$torrc is not writable!"; exit 1 ) || exit 1 + +configure_hidden_service +cat $hidden_service_dir/hostname | send_irc diff --git a/elchos/root-image/krebs/bin/update-search.sh b/elchos/root-image/krebs/bin/update-search.sh new file mode 100755 index 00000000..665f6543 --- /dev/null +++ b/elchos/root-image/krebs/bin/update-search.sh @@ -0,0 +1,5 @@ +#!/bin/sh +for i in /media/vag*;do + updatedb -l 0 -o "$i/mlocate.db" -U "$i" +done +echo "update complete" diff --git a/elchos/root-image/krebs/bin/vim_sane_defaults.ship b/elchos/root-image/krebs/bin/vim_sane_defaults.ship new file mode 100755 index 00000000..fcc7ffcf --- /dev/null +++ b/elchos/root-image/krebs/bin/vim_sane_defaults.ship @@ -0,0 +1,10 @@ +#!/bin/sh +#@strict +#@include core +. /krebs/lib/core +#@include vim +. /krebs/lib/vim +#@mainifyme +touch $vimrc +info "configuring vim" +vim_conf_sane_defaults diff --git a/elchos/root-image/krebs/etc/Reaktor/admin.lst b/elchos/root-image/krebs/etc/Reaktor/admin.lst new file mode 100644 index 00000000..e69de29b diff --git a/elchos/root-image/krebs/etc/Reaktor/auth.lst b/elchos/root-image/krebs/etc/Reaktor/auth.lst new file mode 100644 index 00000000..e69de29b diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/ftpget b/elchos/root-image/krebs/etc/Reaktor/commands/ftpget new file mode 100755 index 00000000..74e76f8e --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/ftpget @@ -0,0 +1,58 @@ +#!/bin/sh +# usage: $0 [-d] uri sharename[/subdirs] +exec 2>&1 +set -euf +ncdc_user=hooker +usage(){ + cat < 0.8 directory is stored to /media/vag0/firefox_releases + + ftpget -d http://speedtest.qsc.de/10MB.qsc vag0/ + -> 10MB.qsc is stored to /media/vag0/10MB.qsc +EOF +} +if test "${1:--h}" == '-h' -o "${1:-}" == '--help';then + usage + examples + exit 0 +fi +if test ${1:-} == '-d' ;then + is_dir=true + shift +fi + +target="${1:-}" +if !( echo "$target" | egrep -q '^(ftps*://|https*://)' );then + exit 23 +fi + +share=$( printf "%s" "${2?provide share name}" |head -1 | sed 's#\.\./##') +sharepath=/media/${share%%/*} +realshare="/media/$share" +test ! -e "$sharepath" && echo "$sharepath does not exist!" && exit 23 + +sudo -u $ncdc_user /usr/bin/mkdir -p "$realshare" + +if test -z ${is_dir:-};then + cmd="lftpget \"$target\"" +else + cmd="lftp -e \"mirror;exit\" $target" +fi + + if ! sudo -u $ncdc_user /usr/bin/tmux has-session -t dl >/dev/null 2>&1 ;then + sudo -u $ncdc_user /usr/bin/tmux new-session -s dl -d -c "$realshare" "$cmd" + else + sudo -u $ncdc_user /usr/bin/tmux new-window -t dl -c "$realshare" "$cmd" + fi +#sudo -u $ncdc_user /usr/bin/tmux new-window -t dl +#cd "$realshare" ;sudo -u hooker /usr/bin/lftpget "$target" +echo "download started, check with 'list_downloads'" diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/identify b/elchos/root-image/krebs/etc/Reaktor/commands/identify new file mode 100755 index 00000000..c2fb2c58 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/identify @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import imp +import os,sys + +def load_config(filename): + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [ dirname ]) + return imp.load_module(modname, file, pathname, description) + +config = load_config(os.environ['config_filename']) + +with open(config.admin_file) as f: + for line in f: + nick,secret = line.split() + if sys.argv[1] == secret: + print("identified you as %s!"%nick) + with open(config.auth_file,'a+') as g: + g.write(os.environ['_prefix'] +"\n") + sys.exit(0) + +print("unable to identify you, sorry") diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/io b/elchos/root-image/krebs/etc/Reaktor/commands/io new file mode 100755 index 00000000..eb04ae9b --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/io @@ -0,0 +1,25 @@ +#!/usr/bin/zsh +printf '%-10s %-7s %-7s %-7s %-7s\n' IFACE rxkB/s txkB/s rxTotal txTotal +sar -n DEV 1 3 | grep Average: | grep -v IFACE | grep -v ' lo ' | while read line;do + dev=$(echo $line | awk '{print $2}') + rxkb=$(echo $line | awk '{print $5}') + txkb=$(echo $line | awk '{print $6}') + total_bytes_r=$(cat /proc/net/dev | grep ${dev}: | awk '{print $2}') + total_bytes_t=$(cat /proc/net/dev | grep ${dev}: | awk '{print $10}') + + printf '%-10s %-7s %-7s %-7s %-7s\n' $dev $rxkb $txkb $((total_bytes_r / (1024*1024))) $((total_bytes_t / (1024*1024))) +done +printf "%-10s %-7s %-7s\n" "DSK" "rxkB/s" "txkB/s" +sar -p -d 1 3 | grep Average: | grep -v ' DEV ' |while read line; +do + dsk=$(echo $line | awk '{print $2}') + rd_sec=$(echo $line | awk '{print $4}') + wr_sec=$(echo $line | awk '{print $5}') + if echo $dsk | egrep -q '(sd|hd|vd)';then + # TODO for some reason 0.00 can only be interpreted correctly as arithmetic + # expession by zsh + # + # rd is counted in blocks (which is 512 bytes) + printf "%-10s %-7.2f %-7.2f\n" "/dev/$dsk" "$((rd_sec*2))" "$((wr_sec*2))" + fi +done diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/ips b/elchos/root-image/krebs/etc/Reaktor/commands/ips new file mode 100755 index 00000000..17c39658 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/ips @@ -0,0 +1,2 @@ +#!/bin/sh +ip addr | grep 'inet ' | awk '{print $2}' | grep -v 127.0.0.1 | grep . diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/list_downloads b/elchos/root-image/krebs/etc/Reaktor/commands/list_downloads new file mode 100755 index 00000000..f53067d8 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/list_downloads @@ -0,0 +1,8 @@ +#!/bin/sh +ncdc_user=hooker +count=$(sudo -u $ncdc_user /usr/bin/tmux list-windows -t dl 2>/dev/null| wc -l) + +test $count -eq 0 && echo "no downloads running" && exit 0 +for i in $(seq 0 $(($count-1)));do + sudo -u $ncdc_user /usr/bin/tmux capture-pane -t dl:$i -p | grep -v '^$' | tail -n 1 +done diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/onion b/elchos/root-image/krebs/etc/Reaktor/commands/onion new file mode 100755 index 00000000..1a202991 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/onion @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo -u tor /krebs/bin/tor-get-hidden-service.sh || echo "no hidden service configured" diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/reboot b/elchos/root-image/krebs/etc/Reaktor/commands/reboot new file mode 100755 index 00000000..a264831a --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/reboot @@ -0,0 +1,3 @@ +#!/bin/sh +echo "system is going down" +sudo /usr/bin/reboot diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares b/elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares new file mode 100755 index 00000000..1005998b --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/refresh_shares @@ -0,0 +1,4 @@ +#!/bin/sh +ncdc_user=hooker +sudo /krebs/bin/refresh-shares.ship 2>&1 +sudo -u $ncdc_user /krebs/bin/update-search.sh 2>&1 diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/shares b/elchos/root-image/krebs/etc/Reaktor/commands/shares new file mode 100755 index 00000000..1601d584 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/shares @@ -0,0 +1,2 @@ +#!/bin/sh +df -h | grep '/media/' diff --git a/elchos/root-image/krebs/etc/Reaktor/commands/update-search b/elchos/root-image/krebs/etc/Reaktor/commands/update-search new file mode 100755 index 00000000..1db1c1b2 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/commands/update-search @@ -0,0 +1,3 @@ +#!/bin/sh +ncdc_user=hooker +sudo -u $ncdc_user /krebs/bin/update-search.sh diff --git a/elchos/root-image/krebs/etc/Reaktor/config.py b/elchos/root-image/krebs/etc/Reaktor/config.py new file mode 100644 index 00000000..5e07b659 --- /dev/null +++ b/elchos/root-image/krebs/etc/Reaktor/config.py @@ -0,0 +1,60 @@ +import socket + +debug = False + +name = socket.gethostname() + +irc_alarm_timeout = 300 +irc_hammer_interval = 10 +irc_kill_timeout = 360 +irc_nickname = name +#irc_server = 'elchirc.nsupdate.info' +irc_server = 'irc.freenode.net' +irc_restart_timeout = 5 +irc_port = 6667 +irc_channels = [ + '#filehooker' +] + +admin_file='admin.lst' +auth_file='auth.lst' + +def default_command(cmd): + return { + 'capname': cmd, + 'pattern': '^(?:' + name + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', + 'argv': [ 'commands/' + cmd ] } + +public_commands = [ + default_command('caps'), + default_command('hello'), + default_command('search'), + default_command('list_downloads'), + default_command('badcommand'), + default_command('rev'), + default_command('io'), + default_command('ips'), + default_command('uptime'), + default_command('shares'), + default_command('onion'), + default_command('nocommand'), + # command not found + { 'pattern': '^(?:' + name + '|\\*):.*', + 'argv': [ 'commands/respond','You are made of stupid!'] }, + # "highlight" + { 'pattern': '.*\\b' + name + '\\b.*', + 'argv': [ 'commands/say', 'I\'m famous' ] }, + # identify via direct connect + { 'capname': 'identify', + 'pattern': 'identify' + '\\s*(?:\\s+(?P.*))?$', + 'argv' : [ 'commands/identify' ]} + +] + +commands = [ + default_command('reload'), + default_command('update-search'), + default_command('refresh_shares'), + default_command('ftpget'), + default_command('reboot') +] diff --git a/elchos/root-image/krebs/etc/authorized_keys b/elchos/root-image/krebs/etc/authorized_keys new file mode 100644 index 00000000..f9446825 --- /dev/null +++ b/elchos/root-image/krebs/etc/authorized_keys @@ -0,0 +1,6 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7YrLdnXDRU2XEdZDu1BmgiT0Vaxplf3bfvSm+5o3g4AcR2yCv7h2D633c9uA0gq52EJ3V5m8B1ZcxqA0zqDptKwx+ZTMUGDls7StH5xpJyk9j5gf8DzyDLQPQG2IYszCH+8esKjo3BOFxfey8NaX+k6gvQsG3lyV0PjLvvIy4gDuMn6dPZfVAlwNYFOUNgwpku3W3A0d+UFyVjt3/sgZxM+8C3y6QE1gwT5/NfBbHM5vaEqjHcVq1ui+7a4iOXFGKkZDcd7EX6cQZSbCzZL7sZ0OmB1WpAsDCvIXfzX1YfNA0sso7ldSF6ZUGNgwEk1LootnQlCK/dfbM+i62SZ+1 tv@iiso +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCv9TTt4FkzT3jlQ0VS2tX/GpQO9Ef0wIQ+g96foe4qSniBwR667T1gIhURrod/p7N9oQcWRrNohjgmSBZRYA0kW6ZyqYJkLvRv54nXv6j/8Xq2nG/KVfDqL0kp8if+JGeFlQElpWJiAbGifYkopFy69QiLYU2ndR7aPbx+5qm/dcwPJ7K+n6dyePynCZadtcabm3PuBFUxGLdT9ImDXMOPfXxPMlN/3eb78byuEuHnhCIvIGLMBGx+8QTXvu7kHpZObvkbsF1xjVs9fDpwVLjh7GWdwf3BZ/agFlI24ffyqCPFnuaxUVyfUZeqf4twRsIZkTTB47lHDhYiVkyGe8gd root@pigstarter.de +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCl3RTOHd5DLiVeUbUr/GSiKoRWknXQnbkIf+uNiFO+XxiqZVojPlumQUVhasY8UzDzj9tSDruUKXpjut50FhIO5UFAgsBeMJyoZbgY/+R+QKU00Q19+IiUtxeFol/9dCO+F4o937MC0OpAC10LbOXN/9SYIXueYk3pJxIycXwUqhYmyEqtDdVh9Rx32LBVqlBoXRHpNGPLiswV2qNe0b5p919IGcslzf1XoUzfE3a3yjk/XbWh/59xnl4V7Oe7+iQheFxOT6rFA30WYwEygs5As//ZYtxvnn0gA02gOnXJsNjOW9irlxOUeP7IOU6Ye3WRKFRR0+7PS+w8IJLag2xb makefu@pornocauster +ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp83zynhIueJJsWlSEykVSBrrgBFKq38+vT8bRfa+csqyjZBl2SQFuCPo+Qbh49mwchpZRshBa9jQEIGqmXxv/PYdfBFQuOFgyUq9ZcTZUXqeynicg/SyOYFW86iiqYralIAkuGPfQ4howLPVyjTZtWeEeeEttom6p6LMY5Aumjz2em0FG0n9rRFY2fBzrdYAgk9C0N6ojCs/Gzknk9SGntA96MDqHJ1HXWFMfmwOLCnxtE5TY30MqSmkrJb7Fsejwjoqoe9Y/mCaR0LpG2cStC1+37GbHJNH0caCMaQCX8qdfgMVbWTVeFWtV6aWOaRgwLrPDYn4cHWQJqTfhtPrNQ== death@uriel +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/mUvSqIroFofp8a+nL6TBgAVvIk8IvFeOsHnRQsvhZX8ddk1+JICipsGwqsT2wRAk9rhcnLU/OdF+PXvykztNa1x4XxNACKnLfWBMk/VGadUkCwsdIwuu80nQfaEz5vNrjgNLfCaNoUa6sg0A2eyyuWH/vruPyfPJNDXA/ZQdXxJCSSfZUnIFW4qjAf4hZ+TK1CY7xECZQ3r+aqhJmSFe3T+ul5ZQLl6fmHP4oTf7sFNV4/fHY8RMxCPMztdyUJc3HB5MhI94VytjXuTSBDAgi5567bH1j1aBco4mAezfgHZy2eqeNVzYmFM/cVGEqyRIjokGYa72ZuGZ5Y58HjVDL8olweUVqOm11ref8+tBovyrHzjNKn6YiiMPYb0j03vBecqZYDA6n24s2WgEniL5WALhi5Y1NgUo1W9WDefhA2xC7p9xSy8kxs1UJH6g9U8SuHY2geJ/dYf3jixB3q/PwAfntejPkX1Pwy+rBVirA1vYIYgOWeifUyq6tYHxVo/kVEbyYkE1B6pBGwRdsWDwT3y02DO3OZFq9QX/0zkJtv2lkMR0LDk8WjZjilfqs1UivDCNY3ZQF+SOvUzeAkQFWSSU+yKlZOGPWcqNUVw8SQCw5/doIKjIclekWJ9KSD1VjTImx2oqYNqOa0kfvX+4cU+ECI1daCR6cjYiuizBIQ== pedro +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTUWm/fISw/gbuHvf3kwxGEuk1aY5HrNNvr8QXCQv0khDdaYmZSELbtFQtE04WGTWmackNcLpld5mETVyCM0BjOgqMJYQNhtywxfYcodEY5xxHCuGgA3S1t94MZub+DRodXCfB0yUV85Wbb0sltkMTJufMwYmLEGxSLRukxAOcNsXdjlyro96csmYrIiV6R7+REnz8OcR7sKlI4tvKA1mbvWmjbDBd1MZ8Jc0Lwf+b0H/rH69wEQIcB5HRHHJIChoAk0t2azSjXagk1+4AebONZTCKvTHxs/D2wUBIzoxyjmh5S0aso/cKw8qpKcl/A2mZiIvW3KMlJAM5U+RQKMrr c1ko diff --git a/elchos/root-image/krebs/etc/vsftpd.conf b/elchos/root-image/krebs/etc/vsftpd.conf new file mode 100644 index 00000000..68e66fa1 --- /dev/null +++ b/elchos/root-image/krebs/etc/vsftpd.conf @@ -0,0 +1,12 @@ +anonymous_enable=YES +dirmessage_enable=YES +xferlog_enable=YES +connect_from_port_20=YES +ftpd_banner=Welcome to the Elch share, use dc++ if you can. This Instance has 10 slots +listen=YES +no_anon_password=YES +anon_root=/media +max_per_ip=2 +max_clients=10 +local_max_rate=1000000 +seccomp_sandbox=NO 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" >