sinn3r
Participant
2019-09-17 at 19:45
Post count: 368
Das hier ist der Code zum Upgrade, es sieht so aus, als würde er recht weit kommen, allerdings fehlt bei Dir die “factoryreset.bef”.
Daher vermute ich, dass der Stick nicht korrekt bespielt wurde.
Beschreibe den nochmal mit “Auf Werkseinstellung zurücksetzen”, sonst formatiert er den Speicher nicht.
#!/bin/sh
# state:
# 1 => hardware detection ok
# 2 => usb ok upgrade
# 3 => usb ok downgrade
# 4 => usb ok eingehangen
# fwstate
# 2=>4.8-
# 3=>4.9+
hs=0
state=0
fwstate=0
check_fw_sources() {
echo "check firmware sources..."
result=0
if [ -f /tmp/upload/firmware/hs.hashes ]; then
echo "- firmware found"
cd /tmp/upload/firmware/
busybox sha256sum -cs hs.hashes
if [ $? -eq 0 ]; then
echo "- firmware: ok"
result=1
if [ -f /tmp/upload/frproject/stamm.dat ]; then
echo "- project found"
cd /tmp/upload/frproject/
result=2
for fn in "stamm.dat" "stammpw.dat" "putemerg.dat" "putemergpw.dat"
do
if [ -f ${fn} ]; then
busybox sha256sum -cs ${fn}.hash
if [ $? -eq 0 ]; then
echo "- project file ${fn}: OK"
else
echo "- project file ${fn}: FAIlED"
result=1
break
fi
fi
done
fi
fi
fi
return ${result}
}
error_signal() {
for i in 1 2 3 4 5 6
do
echo -ne "\a"
sleep 0.3
done
}
fin_signal() {
for i in 1 2 3 4 5 6
do
echo -ne "\a"
sleep 0.3
done
}
echo "check device"
fname="/sys/devices/virtual/dmi/id/product_serial"
if [ -f ${fname} ]; then
prodid=<code>cat ${fname}|cut -c1-8|tr "a-z" "A-Z"</code>
[ "${prodid}" = "000AB302" ] && hs=1
[ "${prodid}" = "000AB304" ] && hs=2
[ "${prodid}" = "000AB3E2" ] && hs=3
fi
if [ ${hs} -eq 0 ]; then
echo "hs/fs not found"
error_signal
exit
fi
# check device
echo "check version"
if [ -b /dev/sda4 ]; then
echo "detecting version 4.8 or older, check files..."
[ -d /sda2 ] || mkdir /sda2
mount -t vfat /dev/sda2 /sda2
if [ -f /sda2/DOLINUX2.BAT ]; then
echo "version 4.8 or older found."
fwstate=2
state=1
fi
umount /sda2
rmdir /sda2
elif [ -b /dev/sda1 -a ! -b /dev/sda4 ]; then
echo "detecting version 4.9 or newer, check files..."
state=1
[ -d /sda1 ] || mkdir /sda1
mount -t ext4 -o noatime /dev/sda1 /sda1
if [ -d /sda1/hsdata/project/ -a -d /sda1/boot/ ]; then
# hs version 4.9+
echo "version 4.9 or newer found."
fwstate=3
fi
umount /sda1
rmdir /sda1
else
echo "unkown device"
ls -l /dev/sd*
echo "---"
fi
if [ ${state} -eq 1 ]; then
# mount usb device
echo "try to mount usb device..."
[ -d /usb ] || mkdir -p /usb
sleep 2
for i in $(seq 1 60)
do
if [ -b /dev/sdb1 ]; then
mount -t vfat /dev/sdb1 /usb 2>&1
if [ $? -eq 0 ]; then
echo "usb device ok"
state=4
if [ -f /usb/upload.hs ]; then
echo "usb device for reset/update/project detected"
state=2
fi
if [ -f /usb/downgrade/p1 -a -f /usb/downgrade/p2 -a -f /usb/downgrade/p3 ]; then
echo "usb device for downgrade detected"
state=3
fi
break
fi
else
echo "device /dev/sdb1 does not exist"
fi
if [ ${state} -ne 2 ]; then
sleep 1
fi
done
fi
if [ ${state} -eq 2 -a -f /usb/upload.hs ]; then
mkdir -p /tmp/upload
rm -rf /tmp/upload/*
unzip -q -o /usb/upload.hs -d /tmp/upload
if [ -f /tmp/upload/factoryreset.bef ]; then
# factory reset 4.9+
echo "factory reset detected..."
check_fw_sources
ok=$?
if [ ${ok} -eq 2 ]; then
echo "- reset storage..."
dd if=/dev/zero of=/dev/sda bs=1M
echo "- create partitions..."
echo -e "n\np\n1\n\n\nw\n" | fdisk /dev/sda >/dev/tty5
sync
echo -e "t\n83\nw\n" | fdisk /dev/sda >/dev/tty5
sync
echo "- format..."
/sbin/mkfs.ext4 /dev/sda1 >/dev/tty5
sync
echo "- set boot flag..."
echo -e "a\n1\nw\n" | fdisk /dev/sda >/dev/tty5
sync
echo "- write mbr..."
install-mbr -v -p 1 -i n /dev/sda
sync
echo "- copy files"
mkdir /sda1
mount -t ext4 -o noatime /dev/sda1 /sda1
extlinux -i /sda1
mkdir -p -m 750 /sda1/boot0/
mkdir -p -m 750 /sda1/boot1/
ln -s boot0 /sda1/boot
mkdir -p /sda1/hsdata/project
mkdir -p -m 750 /sda1/hsdata/remanent
chown 1000.1000 /sda1/hsdata/remanent
mkdir -p -m 755 /sda1/hsdata/cert
mkdir -p -m 755 /sda1/hsdata/ntp
chown 101.101 /sda1/hsdata/ntp
cp -R /tmp/upload/firmware/* /sda1/boot/
cp -R /tmp/upload/frproject/* /sda1/hsdata/project/
for fn in "stammpw.dat" "putemergpw.dat"
do
if [ -f /sda1/hsdata/project/${fn} ]; then
echo "chmod for ${fn}"
chmod 400 /sda1/hsdata/project/${fn}
fi
done
cd /sda1/boot/
sha256sum -c hs.hashes
cd /sda1/hsdata/project/
for fn in "stamm.dat" "stammpw.dat" "putemerg.dat" "putemergpw.dat"
do
sha256sum -c ${fn}.hash
done
cd /
umount /sda1
rmdir /sda1
sleep 1
echo "check partitions..."
/sbin/fsck.ext4 -p /dev/sda1
else
echo "missing files and/or corrupt files found (${ok})"
fi
elif [ -f /tmp/upload/update.bef -a ${fwstate} -eq 3 ]; then
# fw update 4.9+
echo "update detected..."
check_fw_sources
ok=$?
if [ ${ok} -eq 1 ]; then
echo "copy firmware files..."
[ -d /sda1 ] || mkdir /sda1
mount -t ext4 -o noatime /dev/sda1 /sda1
rm -rf /sda1/boot/*
cp -R /tmp/upload/firmware/* /sda1/boot/
umount /sda1
rmdir /sda1
else
echo "missing files and/or corrupt files found (${ok})"
fi
fi
if [ -f /tmp/upload/project.bef -a ${fwstate} -eq 3 ]; then
echo "project file found"
[ -d /sda1 ] || mkdir /sda1
mount -t ext4 -o noatime /dev/sda1 /sda1
diff -q -w -i -B -b /tmp/upload/project/version.dat /sda1/boot/project.version
if [ $? -eq 0 ]; then
echo "- version correct"
if [ -f /tmp/upload/project/stamm.dat ]; then
echo "- project file found"
rm -rf /sda1/hsdata/project/*
cp /tmp/upload/project/stamm.dat /sda1/hsdata/project/
cp /tmp/upload/project/stamm.dat.hash /sda1/hsdata/project/
if [ -f /tmp/upload/project/stammpw.dat ]; then
echo "- project (pw) found"
cp /tmp/upload/project/stammpw.dat /sda1/hsdata/project/
cp /tmp/upload/project/stammpw.dat.hash /sda1/hsdata/project/
chmod 400 /sda1/hsdata/project/stammpw.dat
fi
if [ -f /tmp/upload/project/data.bef ]; then
echo "- project data found"
cp -R /tmp/upload/project/dat /sda1/hsdata/project/
fi
if [ -f /tmp/upload/project/putemerg.dat ]; then
echo "- emergency project found"
cp /tmp/upload/project/putemerg.dat /sda1/hsdata/project/
cp /tmp/upload/project/putemerg.dat.hash /sda1/hsdata/project/
if [ -f /tmp/upload/project/putemergpw.dat ]; then
echo "- emergency project (pw) found"
cp /tmp/upload/project/putemergpw.dat /sda1/hsdata/project/
cp /tmp/upload/project/putemergpw.dat.hash /sda1/hsdata/project/
chmod 400 /sda1/hsdata/project/putemergpw.dat
fi
fi
fi
if [ -f /tmp/upload/project/delrem.bef ]; then
echo "- remove storage"
rm -rf /sda1/hsdata/remanent/*
fi
if [ -f /tmp/upload/project/delcert.bef ]; then
echo "- remove certificates"
rm -rf /sda1/hsdata/cert/*
fi
echo "copy finished"
else
echo "- versions not identical"
fi
umount /sda1
rmdir /sda1
fi
elif [ ${state} -eq 3 -a -d /usb/downgrade ]; then
ok=0
if [ -f /usb/downgrade/hashes ]; then
echo "check files"
cd /usb/downgrade/
busybox sha256sum -c hashes
if [ $? -eq 0 ]; then
echo "- hashes: ok"
ok=1
fi
cd /
else
ok=1
fi
if [ ${ok} -eq 1 ]; then
echo "- reset storage"
dd if=/dev/zero of=/dev/sda bs=1M
size=<code>fdisk -l /dev/sda|grep "Disk /dev/sda:"|awk -F' ' '{print $5}'</code>
echo "- disk size: ${size}"
if [ ${size} -ge 4000000000 ]; then
echo "- partitioning (4GB)..."
echo -e "n\np\n1\n\n2\nn\np\n2\n\n+200M\nn\np\n3\n\n+1840M\nn\np\n\n\n\nw\n" | fdisk /dev/sda
else
echo "- partitioning (2GB)..."
echo -e "n\np\n1\n\n2\nn\np\n2\n\n+100M\nn\np\n3\n\n+920M\nn\np\n\n\n\nw\n" | fdisk /dev/sda
fi
sleep 2
echo -e "t\n1\n6\nt\n2\n6\nw\n" | fdisk /dev/sda
sleep 5
echo "- write partition 1"
dd if=/usb/downgrade/p1 of=/dev/sda1
echo "- write partition 2"
mkdosfs -F 16 /dev/sda2
sync
echo -e "a\n1\nw\n" | fdisk /dev/sda
sleep 5
mkdir -p /sda2
mount -t vfat /dev/sda2 /sda2
unzip /usb/downgrade/p2 -d /sda2/
umount /sda2
echo "- write partition 3"
dd if=/usb/downgrade/p3 of=/dev/sda3
echo "- write mbr"
install-mbr -v -p 1 -i n /dev/sda
echo "check partitions"
fsck.fat -a -w /dev/sda1
fsck.fat -a -w /dev/sda2
fi
fi
if [ ${state} -ge 2 ]; then
echo "unmount usb device..."
umount /usb
rmdir /usb
fi
# finished, wait for reboot
echo "wait for reboot, remove usb or shutdown..."
while :
do
fin_signal
sleep 10
if [ ! -b /dev/sdb1 ]; then
echo "usb device removed, reboot..."
echo -ne "\a"
sleep 0.3
break
else
sleep 20
fi
done
reboot