summaryrefslogtreecommitdiff
path: root/recipes-core/multitech/config/config.init
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/multitech/config/config.init')
-rw-r--r--recipes-core/multitech/config/config.init105
1 files changed, 105 insertions, 0 deletions
diff --git a/recipes-core/multitech/config/config.init b/recipes-core/multitech/config/config.init
new file mode 100644
index 0000000..874416c
--- /dev/null
+++ b/recipes-core/multitech/config/config.init
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+CONFIG_MTDC=/dev/mtd6
+CONFIG_MTDB=/dev/mtdblock6
+CONFIG_DIR=/var/config
+
+OEM_MTDC=/dev/mtd7
+OEM_MTDB=/dev/mtdblock7
+OEM_DIR=/var/oem
+
+FILES="network/interfaces \
+ppp/options \
+ppp/pap-secrets \
+ppp/chap-secrets \
+ppp/peers \
+"
+
+mount_config() {
+ echo "Mounting ${CONFIG_DIR}"
+ mkdir -p ${CONFIG_DIR}
+ mount ${CONFIG_DIR}
+
+ # Prepare flash for JFFS2 if mount fails
+ if [ $? -ne 0 ]; then
+ echo "Creating ${CONFIG_DIR}"
+ flash_erase -j ${CONFIG_MTDC} 0 0
+ mount ${CONFIG_DIR}
+ fi
+}
+
+mount_oem() {
+ echo "Mounting ${OEM_DIR}"
+ mkdir -p ${OEM_DIR}
+ mount ${OEM_DIR}
+
+ # Prepare flash for JFFS2 if mount fails
+ if [ $? -ne 0 ]; then
+ echo "Creating ${OEM_DIR}"
+ flash_erase -j ${OEM_MTDC} 0 0
+ mount ${OEM_DIR}
+ fi
+}
+
+case $1 in
+ start)
+ # mount config if not already mounted
+ if ! grep -q "^${CONFIG_MTDB} " /proc/mounts; then
+ mount_config
+ else
+ echo "$CONFIG_DIR already mounted"
+ fi
+
+ # mount oem if specified in /etc/fstab and it isn't already mounted
+ if grep -qE "^${OEM_MTDB}\s+${OEM_DIR}\s+" /etc/fstab; then
+ if ! grep -q "^${OEM_MTDB} " /proc/mounts; then
+ mount_oem
+ else
+ echo "$OEM_DIR already mounted"
+ fi
+ fi
+
+ # Default all config files if requested
+ cd ${CONFIG_DIR}
+ if [ -f force_defaults ]; then
+ echo "Extracting default config files"
+ tar -xvf /etc/defaults.tar.gz
+
+ if [ -f /etc/default_pass ]; then
+ echo "Defaulting root password"
+ PASSHASH=`cat /etc/default_pass`
+ PASSFILE=/etc/shadow
+ if [ ! -e /etc/shadow ]; then
+ PASSFILE=/etc/passwd
+ fi
+ sed -i "s%^root:[^:]*:%root:${PASSHASH}:%" $PASSFILE
+ fi
+
+ rm -f force_defaults
+ fi
+
+ # Extract any missing files
+ TARFILES=`tar -tf /etc/defaults.tar.gz`
+ for file in $TARFILES; do
+ if [ ! -e $file ]; then
+ tar -xvf /etc/defaults.tar.gz $file
+ fi
+ done
+
+ # Create links in /etc
+ for file in $FILES; do
+ if [ ! -L /etc/$file ]; then
+ echo "Creating link to ${CONFIG_DIR}/$file"
+ rm -rf /etc/$file
+ ln -sf ${CONFIG_DIR}/$file /etc/$file
+ fi
+ done
+
+ ;;
+
+ *)
+ echo "Usage: $0 {start}"
+ exit 2
+ ;;
+
+esac