summaryrefslogtreecommitdiff
path: root/scripts/upgrade/install.sh
blob: 4928d8842251a7f04572d033db0524cbb5c6422e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# This script works with a tar archvie
# called upgrade.bin in either /var/volatile
# or on the SD card.
#
# This is what the tar file upgrade file
# should look like to create an ipk upgrade
# file.  IPK files should be in all,
# arm926ejste, and mtcdt (for mtcdt)
cat <<'!EOF' >/dev/null
.
|-- install_list.txt
|-- install_list.txt.md5
|-- install.sh*
|-- install.sh.md5
|-- local.conf
|-- local.conf.md5
|-- model
|-- repo/
|   |-- arm926ejste/
|   |   |-- busybox_1.24.1-r0.mlinux2.mlinux2.1_arm926ejste.ipk
|   |   |-- busybox-hwclock_1.24.1-r0.mlinux2.mlinux2.1_arm926ejste.ipk
|   |   |-- busybox-ifplugd_1.24.1-r0.mlinux2.mlinux2.1_arm926ejste.ipk
|   |   |-- busybox-syslog_1.24.1-r0.mlinux2.mlinux2.1_arm926ejste.ipk
|   |   |-- busybox-udhcpc_1.24.1-r0.mlinux2.mlinux2.1_arm926ejste.ipk
|   |   |-- initscripts_1.0-r155.3.40.0_arm926ejste.ipk
|   |   |-- initscripts-functions_1.0-r155.3.40.0_arm926ejste.ipk
|   |   |-- Packages
|   |   |-- Packages.gz
|   |   `-- Packages.stamps
|   `-- Packages
!EOF
#
# The tarball must be called upgrade.bin.
#
# The file /var/volatile/do_flash_upgrade must exist and
# be owned by root.
#
# The tar file, upgrade.bin must be either in
# /var/volatile/flash-upgrade or
# /media/card/flash-upgrade
#
# Note that when this script is started, the
# tar file is already unpacked, since this script
# is in the tarball.

# This script assumes that the rootfs and maybe /var
# are writable.  For MTR, we may need to set
# root and var to read/write

NAME=install.sh
echo "$NAME starting"

umount_all() {
  if [[ $1 == "error" ]] ; then
    echo "Cannot continue"
    err_leds
    sleep 10
  fi
  echo "Deactivating swap..."
  swapoff -a

  # We leave /proc mounted.
  echo "Unmounting local filesystems..."
  grep -q /mnt/ram /proc/mounts && mount -o remount,ro /mnt/ram
  umount -f -a -r > /dev/null 2>&1

  mount -o remount,ro /
  ${up_dir}/upgrade-reboot

  # Should not get here normally
  echo "upgrade-reboot failed"
  /sbin/reboot
  exit 1
}
err_leds() {
  led_dir=/sys/class/leds
  # blink all programmable LEDs except status
  leds=$(ls $led_dir/ | grep -v status)
  nleds=$(echo "$leds" | wc -w)

  # turn LEDs off
  for led in $leds; do
      echo "timer" > $led_dir/$led/trigger
      echo 0  > $led_dir/$led/delay_off
  done

  int=200
  total=$(( int * (nleds+1) ))
  on=$(( total - int ))
  off=$(( total - on ))

  # make a pattern
  for led in $leds; do
      echo "$on"  > $led_dir/$led/delay_on
      echo "$off"  > $led_dir/$led/delay_off
  done
  sleep 5
}
flash_dir="$1"
up_dir="${flash_dir}/flash-upgrade"
if ! [[ -d ${up_dir} ]] ; then
    echo "\"${up_dir}\" is not present"
    umount_all error
fi
echo "ls -l ${flash_dir}"
ls -l ${flash_dir}
echo "ls -l ${up_dir}"
ls -l "${up_dir}"
cd "${up_dir}"
if ! md5sum -c local.conf.md5 >/dev/null ; then
   echo "md5sum of local.conf is bad"
    umount_all error
fi

# opkg needs /tmp, so recreate it.
# On a Conduit, this is always /var/volatile
mkdir -m 01777 /var/volatile/tmp
localcnf="${up_dir}/local.conf"
echo "Local configuration file: ${localcnf}"
echo mounts ...
cat /proc/mounts
echo "Update package list ... /usr/bin/opkg -f ${localcnf} update"
/usr/bin/opkg -f "${localcnf}" update
echo "List upgradable packages ... /usr/bin/opkg -f ${localcnf} list-upgradable"
/usr/bin/opkg -f "${localcnf}" list-upgradable
echo "Do package upgrade /usr/bin/opkg -f ${localcnf} upgrade"
/usr/bin/opkg -f "${localcnf}" upgrade
pkglist_file="install_list.txt"
if [[ -r ${pkglist_file} ]] ; then
    if ! md5sum -c ${pkglist_file}.md5 ; then
        echo "md5sum bad on ${pkglist_file}"
        umount_all error
    fi
    OIFS="${IFS}"
    IFS=$'\n'
    for p in $(cat ${pkglist_file}) ; do
        echo /usr/bin/opkg -f "${localcnf}" install $p
        /usr/bin/opkg -f "${localcnf}" install $p
    done
    IFS="${OIFS}"
fi
echo "Rebooting..."

umount_all ok
echo "upgrade-reboot failed"
exit 1