A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1#!/bin/sh
2
3# The updater script on the NWZ has a major bug/feature:
4# it does NOT clear the update flag if the update scrit fails
5# thus causing a update/reboot loop and a bricked device
6# always clear to make sure we don't end up being screwed
7nvpflag fup 0xFFFFFFFF
8
9#
10# FIXME document this
11#
12
13# go to /tmp
14cd /tmp
15
16# get content partition path
17CONTENTS="/contents"
18CONTENTS_PART=`mount | grep contents | awk '{ print $1 }'`
19
20lcdmsg -c -f /usr/local/bin/font_08x12.bmp -l 0,3 "Contents partition:\n$CONTENTS_PART"
21
22# We need to remount the contents partition in read-write mode be able to
23# write something on it
24lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,6 "Remount $CONTENTS rw"
25mount -o remount,rw $CONTENTS_PART $CONTENTS
26if [ "$?" != 0 ]; then
27 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: remount failed"
28 sleep 3
29 exit 0
30fi
31
32# redirect all output to a log file
33exec > "$CONTENTS/install_dualboot_log.txt" 2>&1
34
35# import constants
36. /install_script/constant.txt
37_UPDATE_FN_=`nvpstr ufn`
38ROOTFS_TMP_DIR=/tmp/rootfs
39SPIDERAPP_PATH=$ROOTFS_TMP_DIR/usr/local/bin/SpiderApp
40
41# mount root partition
42lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,7 "Mount root filesystem"
43mkdir $ROOTFS_TMP_DIR
44if [ "$?" != 0 ]; then
45 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: mkdir failed"
46 sleep 3
47 exit 0
48fi
49
50# NOTE some platforms use ext4 with a custom mount program
51# (/usr/local/bin/icx_mount.ext4), some probably use an mtd too
52# try ext3 and if it fails, try ext2
53mount -t ext3 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
54if [ "$?" != 0 ]; then
55 mount -t ext2 $COMMON_ROOTFS_PARTITION $ROOTFS_TMP_DIR
56fi
57if [ "$?" != 0 ]; then
58 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: mount failed"
59 sleep 3
60 exit 0
61fi
62
63# rename the previous main application unless there is already a copy
64lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,8 "Backup OF"
65if [ ! -e $SPIDERAPP_PATH.of ]; then
66 mv $SPIDERAPP_PATH $SPIDERAPP_PATH.of
67fi
68
69# extract our payload executable
70lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,9 "Install rockbox"
71fwpchk -f /contents/$_UPDATE_FN_.UPG -c -1 $SPIDERAPP_PATH
72if [ "$?" != 0 ]; then
73 umount "$ROOTFS_TMP_DIR"
74 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: no file to extract"
75 sleep 3
76 exit 0
77fi
78
79# make it executable and change user/group
80chmod 775 $SPIDERAPP_PATH
81if [ "$?" != 0 ]; then
82 umount "$ROOTFS_TMP_DIR"
83 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: cannot make it executable"
84 sleep 3
85 exit 0
86fi
87chown 500:500 $SPIDERAPP_PATH
88if [ "$?" != 0 ]; then
89 umount "$ROOTFS_TMP_DIR"
90 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: cannot change owner"
91 sleep 3
92 exit 0
93fi
94
95# create a symlink from /.rockbox to /contents/.rockbox (see dualboot code
96# for why)
97lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,10 "Create rockbox symlink"
98rm -f "$ROOTFS_TMP_DIR/.rockbox"
99ln -s "$CONTENTS/.rockbox" "$ROOTFS_TMP_DIR/.rockbox"
100if [ "$?" != 0 ]; then
101 umount "$ROOTFS_TMP_DIR"
102 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: cannot create rockbox symlink"
103 sleep 3
104 exit 0
105fi
106
107# change user/group
108chown -h 500:500 "$ROOTFS_TMP_DIR/.rockbox"
109if [ "$?" != 0 ]; then
110 umount "$ROOTFS_TMP_DIR"
111 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: cannot change symlink owner"
112 sleep 3
113 exit 0
114fi
115
116# unmount root partition
117lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,11 "Unmount root filesystem"
118sync
119if [ "$?" != 0 ]; then
120 umount "$ROOTFS_TMP_DIR"
121 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: sync failed"
122 sleep 3
123 exit 0
124fi
125
126umount $ROOTFS_TMP_DIR
127if [ "$?" != 0 ]; then
128 lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "ERROR: umount failed"
129 sleep 3
130 exit 0
131fi
132
133# Success screen
134lcdmsg -f /usr/local/bin/font_08x12.bmp -l 0,15 "Rebooting in 3 seconds."
135sleep 3
136sync
137
138echo "Installation successful"
139# finish
140exit 0