-
-
Save jsarenik/709c638f5b48c72a220e to your computer and use it in GitHub Desktop.
init.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /etc/tinitrc | |
HOSTNAME=$(cat /etc/hostname) | |
DOMAIN=$(cat /etc/dnsdomainname) | |
FQDN=$HOSTNAME.$DOMAIN | |
NETCONF=/etc/network/interfaces | |
IPV4=$(cat $NETCONF | sed -n 's/.*address //p') | |
IPV6=$(grep "up ifconfig venet0 add" $NETCONF | sed 's/^.*add //') | |
IPV6_ADDRESS=${IPV6%%/*} | |
myshut() { | |
CMD=${1:-"reboot"} | |
: Shutting down | |
: mailx -s "Init log" $MYMAIL < /root/init.log | |
>/reboot | |
#mount -n -o remount,ro -t dummytype dummydev / | |
busybox $CMD -f | |
} | |
trap "myshut echo" INT QUIT | |
mmlog "Called as $0 $*" | |
test "$1" = "-z" || { | |
test "$1" = "6" && { myshut reboot; } | |
test "$1" = "0" && { myshut halt; } | |
exit 0 | |
} | |
exec > /root/init.log 2>&1 | |
exec < /dev/null | |
set -x | |
# Most of these variables are not needed | |
export PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
export CONSOLE="/dev/console" | |
export INIT_VERSION=tinyald-1.1 | |
: Starting init | |
rm /reboot | |
rm /fastboot | |
#mount -n -t proc -onodev,noexec,nosuid proc /proc | |
#mount -n -t sysfs -onodev,noexec,nosuid sysfs /sys | |
mkdir /dev | |
mkdir /run | |
mount -n -t devtmpfs -o rw,nosuid,mode=755 devtmpfs /dev | |
mount -n -t tmpfs -onosuid,noexec,size=10%,mode=755 tmpfs /run | |
mkdir /run/lock | |
mount -n -t tmpfs -onodev,noexec,nosuid,size=5242880,mode=1777 tmpfs /run/lock | |
mkdir /run/shm | |
mount -n -t tmpfs -onosuid,nodev,noexec,size=52420k,mode=1777 tmpfs /run/shm | |
mkdir /dev/pts | |
mount -n -t devpts -onoexec,nosuid,mode=620,ptmxmode=000 -orw devpts /dev/pts | |
mount -n -o remount,defaults,rw /dev/root / | |
mount -oremount -onosuid,noexec,size=10%,mode=755 /run | |
mount -oremount -onodev,noexec,nosuid,size=5242880,mode=1777 /run/lock | |
mount -oremount -onodev,noexec,nosuid -odefaults /proc | |
mount -oremount -onodev,noexec,nosuid /sys | |
mount -oremount -onosuid,nodev,noexec,size=52420k,mode=1777 /run/shm | |
mount -oremount -onoexec,nosuid,mode=620,ptmxmode=000 -orw /dev/pts | |
mount -a -t nonfs,nfs4,smbfs,cifs,ncp,ncpfs,coda,ocfs2,gfs,gfs2,ceph -O no_netdev | |
cat > /etc/hosts <<EOHOSTS | |
127.0.0.1 localhost.localdomain localhost | |
::1 localhost.localdomain localhost | |
$IPV6_ADDRESS $FQDN $HOSTNAME | |
EOHOSTS | |
for IPV4_ADDRESS in $IPV4 | |
do | |
echo $IPV4_ADDRESS $FQDN $HOSTNAME >> /etc/hosts | |
ip -4 address add $IPV4_ADDRESS/32 dev venet0 | |
done | |
hostname $HOSTNAME | |
#/sbin/iptables-restore /root/iptables.state | |
ip -4 address add 127.0.0.1/8 dev lo | |
ip -4 address add 127.0.0.2/32 dev venet0 | |
ip -6 address add $IPV6 dev venet0 | |
ip -6 address add ::1/128 dev lo | |
ip link set lo up | |
ip link set venet0 up | |
ip -4 route add default dev venet0 | |
ip -6 route add default dev venet0 | |
: Daemons | |
#postfix start | |
#httpd -c /httpd.conf | |
touch /root/donotreboot | |
while | |
test -e /root/donotreboot | |
do | |
mmlog "ls -l" | |
ls -l /dev/pts | mml | |
mmlog "Running sshd" | |
mkdir /var/run/sshd | |
/usr/sbin/sshd -D | |
mmlog "Running dropbear" | |
/sbin/dropbear -F -R -W 65536 -p 22 | |
sleep 1 | |
mmlog "Alive and well" | |
done | |
mmlog "After life" | |
myshut reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cp dropbear /sbin | |
mkdir /etc/dropbear | |
rm * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -ex | |
tofile() { | |
# <"question"> <"VARIABLE="> <file> [default] | |
echo "$1 [$4]: " | |
read answer | |
test -z "$answer" -a -n "$4" && answer=$4 | |
echo "${2}$answer" >> "$3" | |
} | |
tofile "Please enter your email address" MYMAIL= /etc/tinitrc [email protected] | |
tofile "DNS Domain Name" "" /etc/dnsdomainname jasan.tk | |
echo "Paste your SSH public key now... (finish with ^D)" | |
mkdir ~/.ssh || true | |
cat <<EOF > ~/.ssh/authorized_keys | |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCa2mv5nTo9jiuRha6PmC5wAcMfqwd81rh/uPFWKu9eFuNSgiSeoBrPwyqjhth6sw2gYRhsM+I27QFfgVc/rv50M6Wf5ksLh+ufNZBsq7BA8md2Y3q5O6BZhosSm9CGwU7JOH8Xf3QOsMINe3vZoSvxo7+ReFco306vkgOZEFcMNfV52vk91D9xgv6ourafa0YZthrxo6XAH/H+jXEFFKn7kTngD6i5QiNBNYZ6RaeeRPRm6lw1zd8f8s/QZa9GASX6a2nMT80EwtPY14f2exYLFS/UsH834F7aA2sdaLh0JnGZeGwvyAwuzrMQa1LEWNHTcl2E2KOyCrqKTfABTDdqdgm1Ch1R+hSI1RWi/8j99gfdnUIHJXqulDwbOgvO+Hl+yVLqkxPpO8zgOMk6zUAZj/SzAGUbgERYlPmonrNkuuQRLTH1svzoRoLDTSep5wroWCLzyYcUzX9mBdsJKTzAl0/v909E2aINSreXX13nihAUycZYWzLwhCUjRsmA1/UCg/us5JCdB/5BMVtlUOgEYk8Hez0oK7Ua5E5LDVsSbffTTF++DwRROpd0IPunKwWlfdx9kqsgx+XhMM8fvG9ZAJnHqCHkN4wWB6ipaq86hS6yFXSI9GuUWm7IJj5LzzreTzxaytChQA3ADI0ouOzavMo7WC+cbk7RKnp7Beqtbw== jasan@arjadnek | |
EOF | |
chmod -R go-rwx ~/.ssh | |
wget -O - http://dl.bintray.com/jsarenik/TinyALD/dropbear.tar.gz | tar xvz | |
mkdir -p /etc/dropbear || true | |
mv dropbear /sbin/dropbear | |
chmod a+x /sbin/dropbear | |
sed -i 's|bash|sh|' /etc/passwd | |
wget http://dl.bintray.com/jsarenik/TinyALD/busybox.bz2 | |
bunzip2 busybox.bz2 | |
mv busybox / | |
chmod a+x,u+s /busybox | |
/busybox mv /bin /bin-old | |
/busybox mkdir /bin || /busybox true | |
/busybox --install /bin | |
MMLOG=/sbin/mmlog | |
cat > $MMLOG <<EOF | |
#!/bin/sh | |
RSERVER=logs3.papertrailapp.com | |
RPORT=42629 | |
echo "\$*" | tee -a /root/init.log | nc \$RSERVER \$RPORT | |
EOF | |
chmod a+x $MMLOG | |
MMLOG=/sbin/mml | |
cat > $MMLOG <<EOF | |
#!/bin/sh | |
RSERVER=logs3.papertrailapp.com | |
RPORT=42629 | |
tee -a /root/init.log | nc \$RSERVER \$RPORT | |
EOF | |
chmod a+x $MMLOG | |
cp init /sbin/init | |
chmod a+x /sbin/init | |
rm -fv /sbin/telinit | |
ln -s init /sbin/telinit | |
> /reboot | |
/busybox reboot -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment