#!/bin/bash ### BEGIN INIT INFO # Provides: firstrun # Required-Start: $all # Required-Stop: # Should-Start: armhwinfo # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Script to run when first starting # Description: Something needs to be done when is # starting at first time. # regenerate ssh host key ### END INIT INFO N=/etc/init.d/firstrun # get some info about the board CURKERNE=$(uname -r | sed 's/\([0-9]\+\.[0-9]\+\)\..*/\1/') MACHINE=$(cat /run/machine.id) MEMTOTAL=$(awk 'BEGIN { printf "%.0f\n", '$(grep MemTotal /proc/meminfo | awk '{print $2}')'/1024/1024 }') EDID=$(dmesg | grep PCLK) set -e do_expand_rootfs(){ device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0) PARTITIONS=$(($(fdisk -l $device | grep $device | wc -l)-1)) PARTSTART=$(parted $LOOP unit s print -sm | tail -1 | cut -d: -f2 | sed 's/s//') # start of first partition PARTEND=$(parted $LOOP unit s print -sm | head -3 | tail -1 | cut -d: -f3 | sed 's/s//') # end of first partition STARTFROM=$(($PARTEND+1)) [[ $PARTITIONS == 1 ]] && STARTFROM=$PARTSTART ((echo d; echo $PARTITIONS; echo n; echo p; echo ; echo $STARTFROM; echo ; echo w;) | fdisk $device)>/dev/null return 0 } case "$1" in start) reboot=false echo "" >/dev/tty1 toilet -f standard "first run" >/dev/tty1 echo "" >/dev/tty1 echo "System will reboot automatically. Please wait!" >/dev/tty1 echo "" >/dev/tty1 if [[ $MACHINE == Lamobo* ]]; then ln -sf /boot/bin/lamobo-r1.bin /boot/script.bin ln -sf /etc/network/interfaces.r1 /etc/network/interfaces # alter hostname echo "lamobo-r1" > /etc/hostname sed 's/ssid=\(.*\)/ssid=lamobo/g' -i /etc/hostapd.conf sed 's/ssid=\(.*\)/ssid=lamobo/g' -i /etc/hostapd.conf-rt if [[ $CURKERNE == "3.4" ]]; then sed -e 's/a20_tp//g' -i /etc/modules # alter configuration for hostapd sed 's/DAEMON_SBIN=\(.*\)/DAEMON_SBIN=\/usr\/sbin\/hostapd-rt/g' -i /etc/init.d/hostapd sed 's/DAEMON_CONF=\(.*\)/DAEMON_CONF=\/etc\/hostapd.conf-rt/g' -i /etc/init.d/hostapd else # alter configuration for hostapd sed 's/DAEMON_SBIN=\(.*\)/DAEMON_SBIN=\/usr\/sbin\/hostapd/g' -i /etc/init.d/hostapd sed 's/DAEMON_CONF=\(.*\)/DAEMON_CONF=\/etc\/hostapd.conf/g' -i /etc/init.d/hostapd fi fi if [[ $(apt-cache policy ramlog | grep Installed) != "" ]]; then service ramlog enable # if we have 1G ram reduce RAMLOG size if (($MEMTOTAL <= 1)); then if [ -f "/etc/default/ramlog" ]; then echo -e "[\e[0;32m ok \x1B[0m] Reducing Ramlog size to 256m" sed -e 's/TMPFS_RAMFS_SIZE=512m/TMPFS_RAMFS_SIZE=256m/g' -i /etc/default/ramlog fi fi fi # Cubietruck fix. Ethernet fails on some boards if hw clock is invalid #if [[ $MACHINE == *truck* ]] ; then # hwclock --set --date 1/1/2015 #fi # if HDMI is attached during boot, set default screen output to HDMI # #if [[ $MACHINE == *truck* && $EDID != "" ]] ; then # echo -e "[\e[0;32m ok \x1B[0m] HDMI detected. Changing default display output" # /usr/local/bin/bin2fex /boot/bin/cubietruck.bin /boot/bin/cubietruck.fex # sed -e 's/screen0_output_type.*/screen0_output_type = 3/g' -i /boot/bin/cubietruck.fex # /usr/local/bin/fex2bin /boot/bin/cubietruck.fex /boot/bin/cubietruck.bin #fi echo -e "[\e[0;32m ok \x1B[0m] SSH keys recreation. One moment please" >/dev/tty1 rm -f /etc/ssh/ssh_host* dpkg-reconfigure openssh-server >/dev/null 2>&1 if [ "$(fping 8.8.8.8 | grep alive)" != "" ]; then set +e echo -e "[\e[0;32m ok \x1B[0m] Updating packages list. One moment please" >/dev/tty1 apt-get update >/dev/null 2>&1 apt-get -y -qq autoremove >/dev/null 2>&1 fi # echo -e "[\e[0;32m ok \x1B[0m] Expanding rootfs." >/dev/tty1 if do_expand_rootfs;then echo -e "[\e[0;32m ok \x1B[0m] Expanding rootfs suceeded, rebooting automatically." >/dev/tty1 update-rc.d resize2fs defaults >/dev/null 2>&1 reboot=true else echo "Expanding rootfs has failed, see log files." >/dev/tty1 fi update-rc.d -f firstrun remove >/dev/null 2>&1 if $reboot;then /sbin/reboot fi ;; *) echo "Usage: $N {start}" >&2 exit 1 ;; esac exit 0