2017-05-26 20:26:25 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# This file will be in /init_functions.sh inside the initramfs.
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
IP=172.16.42.1
|
2017-07-28 18:51:21 +00:00
|
|
|
TELNET_PORT=23
|
2017-05-26 20:26:25 +00:00
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Redirect stdout and stderr to logfile
|
|
|
|
setup_log() {
|
|
|
|
# Bail out if PMOS_NO_OUTPUT_REDIRECT is set
|
|
|
|
echo "### postmarketOS initramfs ###"
|
|
|
|
grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline && return
|
|
|
|
|
|
|
|
# Print a message about what is going on to the normal output
|
|
|
|
echo "NOTE: All output from the initramfs gets redirected to:"
|
|
|
|
echo "/pmOS_init.log"
|
|
|
|
echo "If you want to disable this behavior (e.g. because you're"
|
|
|
|
echo "debugging over serial), please add this to your kernel"
|
|
|
|
echo "command line: PMOS_NO_OUTPUT_REDIRECT"
|
|
|
|
|
|
|
|
# Start redirect, print the first line again
|
|
|
|
exec >/pmOS_init.log 2>&1
|
|
|
|
echo "### postmarketOS initramfs ###"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_proc_sys_dev() {
|
|
|
|
# mdev
|
|
|
|
mount -t proc -o nodev,noexec,nosuid proc /proc
|
|
|
|
mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
|
|
|
|
|
2017-07-13 15:17:48 +00:00
|
|
|
mkdir /config
|
|
|
|
mount -t configfs -o nodev,noexec,nosuid configfs /config
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# /dev/pts (needed for telnet)
|
|
|
|
mkdir -p /dev/pts
|
|
|
|
mount -t devpts devpts /dev/pts
|
2017-06-22 17:36:44 +00:00
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
setup_mdev() {
|
|
|
|
echo /sbin/mdev >/proc/sys/kernel/hotplug
|
|
|
|
mdev -s
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_subpartitions() {
|
2017-05-26 20:26:25 +00:00
|
|
|
for i in /dev/mmcblk*; do
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
case "$(kpartx -l "$i" 2>/dev/null | wc -l)" in
|
2017-05-26 20:26:25 +00:00
|
|
|
2)
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Mount subpartitions of $i"
|
2017-05-26 20:26:25 +00:00
|
|
|
kpartx -afs "$i"
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
find_root_partition() {
|
|
|
|
# The partition layout is one of the following:
|
|
|
|
# a) boot, root partitions on sdcard
|
|
|
|
# b) boot, root partition on the "system" partition (which has its
|
|
|
|
# own partition header! so we have partitions on partitions!)
|
|
|
|
#
|
|
|
|
# mount_subpartitions() must get executed before calling
|
|
|
|
# find_root_partition(), so partitions from b) also get found.
|
|
|
|
#
|
|
|
|
# However, after executing mount_subpartitions(), the partitions
|
|
|
|
# from a) get mounted to /dev/mapper - and then you can only use
|
|
|
|
# the ones from /dev/mapper, not the original partition paths (they
|
|
|
|
# will appear as busy when trying to mount them). This is an
|
|
|
|
# unwanted side-effect, that we must deal with.
|
|
|
|
# The subpartitions from b) get mounted to /dev/mapper, and this is
|
|
|
|
# what we want.
|
|
|
|
#
|
|
|
|
# To deal with the side-effect, we use the partitions from
|
|
|
|
# /dev/mapper first, and then fall back to partitions with all paths
|
|
|
|
# (in case the user inserted an SD card after mount_subpartitions()
|
|
|
|
# ran!).
|
|
|
|
|
|
|
|
# Try the partitions in /dev/mapper first.
|
|
|
|
for id in pmOS_root crypto_LUKS; do
|
|
|
|
DEVICE="$(blkid | grep /dev/mapper | grep "$id" \
|
|
|
|
| cut -d ":" -f 1)"
|
|
|
|
[ -z "$DEVICE" ] || break
|
|
|
|
done
|
2017-06-22 17:34:51 +00:00
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Then try all devices
|
2017-06-22 17:34:51 +00:00
|
|
|
if [ -z "$DEVICE" ]; then
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
for id in pmOS_root crypto_LUKS; do
|
|
|
|
DEVICE="$(blkid | grep "$id" | cut -d ":" -f 1)"
|
|
|
|
[ -z "$DEVICE" ] || break
|
|
|
|
done
|
2017-06-22 17:34:51 +00:00
|
|
|
fi
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
echo "$DEVICE"
|
|
|
|
}
|
2017-06-22 17:34:51 +00:00
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
find_boot_partition() {
|
|
|
|
findfs LABEL="pmOS_boot"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_boot_partition() {
|
|
|
|
partition=$(find_boot_partition)
|
|
|
|
if [ -z "$partition" ]; then
|
|
|
|
echo "ERROR: boot partition not found!"
|
|
|
|
show_splash /splash-noboot.ppm.gz
|
|
|
|
loop_forever
|
|
|
|
fi
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Mount boot partition ($partition)"
|
2017-08-24 21:07:36 +00:00
|
|
|
mount -r "$partition" /boot
|
2017-07-28 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1: initramfs-extra path
|
|
|
|
extract_initramfs_extra() {
|
|
|
|
initramfs_extra="$1"
|
|
|
|
if [ ! -e "$initramfs_extra" ]; then
|
|
|
|
echo "ERROR: initramfs-extra not found!"
|
|
|
|
show_splash /splash-noinitramfsextra.ppm.gz
|
|
|
|
loop_forever
|
|
|
|
fi
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Extract $initramfs_extra"
|
2017-07-28 18:51:21 +00:00
|
|
|
gzip -d -c "$initramfs_extra" | cpio -i
|
|
|
|
}
|
|
|
|
|
2017-08-03 16:01:00 +00:00
|
|
|
wait_root_partition() {
|
|
|
|
while [ -z "$(find_root_partition)" ]; do
|
|
|
|
show_splash /splash-nosystem.ppm.gz
|
|
|
|
echo "Could not find the root partition."
|
|
|
|
echo "Maybe you need to insert the sdcard, if your device has"
|
|
|
|
echo "any? Trying again in one second..."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
resize_root_partition() {
|
|
|
|
partition=$(find_root_partition)
|
|
|
|
# Only resize the partition if it's inside the device-mapper, which means
|
|
|
|
# that the partition is stored as a subpartition inside another one.
|
|
|
|
# In this case we want to resize it to use all the unused space of the
|
|
|
|
# external partition.
|
|
|
|
if [ -z "${partition##"/dev/mapper/"*}" ]; then
|
|
|
|
# Get physical device
|
|
|
|
partition_dev=$(dmsetup deps -o devname "$partition" | \
|
|
|
|
awk -F "[()]" '{print "/dev/"$2}')
|
|
|
|
# Check if there is unallocated space at the end of the device
|
|
|
|
if parted -s "$partition_dev" print free | tail -n2 | \
|
|
|
|
head -n1 | grep -qi "free space"; then
|
|
|
|
echo "Resize root partition ($partition)"
|
|
|
|
# unmount subpartition, resize and remount it
|
|
|
|
kpartx -d "$partition"
|
|
|
|
parted -s "$partition_dev" resizepart 2 100%
|
|
|
|
kpartx -afs "$partition_dev"
|
|
|
|
fi
|
|
|
|
fi
|
2017-08-18 22:39:32 +00:00
|
|
|
# Detect and resize root partition on QEMU
|
|
|
|
if [ -z "${partition##"/dev/hda"*}" ]; then
|
|
|
|
echo "Resize root partition ($partition)"
|
|
|
|
parted -s /dev/hda resizepart 2 100%
|
|
|
|
partprobe
|
|
|
|
fi
|
2017-08-03 16:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock_root_partition() {
|
|
|
|
partition="$(find_root_partition)"
|
|
|
|
if cryptsetup isLuks "$partition"; then
|
|
|
|
until cryptsetup status root | grep -qwi active; do
|
|
|
|
start_usb_unlock
|
|
|
|
cryptsetup luksOpen "$partition" root || continue
|
|
|
|
done
|
|
|
|
# Show again the loading splashscreen
|
|
|
|
show_splash /splash-loading.ppm.gz
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
resize_root_filesystem() {
|
|
|
|
partition="$(find_root_partition)"
|
|
|
|
touch /etc/mtab # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673323
|
|
|
|
echo "Check/repair root filesystem ($partition)"
|
|
|
|
e2fsck -f -y "$partition"
|
|
|
|
echo "Resize root filesystem ($partition)"
|
|
|
|
resize2fs -f "$partition"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_root_partition() {
|
|
|
|
partition="$(find_root_partition)"
|
|
|
|
echo "Mount root partition ($partition)"
|
2017-09-30 21:52:33 +00:00
|
|
|
mount -t ext4 -o ro "$partition" /sysroot
|
2017-08-03 16:01:00 +00:00
|
|
|
if ! [ -e /sysroot/usr ]; then
|
|
|
|
echo "ERROR: unable to mount root partition!"
|
|
|
|
show_splash /splash-mounterror.ppm.gz
|
|
|
|
loop_forever
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
setup_usb_network_android() {
|
|
|
|
# Only run, when we have the android usb driver
|
|
|
|
SYS=/sys/class/android_usb/android0
|
|
|
|
[ -e "$SYS" ] || return
|
2017-06-22 17:34:51 +00:00
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Do the setup
|
|
|
|
printf "%s" "0" >"$SYS/enable"
|
|
|
|
printf "%s" "18D1" >"$SYS/idVendor"
|
|
|
|
printf "%s" "D001" >"$SYS/idProduct"
|
|
|
|
printf "%s" "rndis" >"$SYS/functions"
|
|
|
|
printf "%s" "1" >"$SYS/enable"
|
2017-05-26 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 15:17:48 +00:00
|
|
|
setup_usb_network_configfs() {
|
|
|
|
CONFIGFS=/config/usb_gadget
|
|
|
|
[ -e "$CONFIGFS" ] || return
|
|
|
|
|
|
|
|
mkdir $CONFIGFS/g1
|
|
|
|
printf "%s" "18D1" >"$CONFIGFS/g1/idVendor"
|
|
|
|
printf "%s" "D001" >"$CONFIGFS/g1/idProduct"
|
|
|
|
|
|
|
|
mkdir $CONFIGFS/g1/strings/0x409
|
|
|
|
|
|
|
|
mkdir $CONFIGFS/g1/functions/rndis.usb0
|
|
|
|
|
|
|
|
mkdir $CONFIGFS/g1/configs/c.1
|
|
|
|
mkdir $CONFIGFS/g1/configs/c.1/strings/0x409
|
|
|
|
printf "%s" "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration
|
|
|
|
|
|
|
|
ln -s $CONFIGFS/g1/functions/rndis.usb0 $CONFIGFS/g1/configs/c.1
|
2017-08-09 20:30:41 +00:00
|
|
|
|
|
|
|
# See also: #338
|
|
|
|
# shellcheck disable=SC2005
|
|
|
|
echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC
|
2017-07-13 15:17:48 +00:00
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
setup_usb_network() {
|
|
|
|
# Only run once
|
|
|
|
_marker="/tmp/_setup_usb_network"
|
|
|
|
[ -e "$_marker" ] && return
|
|
|
|
touch "$_marker"
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Setup usb network"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Run all usb network setup functions (add more below!)
|
|
|
|
setup_usb_network_android
|
2017-07-13 15:17:48 +00:00
|
|
|
setup_usb_network_configfs
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start_udhcpd() {
|
|
|
|
# Only run once
|
|
|
|
[ -e /etc/udhcpd.conf ] && return
|
|
|
|
|
|
|
|
# Get usb interface
|
|
|
|
INTERFACE=""
|
|
|
|
ifconfig rndis0 "$IP" && INTERFACE=rndis0
|
|
|
|
if [ -z $INTERFACE ]; then
|
|
|
|
ifconfig usb0 "$IP" && INTERFACE=usb0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create /etc/udhcpd.conf
|
|
|
|
{
|
|
|
|
echo "start 172.16.42.2"
|
2017-09-23 14:23:38 +00:00
|
|
|
echo "end 172.16.42.2"
|
|
|
|
echo "auto_time 0"
|
|
|
|
echo "decline_time 0"
|
|
|
|
echo "conflict_time 0"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
echo "lease_file /var/udhcpd.leases"
|
|
|
|
echo "interface $INTERFACE"
|
|
|
|
echo "option subnet 255.255.255.0"
|
|
|
|
} >/etc/udhcpd.conf
|
|
|
|
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Start the dhcpcd daemon (forks into background)"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
udhcpd
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
start_usb_unlock() {
|
|
|
|
# Only run once
|
|
|
|
_marker="/tmp/_start_usb_unlock"
|
|
|
|
[ -e "$_marker" ] && return
|
|
|
|
touch "$_marker"
|
|
|
|
|
|
|
|
# Set up networking
|
|
|
|
setup_usb_network
|
|
|
|
start_udhcpd
|
|
|
|
|
|
|
|
# Telnet splash
|
|
|
|
show_splash /splash-telnet.ppm.gz
|
|
|
|
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Start the telnet daemon (unlock encrypted partition)"
|
2017-07-28 18:51:21 +00:00
|
|
|
{
|
|
|
|
echo '#!/bin/sh'
|
|
|
|
echo '. /init_functions.sh'
|
|
|
|
echo 'unlock_root_partition'
|
|
|
|
echo 'echo_connect_ssh_message'
|
2017-08-03 16:01:00 +00:00
|
|
|
echo 'killall cryptsetup'
|
|
|
|
echo "pkill -f telnetd.*:${TELNET_PORT}"
|
2017-07-28 18:51:21 +00:00
|
|
|
} >/telnet_connect.sh
|
|
|
|
chmod +x /telnet_connect.sh
|
|
|
|
telnetd -b "${IP}:${TELNET_PORT}" -l /telnet_connect.sh
|
|
|
|
}
|
|
|
|
|
2017-05-26 20:26:25 +00:00
|
|
|
# $1: path to ppm.gz file
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
show_splash() {
|
|
|
|
gzip -c -d "$1" >/tmp/splash.ppm
|
2017-05-26 20:26:25 +00:00
|
|
|
fbsplash -s /tmp/splash.ppm
|
|
|
|
}
|
2017-07-19 18:05:34 +00:00
|
|
|
|
|
|
|
echo_connect_ssh_message() {
|
2017-07-28 18:51:21 +00:00
|
|
|
echo "Your root partition has been decrypted successfully!"
|
|
|
|
echo "You can connect to your device using SSH in a few seconds:"
|
|
|
|
echo "ssh user@$IP"
|
|
|
|
}
|
|
|
|
|
2017-09-18 19:17:30 +00:00
|
|
|
start_msm_refresher() {
|
|
|
|
# shellcheck disable=SC2154,SC2086
|
|
|
|
if [ "${deviceinfo_msm_refresher}" = "true" ]; then
|
|
|
|
/usr/sbin/msm-fb-refresher --loop &
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-29 15:22:20 +00:00
|
|
|
set_framebuffer_mode() {
|
|
|
|
[ -e "/sys/class/graphics/fb0/modes" ] || return
|
|
|
|
[ -z "$(cat /sys/class/graphics/fb0/mode)" ] || return
|
|
|
|
|
|
|
|
_mode="$(cat /sys/class/graphics/fb0/modes)"
|
|
|
|
echo "Setting framebuffer mode to: $_mode"
|
|
|
|
echo "$_mode" > /sys/class/graphics/fb0/mode
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
loop_forever() {
|
|
|
|
while true; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2017-07-19 18:05:34 +00:00
|
|
|
}
|