Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: tools/raspberry-pi2/prepare-image.sh

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/promote.py ('k') | tools/raspberry-pi2/qemufy-image.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 # Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file 2 # Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE.md file. 4 # BSD-style license that can be found in the LICENSE.md file.
5 # 5 #
6 # Script for preparing the Raspberry Pi2 image with the fletch agent. 6 # Script for preparing the Raspberry Pi2 image with the dartino agent.
7 # 7 #
8 # You need 8 # You need
9 # $ sudo apt-get qemu qemu-user-static binfmt-support 9 # $ sudo apt-get qemu qemu-user-static binfmt-support
10 # to run this. 10 # to run this.
11 # 11 #
12 # This must run in the fletch directory. 12 # This must run in the dartino directory.
13 # 13 #
14 # The fletch-agent package must be build before running this, so to 14 # The dartino-agent package must be build before running this, so to
15 # create an image do the following: 15 # create an image do the following:
16 # 16 #
17 # $ tools/create_tarball.py 17 # $ tools/create_tarball.py
18 # $ tools/create_debian_packages.py 18 # $ tools/create_debian_packages.py
19 # $ tools/raspberry_pi2/raspberry-pi2/prepare-image.sh <version> 19 # $ tools/raspberry_pi2/raspberry-pi2/prepare-image.sh <version>
20 # 20 #
21 # Some errors are printed while running in the chroot, e.g. 21 # Some errors are printed while running in the chroot, e.g.
22 # 22 #
23 # Unsupported setsockopt level=1 optname=34 23 # Unsupported setsockopt level=1 optname=34
24 # sudo: unable to resolve host <your hostname> 24 # sudo: unable to resolve host <your hostname>
(...skipping 14 matching lines...) Expand all
39 IMAGE_ZIP_FILE=${IMAGE_ROOT_NAME}.zip 39 IMAGE_ZIP_FILE=${IMAGE_ROOT_NAME}.zip
40 IMAGE_FILE=${IMAGE_ROOT_NAME}.img 40 IMAGE_FILE=${IMAGE_ROOT_NAME}.img
41 41
42 PI_USER_ID=1000 42 PI_USER_ID=1000
43 PI_GROUP_ID=1000 43 PI_GROUP_ID=1000
44 PI_HOME=/home/pi 44 PI_HOME=/home/pi
45 45
46 function usage { 46 function usage {
47 USAGE="Usage: $0 version\n 47 USAGE="Usage: $0 version\n
48 \n 48 \n
49 The first mandatory argument speciifies the version of the fletch-agent\n 49 The first mandatory argument speciifies the version of the dartino-agent\n
50 to install into the image." 50 to install into the image."
51 51
52 echo -e $USAGE 52 echo -e $USAGE
53 exit 1 53 exit 1
54 } 54 }
55 55
56 # Expect exactly one argument, the version. 56 # Expect exactly one argument, the version.
57 if [ $# -ne 1 ] 57 if [ $# -ne 1 ]
58 then 58 then
59 usage 59 usage
60 fi 60 fi
61 61
62 VERSION=$1 62 VERSION=$1
63 TARBALL_FILE=fletch-${VERSION}.tar.gz 63 TARBALL_FILE=dartino-${VERSION}.tar.gz
64 DEB_FILE=fletch-agent_${VERSION}-1_armhf.deb 64 DEB_FILE=dartino-agent_${VERSION}-1_armhf.deb
65 65
66 MOUNT_DIR=out/raspbian 66 MOUNT_DIR=out/raspbian
67 67
68 # Get and unzip the image. 68 # Get and unzip the image.
69 echo "Downloading image ZIP file" 69 echo "Downloading image ZIP file"
70 download_from_google_storage.py -c -b dart-dependencies-fletch \ 70 download_from_google_storage.py -c -b dart-dependencies-fletch \
71 -o out/${IMAGE_ZIP_FILE} -s tools/raspberry-pi2/${IMAGE_SHA_FILE} 71 -o out/${IMAGE_ZIP_FILE} -s tools/raspberry-pi2/${IMAGE_SHA_FILE}
72 echo "Unzipping image file" 72 echo "Unzipping image file"
73 unzip -q -o -d out out/$IMAGE_ZIP_FILE 73 unzip -q -o -d out out/$IMAGE_ZIP_FILE
74 74
(...skipping 11 matching lines...) Expand all
86 sudo cp out/$TARBALL_FILE $MOUNT_DIR/$PI_HOME 86 sudo cp out/$TARBALL_FILE $MOUNT_DIR/$PI_HOME
87 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/$PI_HOME/$TARBALL_FILE 87 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/$PI_HOME/$TARBALL_FILE
88 88
89 # Copy the QEMU user emulation binary the the chroot. 89 # Copy the QEMU user emulation binary the the chroot.
90 sudo cp /usr/bin/qemu-arm-static $MOUNT_DIR/usr/bin 90 sudo cp /usr/bin/qemu-arm-static $MOUNT_DIR/usr/bin
91 91
92 # Put /etc/ld.so.preload away. It links in code which does not run 92 # Put /etc/ld.so.preload away. It links in code which does not run
93 # through qemu-arm-static. 93 # through qemu-arm-static.
94 sudo mv $MOUNT_DIR/etc/ld.so.preload $MOUNT_DIR/tmp 94 sudo mv $MOUNT_DIR/etc/ld.so.preload $MOUNT_DIR/tmp
95 95
96 # Copy the fletch-agent .deb file to the chroot. 96 # Copy the dartino-agent .deb file to the chroot.
97 cp out/$DEB_FILE $MOUNT_DIR/tmp 97 cp out/$DEB_FILE $MOUNT_DIR/tmp
98 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/tmp/$DEB_FILE 98 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/tmp/$DEB_FILE
99 99
100 # Copy the fletch-configuration service script to the chroot. 100 # Copy the dartino-configuration service script to the chroot.
101 cp tools/raspberry-pi2/raspbian-scripts/fletch-configuration $MOUNT_DIR/tmp 101 cp tools/raspberry-pi2/raspbian-scripts/dartino-configuration $MOUNT_DIR/tmp
102 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/tmp/fletch-configuration 102 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/tmp/dartino-configuration
103 103
104 # Create /usr/sbin/policy-rc.d which return 101 to avoid starting the 104 # Create /usr/sbin/policy-rc.d which return 101 to avoid starting the
105 # fletch-agent when installing it, see: 105 # dartino-agent when installing it, see:
106 # https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt 106 # https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt
107 sudo sh -c 'cat << EOF > $0/usr/sbin/policy-rc.d 107 sudo sh -c 'cat << EOF > $0/usr/sbin/policy-rc.d
108 #!/bin/sh 108 #!/bin/sh
109 exit 101 109 exit 101
110 EOF' $MOUNT_DIR 110 EOF' $MOUNT_DIR
111 sudo chmod u+x $MOUNT_DIR/usr/sbin/policy-rc.d 111 sudo chmod u+x $MOUNT_DIR/usr/sbin/policy-rc.d
112 112
113 # Create trampoline script for running the initialization as user pi. 113 # Create trampoline script for running the initialization as user pi.
114 cat << EOF > $MOUNT_DIR/tmp/init_chroot_trampoline.sh 114 cat << EOF > $MOUNT_DIR/tmp/init_chroot_trampoline.sh
115 #!/bin/sh 115 #!/bin/sh
116 su -c /tmp/init_chroot.sh pi 116 su -c /tmp/init_chroot.sh pi
117 EOF 117 EOF
118 118
119 # Create the initialization script which installs the fletch-agent 119 # Create the initialization script which installs the dartino-agent
120 # package. 120 # package.
121 cat << EOF > $MOUNT_DIR/tmp/init_chroot.sh 121 cat << EOF > $MOUNT_DIR/tmp/init_chroot.sh
122 #!/bin/sh 122 #!/bin/sh
123 123
124 cd /tmp 124 cd /tmp
125 125
126 # Install the fletch-agent Debian package. 126 # Install the dartino-agent Debian package.
127 sudo dpkg -i $DEB_FILE 127 sudo dpkg -i $DEB_FILE
128 128
129 # Install the fletch-configuration service script. 129 # Install the dartino-configuration service script.
130 sudo cp /tmp/fletch-configuration /etc/init.d 130 sudo cp /tmp/dartino-configuration /etc/init.d
131 sudo chown root:root /etc/init.d/fletch-configuration 131 sudo chown root:root /etc/init.d/dartino-configuration
132 sudo chmod 755 /etc/init.d/fletch-configuration 132 sudo chmod 755 /etc/init.d/dartino-configuration
133 sudo insserv fletch-configuration 133 sudo insserv dartino-configuration
134 sudo update-rc.d fletch-configuration enable 134 sudo update-rc.d dartino-configuration enable
135 135
136 EOF 136 EOF
137 137
138 chmod u+x $MOUNT_DIR/tmp/init_chroot_trampoline.sh 138 chmod u+x $MOUNT_DIR/tmp/init_chroot_trampoline.sh
139 sudo chown 0:0 $MOUNT_DIR/tmp/init_chroot_trampoline.sh 139 sudo chown 0:0 $MOUNT_DIR/tmp/init_chroot_trampoline.sh
140 140
141 chmod u+x $MOUNT_DIR/tmp/init_chroot.sh 141 chmod u+x $MOUNT_DIR/tmp/init_chroot.sh
142 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/tmp/init_chroot.sh 142 sudo chown $PI_USER_ID:$PI_GROUP_ID $MOUNT_DIR/tmp/init_chroot.sh
143 143
144 # chroot into the Raspbian image and run the required commands. 144 # chroot into the Raspbian image and run the required commands.
145 echo "Running chroot" 145 echo "Running chroot"
146 sudo chroot $MOUNT_DIR /bin/sh /tmp/init_chroot_trampoline.sh 146 sudo chroot $MOUNT_DIR /bin/sh /tmp/init_chroot_trampoline.sh
147 147
148 echo "Cleanup" 148 echo "Cleanup"
149 149
150 # Restore /etc/ld.so.preload 150 # Restore /etc/ld.so.preload
151 sudo mv $MOUNT_DIR/tmp/ld.so.preload $MOUNT_DIR/etc 151 sudo mv $MOUNT_DIR/tmp/ld.so.preload $MOUNT_DIR/etc
152 152
153 # Clean up temporary files 153 # Clean up temporary files
154 sudo rm $MOUNT_DIR/usr/bin/qemu-arm-static 154 sudo rm $MOUNT_DIR/usr/bin/qemu-arm-static
155 sudo rm $MOUNT_DIR//usr/sbin/policy-rc.d 155 sudo rm $MOUNT_DIR//usr/sbin/policy-rc.d
156 sudo rm $MOUNT_DIR/tmp/* 156 sudo rm $MOUNT_DIR/tmp/*
157 157
158 sudo umount $MOUNT_DIR 158 sudo umount $MOUNT_DIR
159 rmdir $MOUNT_DIR 159 rmdir $MOUNT_DIR
160 160
161 # Rename and zip the resulting image file. 161 # Rename and zip the resulting image file.
162 RESULT_IMAGE_ROOT=${IMAGE_ROOT_NAME}-fletch-${VERSION} 162 RESULT_IMAGE_ROOT=${IMAGE_ROOT_NAME}-dartino-${VERSION}
163 RESULT_IMAGE_FILE=${RESULT_IMAGE_ROOT}.img 163 RESULT_IMAGE_FILE=${RESULT_IMAGE_ROOT}.img
164 RESULT_IMAGE_ZIP_FILE=${RESULT_IMAGE_ROOT}.zip 164 RESULT_IMAGE_ZIP_FILE=${RESULT_IMAGE_ROOT}.zip
165 mv out/$IMAGE_FILE out/$RESULT_IMAGE_FILE 165 mv out/$IMAGE_FILE out/$RESULT_IMAGE_FILE
166 zip --junk-paths out/$RESULT_IMAGE_ZIP_FILE out/$RESULT_IMAGE_FILE 166 zip --junk-paths out/$RESULT_IMAGE_ZIP_FILE out/$RESULT_IMAGE_FILE
OLDNEW
« no previous file with comments | « tools/promote.py ('k') | tools/raspberry-pi2/qemufy-image.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698