Skip to content

Instantly share code, notes, and snippets.

@vitouXY
Last active March 8, 2021 04:34
Show Gist options
  • Save vitouXY/97d575797e21d08137df2b3038c8482d to your computer and use it in GitHub Desktop.
Save vitouXY/97d575797e21d08137df2b3038c8482d to your computer and use it in GitHub Desktop.
! Raspberry Pi Zero W | LfS
#!/bin/sh

type wget || exit 1
type grep || exit 1
type sed || exit 1
type cut || exit 1
type touch || exit 1

#REPO="<User>/<Repo>"
REPO='Hexxeh/rpi-firmware'

gMD(){
URL1="${REPO:?}"
while :; do
wget -qO - "https://github.com/${URL1}" | \
grep -E '.*/'"${URL1}"'/(tree|blob)' | \
sed -E 's#.*href="/'"${URL1}"'(/(blob|tree)/master/.*)"(>| [a-zA-Z]).*#\1#g' | \
cut -d'"' -f1 | \
grep -E '^/' && break
done
}
gSD(){
URL1="${REPO:?}" ; URL2="${1:?}"
URL3="$(echo "${URL2:?}" | sed -E 's|^/tree||g')"
while :; do
wget -qO - "https://github.com/${URL1}${URL2}" | \
grep -E '.*/'"${URL1}"'/(tree|blob)' | \
sed -E 's#.*href="/'"${URL1}"'(/(blob|tree)'"${URL3}"'.*)"(>| [a-zA-Z]).*#\1#g' | \
cut -d'"' -f1 | \
grep -E '^/' && break
done
}
SUBD(){
for ITEM in $(gSD "${1:?}")
do
 # Omit Dir
 echo "${ITEM}" | grep -qoE '^/tree/master/modules/([0-9])+.([0-9])+.([0-9])+-v' && continue
 #
 echo "${ITEM}" | grep -qoE '^/tree/' && SUBD "${ITEM}"
 echo "${ITEM}" | grep -qoE '^/blob/' && { echo "${ITEM}" >> "${FILE:?}" ; }
done
}
MAIND(){
echo '-- ['"${REPO}"'] Getting names...'
[ -f "${FILE:?}" ] && rm -f "${FILE:?}"
touch "${FILE:?}"
echo '!! Status - Exec: $ tail -f '"${FILE:?} "
for ITEM in $(gMD)
do
 # Omit Dir
 echo "${ITEM}" | grep -qoE '^/tree/master/vc' && continue
 # Omit File
 echo "${ITEM}" | grep -qoE '^/blob/master/(kernel|Module)(7(|l)|8)\.(img|symvers)' && continue
 echo "${ITEM}" | grep -qoE '^/blob/master/uname_string(7(|l)|8)$' && continue
 echo "${ITEM}" | grep -qoE '^/blob/master/(fixup|start)(4(|cd|db|x))\.(dat|elf)' && continue
 echo "${ITEM}" | grep -qoE '^/blob/master/bcm.*\.dtb' && { echo "${ITEM}" | grep -qo 'zero-w' || continue; }
 #
 echo "${ITEM}" | grep -qoE '^/tree/' && SUBD "${ITEM}"
 echo "${ITEM}" | grep -qoE '^/blob/' && { echo "${ITEM}" >> "${FILE:?}" ; }
done
}
DL(){
[ -s "${FILE:?}" ] || return 0
echo '-- ['"${REPO}"'] Downloading...'
while IFS= read -r ITEM
do
 mkdir -p "${DIR:?}${ITEM%/*}"
 URL="$(echo "${ITEM}" |  sed -E 's|^/blob/master/|https://github.com/'"${REPO:?}"'/raw/master/|g')"
 while :; do
  echo "wget ${URL:?} -P ${DIR:?}${ITEM%/*}/" && break
 done
done < "${FILE:?}"
}
FILE="${REPO##*/}.list"
DIR="${REPO##*/}"

#              Main
# Get name
MAIND
# Fix Kernel Ver.
[ -r "${FILE:?}" ] && sed -i 's|%2B|+|g' "${FILE:?}"
# Download
[ -r "${FILE:?}" ] && DL

echo '-- Done!'
exit 0

#!/bin/rm -rf

Raspberry Pi Zero W - LfS

arm-linux-musleabihf | ARMv6 | BCM2835

           .~~.   .~~.
          '. \ ' ' / .'
           .~ .~~~..~.
          : .~.'~'.~. :
         ~ (    _(   ) ~
        ( : '~'( '-~' : )
         ~ .~ (//\) ~. ~
          (  : V_/_:  )
           '~ .~~~. ~'
               '~'

     * Raspberry Pi Zero W Rev 1.1
     * 5.4.51+ armv6l GNU/Linux

Kernel

bc bison flex make openssl ncurses

Compilar Codigo Fuente (#1)

  • Descargar:
#wget 'https://github.com/raspberrypi/linux/archive/rpi-5.4.y.tar.gz'
git clone --depth=1 --branch rpi-5.4.y https://github.com/raspberrypi/linux
cd linux/
  • Verificar:
#make clean
make mrproper
#make headers_check
  • Cargar Configuración:
  1. Anterior/Actual:
modprobe configs && zcat /proc/config.gz > .config
cp /boot/Module.symvers .
#ln -sv /full/path/to/dir/linux /lib/modules/5.4.51+/build
make oldconfig
  1. Nueva (Predeterminada):
export KERNEL=kernel
make bcmrpi_defconfig

#sed -i -e 's|CONFIG_LOCALVERSION=".*"|CONFIG_LOCALVERSION="-RPi0W"|g' .config
#sh scripts/config --file .config --set-str LOCALVERSION "-RPi0W"
sed -i 's/EXTRAVERSION =.*/EXTRAVERSION = +/' Makefile
  • Realizar Cambios:
#make nconfig
make menuconfig
  • Cambiar Logo Linux (RaspberryPi):

imagemagick perl netpbm

#convert mylogo.png -scale \!80x80 /tmp mylogo.png
pngtopnm /tmp/mylogo.png | ppmquant 224 | pnmnoraw >drivers/video/logo/logo_linux_clut224.ppm
  • Compilar:
  1. Modulo Específico:
#sh scripts/config --module CONFIG_F2FS_FS
make prepare modules_prepare
#make scripts
#make SUBDIRS=scripts/mod
#make SUBDIRS=<path/to/module>
#make -C . M=</path/to/custom/module>
make -C . M=fs/f2fs
#make modules
  1. Kernel (zImage), Modulos y DeviceTreeBlob (dtbs):
#make -j1 headers_install INSTALL_HDR_PATH=/usr
#env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-musleabihf- \
make -j3 zImage modules dtbs
  • Instalar:
mkdir -p ROOT_FS/boot/overlays

make -j1 modules_install INSTALL_MOD_PATH=ROOT_FS

cp arch/arm/boot/dts/*.dtb ROOT_FS/boot/
cp arch/arm/boot/dts/overlays/*.dtb* ROOT_FS/boot/overlays/
cp arch/arm/boot/dts/overlays/README ROOT_FS/boot/overlays/

cp arch/arm/boot/zImage ROOT_FS/boot/kernel.img

cp .config  ROOT_FS/boot/config-5.4.51
cp Module.symvers ROOT_FS/boot/Module.symvers

CPIO Initrd (config.txt:: initramfs rootfs.gz followkernel) (cmdline.txt:: root=/dev/ram0)

#sudo sh -c '(cd ROOT_FS/ && find | cpio -o -H newc) | gzip -2 > /tmp/rootfs.gz' # -2 || -9`
#sudo sh -c 'zcat /tmp/rootfs.gz | (cd ROOT_FS/ && sudo cpio -i -H newc -d)'

Pre-Compilado (#2)

  • Descargar:
#wget 'https://github.com/raspberrypi/firmware/tarball/master' -O raspberrypi-firmware.tar.gz
wget 'https://github.com/Hexxeh/rpi-firmware/tarball/master' -O Hexxeh-rpi-firmware.tar.gz
  • Extraer:
# vc/hardfp/  modules/.*\..*\..../
tar tf pi_linux.tar.gz | grep -E 'overlays/|Module\.symvers$|bcm2708-rpi-zero-w\.dtb$|bootcode\.bin$|kernel\.img$|(start|fixup)(|_(cd|x|db))\.(elf|dat)$|uname_string$|git_hash$|modules/[0-9]+\.[0-9]+\.[0-9]+./' | grep -vE '/$' > Hexxeh-rpi-firmware.tar.gz.list

tar xf Hexxeh-rpi-firmware.tar.gz -T Hexxeh-rpi-firmware.tar.gz.list
#for M in $(lsmod  |cut -d ' ' -f 1);do modinfo ${M} |grep -E 'filename|depend';done > /tmp/rpi0w_modules_usedonly.txt
  • Instalar:
mkdir -p ROOT_FS/lib/modules
rsync -ax -h --progress --delete Hexxeh-rpi-firmware/modules/ ROOT_FS/lib/modules/

#mkdir -p ROOT_FS/opt/vc
#rsync -ax -h --progress --delete Hexxeh-rpi-firmware/vc/hardfp/opt/vc/ ROOT_FS/opt/vc/

mkdir -p ROOT_FS/boot
rsync -rlDx -h --progress --delete --exclude=modules/ --exclude=vc/ Hexxeh-rpi-firmware/ ROOT_FS/boot/

micro ROOT_FS/boot/config.txt
# https://github.com/raspberrypi/documentation/tree/master/configuration
# https://github.com/raspberrypi/documentation/blob/master/configuration/config-txt/overclocking.md
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
# http://elinux.org/RPi_config.txt

#[pi0w]
# ${os_prefix}${overlay_prefix}README
#os_prefix=
##os_prefix=boot_rpi0w-v1/

#initramfs rootfs.gz,modules.gz followkernel
kernel=kernel.img
cmdline=cmdline.txt

# _x(CAM drivers&codec) _db(debug) _cd
start_file=start_cd.elf
fixup_file=fixup_cd.dat

device_tree=bcm2708-rpi-zero-w.dtb
dtparam=random=on
dtparam=watchdog=on
#dtparam=i2c_arm=on
# ~$ /sbin/modprobe i2c-dev
# ~$ /sbin/modprobe i2c_bcm2708
# ~$ /sbin/modprobe i2c-bcm2835
#dtparam=spi=on
# ~$ /sbin/modprobe spidev

overlay_prefix=overlays/
#dtoverlay=dwc2
#dtoverlay=dwc-otg
dtoverlay=disable-bt
#dtoverlay=sh1106-spi

# ip - Input
# op - Output
# a0-a5 - Alt0-Alt5
# dh - Driving high (for outputs)
# dl - Driving low (for outputs)
# pu - Pull up
# pd - Pull down
# pn/np - No pull
#gpio=6,19,5,26,13,21,20,16=pu

disable_splash=0

# 16:Require _cd ; 128:Require _x
gpu_mem=16

# MHz
# /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq (/1000)
#arm_freq=1000
#arm_freq_min=700
# gpu_freq
#gpu_freq_min=250
#core_freq=400
#core_freq_min=250
#h264_freq=300
#h264_freq_min=250
#isp_freq=300
#isp_freq_min=250
#v3d_freq=300
#v3d_freq_min=250
#
#sdram_freq=450
#sdram_freq_min=400
# /sys/class/thermal/thermal_zone0/temp (/1000)
#temp_limit=85
#force_turbo=0
#initial_turbo=0
#overvoltage_min=0
# 6=1.35V ; 0=1.2V ; (0.025V)
#over_voltage=6
# over_voltage_sdram
#over_voltage_sdram_c=0
#over_voltage_sdram_i=0
#over_voltage_sdram_p=0

#include config-extra.txt
micro ROOT_FS/boot/cmdline.txt
dwc_otg.lpm_enable=0 smsc95xx.turbo_mode=N console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes init=/sbin/init rootwait quiet

# console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 ... modules-load=dwc2 ,g_ether|,g_serial



Firmware - Wireless & Bluetooth

Pre-Compilado

  • Descargar:
wget 'https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43430-sdio.bin'
wget 'https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43430-sdio.txt'
wget 'https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/brcmfmac43430-sdio.raspberrypi-rpi.txt'

wget 'https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm/BCM43430A1.hcd'

wget 'https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git/plain/regulatory.db'
wget 'https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git/plain/regulatory.db.p7s'
  • Instalar:
mkdir -p ROOT_FS/lib/firmware/brcm

cp brcmfmac43430-sdio.* BCM43430A1.hcd ROOT_FS/lib/firmware/brcm/
ln -s brcmfmac43430-sdio.raspberrypi-rpi.txt ROOT_FS/lib/firmware/brcm/brcmfmac43430-sdio.raspberrypi,model-zero-w.txt

cp regulatory.d* ROOT_FS/lib/firmware/


Busybox

https://busybox.net/downloads/busybox-1.32.0.tar.bz2

#make defconfig
#make LDFLAGS='-static --static'
#make LDFLAGS='-static --static' CONFIG_PREFIX=ROOT_FS install

Pre-Compilado

  • Descargar:
wget 'http://raspbian.raspberrypi.org/raspbian/pool/main/b/busybox/busybox-static_1.30.1-6_armhf.deb'
  • Extraer:
ar x busybox-static_1.30.1-6_armhf.deb
tar xf data.tar.gz
  • Instalar:
mkdir -p ROOT_FS/bin
mv bin/busybox ROOT_FS/bin
micro ROOT_FS/BusyBox_Linker.sh
#!/bin/sh
XD=$(pwd)
for APPLET in $(./bin/busybox --list-full | sort -u)
do APPLET="./${APPLET}" ;cd "${XD}"
 mkdir -p "${APPLET%/*}" 2>&-
 cd "${APPLET%/*}"
 xPath="bin/"
 [ -x busybox ] && xPath=''
 while :; do
 [ -x bin/busybox ] && break
 [ -x busybox ] && break
 xPath="../${xPath}" && cd ../ ;done
 [ -x busybox ] || cd "${APPLET%/*}"
 ln -sfv ${xPath}busybox ${APPLET##*/}
done
cd "${XD}"
ls -l linuxrc sbin/init
#find . -type l -exec unlink {} \;


Directorios & Archivos Base

cd ROOT_FS/

mkdir -p mnt home bin root proc sbin tmp sys dev srv opt boot
mkdir -p etc/init.d
mkdir -p lib/modules lib/firmware/brcm opt/vc srv/ftp var/www
mkdir -p usr/local/src usr/local/bin usr/local/misc usr/local/sbin usr/bin usr/sbin usr/src
mkdir -p var/cache var/spool var/opt var/lib/misc var/lib/locate var/run var/log var/local var/lock var/mail
mkdir -p usr/include usr/lib usr/libexec usr/local/libexec usr/local/include usr/local/lib/modules
mkdir -p usr/share/udhcpc/default.script.d

mkdir -p usr/share/terminfo usr/share/zoneinfo usr/share/info usr/share/doc usr/share/locale usr/share/misc
mkdir -p usr/share/man/man2 usr/share/man/man5 usr/share/man/man3 usr/share/man/man6 usr/share/man/man8 usr/share/man/man1 usr/share/man/man7 usr/share/man/man4
ln -sf share/doc usr/doc
ln -sf share/info usr/info
ln -sf share/man usr/man
mkdir -p usr/local/share/terminfo usr/local/share/zoneinfo usr/local/share/info usr/local/share/doc usr/local/share/locale usr/local/share/misc
mkdir -p usr/local/share/man/man2 usr/local/share/man/man5 usr/local/share/man/man3 usr/local/share/man/man6 usr/local/share/man/man8 usr/local/share/man/man1 usr/local/share/man/man7 usr/local/share/man/man4
ln -sf share/doc usr/local/doc
ln -sf share/info usr/local/info
ln -sf share/man usr/local/man

ln -sf ../srv/ftp home/ftp
ln -sf ../proc/mounts etc/mtab
ln -sf ../tmp/resolv.conf etc/resolv.conf
mknod dev/console c 5 1
mknod -m 666 dev/null c 1 3
mknod -m 666 dev/tty0 c 4 0
mknod -m 666 dev/tty1 c 4 1
mknod -m 666 dev/tty2 c 4 2
mknod -m 666 dev/tty3 c 4 3
mknod -m 666 dev/ttyS0 c 4 64
mknod -m 666 dev/ttyAMA0 c 204 64
mknod -m 666 dev/urandom c 1 9
mknod -m 666 dev/ptmx c 5 2
#mknod -m 666 dev/sda b 8 0
#mknod -m 666 dev/sda1 b 8 1
micro etc/inittab
::sysinit:/etc/init.d/rcS

::askfirst:-/bin/sh
#::respawn:-/bin/login -f root
# /sbin/alogin.sh| #!/bin/sh
# /sbin/alogin.sh| exec /bin/login -f root
#tty1::respawn:/sbin/getty -L -nl /sbin/alogin.sh 38400 tty1
#tty2::respawn:/sbin/getty -L tty2 115200 vt100
#tty3::respawn:/sbin/getty 38400 tty3
#tty4::askfirst:/sbin/getty 38400 tty4
#tty5::askfirst:/sbin/getty 38400 tty5
#tty6::askfirst:/sbin/getty 38400 tty6
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100

::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
micro etc/init.d/rcS
#!/bin/sh

umask  022

#clear
/bin/echo 'Starting...' | /usr/bin/logger -t rcS -p kern.info

/bin/mkdir -p /proc /sys /dev
/bin/mountpoint -q /proc || /bin/mount -t proc -o nosuid,nodev,noexec proc /proc
/bin/mountpoint -q /sys  || /bin/mount -t sysfs -o nosuid,nodev,noexec sys /sys
/bin/mountpoint -q /dev  || /bin/mount -t devtmpfs -o nosuid,mode=0755 dev /dev

/bin/ln -sf /proc/self/fd /dev/fd
/bin/ln -sf /proc/self/fd/0 /dev/stdin
/bin/ln -sf /proc/self/fd/1 /dev/stdout
/bin/ln -sf /proc/self/fd/2 /dev/stderr

/bin/mkdir -p /dev/pts /dev/shm
/bin/mountpoint -q /dev/pts || /bin/mount -t devpts -o nosuid,noexec,gid=5,mode=620 devpts /dev/pts
/bin/mountpoint -q /dev/shm || /bin/mount -t tmpfs -o nosuid,nodev,noexec,mode=1777 shm /dev/shm

#/bin/mount -o remount,ro /
/bin/fsck -ATp
/bin/mount -a -O no_netdev
#
/bin/mount -o remount,rw /
##/bin/mount -o remount,rw -o nodiscard,errors=remount-ro /
##/bin/mount -o remount,rw -o defaults,noatime,discard,errors=remount-ro /
#/bin/mount -o remount,ro /
#/bin/mount -t tmpfs -o nosuid,nodev,noexec tmpfs /var

/bin/rm -rf /var/run/*
/bin/touch /var/run/utmp
/bin/chgrp 43 /var/run/utmp
[ -f /var/log/lastlog ] && /bin/chgrp 43 /var/log/lastlog

/bin/hostname -F /etc/hostname

/sbin/syslogd
/sbin/klogd &

/sbin/sysctl -p /etc/sysctl.conf

#/bin/echo /sbin/mdev >/proc/sys/kernel/hotplug
##/sbin/sysctl -w kernel.hotplug=/sbin/mdev
/sbin/mdev -s
/usr/bin/find /sys/ -name modalias -print0 | /usr/bin/xargs -0 /usr/bin/sort -u | /usr/bin/tr '\n' '\0' | /usr/bin/xargs -0 /sbin/modprobe -bq #-abq

/bin/mkdir -p /var/lib
[ -f /var/lib/random-seed ] && /bin/cat /var/lib/random-seed >/dev/urandom
/bin/dd if=/dev/urandom of=/var/lib/random-seed count=1 bs="$(/bin/cat /proc/sys/kernel/random/poolsize)" 2>/dev/null
/bin/chmod 600 /var/lib/random-seed

#/sbin/modprobe zram #num_devices=$(/usr/bin/nproc --all)
#while [ ! -e /dev/zram0 ]; do /bin/sleep 0.1; done
## $(( $(/bin/grep MemTotal /proc/meminfo | /usr/bin/awk '{print $2}') / $(/usr/bin/nproc --all)) ))K # zram0.. core-1
#/bin/grep MemFree /proc/meminfo | /usr/bin/awk '{print $2/4 "K"}' > /sys/block/zram0/disksize
#/sbin/mkswap /dev/zram0 >/dev/null 2>&1
##/sbin/swapon -p 5 /dev/zram0
#/sbin/swapon /dev/zram0

/sbin/watchdog -t PERIOD /dev/watchdog

# Setting CPU frequency governor to ondemand (default is performance)
#/bin/echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

/sbin/ifconfig lo 127.0.0.1 up
/sbin/route add 127.0.0.1 lo &

for i in /etc/init.d/S??* ;do
 [ ! -f "$i" ] && continue
 case "$i" in
  *.sh) (trap - INT QUIT TSTP ;set start; . $i) ;;
  *) $i start ;;
 esac
done

/bin/echo "$(/usr/bin/cut -d' ' -f1 /proc/uptime) sec" > /tmp/rcS.log
/bin/echo 'Starting... done!' | /usr/bin/logger -t rcS -p kern.info
micro etc/init.d/rcK
#!/bin/sh

/bin/echo 'Stopping...' | /usr/bin/logger -t rcK -p kern.info
for i in $(/bin/ls -r /etc/init.d/S??*) ;do
 [ ! -f "$i" ] && continue
 case "$i" in
  *.sh) (trap - INT QUIT TSTP ;set stop; . $i);;
  *) $i stop ;;
 esac
done
/bin/echo 'Stopping... done!' | /usr/bin/logger -t rcK -p kern.info
micro etc/init.d/S50telnetd
#!/bin/busybox ash

case "${1}" in
 start) (/usr/sbin/telnetd -p9992 -|/bin/sh) & ;;
 stop) /usr/bin/pkill telnetd ;;
 restart) $(0) stop ;/bin/sleep 1s; ${0} start ;;
 status) /bin/pidof telnetd ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac

exit ${?}
micro etc/mdev.conf
null            root:root 666 @/bin/chmod 666 $MDEV
zero            root:root 666
full            root:root 666
random          root:root 444
urandom         root:root 444
hwrandom        root:root 444
grsec           root:root 660
kmem            root:root 640
mem             root:root 640
port            root:root 640
console         root:tty 600 @/bin/chmod 600 $MDEV
ptmx            root:tty 666
pty.*           root:tty 660
tty             root:tty 666
tty[0-9]*       root:tty 660
vcsa*[0-9]*     root:tty 660
ttyS[0-9]*      root:root 660
ttyUSB[0-9]*    root:root 660
ram([0-9]*)	root:disk 660 >rd/%1
loop([0-9]+)	root:disk 660 >loop/%1
sd[a-z].*	root:disk 660 */lib/mdev/usbdisk_link
hd[a-z][0-9]*	root:disk 660 */lib/mdev/ide_links
vd[a-z][0-9]*   root:disk 660
md[0-9]*	root:disk 660
sr[0-9]*	root:cdrom 660 @/bin/ln -sf $MDEV cdrom
SUBSYSTEM=net;.* root:root 600 @/sbin/nameif -s
tun[0-9]*	root:root 600 =net/
tap[0-9]*	root:root 600 =net/
usb/lp[0-9]*    root:lp 660
snd/pcm.*       root:audio 660
snd/control.*   root:audio 660
snd/midi.*      root:audio 660
snd/seq         root:audio 660
snd/timer       root:audio 660
input/event[0-9]+       root:root 640
input/mice              root:root 640
input/mouse[0-9]        root:root 640
input/ts[0-9]           root:root 600
$MODALIAS=.*    root:root 660 @/sbin/modprobe "$MODALIAS"
micro etc/sysctl.conf
# Reboot the system after 10 seconds if a panic occurs
kernel.panic = 30
# Disable dmesg command for unprivileged users
kernel.dmesg_restrict = 1
# Hide kernel pointers
kernel.kptr_restrict = 1
# Enable ASLR to mitigate buffer overflows
kernel.randomize_va_space = 2
# Protect links
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
# Keep 8MB of memory free
vm.min_free_kbytes = 8192
micro etc/fstab
#<device>	<mount-point>	<type>	<options>	<dump>	<fsck_order>
tmpfs	/tmp	tmpfs	nosuid,nodev,noexec	0	0
#/swapfile	swap	swap	pri=1	0	0

#PARTUUID=xxxxxxxx-01	/boot	vfat	defaults	0	2
#PARTUUID=xxxxxxxx-xx	/	ext4	defaults,noatime	0	1
#PARTUUID=xxxxxxxx-xx	/	f2fs	defaults,noatime,discard	0	1
micro etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
kmem:x:9:
wheel:x:10:root
cdrom:x:11:
usb:x:14:
proxy:x:15:
dialout:x:18:
floppy:x:19:
video:x:28:
audio:x:29:
tape:x:32:
www-data:x:33:
ftp:x:37:
operator:x:38:
utmp:x:43:
plugdev:x:46:
staff:x:50:
lock:x:54:
netdev:x:82:
users:x:100:
nogroup:x:65534:
p0:x:1001:p0
micro etc/passwd
root:x:0:0:root:/root:/bin/sh
daemon:x:1:1:daemon:/usr/sbin:/bin/false
bin:x:2:2:bin:/bin:/bin/false
sys:x:3:3:sys:/dev:/bin/false
sync:x:4:100:sync:/bin:/bin/sync
mail:x:8:8:mail:/var/spool/mail:/bin/false
proxy:x:15:15:proxy:/tmp/proxy:/dev/null
www-data:x:33:33:www-data:/var/www:/bin/false
ftp:x:37:37:ftp:/srv/ftp:/bin/false
operator:x:38:38:operator:/var:/bin/false
nobody:x:65534:65534:nobody:/home:/bin/false
p0:x:1001:1001:RPi0W User:/home/p0:/bin/sh
micro etc/shadow
root:12lYmRWCpMh8k:0:0:99999:7:::
daemon:*:::::::
bin:*:::::::
sys:*:::::::
sync:*:::::::
mail:*:::::::
proxy:*:::::::
www-data:*:::::::
ftp:*:::::::
operator:*:::::::
nobody:*:::::::
p0:8mtRGI0bdpmA2:0:0:99999:7:::
#echo 'toor' | openssl passwd -1 -stdin

#echo 'p0' | openssl passwd -1 -salt yoursalt -stdin`

#perl -e 'printf("%s\n", crypt("toor","12"));'
busybox addgroup -g ${GID} ${GROUP} 
busybox adduser -h /home/${USER} -G ${GROUP} -u ${UID} -s /bin/sh ${USER}
micro etc/ld.so.conf
/lib
/usr/lib
/usr/local/lib
micro etc/shells
/bin/sh
/bin/false
micro etc/mactab
wlan0 b8:27:eb:c6:ed:59
micro etc/hosts
127.0.0.1 rpi0w localhost rpi0w.local

::1        ip6-localhost    ip6-loopback
fe00::0    ip6-localnet
ff00::0    ip6-mcastprefix
ff02::1    ip6-allnodes
ff02::2    ip6-allrouters
micro etc/hostname
rpi0w
micro etc/issue
RPi0W Kernel \r on an \m
micro etc/issue.net
RPi0W Kernel \r on an \m
micro etc/motd
 ,_             _, 
( '-           -' ) 
/ \    RPi0W    / \ 
V_/_           _\_V 
micro etc/os-release
NAME=RPi0W
VERSION="5.4.51"
ID=rpi0w
VERSION_ID=5.4.51
PRETTY_NAME="RPi0W 5.4.51"
micro etc/profile
umask 022

export PATH=/usr/local/bin:/bin:/usr/bin
[ $(id -u) -eq 0 ] && {
PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
unset HISTFILE; }

export USER=$(id -un)
export LOGNAME=${USER}
export HOSTNAME=$(/bin/hostname)
export HISTSIZE=1000
export HISTFILESIZE=1000

export PAGER='less -EM'
export PAGER='less -r'
export MANPAGER='less -isR'
export EDITOR='/bin/vi'

export LANG='C.UTF-8'
export TERM='xterm'

export PS1='\u@\h:\w \\$ '
export PS2='> '
export PS4='+ '
export TZ='CLT'

alias df='df -h'
alias du='du -h'
alias ls='ls --color=always -p'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'

[ -x /usr/local/bin/wget ] && alias wgets='/usr/local/bin/wget --no-check-certificate'
micro etc/protocols
# Internet (IP) protocols
#
# Updated from http://www.iana.org/assignments/protocol-numbers and other
# sources.

ip	0	IP		# internet protocol, pseudo protocol number
hopopt	0	HOPOPT		# IPv6 Hop-by-Hop Option [RFC1883]
icmp	1	ICMP		# internet control message protocol
igmp	2	IGMP		# Internet Group Management
ggp	3	GGP		# gateway-gateway protocol
ipencap	4	IP-ENCAP	# IP encapsulated in IP (officially ``IP'')
st	5	ST		# ST datagram mode
tcp	6	TCP		# transmission control protocol
egp	8	EGP		# exterior gateway protocol
igp	9	IGP		# any private interior gateway (Cisco)
pup	12	PUP		# PARC universal packet protocol
udp	17	UDP		# user datagram protocol
hmp	20	HMP		# host monitoring protocol
xns-idp	22	XNS-IDP		# Xerox NS IDP
rdp	27	RDP		# "reliable datagram" protocol
iso-tp4	29	ISO-TP4		# ISO Transport Protocol class 4 [RFC905]
dccp	33	DCCP		# Datagram Congestion Control Prot. [RFC4340]
xtp	36	XTP		# Xpress Transfer Protocol
ddp	37	DDP		# Datagram Delivery Protocol
idpr-cmtp 38	IDPR-CMTP	# IDPR Control Message Transport
ipv6	41	IPv6		# Internet Protocol, version 6
ipv6-route 43	IPv6-Route	# Routing Header for IPv6
ipv6-frag 44	IPv6-Frag	# Fragment Header for IPv6
idrp	45	IDRP		# Inter-Domain Routing Protocol
rsvp	46	RSVP		# Reservation Protocol
gre	47	GRE		# General Routing Encapsulation
esp	50	IPSEC-ESP	# Encap Security Payload [RFC2406]
ah	51	IPSEC-AH	# Authentication Header [RFC2402]
skip	57	SKIP		# SKIP
ipv6-icmp 58	IPv6-ICMP	# ICMP for IPv6
ipv6-nonxt 59	IPv6-NoNxt	# No Next Header for IPv6
ipv6-opts 60	IPv6-Opts	# Destination Options for IPv6
rspf	73	RSPF CPHB	# Radio Shortest Path First (officially CPHB)
vmtp	81	VMTP		# Versatile Message Transport
eigrp	88	EIGRP		# Enhanced Interior Routing Protocol (Cisco)
ospf	89	OSPFIGP		# Open Shortest Path First IGP
ax.25	93	AX.25		# AX.25 frames
ipip	94	IPIP		# IP-within-IP Encapsulation Protocol
etherip	97	ETHERIP		# Ethernet-within-IP Encapsulation [RFC3378]
encap	98	ENCAP		# Yet Another IP encapsulation [RFC1241]
#	99			# any private encryption scheme
pim	103	PIM		# Protocol Independent Multicast
ipcomp	108	IPCOMP		# IP Payload Compression Protocol
vrrp	112	VRRP		# Virtual Router Redundancy Protocol [RFC5798]
l2tp	115	L2TP		# Layer Two Tunneling Protocol [RFC2661]
isis	124	ISIS		# IS-IS over IPv4
sctp	132	SCTP		# Stream Control Transmission Protocol
fc	133	FC		# Fibre Channel
mobility-header 135 Mobility-Header # Mobility Support for IPv6 [RFC3775]
udplite	136	UDPLite		# UDP-Lite [RFC3828]
mpls-in-ip 137	MPLS-in-IP	# MPLS-in-IP [RFC4023]
manet	138			# MANET Protocols [RFC5498]
hip	139	HIP		# Host Identity Protocol
shim6	140	Shim6		# Shim6 Protocol [RFC5533]
wesp	141	WESP		# Wrapped Encapsulating Security Payload
rohc	142	ROHC		# Robust Header Compression
micro etc/services
# /etc/services:
# $Id: services,v 1.1 2004/10/09 02:49:18 andersen Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.

tcpmux		1/tcp				# TCP port service multiplexer
echo		7/tcp
echo		7/udp
discard		9/tcp		sink null
discard		9/udp		sink null
systat		11/tcp		users
daytime		13/tcp
daytime		13/udp
netstat		15/tcp
qotd		17/tcp		quote
msp		18/tcp				# message send protocol
msp		18/udp				# message send protocol
chargen		19/tcp		ttytst source
chargen		19/udp		ttytst source
ftp-data	20/tcp
ftp		21/tcp
fsp		21/udp		fspd
ssh		22/tcp				# SSH Remote Login Protocol
ssh		22/udp				# SSH Remote Login Protocol
telnet		23/tcp
# 24 - private
smtp		25/tcp		mail
# 26 - unassigned
time		37/tcp		timserver
time		37/udp		timserver
rlp		39/udp		resource	# resource location
nameserver	42/tcp		name		# IEN 116
whois		43/tcp		nicname
re-mail-ck	50/tcp				# Remote Mail Checking Protocol
re-mail-ck	50/udp				# Remote Mail Checking Protocol
domain		53/tcp		nameserver	# name-domain server
domain		53/udp		nameserver
mtp		57/tcp				# deprecated
bootps		67/tcp				# BOOTP server
bootps		67/udp
bootpc		68/tcp				# BOOTP client
bootpc		68/udp
tftp		69/udp
gopher		70/tcp				# Internet Gopher
gopher		70/udp
rje		77/tcp		netrjs
finger		79/tcp
www		80/tcp		http		# WorldWideWeb HTTP
www		80/udp				# HyperText Transfer Protocol
link		87/tcp		ttylink
kerberos	88/tcp		kerberos5 krb5	# Kerberos v5
kerberos	88/udp		kerberos5 krb5	# Kerberos v5
supdup		95/tcp
# 100 - reserved
hostnames	101/tcp		hostname	# usually from sri-nic
iso-tsap	102/tcp		tsap		# part of ISODE.
csnet-ns	105/tcp		cso-ns		# also used by CSO name server
csnet-ns	105/udp		cso-ns
# unfortunately the poppassd (Eudora) uses a port which has already
# been assigned to a different service. We list the poppassd as an
# alias here. This should work for programs asking for this service.
# (due to a bug in inetd the 3com-tsmux line is disabled)
#3com-tsmux	106/tcp		poppassd
#3com-tsmux	106/udp		poppassd
rtelnet		107/tcp				# Remote Telnet
rtelnet		107/udp
pop-2		109/tcp		postoffice	# POP version 2
pop-2		109/udp
pop-3		110/tcp				# POP version 3
pop-3		110/udp
sunrpc		111/tcp		portmapper	# RPC 4.0 portmapper TCP
sunrpc		111/udp		portmapper	# RPC 4.0 portmapper UDP
auth		113/tcp		authentication tap ident
sftp		115/tcp
uucp-path	117/tcp
nntp		119/tcp		readnews untp	# USENET News Transfer Protocol
ntp		123/tcp
ntp		123/udp				# Network Time Protocol
netbios-ns	137/tcp				# NETBIOS Name Service
netbios-ns	137/udp
netbios-dgm	138/tcp				# NETBIOS Datagram Service
netbios-dgm	138/udp
netbios-ssn	139/tcp				# NETBIOS session service
netbios-ssn	139/udp
imap2		143/tcp				# Interim Mail Access Proto v2
imap2		143/udp
snmp		161/udp				# Simple Net Mgmt Proto
snmp-trap	162/udp		snmptrap	# Traps for SNMP
cmip-man	163/tcp				# ISO mgmt over IP (CMOT)
cmip-man	163/udp
cmip-agent	164/tcp
cmip-agent	164/udp
xdmcp		177/tcp				# X Display Mgr. Control Proto
xdmcp		177/udp
nextstep	178/tcp		NeXTStep NextStep	# NeXTStep window
nextstep	178/udp		NeXTStep NextStep	# server
bgp		179/tcp				# Border Gateway Proto.
bgp		179/udp
prospero	191/tcp				# Cliff Neuman's Prospero
prospero	191/udp
irc		194/tcp				# Internet Relay Chat
irc		194/udp
smux		199/tcp				# SNMP Unix Multiplexer
smux		199/udp
at-rtmp		201/tcp				# AppleTalk routing
at-rtmp		201/udp
at-nbp		202/tcp				# AppleTalk name binding
at-nbp		202/udp
at-echo		204/tcp				# AppleTalk echo
at-echo		204/udp
at-zis		206/tcp				# AppleTalk zone information
at-zis		206/udp
qmtp		209/tcp				# The Quick Mail Transfer Protocol
qmtp		209/udp				# The Quick Mail Transfer Protocol
z3950		210/tcp		wais		# NISO Z39.50 database
z3950		210/udp		wais
ipx		213/tcp				# IPX
ipx		213/udp
imap3		220/tcp				# Interactive Mail Access
imap3		220/udp				# Protocol v3
ulistserv	372/tcp				# UNIX Listserv
ulistserv	372/udp
https		443/tcp				# MCom
https		443/udp				# MCom
snpp		444/tcp				# Simple Network Paging Protocol
snpp		444/udp				# Simple Network Paging Protocol
saft		487/tcp				# Simple Asynchronous File Transfer
saft		487/udp				# Simple Asynchronous File Transfer
npmp-local	610/tcp		dqs313_qmaster	# npmp-local / DQS
npmp-local	610/udp		dqs313_qmaster	# npmp-local / DQS
npmp-gui	611/tcp		dqs313_execd	# npmp-gui / DQS
npmp-gui	611/udp		dqs313_execd	# npmp-gui / DQS
hmmp-ind	612/tcp		dqs313_intercell# HMMP Indication / DQS
hmmp-ind	612/udp		dqs313_intercell# HMMP Indication / DQS
#
# UNIX specific services
#
exec		512/tcp
biff		512/udp		comsat
login		513/tcp
who		513/udp		whod
shell		514/tcp		cmd		# no passwords used
syslog		514/udp
printer		515/tcp		spooler		# line printer spooler
talk		517/udp
ntalk		518/udp
route		520/udp		router routed	# RIP
timed		525/udp		timeserver
tempo		526/tcp		newdate
courier		530/tcp		rpc
conference	531/tcp		chat
netnews		532/tcp		readnews
netwall		533/udp				# -for emergency broadcasts
uucp		540/tcp		uucpd		# uucp daemon
afpovertcp	548/tcp				# AFP over TCP
afpovertcp	548/udp				# AFP over TCP
remotefs	556/tcp		rfs_server rfs	# Brunhoff remote filesystem
klogin		543/tcp				# Kerberized `rlogin' (v5)
kshell		544/tcp		krcmd		# Kerberized `rsh' (v5)
kerberos-adm	749/tcp				# Kerberos `kadmin' (v5)
#
webster		765/tcp				# Network dictionary
webster		765/udp
#
# From ``Assigned Numbers'':
#
#> The Registered Ports are not controlled by the IANA and on most systems
#> can be used by ordinary user processes or programs executed by ordinary
#> users.
#
#> Ports are used in the TCP [45,106] to name the ends of logical
#> connections which carry long term conversations.  For the purpose of
#> providing services to unknown callers, a service contact port is
#> defined.  This list specifies the port used by the server process as its
#> contact port.  While the IANA can not control uses of these ports it
#> does register or list uses of these ports as a convienence to the
#> community.
#
nfsdstatus	1110/tcp
nfsd-keepalive	1110/udp

ingreslock	1524/tcp
ingreslock	1524/udp
prospero-np	1525/tcp			# Prospero non-privileged
prospero-np	1525/udp
datametrics	1645/tcp	old-radius	# datametrics / old radius entry
datametrics	1645/udp	old-radius	# datametrics / old radius entry
sa-msg-port	1646/tcp	old-radacct	# sa-msg-port / old radacct entry
sa-msg-port	1646/udp	old-radacct	# sa-msg-port / old radacct entry
radius		1812/tcp			# Radius
radius		1812/udp			# Radius
radacct		1813/tcp			# Radius Accounting
radacct		1813/udp			# Radius Accounting
nfsd		2049/tcp	nfs
nfsd		2049/udp	nfs
cvspserver	2401/tcp			# CVS client/server operations
cvspserver	2401/udp			# CVS client/server operations
mysql		3306/tcp			# MySQL
mysql		3306/udp			# MySQL
rfe		5002/tcp			# Radio Free Ethernet
rfe		5002/udp			# Actually uses UDP only
cfengine	5308/tcp			# CFengine
cfengine	5308/udp			# CFengine
bbs		7000/tcp			# BBS service
#
#
# Kerberos (Project Athena/MIT) services
# Note that these are for Kerberos v4, and are unofficial.  Sites running
# v4 should uncomment these and comment out the v5 entries above.
#
kerberos4	750/udp		kerberos-iv kdc	# Kerberos (server) udp
kerberos4	750/tcp		kerberos-iv kdc	# Kerberos (server) tcp
kerberos_master	751/udp				# Kerberos authentication
kerberos_master	751/tcp				# Kerberos authentication
passwd_server	752/udp				# Kerberos passwd server
krb_prop	754/tcp				# Kerberos slave propagation
krbupdate	760/tcp		kreg		# Kerberos registration
kpasswd		761/tcp		kpwd		# Kerberos "passwd"
kpop		1109/tcp			# Pop with Kerberos
knetd		2053/tcp			# Kerberos de-multiplexor
zephyr-srv	2102/udp			# Zephyr server
zephyr-clt	2103/udp			# Zephyr serv-hm connection
zephyr-hm	2104/udp			# Zephyr hostmanager
eklogin		2105/tcp			# Kerberos encrypted rlogin
#
# Unofficial but necessary (for NetBSD) services
#
supfilesrv	871/tcp				# SUP server
supfiledbg	1127/tcp			# SUP debugging
#
# Datagram Delivery Protocol services
#
rtmp		1/ddp				# Routing Table Maintenance Protocol
nbp		2/ddp				# Name Binding Protocol
echo		4/ddp				# AppleTalk Echo Protocol
zip		6/ddp				# Zone Information Protocol
#
# Services added for the Debian GNU/Linux distribution
poppassd	106/tcp				# Eudora
poppassd	106/udp				# Eudora
mailq		174/tcp				# Mailer transport queue for Zmailer
mailq		174/tcp				# Mailer transport queue for Zmailer
omirr		808/tcp		omirrd		# online mirror
omirr		808/udp		omirrd		# online mirror
rmtcfg		1236/tcp			# Gracilis Packeten remote config server
xtel		1313/tcp			# french minitel
coda_opcons	1355/udp			# Coda opcons            (Coda fs)
coda_venus	1363/udp			# Coda venus             (Coda fs)
coda_auth	1357/udp			# Coda auth              (Coda fs)
coda_udpsrv	1359/udp			# Coda udpsrv            (Coda fs)
coda_filesrv	1361/udp			# Coda filesrv           (Coda fs)
codacon		1423/tcp	venus.cmu	# Coda Console           (Coda fs)
coda_aux1	1431/tcp			# coda auxiliary service (Coda fs)
coda_aux1	1431/udp			# coda auxiliary service (Coda fs)
coda_aux2	1433/tcp			# coda auxiliary service (Coda fs)
coda_aux2	1433/udp			# coda auxiliary service (Coda fs)
coda_aux3	1435/tcp			# coda auxiliary service (Coda fs)
coda_aux3	1435/udp			# coda auxiliary service (Coda fs)
cfinger		2003/tcp			# GNU Finger
afbackup	2988/tcp			# Afbackup system
afbackup	2988/udp			# Afbackup system
icp		3130/tcp			# Internet Cache Protocol (Squid)
icp		3130/udp			# Internet Cache Protocol (Squid)
postgres	5432/tcp			# POSTGRES
postgres	5432/udp			# POSTGRES
fax		4557/tcp			# FAX transmission service        (old)
hylafax		4559/tcp			# HylaFAX client-server protocol  (new)
noclog		5354/tcp			# noclogd with TCP (nocol)
noclog		5354/udp			# noclogd with UDP (nocol)
hostmon		5355/tcp			# hostmon uses TCP (nocol)
hostmon		5355/udp			# hostmon uses TCP (nocol)
ircd		6667/tcp			# Internet Relay Chat
ircd		6667/udp			# Internet Relay Chat
webcache	8080/tcp			# WWW caching service
webcache	8080/udp			# WWW caching service
tproxy		8081/tcp			# Transparent Proxy
tproxy		8081/udp			# Transparent Proxy
mandelspawn	9359/udp	mandelbrot	# network mandelbrot
amanda		10080/udp			# amanda backup services
amandaidx	10082/tcp			# amanda backup services
amidxtape	10083/tcp			# amanda backup services
isdnlog		20011/tcp			# isdn logging system
isdnlog		20011/udp			# isdn logging system
vboxd		20012/tcp			# voice box system
vboxd		20012/udp			# voice box system
binkp           24554/tcp			# Binkley
binkp           24554/udp			# Binkley
asp		27374/tcp			# Address Search Protocol
asp		27374/udp			# Address Search Protocol
tfido           60177/tcp			# Ifmail
tfido           60177/udp			# Ifmail
fido            60179/tcp			# Ifmail
fido            60179/udp			# Ifmail

# Local services
micro usr/share/udhcpc/default.script
#!/bin/sh

# udhcpc script edited by Tim Riker <Tim@Rikers.org>

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

RESOLV_CONF="/etc/resolv.conf"
[ -e $RESOLV_CONF ] || touch $RESOLV_CONF
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
# Handle stateful DHCPv6 like DHCPv4
[ -n "$ipv6" ] && ip="$ipv6/128"

if [ -z "${IF_WAIT_DELAY}" ]; then
	IF_WAIT_DELAY=10
fi

wait_for_ipv6_default_route() {
	printf "Waiting for IPv6 default route to appear"
	while [ $IF_WAIT_DELAY -gt 0 ]; do
		if [ -z "$(ip -6 route list | grep default)" ]; then
			printf "\n"
			return
		fi
		sleep 1
		printf "."
		: $((IF_WAIT_DELAY -= 1))
	done
	printf " timeout!\n"
}

case "$1" in
	deconfig)
		/sbin/ifconfig $interface up
		/sbin/ifconfig $interface 0.0.0.0

		# drop info from this interface
		# resolv.conf may be a symlink to /tmp/, so take care
		TMPFILE=$(mktemp)
		grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
		cat $TMPFILE > $RESOLV_CONF
		rm -f $TMPFILE

		if [ -x /usr/sbin/avahi-autoipd ]; then
			/usr/sbin/avahi-autoipd -k $interface
		fi
		;;

	leasefail|nak)
		if [ -x /usr/sbin/avahi-autoipd ]; then
			/usr/sbin/avahi-autoipd -wD $interface --no-chroot
		fi
		;;

	renew|bound)
		if [ -x /usr/sbin/avahi-autoipd ]; then
			/usr/sbin/avahi-autoipd -k $interface
		fi
		/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
		if [ -n "$ipv6" ] ; then
			wait_for_ipv6_default_route
		fi

		if [ -n "$router" ] ; then
			echo "deleting routers"
			while route del default gw 0.0.0.0 dev $interface 2> /dev/null; do
				:
			done

			for i in $router ; do
				route add default gw $i dev $interface
			done
		fi

		# drop info from this interface
		# resolv.conf may be a symlink to /tmp/, so take care
		TMPFILE=$(mktemp)
		grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
		cat $TMPFILE > $RESOLV_CONF
		rm -f $TMPFILE

		# prefer rfc3397 domain search list (option 119) if available
		if [ -n "$search" ]; then
			search_list=$search
		elif [ -n "$domain" ]; then
			search_list=$domain
		fi

		[ -n "$search_list" ] &&
			echo "search $search_list # $interface" >> $RESOLV_CONF

		for i in $dns ; do
			echo adding dns $i
			echo "nameserver $i # $interface" >> $RESOLV_CONF
		done
		;;
esac

HOOK_DIR="$0.d"
for hook in "${HOOK_DIR}/"*; do
    [ -f "${hook}" -a -x "${hook}" ] || continue
    "${hook}" "${@}"
done

exit 0
mkdir -p home/p0
chown -R root:root .
chown -R 1001:1001 home/p0
chmod 2755 home/p0
chmod 0700 root
chmod 1777 var tmp
chmod 600 etc/shadow
chmod 4755 bin/busybox
chmod -R 755 etc/init.d/
chgrp 33 var/www
chgrp 37 srv/ftp
chmod 777 srv/ftp
touch var/run/utmp var/log/lastlog
chgrp 43 var/run/utmp var/log/lastlog
chmod 755 usr/share/udhcpc/default.script

date > etc/rpi0w.current


SD Card Image (Fail!)

boot20M lib60M

  • Crear Imagen:
#dd bs=512 count=$(((150 *1024*1024)/512)) if=/dev/zero of=rpi0w-os.img
truncate -s 150M rpi0w-os.img
  • Crear Particiones:
  1. Parted:
parted rpi0w-os.img mktable msdos
parted rpi0w-os.img mkpart primary fat32 2048s 32MiB
parted rpi0w-os.img mkpart primary ext4 32MiB 100%
parted rpi0w-os.img print
  1. FDisk:
#cylinder=$(du -b rpi0w-os.img | awk '{print int($1/255/63/512)}')
fdisk rpi0w-os.img

x h 255 s 63 c $(((150 *1024*1024)/255/63/512)) r n p 1 _ +32M t c a n p 2 _ _ p w

  • Formato:
losetup  --find --partscan --show rpi0w-os.img

mkdosfs -F 32 -n bOOTFS /dev/loopXp1
mkfs.ext4 -L rOOTFS /dev/loopXp2
#mkfs.f2fs -l rOOTFS /dev/loopXp2
  • Montar:
mount -t ext4 /dev/loopXp2 MOUNT_POINT
mkdir -p MOUNT_POINT/boot
mount -t vfat /dev/loopXp1 MOUNT_POINT/boot
#rsync -axvh ROOT_FS/ MOUNT_POINT/
  • Desmontar:
umount MOUNT_POINT/boot
umount MOUNT_POINT

losetup  --detach /dev/loopX
parted rpi0w-os.img print || fdisk -l rpi0w-os.img
dd if=rpi0w-os.img of=/dev/sdx bs=1M


(Algunas) Referencias:



#| haveged@ https://github.com/jirka-h/haveged/archive/v1.9.13.tar.gz
#| wireless_tools@https://hewlettpackard.github.io/wireless-tools/wireless_tools.30.pre9.tar.gz
#| wpa_supplicant@https://w1.fi/releases/wpa_supplicant-2.9.tar.gz (openssl,libnl)
#| (e)iwd@https://github.com/dylanaraps/eiwd/releases/download/1.6-1/eiwd-1.6-1.tar.xz (openssl,readline,ncurses)
#| dropbear@https://github.com/mkj/dropbear/archive/DROPBEAR_2020.80.tar.gz
#| f2fs-tools@https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git (util-linux
#| e2fsprogs@https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.45.6/e2fsprogs-1.45.6.tar.xz (util-linux)
#| ntfs-3g@https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz (util-linux)
#| less@http://www.greenwoodsoftware.com/less/less-551.tar.gz (ncurses,pcre2)
#|
#| @https://git.suckless.org/ubase/files.html
#| @http://git.suckless.org/sbase/files.html
#| @http://landley.net/toybox/bin/
#| @https://github.com/xanmanning/alarm-fake-hwclock
#| @https://github.com/NXP/linux-firmware
#| @https://www.oracle.com/java/technologies/javaseembedded8u211-downloads.html
#| @https://golang.org/dl/ (# -ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build')
#| @http://b0llix.net/perp/site.cgi
#| @https://github.com/mpwillson/rogue
#|
#| @https://github.com/zyedidia/micro
#| @https://github.com/gokcehan/lf
#| @https://github.com/yudai/gotty
#| @https://github.com/anacrolix/dms
#| @https://github.com/aler9/rtsp-simple-server
#| @https://github.com/shazow/ssh-chat
#| @https://github.com/jingweno/ccat
#| @https://github.com/charmbracelet/glow
#| @https://github.com/Psiphon-Labs/psiphon-tunnel-core
#| @https://awesome-go.com/


micro etc/init.d/S40wpa_supplicant
#!/bin/busybox ash
# Deamon: WPA_Supplicant

#

PROG=/usr/local/sbin/wpa_supplicant
PIDFILE=/var/run/${PROG##*/}.pidm
ARGS=''
#ARGS='-D wext -i wlan0'
ARGS='-D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf'

[ -x "${PROG}" ] || exit 0
case "${1}" in
 start)
  # brcmutil,cfg80211,rfkill
  /bin/grep -qo "brcmfmac" /proc/modules || /sbin/modprobe brcmfmac ; /bin/sleep 1s
  /sbin/ifconfig wlan0 up
  /bin/mkdir -p /etc/wpa_supplicant
  [ -f /etc/wpa ] && /bin/rm -f /var/lib/iwd/.known_network.freq
  /bin/sleep 1s
  #/usr/bin/setsid /usr/bin/nohup
  /sbin/start-stop-daemon -S -q -m -b -p "${PIDFILE}" -x ${PROG} -- ${ARGS}
  #${PROG} -B ${ARGS} -P "${PIDFILE}"
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 stop)
  /sbin/start-stop-daemon -K -q -p "${PIDFILE}"
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 restart) ${0} stop ;/bin/sleep 1s; ${0} start ;;
 status) [ -r "${PIDFILE}" ] && /bin/echo "$(/bin/cat "${PIDFILE}")" ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac
exit ${?}

# Networking setup - for STATIC_IP
#/sbin/ifconfig wlan0 192.168.8.9 netmask 255.255.255.0 broadcast 192.168.8.255 up
#/sbin/route add default gw 192.168.8.1
#/bin/echo 'nameserver 192.168.8.1' > /etc/resolv.conf
micro etc/wpa_supplicant/wpa_supplicant.conf
# ~$ wpa_passphrase ${SSID_REDACCESO} >> wlpoints.cfg # reading passphrase from stdin
# ~$ wpa_supplicant -B -D nl80211,wext -i wlan0 -c ETC/wpa_supplicant.conf &
# ~$ wpa_supplicant -B -D nl80211,wext -i wlan0 -c <( echo '') &

country=US
#ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=0
#ctrl_interface=/var/run/wpa_supplicant
#ctrl_interface_group=0
#ctrl_interface_group=netdev
#ctrl_interface_group=wheel
eapol_version=1
update_config=1
ap_scan=1
fast_reauth=1

network={
  ssid="HUAWEI-D8CD"
  #bssid=FF:0F:0F:0F:0F:0F
  #proto=WPA
  #key_mgmt=WPA-PSK
  psk="31693548"
  #key_mgmt=NONE
  #pairwise=CCMP TKIP
  #group=CCMP TKIP
  scan_ssid=1
  priority=3
}
network={
  key_mgmt=NONE
  priority=-9999999
}
micro etc/init.d/S40iwd
#!/bin/busybox ash
# Deamon: IWD

# # Add network:
# printf 'MyP455' | /usr/bin/iwd_passphrase 'MyESSID'
#

PROG=/usr/libexec/iwd
PIDFILE=/var/run/${PROG##*/}.pidm
ARGS=''
#ARGS='-i wlan0'

[ -x "${PROG}" ] || exit 0
case "${1}" in
 start)
  # brcmutil,cfg80211,rfkill
  /bin/grep -qo "brcmfmac" /proc/modules || /sbin/modprobe brcmfmac ; /bin/sleep 1s
  /sbin/ifconfig wlan0 up
  /bin/mkdir -p /var/lib/iwd /etc/iwd
  # /usr/bin/setsid \
  /sbin/start-stop-daemon -S -q -m -b -p "${PIDFILE}" -x ${PROG} -- ${ARGS}
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 stop)
  /sbin/start-stop-daemon -K -q -p "${PIDFILE}"
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 restart) ${0} stop ;/bin/sleep 1s; ${0} start ;;
 status) [ -r "${PIDFILE}" ] && /bin/echo "$(/bin/cat "${PIDFILE}")" ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac
exit ${?}

# Networking setup - for STATIC_IP
#/sbin/ifconfig wlan0 192.168.8.9 netmask 255.255.255.0 broadcast 192.168.8.255 up
#/sbin/route add default gw 192.168.8.1
#/bin/echo 'nameserver 192.168.8.1' > /etc/resolv.conf
micro etc/iwd/main.conf
[General]
EnableNetworkConfiguration=true
UseDefaultInterface=true
#AddressRandomization=disabled
#AddressRandomizationRange=full
#RoamThreshold=-70
#ManagementFrameProtection=1
#ControlPortOverNL80211=true
#DisableANQP=true

[Network]
NameResolvingService=resolvconf
RoutePriorityOffset=300

#[Blacklist]
#InitialTimeout=60
#Multiplier=30
#MaximumTimeout=86400

#[Rank]
#BandModifier5Ghz=1.0

[Scan]
DisablePeriodicScan=false
DisableRoamingScan=false
micro var/lib/iwd/myHOMEpot.psk
[Settings]
AutoConnect=true
#Hidden=false
#AlwaysRandomizeAddress=false

[Security]
PreSharedKey=66bb7c9ea428b0cc0ea3924788fa8817447885fa4544828318512d834dc37d0b
#Passphrase=

[IPv4]
Address=192.168.8.99
Netmask=255.255.255.0
Gateway=192.168.8.1
Broadcast=192.168.8.255
DNS=192.168.8.1
#DomainName=rpi0w.local
#// kernel config required by IWD
scripts/config --enable CONFIG_CRYPTO_USER_API_SKCIPHER
scripts/config --enable CONFIG_CRYPTO_USER_API_HASH
scripts/config --enable CONFIG_CRYPTO_HMAC
scripts/config --enable CONFIG_CRYPTO_CMAC
scripts/config --enable CONFIG_CRYPTO_MD4
scripts/config --enable CONFIG_CRYPTO_MD5
scripts/config --enable CONFIG_CRYPTO_SHA256
scripts/config --enable CONFIG_CRYPTO_SHA512
scripts/config --enable CONFIG_CRYPTO_AES
scripts/config --enable CONFIG_CRYPTO_ECB
scripts/config --enable CONFIG_CRYPTO_ARC4
scripts/config --enable CONFIG_CRYPTO_DES
scripts/config --enable CONFIG_CRYPTO_CBC
scripts/config --enable CONFIG_KEY_DH_OPERATIONS
micro etc/init.d/S60dhcp
#!/bin/busybox ash
# DCHP broadcasting

case "${1}" in
 start)

  # Networking setup - for STATIC_IP
  #
  #/sbin/ifconfig wlan0 192.168.8.9 netmask 255.255.255.0 broadcast 192.168.8.255 up
  #/sbin/route add default gw 192.168.8.1
  #/bin/echo 'nameserver 192.168.8.1' > /etc/resolv.conf
  #
  #/sbin/ifconfig eth0 192.168.8.8 netmask 255.255.255.0 broadcast 192.168.8.255 up
  #/sbin/route add default gw 192.168.8.1
  #/bin/echo 'nameserver 192.168.8.1' > /etc/resolv.conf

  NETDEV="$(/usr/bin/awk -F: '/eth.:|tr.:|wlan[0-9]:|usb.:/{print $1}' /proc/net/dev 2>/dev/null)"
  [ -f /usr/share/udhcpc/default.script ] && /bin/chmod 755 /usr/share/udhcpc/default.script
  for DEV in ${NETDEV}; do
   /sbin/ifconfig ${DEV} | /bin/grep -q "inet addr"
   [ "${?}" = 0 ] && continue
   #[ -r /var/run/udhcpc.${DEV}.pid ] && /bin/kill -15 "$(/bin/cat /var/run/udhcpc.${DEV}.pid)"
   /bin/echo "Network device ${DEV} detected, DHCP broadcasting for IP." | /usr/bin/logger -t uDHCPc -p kern.info
   trap 2 3 11
   /sbin/udhcpc -S -A 20 -b -i ${DEV} -x hostname:$(/bin/hostname) -p /var/run/udhcpc.${DEV}.pid >/dev/null 2>&1 & # -n # -A 20
   trap "" 2 3 11
   /bin/sleep 1s
  done
  ;;
 stop) /usr/bin/pkill udhcpc ;;
 restart) $(0) stop ;/bin/sleep 1s; ${0} start ;;
 status) /bin/pidof udhcpc ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac
exit ${?}
micro cmdline-parser.src
#!/bin/busybox ash
# . /etc/init.d/scripts/cmdline-parser.src

# Reading custom entries (cmdline.txt:: ... rootwait quiet anythinga=192.168.1.10 anythingb)
unset CMDLN
for CMDLN in $(/bin/cat /proc/cmdline); do
 case "${CMDLN}" in
 *=*)
  case "${CMDLN}" in
   anythinga*) ANYTHINGA=${CMDLN#*=} ;;
  esac
 ;;
 *)
  case "${CMDLN}" in
   anythingb) ANYTHINGB=1 ;;
  esac
 ;;
 esac
done
unset CMDLN
#[ -n "${ANYTHINGA}" ] && /bin/echo "${ANYTHINGA}"
#[ -n "${ANYTHINGB}" ] && /bin/true
micro led.sh
#!/bin/busybox ash
  (while :;do
  (#STAT0=$(/bin/cat /sys/class/leds/led0/trigger | /bin/sed -E 's|.*\[(.*)\].*|\1|g')
  /bin/echo none | /usr/bin/tee /sys/class/leds/led0/trigger ; N=0
  while [ ${N} -lt 2 ] ;do N=$((N+1))
  /bin/echo 1 | /usr/bin/tee /sys/class/leds/led0/brightness;/bin/sleep 0.1
  /bin/echo 0 | /usr/bin/tee /sys/class/leds/led0/brightness;/bin/sleep 0.1;done
  #/bin/echo ${STAT0:-actpwr} | /usr/bin/tee /sys/class/leds/led0/trigger)
  /bin/echo none | /usr/bin/tee /sys/class/leds/led0/trigger)
  /bin/sleep 1m;done) &
exit ${?}
micro setDate.sh
#!/bin/busybox ash
[ $(/usr/bin/id -u) = 0 ] || { /bin/echo 'must be root';exit 1; }
([ -x /usr/sbin/fake-hwclock ] && /usr/sbin/fake-hwclock)
export TZ=CLT
/bin/touch /tmp/date.header 2>&-
/bin/busybox date | /usr/bin/logger -t setDate -p kern.info
/bin/busybox wget --spider -S http://190.107.229.5:80/movil/ &> /tmp/date.header
[ -r /tmp/date.header ] || { /bin/echo 'Fail' && exit 1; }
DATE_G="$(/bin/grep -E '^[[:space:]]*[dD]ate:' /tmp/date.header \
| /bin/sed 's/^[[:space:]]*[dD]ate:[[:space:]]*//')"
[ "${DATE_G:-}z" = "z" ] && { /bin/echo 'Fail' && exit 1; }
DATE_C=$(/bin/busybox date --utc --date "${DATE_G}" -D "%a, %d %b %Y %T %Z" +'%Y-%m-%d %H:%M:%S' 2>&-)
/bin/echo "${DATE_C}" | /bin/grep -qoe "....-..-.. ..:..:.." || { /bin/echo 'Fail' && exit 1; }
# 3 Verano 4 Invierno
TZ='GMT-4' /bin/busybox date --set "${DATE_C}"
#/bin/busybox date -d @$(($(/bin/busybox date +%s)-3600*4))
/bin/busybox date | /usr/bin/logger -t setDate -p kern.info
([ -x /usr/sbin/fake-hwclock ] && /usr/sbin/fake-hwclock)
exit 0
micro etc/init.d/S20haveged
#!/bin/busybox ash
# Deamon: haveged
# Fixing Low-Entry
# Collect entropy and feed into random pool or write to file.

# # -
# -
#

PROG=/usr/sbin/haveged
PIDFILE=/var/run/${PROG#*/}.pid
ARGS='-w 1024 -r 0'

[ -x "${PROG}" ] || exit 0
case "${1}" in
 start)
  /sbin/start-stop-daemon -S -x ${PROG} -- ${ARGS}
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 stop)
  /sbin/start-stop-daemon -K -x ${PROG}
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 restart) ${0} stop ;/bin/sleep 1s; ${0} start ;;
 status)
  [ -r "${PIDFILE}" ] && /bin/echo "$(/bin/cat "${PIDFILE}")" ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac

exit ${?}
micro etc/init.d/S20swclock
#!/bin/busybox ash
# Fake HwClock

[ -x /usr/sbin/fake-hwclock ] || exit 0
case "${1}" in
 start) /usr/sbin/fake-hwclock ;;
 stop) /usr/sbin/fake-hwclock ;;
 status) /bin/date ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|status}";exit 1 ;;
esac
micro etc/init.d/S50dropbear
#!/bin/busybox ash
# Deamon: DropBear

# # Generate Private&Public Keys
# /usr/bin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
# /usr/bin/dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key | grep "^ssh-rsa " > /etc/dropbear/dropbear_rsa_host_key.pub
#

PROG=/usr/sbin/dropbear
PIDFILE=/var/run/${PROG#*/}.pid
ARGS='-R'

[ -x "${PROG}" ] || exit 0
case "${1}" in
 start)
  /bin/mkdir -p /etc/dropbear
  umask 077
  [ -r /etc/dropbear/dropbear_rsa_host_key ] || /usr/bin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
  /bin/sleep 1s
  /sbin/start-stop-daemon -S -q -p "${PIDFILE}" -x ${PROG} -- ${ARGS}
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 stop)
  /sbin/start-stop-daemon -K -q -p "${PIDFILE}"
  [ ${?} = 0 ] && /bin/echo "OK" || /bin/echo "FAIL"
 ;;
 restart) ${0} stop ;/bin/sleep 1s; ${0} start ;;
 status)
  [ -r "${PIDFILE}" ] && /bin/echo "$(/bin/cat "${PIDFILE}")" ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac

exit ${?}
micro etc/init.d/S55usbm
#!/bin/busybox ash
# USB_ModeSwitch
# 12d1:1f01 -> 12d1:14db

[ -x /usr/local/sbin/usb_modeswitch ] || exit 0
#[ -r /etc/usb_modeswitch/12d1_1f01 ] || exit 0
case "${1}" in
 start)
  (while ! /usr/bin/lsusb | /bin/grep -qoE '12d1.(14db|1f01)' ;do
  N=$((${N:-0}+1)) ; [ ${N} -gt 90 ] && exit 0
  /bin/sleep 2;done
  
  /sbin/ifconfig eth0 || {
  # cdc-wdm,cdc_ncm
  /bin/grep -qo "cdc_mbim" /proc/modules || /sbin/modprobe cdc_mbim
  /bin/grep -qo "cdc_ether" /proc/modules || /sbin/modprobe cdc_ether
  /bin/sleep 1s
  # -c /etc/usb_modeswitch/12d1_1f01
  /usr/local/sbin/usb_modeswitch -I -W -s 10 -v 12d1 -p 1f01 -M '55534243123456780000000000000a11062000000000000100000000000000' -V 12d1 -P 14db >/dev/null 2>&1 &
  /bin/sleep 2s; }
  /sbin/ifconfig eth0 up #&& /etc/init.d/scripts/dhcp.sh
  ) &
  ;;
 stop) /sbin/ifconfig eth0 && /sbin/ifconfig eth0 down ;;
esac

# Networking setup - for STATIC_IP
#/sbin/ifconfig eth0 192.168.8.8 netmask 255.255.255.0 broadcast 192.168.8.255 up
#/sbin/route add default gw 192.168.8.1
#/bin/echo 'nameserver 192.168.8.1' > /etc/resolv.conf

exit ${?}
micro etc/init.d/__S40serial
#!/bin/busybox ash
# Starting serial terminal
#/bin/mknod -m 666 /dev/ttyS0 c 4 64

case "${1}" in
 start) (while :;do /sbin/getty -L ttyS0 115200 vt100; /bin/sleep 5s;done) & ;;
esac
micro etc/init.d/S98pftpd
#!/bin/busybox ash

PROG=/usr/local/sbin/pure-ftpd
PIDFILE=/var/run/${PROG#*/}.pid
ARGS="--daemonize --ipv4only --pidfile ${PIDFILE}"

[ -x "${PROG}" ] || exit 0
case "${1}" in
 start) ${PROG} ${ARGS} ;;
 stop) [ -r "${PIDFILE}" ] && /bin/kill -9 "$(/bin/cat "${PIDFILE}")" ;;
 restart) $(0) stop ;/bin/sleep 1s; ${0} start ;;
 status) [ -r "${PIDFILE}" ] && /bin/echo "$(/bin/cat "${PIDFILE}")" ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac
micro etc/init.d/S99local
#!/bin/busybox ash
case "${1}" in
 start) (/etc/init.d/scripts/led.sh) >/dev/null 2>&1 &
  #(/home/proxy/run.sh &)&
  ;;
 #stop) /usr/bin/pkill ${0} ;;
 #restart) $(0) stop ;/bin/sleep 1s; ${0} start ;;
 #status) /bin/pidof ${0} ;;
 *) /bin/echo "Usage: ${0##*/} {start|stop|restart|status}";exit 1 ;;
esac
micro etc/syslogd.conf
# all messages of kern and user facilities
kern,user.*                                 /var/log/messages
# all messages of kern facility with priorities lower than err (warn, notice ...)
kern.!err                                   /var/log/critical
# all messages except ones with auth and authpriv facilities
*.*;auth,authpriv.none                      /var/log/noauth
# some whicked rule just as an example =)
kern,user.*;kern.!=notice;*.err;syslog.none /var/log/OMG
# this prevents from logging to default log file (-O FILE or /var/log/messages)
*.*                                         /dev/null
micro usr/share/udhcpc/default.script
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>

RESOLV_CONF="/etc/resolv.conf"

[ -n "$1" ] || { /bin/echo "Error: should be called from udhcpc"; exit 1; }

NETMASK=""
if command -v ip >/dev/null; then
	[ -n "$subnet" ] && NETMASK="/$subnet"
else
	[ -n "$subnet" ] && NETMASK="netmask $subnet"
fi
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"

case "$1" in
	deconfig)
		/bin/echo "Setting IP address 0.0.0.0 on $interface"
		if command -v ip >/dev/null; then
			ip addr flush dev $interface
		else
			/sbin/ifconfig $interface 0.0.0.0
		fi
		;;

	renew|bound)
		/bin/echo "Setting IP address $ip on $interface"
		if command -v ip >/dev/null; then
			ip addr add $ip$NETMASK $BROADCAST dev $interface
		else
			/sbin/ifconfig $interface $ip $NETMASK $BROADCAST
		fi

		if [ -n "$router" ] ; then
			/bin/echo "Deleting routers"
			while /sbin/route del default gw 0.0.0.0 dev $interface ; do
				:
			done

			metric=0
			for i in $router ; do
				/bin/echo "Adding router $i"
				if [ "$subnet" = "255.255.255.255" ]; then
	# special case for /32 subnets:
	# /32 instructs kernel to always use routing for all outgoing packets
	# (they can never be sent to local subnet - there is no local subnet for /32).
	# Used in datacenters, avoids the need for private ip-addresses between two hops.
					ip route add $i dev $interface
				fi
				/sbin/route add default gw $i dev $interface metric $((metric++))
			done
		fi

		echo "Recreating $RESOLV_CONF"
		# If the file is a symlink somewhere (like /etc/resolv.conf
		# pointing to /run/resolv.conf), make sure things work.
		realconf=$(/usr/bin/readlink -f "$RESOLV_CONF" 2>/dev/null || /bin/echo "$RESOLV_CONF")
		tmpfile="$realconf-$$"
		> "$tmpfile"
		[ -n "$domain" ] && /bin/echo "search $domain" >> "$tmpfile"
		for i in $dns ; do
			/bin/echo " Adding DNS server $i"
			/bin/echo "nameserver $i" >> "$tmpfile"
		done
		/bin/mv "$tmpfile" "$realconf"
		;;
esac

exit 0
linux-upgrade.sh
#!/bin/busybox ash
[ $(/usr/bin/id -u) = 0 ] || { /bin/echo 'must be root';exit 1; }
type rsync || exit 1
RSYNC_ARGS='--delete'
/bin/mountpoint /boot || { /bin/echo '-- Err:BootDir!';exit 1; }
/bin/echo '-- Downloading...'
/usr/local/bin/wget -c 'https://github.com/Hexxeh/rpi-firmware/tarball/master' -O pi_linux.tar.gz --no-check-certificate
/bin/echo '-- Decompressing...'
# vc/hardfp/
/bin/tar tf pi_linux.tar.gz | /bin/grep -E 'overlays/|Module\.symvers$|bcm2708-rpi-zero-w\.dtb$|bootcode\.bin$|kernel\.img$|(start|fixup)(|_(cd|x|db))\.(elf|dat)$|uname_string$|git_hash$|modules/[0-9]+\.[0-9]+\.[0-9]+./' | /bin/grep -vE '/$' > pi_linux.tar.gz.list
/bin/tar xf pi_linux.tar.gz -T pi_linux.tar.gz.list || { /bin/echo '-- Err:Tar!';exit 1; }
/bin/echo '-- Checking...'
/bin/ls -dp Hexxeh-rpi-firmware-* || { /bin/echo '-- Err:Repo!';exit 1; }
BDir=$(/bin/ls -dp Hexxeh-rpi-firmware-*)
/bin/ls -dp ${BDir}modules || { /bin/echo '-- Err:Modules!';exit 1; }
/bin/ls -dp ${BDir}overlays || { /bin/echo '-- Err:Overlays!';exit 1; }
#/bin/ls -dp ${BDir}vc/hardfp/opt/vc || { /bin/echo '-- Err:VC!';exit 1; }
/bin/echo '-- Syncing...'
rsync -axh ${RSYNC_ARGS} ${BDir}modules/ /lib/modules/ || { /bin/echo '-- Err:SyncModules!';exit 1; }
#/bin/mkdir -p /opt/vc/
#rsync -axh ${RSYNC_ARGS} ${BDir}vc/hardfp/opt/vc/ /opt/vc/ || { /bin/echo '-- Err:SyncVC!';exit 1; }
/bin/mountpoint /boot || { /bin/echo '-- Err:BootDir!';exit 1; }
/bin/cp -f /boot/config.tx* /boot/cmdline.tx* /tmp/
rsync -rlDxh ${RSYNC_ARGS} --exclude=modules/ --exclude=vc/ ${BDir} /boot/ || { /bin/echo '-- Err:SyncBoot!';exit 1; }
/bin/cp -f /tmp/config.tx* /tmp/cmdline.tx* /boot/
/bin/echo '-- Cleaning...'
/bin/rm -rf ${BDir}
/bin/rm -rf pi_linux.tar.gz
micro pkg-musl.sh
#!/bin/busybox ash
[ $(/usr/bin/id -u) = 0 ] || { /bin/echo 'must be root';exit 1; }
trap '/bin/echo "-- Ctrl-C!"' 2
trap '/bin/echo "-- uOps!"' 1
TMP_DIR=$(mktemp -d)
trap ' [ -d "${TMP_DIR:?}" ] && /bin/rm -rf "${TMP_DIR:?}" 2>&- ;/bin/echo "-- Exiting!";exit ${?}' 0

ARCH=arm-linux-musleabihf
PREFIX_DIR=/usr/local
DATA_DIR=/usr/local/share/pkg-musl.d

WGET_BIN=/usr/bin/wget
[ -x /usr/local/bin/wget ] && WGET_BIN=/usr/local/bin/wget
WGET_EXTRA_OPS=''
# --header='Host: twitter.com' --no-check-certificate
# --spider -S

LIST_RAW="${DATA_DIR:?}"/pkg.html
LIST_FILE="${DATA_DIR:?}"/pkg.list

CHK_DIR(){
/bin/mkdir -p "${PREFIX_DIR:?}"/bin
/bin/mkdir -p "${DATA_DIR:?}"
[ -d "${PREFIX_DIR:?}"/bin ] || { /bin/echo "-- Err:Dir!";exit 1; }
[ -d "${DATA_DIR:?}" ] || { /bin/echo "-- Err:Dir!";exit 1; }
}

CHK_LIST_FILE(){
CHK_DIR
/bin/echo "-- Checking... Package list!"
[ -s "${LIST_RAW:?}" ] || ${WGET_BIN} ${WGET_EXTRA_OPS} -qO "${LIST_RAW:?}" 'http://pkg.musl.cc/'
[ -r "${LIST_RAW:?}" ] && /bin/grep -o '<a href=".*">' "${LIST_RAW:?}" | /bin/sed -E 's|<a href="(.*)/">|\1|g' | /usr/bin/sort -u > "${LIST_FILE:?}"
[ -s "${LIST_FILE:?}" ] || { /bin/echo "-- Err:List!"; exit 1; }
/bin/echo "-- Package list is ready!"
}

case "${1}" in
 search|-S) [ "${#}" -ge 2 ] || { /bin/echo "-- What!?"; exit 0; }
  CHK_DIR
  CHK_LIST_FILE ; /bin/grep "${2:?}" "${LIST_FILE:?}" || { /bin/echo "-- Nothing:Search!"; exit 0; }
  /bin/echo "-- Done!"
  ;;
 iget|isrc|-I|-F) [ "${#}" -ge 2 ] || { /bin/echo "-- What!?"; exit 0; }
  CHK_DIR
  case "${1}" in
   iget|-I)
    CHK_LIST_FILE ; /bin/grep -q "${2:?}" "${LIST_FILE:?}" || { /bin/echo "-- Nothing:Get!"; exit 0; }
    PKG="$(/bin/grep "${2:?}" "${LIST_FILE:?}" | /usr/bin/head -n1)"
    [ -f "${DATA_DIR:?}"/"${PKG:?}".install ] && PKG_EXIST='!' || PKG_EXIST='+'
    read -r -n1 -p "?? Cancel [Ctrl-C] : ${PKG_EXIST:-}'${PKG:?}' Continue " Key
    /bin/echo
    TMP_PKG_FILE="${TMP_DIR:?}"/"${PKG:?}".tgz
    /bin/echo "-- Downloading..."
    ${WGET_BIN} ${WGET_EXTRA_OPS} -c -qO "${TMP_PKG_FILE:?}" "http://pkg.musl.cc/${PKG:?}/${ARCH:?Invalid Arch}.tgz" || { /bin/echo "-- Err:Wget!"; exit 1; }
    ;;
   isrc|-F)
    [ -s "${2:?}" ] || { /bin/echo "-- Where!?"; exit 0; }
    CHK_LIST_FILE ; SRC="${2:?}" ; SRC_N="${SRC##*/}" ; SRC_N="${SRC_N%%.*}"
    /bin/grep -q "^${SRC_N:?}" "${LIST_FILE:?}" || { /bin/echo "-- Nothing:Get!"; exit 0; }
    PKG="$(/bin/grep "^${SRC_N:?}" "${LIST_FILE:?}" | /usr/bin/head -n1)"
    [ -f "${DATA_DIR:?}"/"${PKG:?}".install ] && PKG_EXIST='!' || PKG_EXIST='+'
    read -r -n1 -p "?? Cancel [Ctrl-C] : ${PKG_EXIST:-}'${PKG:?}' Continue " Key
    /bin/echo
    TMP_PKG_FILE="${TMP_DIR:?}"/"${PKG:?}".tgz
    /bin/echo "-- Checking..."
    /bin/cp -f "${SRC:?}" "${TMP_PKG_FILE:?}" || { /bin/echo "-- Err:Cp!"; exit 1; }
    [ -f "${TMP_PKG_FILE:?}" ] && /bin/tar tf "${TMP_PKG_FILE:?}" | /bin/grep -qo "^${ARCH}/" || { /bin/echo "-- Err:Arch!"; exit 1; }
    ;;
  esac
  /bin/echo "-- Preparing..."
  [ -f "${TMP_PKG_FILE:?}" ] && /bin/tar xf "${TMP_PKG_FILE:?}" -C "${TMP_DIR:?}"/ || { /bin/echo "-- Err:Tar!"; /bin/rm -f "${TMP_PKG_FILE:?}" ; exit 1; }
  [ -f "${TMP_PKG_FILE:?}" ] || { /bin/echo "-- Err:Get!"; exit 1; }
  /bin/echo "-- Installing..."
  [ -f "${TMP_PKG_FILE:?}" ] && /bin/tar tf "${TMP_PKG_FILE:?}" | /bin/grep -vE '/$' | /bin/sed "s|${ARCH:?}|${PREFIX_DIR:?}|g" > "${DATA_DIR:?}"/"${PKG:?}".install
  (cd "${TMP_DIR:?}"/"${ARCH:?}"/ && /bin/tar cf - .)|(cd "${PREFIX_DIR:?}"/ && /bin/tar xf -)
  #/bin/sed -i "s|/usr/local|${PREFIX_DIR:?}|g" "${PREFIX_DIR:?}"/lib/pkgconfig/*.pc
  /bin/echo "-- Finishing..."
  #[ -f "${TMP_PKG_FILE:?}" ] && /bin/echo "${PATH}" | /bin/grep -qo "${PREFIX_DIR:?}/bin" || /bin/echo "# export PATH=\${PATH}:${PREFIX_DIR:?}/bin:${PREFIX_DIR:?}/sbin"
  [ -f "${TMP_PKG_FILE:?}" ] && /bin/rm -rf "${TMP_DIR:?}"
  [ -f "${TMP_PKG_FILE:?}" ] || /bin/echo "-- Done!"  
  ;;
 remove|-R) [ "${#}" -ge 2 ] || { /bin/echo "-- What!?"; exit 0; }
  DATA_INSTALL_FILE="${DATA_DIR:?}"/"${2:?}".install
  [ -s "${DATA_INSTALL_FILE:?}" ] || { /bin/echo "-- Nothing:Remove!"; exit 0; }
  [ -r "${DATA_INSTALL_FILE:?}" ] && { while IFS= read -r rLINE
   do set -x;/bin/rm -f "${rLINE:?}" || { /bin/echo "-- Err:Remove!";exit 1; } ;set +x;done < "${DATA_INSTALL_FILE:?}" ; }
  [ -f "${DATA_INSTALL_FILE:?}" ] && /bin/rm -f "${DATA_INSTALL_FILE:?}"
  [ -f "${DATA_INSTALL_FILE:?}" ] || /bin/echo "-- Done!"
  ;;
 *) /bin/echo "Usage: ${0##*/} {search|iget} package-name"
    /bin/echo "       ${0##*/} {search|iget} ^package-name"
    /bin/echo "       ${0##*/} isrc package-name.tar.gz" ;;
esac

exit 0


#| musl@https://musl.cc/arm-linux-musleabihf-native.tgz
#|      $ export PATH=${PATH:?}:/tmp/arm-linux-musleabihf-native/bin
#|      $ export CC='arm-linux-musleabihf-gcc'
#|      $ export CXX='arm-linux-musleabihf-g++'
#|      $ export LDFLAGS="${LDFLAGS} -static --static"
#|     @https://pkg.musl.cc/<package-name>/arm-linux-musleabihf.tgz
#|      $ export CPPLAGS="${CPPLAGS} -I/tmp/arm-linux-musleabihf/include"
#|      $ export LDFLAGS="${LDFLAGS} -L/tmp/arm-linux-musleabihf/lib"
# --with-arch=armv6 --with-fpu=vfp --with-float=hard
#export CFLAGS="-O2 -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -pipe"
#export CFLAGS="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp"
# Err: scripts/basic/fixdep: not found
# Fix: gcc -static
# Err: <openssl/bio.h>
# Fix: -I/usr/local/include
# Err: -lcypto
# Fix: -L/usr/local/lib
# Err: selected processor does not support 'cpsid i' in ARM mode
# Fix: -march=armv6zk -mtune=arm1176jzf-s
#
# linux/Makefile
HOST_LFS_CFLAGS := -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -I/usr/local/include $(shell getconf LFS_CFLAGS 2>/dev/null)
HOST_LFS_LDFLAGS := -L/usr/local/lib -I/usr/local/include  $(shell getconf LFS_LDFLAGS 2>/dev/null)
HOST_LFS_LIBS := -L/usr/local/lib $(shell getconf LFS_LIBS 2>/dev/null)
HOSTCC       = gcc -static
HOSTCXX      = g++ -static
CC             = $(CROSS_COMPILE)gcc  -static
KBUILD_CPPFLAGS := -D__KERNEL__ -O2 -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -pipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment