Skip to content

Commit

Permalink
board: pluto & m2k: Enable persistent ssh keys and passwd changes
Browse files Browse the repository at this point in the history
This patch adds support for saving the SSH keys and password files on the
JFFS2 partition on mtd2. There are three new helper scripts for this.

Signed-off-by: Michael Hennerich <[email protected]>
  • Loading branch information
mhennerich authored and commodo committed Jun 21, 2020
1 parent 1bfa9dc commit 2ee30e3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions board/m2k/S21misc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ handle_calibration_files() {

case "$1" in
start)
# Restore saved password and Dropbear keys
[[ -d /mnt/jffs2/etc ]] && cd /mnt/jffs2/etc && md5sum -s -c password.md5 && cp passwd shadow group /etc
[[ -d /mnt/jffs2/etc/dropbear ]] && cd /mnt/jffs2/etc/dropbear && md5sum -s -c keys.md5 && cp dropbear* /etc/dropbear/
iio_attr -q -d m2k-fabric clk_powerdown 1
handle_calibration_files
;;
Expand Down
4 changes: 4 additions & 0 deletions board/m2k/post-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ genimage \

rm -f ${TARGET_DIR}/opt/boot.vfat
rm -f ${TARGET_DIR}/etc/init.d/S99iiod
rm -Rf ${TARGET_DIR}/etc/dropbear

mkdir -p ${TARGET_DIR}/www/img
mkdir -p ${TARGET_DIR}/mnt/jffs2
mkdir -p ${TARGET_DIR}/mnt/msd
mkdir -p ${TARGET_DIR}/etc/wpa_supplicant/
mkdir -p ${TARGET_DIR}/etc/dropbear

${INSTALL} -D -m 0755 ${BOARD_DIR}/../pluto/update.sh ${TARGET_DIR}/sbin/
${INSTALL} -D -m 0755 ${BOARD_DIR}/../pluto/update_frm.sh ${TARGET_DIR}/sbin/
Expand All @@ -55,6 +57,8 @@ ${INSTALL} -D -m 0644 ${BOARD_DIR}/../pluto/fw_env.config ${TARGET_DIR}/etc/
${INSTALL} -D -m 0644 ${BOARD_DIR}/VERSIONS ${TARGET_DIR}/opt/
${INSTALL} -D -m 0644 ${BOARD_DIR}/m2k-calib.ini ${TARGET_DIR}/opt/
${INSTALL} -D -m 0755 ${BOARD_DIR}/../pluto/device_reboot ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0755 {BOARD_DIR}/../pluto/device_passwd ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0755 {BOARD_DIR}/../pluto/device_persistent_keys ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0644 ${BOARD_DIR}/motd ${TARGET_DIR}/etc/
${INSTALL} -D -m 0644 ${BOARD_DIR}/device_config ${TARGET_DIR}/etc/
${INSTALL} -D -m 0644 ${BOARD_DIR}/../pluto/mdev.conf ${TARGET_DIR}/etc/
Expand Down
3 changes: 3 additions & 0 deletions board/pluto/S21misc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ xo_correction() {
case "$1" in
start|"")
echo -n "Starting miscellaneous setup: "
# Restore saved password and Dropbear keys
[[ -d /mnt/jffs2/etc ]] && cd /mnt/jffs2/etc && md5sum -s -c password.md5 && cp passwd shadow group /etc
[[ -d /mnt/jffs2/etc/dropbear ]] && cd /mnt/jffs2/etc/dropbear && md5sum -s -c keys.md5 && cp dropbear* /etc/dropbear/
xo_correction
MAX_BS=`fw_printenv -n iio_max_block_size 2> /dev/null || echo 67108864`
echo ${MAX_BS} > /sys/module/industrialio_buffer_dma/parameters/max_block_size
Expand Down
12 changes: 12 additions & 0 deletions board/pluto/device_format_jffs2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set +e

while true;
do
read -p "Are you sure to delete/format your mtd2 JFFS2 partition? (yes/no) " answ
case $answ in
[Yy]* ) flash_erase -j /dev/mtd2 0 0; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
10 changes: 10 additions & 0 deletions board/pluto/device_passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set +e

cat /proc/mounts | grep -q mtd2 || (echo "Filesystem not mounted use device_format_jffs2 command to setup your partition"; exit 1)

passwd
install -D /etc/passwd /etc/shadow /etc/group -t /mnt/jffs2/etc
cd /etc
md5sum passwd shadow group 2>/dev/null > /mnt/jffs2/etc/password.md5

15 changes: 15 additions & 0 deletions board/pluto/device_persistent_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set +e

KEYFILE=/etc/dropbear/dropbear_ecdsa_host_key

cat /proc/mounts | grep -q mtd2 || (echo "Filesystem not mounted use device_format_jffs2 command to setup your partition"; exit 1)

#dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
[[ ! -f ${KEYFILE} ]] && dropbearkey -t ecdsa -f ${KEYFILE}
install -D ${KEYFILE} -t /mnt/jffs2/etc/dropbear
cd /etc/dropbear
md5sum dropbear* /etc/dropbear/ 2>/dev/null > /mnt/jffs2/etc/dropbear/keys.md5



5 changes: 5 additions & 0 deletions board/pluto/post-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ genimage \

rm -f ${TARGET_DIR}/opt/boot.vfat
rm -f ${TARGET_DIR}/etc/init.d/S99iiod
rm -Rf ${TARGET_DIR}/etc/dropbear

mkdir -p ${TARGET_DIR}/www/img
mkdir -p ${TARGET_DIR}/etc/wpa_supplicant/
mkdir -p ${TARGET_DIR}/mnt/jffs2
mkdir -p ${TARGET_DIR}/mnt/msd
mkdir -p ${TARGET_DIR}/etc/dropbear

${INSTALL} -D -m 0755 ${BOARD_DIR}/update.sh ${TARGET_DIR}/sbin/
${INSTALL} -D -m 0755 ${BOARD_DIR}/update_frm.sh ${TARGET_DIR}/sbin/
Expand All @@ -65,6 +67,9 @@ ${INSTALL} -D -m 0755 ${BOARD_DIR}/S45msd ${TARGET_DIR}/etc/init.d/
${INSTALL} -D -m 0644 ${BOARD_DIR}/fw_env.config ${TARGET_DIR}/etc/
${INSTALL} -D -m 0644 ${BOARD_DIR}/VERSIONS ${TARGET_DIR}/opt/
${INSTALL} -D -m 0755 ${BOARD_DIR}/device_reboot ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0755 ${BOARD_DIR}/device_passwd ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0755 ${BOARD_DIR}/device_persistent_keys ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0755 ${BOARD_DIR}/device_format_jffs2 ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0644 ${BOARD_DIR}/motd ${TARGET_DIR}/etc/
${INSTALL} -D -m 0755 ${BOARD_DIR}/test_ensm_pinctrl.sh ${TARGET_DIR}/usr/sbin/
${INSTALL} -D -m 0644 ${BOARD_DIR}/device_config ${TARGET_DIR}/etc/
Expand Down

0 comments on commit 2ee30e3

Please sign in to comment.