Skip to content

Commit

Permalink
feat: use init and entrypoint from device tree
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jul 21, 2023
1 parent f64718c commit 506f21e
Showing 1 changed file with 17 additions and 42 deletions.
59 changes: 17 additions & 42 deletions skel/sbin/init
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
#!/bin/busybox sh

# Copyright 2019 Cartesi Pte. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#

# rndaddentropy can be in different places, make sure we can find it
export PATH=/opt/cartesi/bin:"$PATH"

[ ! -f /opt/cartesi/etc/motd -o "$splash" == "no" ] || busybox cat /opt/cartesi/etc/motd

# mount
busybox mkdir -p /dev/pts /dev/shm
busybox mount -t proc proc /proc -o nosuid,nodev,noexec
busybox mount -t sysfs sys /sys -o nosuid,nodev,noexec
busybox mount -t devpts devpts /dev/pts -o nosuid,noexec,gid=5,mode=620
busybox mount -t tmpfs tmpfs /dev/shm -o nosuid,nodev,mode=1777
#busybox mdev -s

# rand
if [ -f /opt/cartesi/var/run/random-seed ]; then
rndaddentropy < /opt/cartesi/var/run/random-seed
busybox chmod 600 /opt/cartesi/var/run/random-seed
fi
# net
[ -f /etc/hostname ] && busybox hostname -F /etc/hostname
busybox ifconfig lo up

# disk
if [ -d /mnt ]; then
(cd /sys/block && for DEV in *; do
[ ! "$DEV" = "mtdblock0" ] && \
NAME=$(busybox cat /sys/block/"$DEV"/device/name) && \
busybox mkdir "/mnt/$NAME" && \
busybox mount "/dev/$DEV" "/mnt/$NAME"
done)
# custom init
if [ -f /proc/device-tree/cartesi/init ]; then
. /proc/device-tree/cartesi/init
fi

# net
[ -f /etc/hostname ] && busybox hostname -F /etc/hostname
busybox ifconfig lo 127.0.0.1
# use entrypoint from device tree when available
if [ -s /proc/device-tree/cartesi/entrypoint ]; then
ENTRYPOINT=". /proc/device-tree/cartesi/entrypoint"
else
ENTRYPOINT="$*"
fi

# cmdline application
if [ -n "$*" ]; then
[ -f /etc/environment ] && \
source /etc/environment && \
export PATH=/opt/cartesi/bin:"$PATH" # put it back on PATH
# execute entrypoint
if [ -n "$ENTRYPOINT" ]; then
[ -f /etc/environment ] && . /etc/environment
export PATH="/opt/cartesi/bin:$PATH"

# can login as dapp user?
if [ ! "$single" == "yes" ] && busybox id dapp &> /dev/null; then
Expand All @@ -67,11 +43,10 @@ if [ -n "$*" ]; then
export HOME=~root USER=root LOGNAME=root
fi

# execute cmdline
cd $HOME &&
busybox setsid \
busybox cttyhack \
busybox su -p $USER -c "$*"
busybox su -p $USER -c "$ENTRYPOINT"
else
echo "Nothing to do."
fi
Expand Down

0 comments on commit 506f21e

Please sign in to comment.