Skip to content

Instantly share code, notes, and snippets.

@epinna
Created May 11, 2014 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epinna/c6290b2b2c5038e8b94f to your computer and use it in GitHub Desktop.
Save epinna/c6290b2b2c5038e8b94f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Copyright notice
# ================
#
# Copyright (C) 2014
# Emilio Pinna <emilio.pinn@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Cooxie is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# Argument check
if [ $# -ne 1 ]
then
printf "Error.\nUsage: ./jffs2mount.sh <jffs2 image>\n" 1>&2
exit 1
fi
# UID check
if [[ $EUID -ne 0 ]]; then
printf "Error.\nThis script must be run as root.\n" 1>&2
exit 1
fi
# Skip if target folder already exists
mnt_folder="${1}_FS"
if [ -d "$mnt_folder" ]; then
printf "Error.\nFolder $mnt_folder already exists, skipping mount.\n" 1>&2
exit 1
fi
# Redundant module loading - who cares
modprobe mtd
modprobe jffs2
modprobe mtdram total_size=16384 erase_size=512
#modprobe mtdchar
modprobe mtdblock
# Jffs2 odd mount procedure
dd if=${1} of=/dev/mtd0
mnt_temp=`mktemp -d`
mount -t jffs2 /dev/mtdblock0 $mnt_temp
# Copy filesystem content in ${1}_FS
mkdir $mnt_folder
cp $mnt_temp/* $mnt_folder/ -rf
umount $mnt_temp
chown -R $SUDO_USER: $mnt_folder/
# Success!
printf "Success.\nData copied in $mnt_folder.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment