summaryrefslogtreecommitdiff
path: root/recipes-core/multitech/config
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/multitech/config')
-rwxr-xr-xrecipes-core/multitech/config/config297
-rw-r--r--recipes-core/multitech/config/config.init215
2 files changed, 454 insertions, 58 deletions
diff --git a/recipes-core/multitech/config/config b/recipes-core/multitech/config/config
new file mode 100755
index 0000000..8c43e24
--- /dev/null
+++ b/recipes-core/multitech/config/config
@@ -0,0 +1,297 @@
+#!/bin/sh
+
+CONFIG_DIR=/var/config
+RUN_CONF_DIR=/run/config
+
+CONFIG_PARTITION="Config"
+OEM_PARTITION="OEM Config"
+TABLE=$'\n'"$(cat /proc/mtd)"
+if [[ $TABLE =~ [[:space:]]mtd([[:digit:]]+)[^\"]*\"$CONFIG_PARTITION\" ]] ; then
+ CONFIG_MTDC=/dev/mtd${BASH_REMATCH[1]}
+ CONFIG_MTDB=/dev/mtdblock${BASH_REMATCH[1]}
+else
+ echo "Cannot find a ${CONFIG_PARTITION} partition"
+ exit 0
+fi
+if [[ $TABLE =~ [[:space:]]mtd([[:digit:]]+)[^\"]*\"$OEM_PARTITION\" ]] ; then
+ OEM_MTDC=/dev/mtd${BASH_REMATCH[1]}
+ OEM_MTDB=/dev/mtdblock${BASH_REMATCH[1]}
+else
+ echo "Cannot find a ${OEM_PARTITION} partition"
+ exit 0
+fi
+
+CONFIG_DIR=/var/config
+OEM_DIR=/var/oem
+
+FILES="network/interfaces \
+ppp/options \
+ppp/pap-secrets \
+ppp/chap-secrets \
+ppp/peers \
+"
+
+# Files used by bluetooth or wifi.
+BTWIFIFILES="\
+bluetooth/ \
+default/ \
+dnsmasq.d/ \
+hosts \
+hostname \
+hostapd.conf \
+modprobe.d/ \
+wpa_supplicant.conf \
+"
+
+# File hidden so it is not removed on hardware reset
+WIFITAR=".defaults2.tar.gz"
+
+mount_config() {
+ echo "Mounting ${CONFIG_DIR}"
+ mkdir -p ${CONFIG_DIR}
+ mount ${CONFIG_DIR}
+
+ # Prepare flash for JFFS2 or EXT4 if mount fails
+ if [ $? -ne 0 ]; then
+ echo "Creating ${CONFIG_DIR}"
+ fs=$(mount -fvn ${CONFIG_DIR})
+ if [[ $fs =~ [[:space:]]*(/dev/(...)[^[:space:]]*) ]] ; then
+ if [[ ${BASH_REMATCH[2]} == mmc ]] ; then
+ # One more check for empty
+ mdev="${BASH_REMATCH[1]}"
+ if [[ $(dd if=$mdev count=4 2>/dev/null | tr -d '\0' | wc -c) == 0 ]] ; then
+ mkfs.ext4 -O 64bit ${mdev}
+ fi
+ else
+ flash_erase -j ${CONFIG_MTDC} 0 0
+ fi
+ fi
+ mount ${CONFIG_DIR}
+ fi
+}
+
+mount_oem() {
+ echo "Mounting ${OEM_DIR}"
+ mkdir -p ${OEM_DIR}
+ mount ${OEM_DIR}
+
+ # Prepare flash for JFFS2 or EXT4 if mount fails
+ # Prepare flash for JFFS2 or EXT4 if mount fails
+ if [ $? -ne 0 ]; then
+ echo "Creating ${OEM_DIR}"
+ fs=$(mount -fvn ${OEM_DIR})
+ if [[ $fs =~ [[:space:]]*(/dev/(...)[^[:space:]]*) ]] ; then
+ if [[ ${BASH_REMATCH[2]} == mmc ]] ; then
+ mdev="${BASH_REMATCH[1]}"
+ if [[ $(dd if=$mdev count=4 2>/dev/null | tr -d '\0' | wc -c) == 0 ]] ; then
+ mkfs.ext4 -O 64bit ${mdev}
+ fi
+ else
+ flash_erase -j ${OEM_MTDC} 0 0
+ fi
+ fi
+ mount ${OEM_DIR}
+ fi
+}
+
+# Create symlinks in directory $2
+# that point to non-directory items
+# in directory $1
+# No recursion.
+#
+# /etc/default/rcS must be in the
+# root file system
+#
+function linkdir {
+ from="$1"
+ to="$2"
+ newdir=$(basename "$from")
+ savedir=$(pwd)
+ cd "${from}"
+ set -x
+ for f in * ; do
+ if [[ ${to} == /etc/default ]] && [[ $f == rcS ]] ; then
+ continue
+ fi
+ if [[ $f == \* ]] ; then
+ break
+ fi
+ echo "linkdir: Testing ${to}/${f}"
+ if ! [[ -L ${to}/${f} ]] ; then
+ ln -sf "${from}/${f}" "${to}/${f}"
+ else
+ echo Skipping directory "$to/$f"
+ fi
+ done
+ cd "$savedir"
+ set +x
+}
+
+# parameter 1 Input directory
+# parameter 2 Parent of output directory
+#
+# The basename (final component) of parameter 1
+# is created as a directory in the directory
+# of parameter 2.
+#
+# Any symlinks found are not copied, but instead
+# updated to point to the "to" directory.
+#
+function copydir {
+ from="$1"
+ to="$2"
+ newdir=$(basename "$from")
+ links=()
+ if rmdir $from >/dev/null 2>&1 ; then
+ ln -sf "$to/$newdir" "$from"
+ else
+ mkdir "$to/$newdir" >/dev/null 2>&1 || true
+ savedir=$(pwd)
+ cd "$from"
+ for f in * ; do
+ if [[ $f == \* ]] ; then
+ break
+ fi
+ if [[ -L ${f} ]] ; then
+ links+=(${f})
+ continue
+ fi
+ if ! [[ -f "$to/$f" ]] ; then
+ cp -a "${f}" "$to/${newdir}/${f}"
+ fi
+ done
+ for l in ${links[*]} ; do
+ mylink=$(readlink "$l"))
+ if [[ $(dirname ${mylink}) == ${from} ]] ; then
+ base=$(basename "${mylink}")
+ if [[ $base != $l ]] ; then
+ echo "Writing symlink $to/$base $l"
+ ln -sf $to/$base $l
+ fi
+ fi
+ done
+ cd "$savedir"
+ fi
+}
+
+case $1 in
+ start)
+ # mount config if not already mounted
+ if ! grep -q " ${CONFIG_DIR} " /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 mount -fvn "${OEM_DIR}" ; then
+ if ! grep -q " ${OEM_DIR} " /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 -xf /etc/defaults.tar.gz
+ if [[ -f ${WIFITAR} ]] ; then
+ echo "Extract original wifi related files"
+ tar -xvf ${WIFITAR}
+ 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 ]] && ! [[ -d /etc/$file ]] ; then
+ rm -rf /etc/$file
+ ln -sf ${CONFIG_DIR}/$file /etc/$file
+ elif [[ -d /etc/$file ]] ; then
+ # JAK create links in directory.
+ linkdir "${CONFIG_DIR}/${file}" "/etc/${file}"
+ fi
+ done
+
+ # Move bluetooth wifi stuff to config directory.
+ # We don't have factory defaults.
+ ((dobackup=1))
+ for file in ${BTWIFIFILES}; do
+ if [[ -L /etc/$file ]]; then
+ ((dobackup=0))
+ break
+ fi
+ done
+ if ((dobackup==1)) ; then
+ echo "Creating backup of Config files"
+ tar -C /etc -czf ${CONFIG_DIR}/${WIFITAR} ${BTWIFIFILES}
+ fi
+
+ # For jffs2, you cannot remove a populated directory in an overlay.
+ # We must copy individual files and create symlinks instead.
+ for file in ${BTWIFIFILES}; do
+ isdir=0
+ # If last character is /, make the CONFIG directory.
+ if [[ ${file: -1} == / ]] ; then
+ isdir=1
+ file=${file%?}
+ if ! [[ -d ${CONFIG_DIR}/$file ]] ; then
+ rm -f ${CONFIG_DIR}/$file 2>/dev/null || true
+ mkdir ${CONFIG_DIR}/$file
+ fi
+ if [[ -d ${file} ]] ; then
+ copydir "/etc/${file}" "${CONFIG_DIR}"
+ fi
+ fi
+
+ if ((isdir == 0)); then
+ dir=$(dirname $file)
+ if [[ $dir != '.' ]] ; then
+ mkdir -p "$dir"
+ fi
+ rm -rf old
+ mkdir old
+ if ! [[ -f $file ]] ; then
+ # Need to preserve old files which is difficult with busybox!
+ if [[ -d $file ]] || [[ -f $file ]] ; then
+ cp --parents -a $file old || true
+ fi
+ (
+ cd /etc
+ if [[ -d $file ]] || [[ -f $file ]] ; then
+ cp --parents -a $file ${CONFIG_DIR} || true
+ fi
+ )
+ (
+ cd old
+ if [[ -d $file ]] || [[ -f $file ]] ; then
+ cp --parents -a $file .. || true
+ fi
+ )
+ rm -rf old
+ fi
+ rm -rf /etc/$file
+ ln -sf ${CONFIG_DIR}/$file /etc/$file
+ else
+ rm -f "/etc/${file}/*"
+ linkdir "${CONFIG_DIR}/${file}" "/etc/${file}"
+ fi
+ done
+ ;;
+
+ *)
+ echo "Usage: $0 {start}"
+ exit 2
+ ;;
+
+esac
diff --git a/recipes-core/multitech/config/config.init b/recipes-core/multitech/config/config.init
index f60fbfc..282b0bb 100644
--- a/recipes-core/multitech/config/config.init
+++ b/recipes-core/multitech/config/config.init
@@ -1,12 +1,27 @@
#!/bin/sh
-CONFIG_MTDC=/dev/mtd6
-CONFIG_MTDB=/dev/mtdblock6
CONFIG_DIR=/var/config
RUN_CONF_DIR=/run/config
-OEM_MTDC=/dev/mtd7
-OEM_MTDB=/dev/mtdblock7
+CONFIG_PARTITION="Config"
+OEM_PARTITION="OEM Config"
+TABLE=$'\n'"$(cat /proc/mtd)"
+if [[ $TABLE =~ [[:space:]]mtd([[:digit:]]+)[^\"]*\"$CONFIG_PARTITION\" ]] ; then
+ CONFIG_MTDC=/dev/mtd${BASH_REMATCH[1]}
+ CONFIG_MTDB=/dev/mtdblock${BASH_REMATCH[1]}
+else
+ echo "Cannot find a ${CONFIG_PARTITION} partition"
+ exit 0
+fi
+if [[ $TABLE =~ [[:space:]]mtd([[:digit:]]+)[^\"]*\"$OEM_PARTITION\" ]] ; then
+ OEM_MTDC=/dev/mtd${BASH_REMATCH[1]}
+ OEM_MTDB=/dev/mtdblock${BASH_REMATCH[1]}
+else
+ echo "Cannot find a ${OEM_PARTITION} partition"
+ exit 0
+fi
+
+CONFIG_DIR=/var/config
OEM_DIR=/var/oem
FILES="network/interfaces \
@@ -19,11 +34,7 @@ ppp/peers \
# Files used by bluetooth or wifi.
BTWIFIFILES="\
bluetooth/ \
-default/bluetooth \
-default/bt-pan \
-default/dnsmasq \
-default/hostapd \
-default/ifplugd \
+default/ \
dnsmasq.d/ \
hosts \
hostname \
@@ -31,10 +42,6 @@ hostapd.conf \
modprobe.d/ \
wpa_supplicant.conf \
"
-# mts-io driver may not be loaded
-if [[ -L /etc/default/rs9113 ]] || [[ -f /etc/default/rs9113 ]] || [[ -d /opt/rs9113 ]] ; then
- BTWIFIFILES+="default/rs9113 "
-fi
# File hidden so it is not removed on hardware reset
WIFITAR=".defaults2.tar.gz"
@@ -87,6 +94,88 @@ mount_oem() {
fi
}
+# Create symlinks in directory $2
+# that point to non-directory items
+# in directory $1
+# No recursion.
+#
+# /etc/default/rcS must be in the
+# root file system
+#
+function linkdir {
+ from="$1"
+ to="$2"
+ newdir=$(basename "$from")
+ savedir=$(pwd)
+ cd "${from}"
+ for f in * ; do
+ if [[ ${to} == /etc/default ]] && [[ $f == rcS ]] ; then
+ continue
+ fi
+ if [[ $f == volatiles ]] ; then
+ continue
+ fi
+ if [[ $f == \* ]] ; then
+ break
+ fi
+
+ if ! [[ -h ${to}/${f} ]] ; then
+ ln -sf "${from}/${f}" "${to}/${f}"
+ fi
+ done
+ cd "$savedir"
+}
+
+# parameter 1 Input directory
+# parameter 2 Parent of output directory
+#
+# The basename (final component) of parameter 1
+# is created as a directory in the directory
+# of parameter 2.
+#
+# Any symlinks found are not copied, but instead
+# updated to point to the "to" directory.
+#
+function copydir {
+ from="$1"
+ to="$2"
+ newdir=$(basename "$from")
+ links=()
+ if rmdir $from >/dev/null 2>&1 ; then
+ ln -sf "$to/$newdir" "$from"
+ else
+ mkdir "$to/$newdir" >/dev/null 2>&1 || true
+ savedir=$(pwd)
+ cd "$from"
+ for f in * ; do
+ if [[ $f == \* ]] ; then
+ break
+ fi
+ if [[ $f == volatiles ]] ; then
+ continue
+ fi
+ if [[ -L ${f} ]] ; then
+ links+=(${f})
+ continue
+ fi
+ if ! [[ -f "$to/$f" ]] ; then
+ cp -a "${f}" "$to/${newdir}/${f}"
+ fi
+ done
+ for l in ${links[*]} ; do
+ mylink=$(readlink "$l")
+ if [[ $(dirname ${mylink}) == ${from} ]] ; then
+ base=$(basename "${mylink}")
+ if [[ $base != $l ]] ; then
+ echo "Writing symlink $to/$base $l"
+ ln -sf $to/${newdir}/$base $l
+ fi
+ fi
+ done
+ cd "$savedir"
+ fi
+}
+
case $1 in
start)
# mount config if not already mounted
@@ -109,28 +198,30 @@ case $1 in
cd ${CONFIG_DIR}
if [ -f force_defaults ]; then
echo "Extracting default config files"
- tar -xvf /etc/defaults.tar.gz
+ tar -xf /etc/defaults.tar.gz
if [[ -f ${WIFITAR} ]] ; then
echo "Extract original wifi related files"
- tar -xvf ${WIFITAR}
+ tar -xf ${WIFITAR}
fi
rm -f force_defaults
fi
# Extract any missing files
- TARFILES=`tar -tf /etc/defaults.tar.gz`
+ TARFILES=$(tar -tf /etc/defaults.tar.gz)
for file in $TARFILES; do
if [ ! -e $file ]; then
- tar -xvf /etc/defaults.tar.gz $file
+ tar -xf /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"
+ if ! [[ -L /etc/$file ]] && ! [[ -d /etc/$file ]] ; then
rm -rf /etc/$file
ln -sf ${CONFIG_DIR}/$file /etc/$file
+ elif [[ -d /etc/$file ]] ; then
+ # JAK create links in directory.
+ linkdir "${CONFIG_DIR}/${file}" "/etc/${file}"
fi
done
@@ -144,52 +235,60 @@ case $1 in
fi
done
if ((dobackup==1)) ; then
+ echo "Creating backup of Config files"
tar -C /etc -czf ${CONFIG_DIR}/${WIFITAR} ${BTWIFIFILES}
fi
+ # For jffs2, you cannot remove a populated directory in an overlay.
+ # We must copy individual files and create symlinks instead.
for file in ${BTWIFIFILES}; do
- # If last character is /, make the CONFIG directory.
- if [[ ${file: -1} == / ]] ; then
- file=${file%?}
- echo directory $file operations
- if ! [[ -d ${CONFIG_DIR}/$file ]] ; then
- rm -f ${CONFIG_DIR}/$file 2>/dev/null || true
- mkdir ${CONFIG_DIR}/$file
- fi
- fi
- if [[ ! -L /etc/$file ]]; then
- echo "Creating link to ${CONFIG_DIR}/$file"
- dir=$(dirname $file)
- if [[ $dir != '.' ]] ; then
- mkdir -p "$dir"
+ isdir=0
+ # If last character is /, make the CONFIG directory.
+ if [[ ${file: -1} == / ]] ; then
+ isdir=1
+ file=${file%?}
+ if ! [[ -d ${CONFIG_DIR}/$file ]] ; then
+ rm -f ${CONFIG_DIR}/$file 2>/dev/null || true
+ mkdir ${CONFIG_DIR}/$file
+ fi
+ if [[ -d ${file} ]] ; then
+ copydir "/etc/${file}" "${CONFIG_DIR}"
+ fi
+ fi
+
+ if ((isdir == 0)); then
+ dir=$(dirname $file)
+ if [[ $dir != '.' ]] ; then
+ mkdir -p "$dir"
+ fi
+ rm -rf old
+ mkdir old
+ if ! [[ -f $file ]] ; then
+ # Need to preserve old files which is difficult with busybox!
+ if [[ -d $file ]] || [[ -f $file ]] ; then
+ cp --parents -a $file old || true
fi
+ (
+ cd /etc
+ if [[ -d $file ]] || [[ -f $file ]] ; then
+ cp --parents -a $file ${CONFIG_DIR} || true
+ fi
+ )
+ (
+ cd old
+ if [[ -d $file ]] || [[ -f $file ]] ; then
+ cp --parents -a $file .. || true
+ fi
+ )
rm -rf old
- mkdir old
- if ! [[ -f $file ]] ; then
- # Need to preserve old files which is difficult with busybox!
- if [[ -d $file ]] || [[ -f $file ]] ; then
- cp --parents -a $file old || true
- fi
- (
- cd /etc
- if [[ -d $file ]] || [[ -f $file ]] ; then
- cp --parents -a $file ${CONFIG_DIR} || true
- fi
- )
- (
- cd old
- if [[ -d $file ]] || [[ -f $file ]] ; then
- cp --parents -a $file .. || true
- fi
- )
- rm -rf old
- fi
- rm -rf /etc/$file
- ln -sf ${CONFIG_DIR}/$file /etc/$file
- fi
+ fi
+ rm -rf /etc/$file
+ ln -sf ${CONFIG_DIR}/$file /etc/$file
+ else
+ rm -f "/etc/${file}/*"
+ linkdir "${CONFIG_DIR}/${file}" "/etc/${file}"
+ fi
done
-
-
;;
*)