pilc-bootstrap.sh 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. #!/bin/sh
  2. #
  3. # PiLC bootstrap
  4. #
  5. # Copyright 2016-2019 Michael Buesch <m@bues.ch>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. basedir="$(dirname "$0")"
  22. [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
  23. # The repository root is basedir.
  24. basedir="$basedir/.."
  25. MAIN_MIRROR="http://mirrordirector.raspbian.org/raspbian/"
  26. #MAIN_MIRROR="http://mirror1.hs-esslingen.de/pub/Mirrors/archive.raspbian.org/raspbian/"
  27. #MAIN_MIRROR="http://ftp.gwdg.de/pub/linux/debian/raspbian/raspbian/"
  28. DEFAULT_SUITE=buster
  29. KEYRING_VERSION="20120528.2"
  30. KEYRING_BASEURL="$MAIN_MIRROR/pool/main/r/raspbian-archive-keyring"
  31. KEYRING_TGZ_FILE="raspbian-archive-keyring_${KEYRING_VERSION}.tar.gz"
  32. KEYRING_TGZ_SHA256="fdf50f775b60901a2783f21a6362e2bf5ee6203983e884940b163faa1293c002"
  33. PPL_VERSION="0.1.1"
  34. PPL_FILE="ppl_v$PPL_VERSION.zip"
  35. PPL_MIRROR="./libs/pixtend/v1/ppl/$PPL_FILE"
  36. PPL_SHA256="103edcdbc377f8b478fcbc89117cbad143500c611cb714568f55513cece220d4"
  37. PPL2_VERSION="0.1.3"
  38. PPL2_FILE="pplv2_v$PPL2_VERSION.zip"
  39. PPL2_MIRROR="./libs/pixtend/v2/pplv2/$PPL2_FILE"
  40. PPL2_SHA256="cab6e7cd9062ffbf81a8f570ea0cad663addd8fe22e31cb75e887ae89e425651"
  41. info()
  42. {
  43. echo "--- $*"
  44. }
  45. error()
  46. {
  47. echo "=== ERROR: $*" >&2
  48. }
  49. warning()
  50. {
  51. echo "=== WARNING: $*" >&2
  52. }
  53. die()
  54. {
  55. error "$*"
  56. exit 1
  57. }
  58. # print the first of its arguments.
  59. first()
  60. {
  61. echo "$1"
  62. }
  63. # print the last of its arguments.
  64. last()
  65. {
  66. while [ $# -gt 1 ]; do shift; done
  67. echo "$1"
  68. }
  69. # $1=program_name
  70. have_program()
  71. {
  72. which "$1" >/dev/null 2>&1
  73. }
  74. # $1=program_name, ($2=description)
  75. assert_program()
  76. {
  77. local bin="$1"
  78. local desc="$2"
  79. [ -n "$desc" ] || desc="$bin"
  80. have_program "$bin" || die "$bin not found. Please install $desc."
  81. }
  82. term_signal()
  83. {
  84. die "Terminating signal received"
  85. }
  86. cleanup()
  87. {
  88. info "Cleaning up..."
  89. for mp in "$mp_shm" "$mp_proc_binfmt_misc" "$mp_proc" "$mp_sys" "$mp_bootimgfile" "$mp_rootimgfile"; do
  90. [ -n "$mp" -a -d "$mp" ] &&\
  91. umount -l "$mp" >/dev/null 2>&1
  92. done
  93. for mp in "$mp_bootimgfile" "$mp_rootimgfile"; do
  94. [ -n "$mp" -a -d "$mp" ] &&\
  95. rmdir "$mp" >/dev/null 2>&1
  96. done
  97. }
  98. do_install()
  99. {
  100. install "$@" || die "Failed install $*"
  101. }
  102. do_systemctl()
  103. {
  104. info "systemctl $*"
  105. systemctl "$@" || die "Failed to systemctl $*"
  106. }
  107. write_image()
  108. {
  109. local image="$1"
  110. local dev="$2"
  111. [ -b "$dev" ] || die "$dev is not a block device"
  112. mount | grep -q "$dev" && die "$dev is mounted. Refusing to write to it!"
  113. if have_program blkdiscard; then
  114. info "Discarding $dev ..."
  115. blkdiscard "$dev" ||\
  116. error "blkdiscard failed."
  117. else
  118. warning "Skipping discard. blkdiscard not installed."
  119. fi
  120. info "Writing $image to $dev ..."
  121. dd if="$image" of="$dev" bs=32M status=progress ||\
  122. die "Failed to write image."
  123. }
  124. download()
  125. {
  126. local target="$1"
  127. local mirror="$2"
  128. local sha256="$3"
  129. info "Downloading $mirror..."
  130. rm -f "$target"
  131. if printf '%s' "$mirror" | grep -qe '^\./'; then
  132. # "mirror" starts with ./
  133. # This is a local file in the repository.
  134. cp "$basedir/$mirror" "$target" || die "Failed to fetch $mirror"
  135. else
  136. # Download the file
  137. wget -O "$target" "$mirror" || die "Failed to fetch $mirror"
  138. fi
  139. [ "$(sha256sum -b "$target" | cut -f1 -d' ')" = "$sha256" ] ||\
  140. die "SHA256 verification of $target failed"
  141. }
  142. extract_archive()
  143. {
  144. local archive="$1"
  145. local extract_dir="$2"
  146. local make_extract_dir="$3"
  147. if [ $make_extract_dir -ne 0 ]; then
  148. mkdir "$extract_dir" ||\
  149. die "Failed to create directory $extract_dir"
  150. fi
  151. if printf '%s' "$archive" | grep -qEe '\.zip$'; then
  152. if [ $make_extract_dir -ne 0 ]; then
  153. unzip -d "$extract_dir" "$archive" ||\
  154. die "Failed to unpack $archive"
  155. else
  156. unzip "$archive" ||\
  157. die "Failed to unpack $archive"
  158. fi
  159. else
  160. if [ $make_extract_dir -ne 0 ]; then
  161. tar --one-top-level="$extract_dir" -xf "$archive" ||\
  162. die "Failed to unpack $archive"
  163. else
  164. tar -xf "$archive" ||\
  165. die "Failed to unpack $archive"
  166. fi
  167. fi
  168. }
  169. build_pythonpack()
  170. {
  171. local python="$1"
  172. local name="$2"
  173. local archive="$3"
  174. local extract_dir="$4"
  175. local make_extract_dir="$5"
  176. info "Building $name for $python..."
  177. rm -rf "/tmp/$extract_dir"
  178. (
  179. cd /tmp || die "Failed to cd /tmp"
  180. extract_archive "$archive" "$extract_dir" "$make_extract_dir"
  181. cd "$extract_dir" ||\
  182. die "Failed to cd $extract_dir"
  183. "$python" ./setup.py install ||\
  184. die "Failed to install $name"
  185. ) || die
  186. rm -r "/tmp/$extract_dir" ||\
  187. die "Failed to remove $name build files."
  188. }
  189. build_ppl()
  190. {
  191. local archive="$PPL_FILE"
  192. for python in python3; do
  193. build_pythonpack "$python" "ppl-$PPL_VERSION" \
  194. "$archive" "ppl-$PPL_VERSION" 1
  195. done
  196. rm "/tmp/$archive" ||\
  197. die "Failed to remove /tmp/$archive."
  198. }
  199. build_ppl2()
  200. {
  201. local archive="$PPL2_FILE"
  202. for python in python3; do
  203. build_pythonpack "$python" "ppl2-$PPL2_VERSION" \
  204. "$archive" "ppl2-$PPL2_VERSION" 1
  205. done
  206. rm "/tmp/$archive" ||\
  207. die "Failed to remove /tmp/$archive."
  208. }
  209. pilc_bootstrap_first_stage()
  210. {
  211. echo "Running first stage..."
  212. [ "$(id -u)" = "0" ] || die "Permission denied. Must be root."
  213. # Check host tools (first/third stage).
  214. assert_program 7z
  215. assert_program chroot
  216. assert_program dd
  217. assert_program debootstrap
  218. assert_program git
  219. assert_program gpg
  220. assert_program install
  221. assert_program mkfs.ext4
  222. assert_program mkfs.vfat
  223. assert_program parted
  224. assert_program rsync
  225. assert_program setarch
  226. assert_program tar
  227. assert_program unzip
  228. assert_program wget
  229. [ -x "$opt_qemu" ] ||\
  230. die "The qemu binary '$opt_qemu' is not executable."
  231. info "Cleaning tmp..."
  232. rm -rf "$opt_target_dir"/tmp/*
  233. do_install -d -o root -g root -m 1777 "$opt_target_dir/tmp"
  234. info "Downloading and extracting keys..."
  235. do_install -o root -g root -m 644 \
  236. "$basedir_pilc/CF8A1AF502A2AA2D763BAE7E82B129927FA3303E.gpg" \
  237. "$opt_target_dir/tmp/"
  238. download "$opt_target_dir/tmp/$KEYRING_TGZ_FILE" \
  239. "$KEYRING_BASEURL/$KEYRING_TGZ_FILE" \
  240. "$KEYRING_TGZ_SHA256"
  241. tar -C "$opt_target_dir/tmp" -x -f "$opt_target_dir/tmp/$KEYRING_TGZ_FILE" ||\
  242. die "Failed to extract keys."
  243. local raspbian_asc="$opt_target_dir/tmp/raspbian-archive-keyring-$KEYRING_VERSION/raspbian.public.key"
  244. local raspbian_gpg="$raspbian_asc.gpg"
  245. gpg --dearmor < "$raspbian_asc" > "$raspbian_gpg" ||\
  246. die "Failed to convert key."
  247. # debootstrap first stage.
  248. if [ $opt_skip_debootstrap1 -eq 0 ]; then
  249. info "Running debootstrap first stage..."
  250. setarch linux32 \
  251. debootstrap --arch="$opt_arch" --foreign --verbose \
  252. --components="main,contrib,non-free" \
  253. --keyring="$raspbian_gpg" \
  254. "$opt_suite" "$opt_target_dir" "$MAIN_MIRROR" \
  255. || die "debootstrap failed"
  256. fi
  257. [ -d "$opt_target_dir" ] ||\
  258. die "Target directory '$opt_target_dir' does not exist."
  259. # Avoid the start of daemons during second stage.
  260. do_install -o root -g root -m 755 \
  261. "$basedir_pilc/templates/policy-rc.d" \
  262. "$opt_target_dir/usr/sbin/"
  263. # Copy qemu.
  264. local qemu_bin="$opt_target_dir/$opt_qemu"
  265. if ! [ -x "$qemu_bin" ]; then
  266. info "Copying qemu binary from '$opt_qemu' to '$qemu_bin'..."
  267. do_install -d -o root -g root -m 755 \
  268. "$(dirname "$qemu_bin")"
  269. do_install -T -o root -g root -m 755 \
  270. "$opt_qemu" "$qemu_bin"
  271. fi
  272. info "Copying PiLC bootstrap script and templates..."
  273. do_install -o root -g root -m 755 \
  274. "$basedir_pilc/pilc-bootstrap.sh" \
  275. "$opt_target_dir/"
  276. cp -r "$basedir_pilc/templates" "$opt_target_dir/tmp/" ||\
  277. die "Failed to copy PiLC templates"
  278. cp -r "$basedir_pilc/deb" "$opt_target_dir/tmp/" ||\
  279. die "Failed to copy PiLC deb packages"
  280. info "Checking out awlsim..."
  281. local awlsim_dir="$opt_target_dir/tmp/awlsim"
  282. local checkout_dir="$awlsim_dir/src"
  283. rm -rf "$awlsim_dir"
  284. do_install -d -o root -g root -m 755 "$awlsim_dir"
  285. git clone --no-checkout "$basedir/.git" "$checkout_dir" ||\
  286. die "Failed to clone"
  287. (
  288. cd "$checkout_dir" ||\
  289. die "Failed to cd"
  290. git checkout "$opt_branch" ||\
  291. die "Failed to check out branch."
  292. git submodule update --init submodules/pyprofibus ||\
  293. die "Failed to pull pyprofibus submodule"
  294. rm -r .git submodules/pyprofibus/.git ||\
  295. die "Failed to remove .git directory."
  296. mv submodules/pyprofibus .. ||\
  297. die "Failed to move pyprofibus submodule."
  298. ) || die
  299. # Fetch packages
  300. download "$opt_target_dir/tmp/$PPL_FILE" \
  301. "$PPL_MIRROR" \
  302. "$PPL_SHA256"
  303. download "$opt_target_dir/tmp/$PPL2_FILE" \
  304. "$PPL2_MIRROR" \
  305. "$PPL2_SHA256"
  306. # Second stage will mount a few filesystems.
  307. # Keep track to umount them in cleanup.
  308. mp_proc="$opt_target_dir/proc"
  309. mp_proc_binfmt_misc="$opt_target_dir/proc/sys/fs/binfmt_misc"
  310. mp_sys="$opt_target_dir/sys"
  311. mp_shm="$opt_target_dir/dev/shm"
  312. }
  313. pilc_bootstrap_second_stage()
  314. {
  315. info "Running second stage ($opt_arch)..."
  316. [ -x /pilc-bootstrap.sh ] ||\
  317. die "Second stage does not contain the bootstrap script."
  318. # Set up environment.
  319. export LC_ALL=C
  320. export LANGUAGE=C
  321. export LANG=C
  322. if [ "$opt_rpiver" = "1" -o "$opt_rpiver" = "0" ]; then
  323. info "Optimizing for RPi 1, zero(w)"
  324. local march="-march=armv6kz"
  325. local mtune="-mtune=arm1176jzf-s"
  326. elif [ "$opt_rpiver" = "2" ]; then
  327. info "Optimizing for RPi 2"
  328. local march="-march=armv7-a"
  329. local mtune="-mtune=cortex-a7"
  330. elif [ "$opt_rpiver" = "3" ]; then
  331. info "Optimizing for RPi 3"
  332. local march="-march=armv8-a"
  333. local mtune="-mtune=cortex-a53"
  334. elif [ "$opt_rpiver" = "4" ]; then
  335. info "Optimizing for RPi 4"
  336. local march="-march=armv8-a"
  337. local mtune="-mtune=cortex-a72"
  338. else
  339. info "Optimizing for generic RPi"
  340. local march="-march=armv6kz"
  341. local mtune=
  342. fi
  343. export CFLAGS="-O3 $march $mtune -mfpu=vfp -mfloat-abi=hard -pipe"
  344. export CXXFLAGS="$CFLAGS"
  345. # debootstrap second stage.
  346. if [ $opt_skip_debootstrap2 -eq 0 ]; then
  347. info "Running debootstrap second stage..."
  348. /debootstrap/debootstrap --verbose --second-stage ||\
  349. die "Debootstrap second stage failed."
  350. fi
  351. info "Disabling raspi-copies-and-fills..."
  352. rm -f /etc/ld.so.preload || die "Failed to disable raspi-copies-and-fills"
  353. info "Mounting /proc..."
  354. do_install -d -o root -g root -m 755 /proc
  355. mount -t proc proc /proc || die "Mounting /proc failed."
  356. info "Mounting /sys..."
  357. do_install -d -o root -g root -m 755 /sys
  358. mount -t sysfs sysfs /sys || die "Mounting /sys failed."
  359. info "Mounting /dev/shm..."
  360. do_install -d -o root -g root -m 755 /dev/shm
  361. mount -t tmpfs tmpfs /dev/shm || die "Mounting /dev/shm failed."
  362. info "Writing apt configuration..."
  363. cat > /etc/apt/sources.list <<EOF
  364. deb $MAIN_MIRROR $opt_suite main contrib non-free rpi firmware
  365. deb http://archive.raspberrypi.org/debian/ $opt_suite main ui
  366. EOF
  367. [ $? -eq 0 ] || die "Failed to set sources.list"
  368. echo 'Acquire { Languages "none"; };' > /etc/apt/apt.conf.d/99no-translations ||\
  369. die "Failed to set apt.conf.d"
  370. info "Creating /etc/fstab"
  371. do_install -d -o root -g root -m 755 /config
  372. do_install -T -o root -g root -m 644 \
  373. /tmp/templates/fstab \
  374. /etc/fstab
  375. info "Writing misc /etc stuff..."
  376. echo "pilc" > /etc/hostname || die "Failed to set hostname"
  377. printf 'PiLC GNU/Linux (based on Raspbian) \\n \\l\n\n' > /etc/issue ||\
  378. die "Failed to create /etc/issue"
  379. printf 'PiLC GNU/Linux (based on Raspbian)\n' > /etc/issue.net ||\
  380. die "Failed to create /etc/issue.net"
  381. sed -i -e 's|PRETTY_NAME=.*|PRETTY_NAME="PiLC"|' \
  382. /etc/os-release ||\
  383. die "Failed to set os-release PRETTY_NAME."
  384. sed -i -e 's|NAME=.*|NAME="PiLC"|' \
  385. /etc/os-release ||\
  386. die "Failed to set os-release NAME."
  387. sed -i -e 's|ID=.*|ID=pilc|' \
  388. /etc/os-release ||\
  389. die "Failed to set os-release ID."
  390. sed -i -e 's|ID_LIKE=.*|ID_LIKE=raspbian|' \
  391. /etc/os-release ||\
  392. die "Failed to set os-release ID_LIKE."
  393. sed -i -e 's|HOME_URL=.*|HOME_URL="https://bues.ch/a/pilc"|' \
  394. /etc/os-release ||\
  395. die "Failed to set os-release HOME_URL."
  396. sed -i -e 's|SUPPORT_URL=.*|SUPPORT_URL="https://bues.ch/a/pilc"|' \
  397. /etc/os-release ||\
  398. die "Failed to set os-release SUPPORT_URL."
  399. sed -i -e 's|BUG_REPORT_URL=.*|BUG_REPORT_URL="https://bues.ch/a/pilc"|' \
  400. /etc/os-release ||\
  401. die "Failed to set os-release BUG_REPORT_URL."
  402. info "Updating package list..."
  403. cat /tmp/templates/debconf-set-selections-preinstall.conf | debconf-set-selections ||\
  404. die "Failed to configure debconf settings"
  405. apt-key add /tmp/CF8A1AF502A2AA2D763BAE7E82B129927FA3303E.gpg ||\
  406. die "apt-key add failed"
  407. local apt_opts="-y -o Acquire::Retries=3"
  408. apt-get $apt_opts update ||\
  409. die "apt-get update failed"
  410. apt-get $apt_opts install apt-transport-https ||\
  411. die "apt-get install apt-transport-https failed"
  412. apt-get $apt_opts install \
  413. debian-keyring \
  414. raspberrypi-archive-keyring \
  415. raspbian-archive-keyring \
  416. || die "apt-get install keyrings failed"
  417. info "Upgrading system..."
  418. apt-get $apt_opts dist-upgrade ||\
  419. die "apt-get dist-upgrade failed"
  420. info "Installing packages..."
  421. apt-get $apt_opts install \
  422. aptitude \
  423. bash \
  424. build-essential \
  425. console-setup \
  426. cython3 \
  427. dbus \
  428. debconf-utils \
  429. debsums \
  430. devscripts \
  431. ethtool \
  432. fdisk \
  433. firmware-atheros \
  434. firmware-brcm80211 \
  435. firmware-libertas \
  436. firmware-linux \
  437. firmware-linux-free \
  438. firmware-linux-nonfree \
  439. firmware-misc-nonfree \
  440. firmware-realtek \
  441. git \
  442. htop \
  443. i2c-tools \
  444. irqbalance \
  445. iw \
  446. locales \
  447. nano \
  448. ntp \
  449. openssh-server \
  450. parted \
  451. python3 \
  452. python3-cffi \
  453. python3-dev \
  454. python3-serial \
  455. python3-setuptools \
  456. python3-spidev \
  457. rng-tools \
  458. schedtool \
  459. sudo \
  460. systemd \
  461. tmux \
  462. vim \
  463. wireless-tools \
  464. wpasupplicant \
  465. || die "apt-get install failed"
  466. info "Configuring locales..."
  467. dpkg-reconfigure -u locales ||\
  468. die "Failed to reconfigure locales"
  469. info "Configuring console..."
  470. sed -i -e 's|CHARMAP=.*|CHARMAP="UTF-8"|' \
  471. -e 's|FONTFACE=.*|FONTFACE=""|' \
  472. -e 's|FONTSIZE=.*|FONTSIZE=""|' \
  473. /etc/default/console-setup ||\
  474. die "Failed to edit /etc/default/console-setup"
  475. info "Creating /etc/rc.local..."
  476. do_install -o root -g root -m 755 \
  477. /tmp/templates/rc.local \
  478. /etc/
  479. info "Creating users/groups..."
  480. userdel -f pi
  481. groupdel pi
  482. rm -rf /home/pi
  483. groupadd -g 1000 pi ||\
  484. die "Failed to create group pi."
  485. useradd -u 1000 -d /home/pi -m -g pi\
  486. -G pi,lp,dialout,cdrom,floppy,audio,dip,src,video,plugdev,netdev,i2c\
  487. -s /bin/bash\
  488. pi ||\
  489. die "Failed to create user pi."
  490. printf 'raspberry\nraspberry\n' | passwd pi ||\
  491. die "Failed to set 'pi' password."
  492. info "Initializing home directory..."
  493. do_install -d -o pi -g pi -m 755 /home/pi/.vim
  494. do_install -o pi -g pi -m 644 \
  495. /tmp/templates/vimrc \
  496. /home/pi/.vim/
  497. do_install -T -o pi -g pi -m 644 \
  498. /tmp/templates/tmux.conf \
  499. /home/pi/.tmux.conf
  500. info "Installing raspbian packages..."
  501. apt-get $apt_opts install \
  502. libraspberrypi-bin \
  503. libraspberrypi-dev \
  504. libraspberrypi-doc \
  505. python3-rpi.gpio \
  506. raspberrypi-bootloader \
  507. raspberrypi-kernel \
  508. raspberrypi-net-mods \
  509. raspberrypi-sys-mods \
  510. raspi-config \
  511. raspi-gpio \
  512. raspinfo \
  513. || die "apt-get install failed"
  514. info "Running debconf-set-selections..."
  515. cat /tmp/templates/debconf-set-selections-postinstall.conf | debconf-set-selections ||\
  516. die "Failed to configure debconf settings"
  517. info "Cleaning apt..."
  518. apt-get $apt_opts autoremove --purge ||\
  519. die "apt-get autoremove failed"
  520. apt-get $apt_opts clean ||\
  521. die "apt-get clean failed"
  522. info "Disabling some services..."
  523. do_systemctl mask apt-daily.service
  524. do_systemctl mask apt-daily.timer
  525. do_systemctl mask apt-daily-upgrade.timer
  526. do_systemctl mask rsync.service
  527. do_systemctl mask exim4.service
  528. do_systemctl mask triggerhappy.service
  529. do_systemctl mask triggerhappy.socket
  530. do_systemctl mask alsa-state.service
  531. do_systemctl mask alsa-restore.service
  532. do_systemctl mask alsa-utils.service
  533. info "Building and installing PiLC system package..."
  534. (
  535. cd /tmp/deb/pilc-system || die "Failed to cd to pilc-system"
  536. debuild -uc -us -b -d || die "debuild failed"
  537. dpkg -i ../pilc-system_*.deb || die "Failed to install pilc-system"
  538. # Copy debs
  539. rm -rf /home/pi/deb/pilc-system
  540. do_install -d -o pi -g pi -m 755 /home/pi/deb/pilc-system
  541. do_install -o pi -g pi -m 644 \
  542. ../*pilc-system*.deb \
  543. /home/pi/deb/pilc-system/
  544. ) || die
  545. info "Updating /etc/hosts..."
  546. if ! grep -qe pilc /etc/hosts; then
  547. printf '\n127.0.0.1\tpilc\n' >> /etc/hosts ||\
  548. die "Failed to update /etc/hosts"
  549. fi
  550. info "Building Python modules..."
  551. build_ppl
  552. build_ppl2
  553. info "Building awlsim..."
  554. (
  555. cd /tmp/awlsim/src || die "Failed to cd"
  556. if [ $opt_cython -eq 0 ]; then
  557. # Disable cython
  558. sed -i -e '/Package: cython/,/^$/ d' \
  559. debian/control ||\
  560. die "Failed to patch control file (cython)"
  561. sed -i -e 's/export AWLSIM_CYTHON_BUILD=1/export AWLSIM_CYTHON_BUILD=0/' \
  562. debian/rules ||\
  563. die "Failed to patch rules file (cython)"
  564. fi
  565. # Disable pypy
  566. sed -i -e '/Package: pypy/,/^$/ d' -e '/^\s*pypy.*$/ d'\
  567. debian/control ||\
  568. die "Failed to patch control file (pypy)"
  569. sed -i -e 's/,pypy//' \
  570. debian/rules ||\
  571. die "Failed to patch rules file (pypy)"
  572. # Update the systemd service file.
  573. sed -i -e 's|AWLSIM_SCHED=|AWLSIM_SCHED=realtime-if-multicore|g' \
  574. -e 's|AWLSIM_PRIO=|AWLSIM_PRIO=50|g' \
  575. -e 's|AWLSIM_AFFINITY=|AWLSIM_AFFINITY=-1,-2,-3|g' \
  576. -e 's|AWLSIM_MLOCK=|AWLSIM_MLOCK=1|g' \
  577. awlsim-server.service ||\
  578. die "Failed to patch awlsim-server.service"
  579. # Build the packages.
  580. debuild -uc -us -b -d || die "debuild failed"
  581. info "Installing awlsim..."
  582. # Core
  583. dpkg -i ../python3-awlsim_*.deb ||\
  584. die "Failed to install python3-awlsim"
  585. if [ $opt_cython -ne 0 ]; then
  586. dpkg -i ../cython3-awlsim_*.deb ||\
  587. die "Failed to install cython3-awlsim"
  588. fi
  589. # hardware: dummy
  590. dpkg -i ../python3-awlsimhw-dummy_*.deb ||\
  591. die "Failed to install python3-awlsimhw-dummy"
  592. if [ $opt_cython -ne 0 ]; then
  593. dpkg -i ../cython3-awlsimhw-dummy_*.deb ||\
  594. die "Failed to install cython3-awlsimhw-dummy"
  595. fi
  596. # hardware: linuxcnc
  597. dpkg -i ../python3-awlsimhw-linuxcnc_*.deb ||\
  598. die "Failed to install python3-awlsimhw-linuxcnc"
  599. if [ $opt_cython -ne 0 ]; then
  600. dpkg -i ../cython3-awlsimhw-linuxcnc_*.deb ||\
  601. die "Failed to install cython3-awlsimhw-linuxcnc"
  602. fi
  603. # hardware: profibus
  604. dpkg -i ../python3-awlsimhw-profibus_*.deb ||\
  605. die "Failed to install python3-awlsimhw-profibus"
  606. if [ $opt_cython -ne 0 ]; then
  607. dpkg -i ../cython3-awlsimhw-profibus_*.deb ||\
  608. die "Failed to install cython3-awlsimhw-profibus"
  609. fi
  610. # hardware: RPi GPIO
  611. dpkg -i ../python3-awlsimhw-rpigpio_*.deb ||\
  612. die "Failed to install python3-awlsimhw-rpigpio"
  613. if [ $opt_cython -ne 0 ]; then
  614. dpkg -i ../cython3-awlsimhw-rpigpio_*.deb ||\
  615. die "Failed to install cython3-awlsimhw-rpigpio"
  616. fi
  617. # hardware: PiXtend
  618. dpkg -i ../python3-awlsimhw-pixtend_*.deb ||\
  619. die "Failed to install python3-awlsimhw-pixtend"
  620. if [ $opt_cython -ne 0 ]; then
  621. dpkg -i ../cython3-awlsimhw-pixtend_*.deb ||\
  622. die "Failed to install cython3-awlsimhw-pixtend"
  623. fi
  624. # Executables
  625. dpkg -i ../awlsim-server_*.deb ||\
  626. die "Failed to install awlsim-server"
  627. dpkg -i ../awlsim-client_*.deb ||\
  628. die "Failed to install awlsim-client"
  629. dpkg -i ../awlsim-symtab_*.deb ||\
  630. die "Failed to install awlsim-symtab"
  631. dpkg -i ../awlsim-test_*.deb ||\
  632. die "Failed to install awlsim-test"
  633. dpkg -i ../awlsim-proupgrade_*.deb ||\
  634. die "Failed to install awlsim-proupgrade"
  635. # Copy debs
  636. rm -rf /home/pi/deb/awlsim
  637. do_install -d -o pi -g pi -m 755 /home/pi/deb/awlsim
  638. do_install -o pi -g pi -m 644 \
  639. ../*awlsim*.deb \
  640. /home/pi/deb/awlsim/
  641. # Copy examples
  642. do_install -T -o pi -g pi -m 644 \
  643. examples/EXAMPLE.awlpro \
  644. /home/pi/generic-example.awlpro
  645. do_install -T -o pi -g pi -m 644 \
  646. examples/raspberrypi-gpio.awlpro \
  647. /home/pi/raspberrypi-gpio-example.awlpro
  648. do_install -T -o pi -g pi -m 644 \
  649. examples/raspberrypi-profibus.awlpro \
  650. /home/pi/raspberrypi-profibus-example.awlpro
  651. do_install -T -o pi -g pi -m 644 \
  652. examples/raspberrypi-pixtend.awlpro \
  653. /home/pi/raspberrypi-pixtend-example.awlpro
  654. ) || die
  655. info "Building pyprofibus..."
  656. (
  657. cd /tmp/awlsim/pyprofibus ||\
  658. die "Failed to cd"
  659. if [ $opt_cython -eq 0 ]; then
  660. # Disable cython
  661. sed -i -e '/Package: cython/,/^$/ d' \
  662. debian/control ||\
  663. die "Failed to patch control file (cython)"
  664. sed -i -e 's/export PYPROFIBUS_CYTHON_BUILD=1/export PYPROFIBUS_CYTHON_BUILD=0/' \
  665. debian/rules ||\
  666. die "Failed to patch rules file (cython)"
  667. fi
  668. # Build the packages.
  669. debuild -uc -us -b -d || die "debuild failed"
  670. info "Installing pyprofibus..."
  671. dpkg -i ../python3-pyprofibus_*.deb ||\
  672. die "Failed to install python3-pyprofibus"
  673. dpkg -i ../profisniff_*.deb ||\
  674. die "Failed to install profisniff"
  675. dpkg -i ../gsdparser_*.deb ||\
  676. die "Failed to install gsdparser"
  677. # Copy debs
  678. rm -rf /home/pi/deb/pyprofibus
  679. do_install -d -o pi -g pi -m 755 /home/pi/deb/pyprofibus
  680. do_install -o pi -g pi -m 644 \
  681. ../*pyprofibus*.deb \
  682. ../profisniff_*.deb \
  683. ../gsdparser_*.deb \
  684. /home/pi/deb/pyprofibus/
  685. ) || die
  686. rm -r /tmp/awlsim ||\
  687. die "Failed to remove awlsim checkout."
  688. info "Updating home directory permissions..."
  689. chown -R pi:pi /home/pi || die "Failed to change /home/pi permissions."
  690. # Remove rc.d policy file
  691. if [ -e /usr/sbin/policy-rc.d ]; then
  692. rm /usr/sbin/policy-rc.d ||\
  693. die "Failed to remove policy-rc.d"
  694. fi
  695. # Install this last. It won't work correctly in the qemu environment.
  696. info "Installing raspi-copies-and-fills..."
  697. apt-get $apt_opts install --reinstall raspi-copies-and-fills ||\
  698. die "apt-get install failed"
  699. info "Stopping processes..."
  700. for i in dbus ssh irqbalance; do
  701. /etc/init.d/$i stop
  702. done
  703. }
  704. pilc_bootstrap_third_stage()
  705. {
  706. info "Running third stage..."
  707. info "Umounting /dev/shm..."
  708. umount -l "$mp_shm" || die "Failed to umount /dev/shm"
  709. info "Umounting /sys..."
  710. umount -l "$mp_sys" || die "Failed to umount /sys"
  711. info "Umounting /proc/sys/fs/binfmt_misc..."
  712. umount -l "$mp_proc_binfmt_misc"
  713. info "Umounting /proc..."
  714. umount -l "$mp_proc" || die "Failed to umount /proc"
  715. info "Removing PiLC bootstrap script..."
  716. rm "$opt_target_dir/pilc-bootstrap.sh" ||\
  717. die "Failed to remove bootstrap script."
  718. info "Cleaning tmp..."
  719. rm -rf "$opt_target_dir"/tmp/*
  720. info "Configuring boot..."
  721. do_install -T -o root -g root -m 644 \
  722. "$basedir_pilc/templates/boot_cmdline.txt" \
  723. "$opt_target_dir/boot/cmdline.txt"
  724. do_install -T -o root -g root -m 644 \
  725. "$basedir_pilc/templates/boot_config.txt" \
  726. "$opt_target_dir/boot/config.txt"
  727. # Prepare image paths.
  728. local imgfile="${opt_target_dir}${opt_imgsuffix}.img"
  729. local imgfile_zip="${imgfile}.7z"
  730. local bootimgfile="${imgfile}.boot"
  731. mp_bootimgfile="${bootimgfile}.mp"
  732. local rootimgfile="${imgfile}.root"
  733. mp_rootimgfile="${rootimgfile}.mp"
  734. rm -f "$imgfile" "$imgfile_zip" "$rootimgfile" "$bootimgfile"
  735. rmdir "$mp_bootimgfile" "$mp_rootimgfile" 2>/dev/null
  736. # Create images.
  737. if [ "$opt_img" -ne 0 ]; then
  738. # Calculate image size.
  739. local imgsize_b="$(expr "$opt_imgsize" \* 1000 \* 1000 \* 1000)"
  740. local imgsize_mib="$(expr "$imgsize_b" \/ 1024 \/ 1024)"
  741. # Reduce the size to make sure it fits every SD card.
  742. local imgsize_mib_red="$(expr \( "$imgsize_mib" \* 98 \) \/ 100)"
  743. [ -n "$imgsize_mib_red" ] || die "Failed to calculate image size"
  744. info "SD image size = $imgsize_mib_red MiB"
  745. info "Creating boot image..."
  746. mkfs.vfat -F 32 -i 7771B0BB -n boot -C "$bootimgfile" \
  747. $(expr \( 256 \* 1024 \) ) ||\
  748. die "Failed to create boot partition file system."
  749. mkdir "$mp_bootimgfile" ||\
  750. die "Failed to make boot partition mount point."
  751. mount -o loop "$bootimgfile" "$mp_bootimgfile" ||\
  752. die "Failed to mount boot partition."
  753. rsync -aHAX --inplace \
  754. "$opt_target_dir/boot/" "$mp_bootimgfile/" ||\
  755. die "Failed to copy boot files."
  756. umount "$mp_bootimgfile" ||\
  757. die "Failed to umount boot partition."
  758. rmdir "$mp_bootimgfile" ||\
  759. die "Failed to remove boot partition mount point."
  760. info "Creating root image..."
  761. mkfs.ext4 "$rootimgfile" $(expr \( "$imgsize_mib_red" - \( 256 + 4 + 4 \) \) \* 1024 ) ||\
  762. die "Failed to create root filesystem."
  763. mkdir "$mp_rootimgfile" ||\
  764. die "Failed to make root partition mount point."
  765. mount -o loop "$rootimgfile" "$mp_rootimgfile" ||\
  766. die "Failed to mount root partition."
  767. rsync -aHAX --inplace \
  768. --exclude='boot/*' \
  769. --exclude='dev/shm/*' \
  770. --exclude='proc/*' \
  771. --exclude='run/*' \
  772. --exclude='sys/*' \
  773. --exclude='tmp/*' \
  774. --exclude="$(basename "$opt_qemu")" \
  775. "$opt_target_dir/" "$mp_rootimgfile/" ||\
  776. die "Failed to copy root files."
  777. umount "$mp_rootimgfile" ||\
  778. die "Failed to umount root partition."
  779. rmdir "$mp_rootimgfile" ||\
  780. die "Failed to remove root partition mount point."
  781. info "Creating image '$imgfile'..."
  782. dd if=/dev/zero of="$imgfile" bs=1M count="$imgsize_mib_red" conv=sparse ||\
  783. die "Failed to create image file."
  784. parted "$imgfile" <<EOF
  785. unit b
  786. mklabel msdos
  787. mkpart primary fat32 $(expr 4 \* 1024 \* 1024) $(expr \( 256 + 4 \) \* 1024 \* 1024)
  788. mkpart primary ext4 $(expr \( 256 + 4 + 4 \) \* 1024 \* 1024) 100%
  789. EOF
  790. [ $? -eq 0 ] || die "Failed to create partitions."
  791. info "Integrating boot image..."
  792. dd if="$bootimgfile" of="$imgfile"\
  793. seek=4 bs=1M conv=notrunc,sparse ||\
  794. die "Failed to integrate boot partition."
  795. rm "$bootimgfile" ||\
  796. die "Failed to delete boot partition image."
  797. info "Integrating root image..."
  798. dd if="$rootimgfile" of="$imgfile"\
  799. seek="$(expr 256 + 4 + 4)" bs=1M conv=notrunc,sparse ||\
  800. die "Failed to integrate root partition."
  801. rm "$rootimgfile" ||\
  802. die "Failed to delete root partition image."
  803. # Create zipped image.
  804. if [ "$opt_zimg" -ne 0 ]; then
  805. info "Compressing image..."
  806. 7z -mx=9 a "$imgfile_zip" "$imgfile" ||\
  807. die "Failed to compress partition image."
  808. fi
  809. # Write the image to the SD card.
  810. if [ -n "$opt_writedev" ]; then
  811. write_image "$imgfile" "$opt_writedev"
  812. fi
  813. fi
  814. }
  815. usage()
  816. {
  817. echo "pilc-bootstrap.sh [OPTIONS] TARGET_DIR"
  818. echo
  819. echo "Options:"
  820. echo
  821. echo " --branch|-b BRANCH Select the awlsim branch or tag."
  822. echo " Default: $default_branch"
  823. echo
  824. echo " --no-cython|-C Do not build Cython modules."
  825. echo " Default: Build cython modules"
  826. echo
  827. echo " --suite|-s SUITE Select the suite."
  828. echo " Default: $default_suite"
  829. echo
  830. echo " --arch|-a ARCH Select the default arch."
  831. echo " Default: $default_arch"
  832. echo
  833. echo " --qemu-bin|-Q PATH Select qemu-user-static binary."
  834. echo " Default: $default_qemu"
  835. echo
  836. echo " --img-suffix|-X SUFFIX Image file suffix."
  837. echo " Default: $default_imgsuffix"
  838. echo
  839. echo " --img-size|-S SIZEGB Image file size, in Gigabytes (base 1000)."
  840. echo " Default: $default_imgsize"
  841. echo
  842. echo " --no-img|-I Do not create an image."
  843. echo " Default: Create image."
  844. echo
  845. echo " --no-zimg|-Z Do not create a 7zipped image."
  846. echo " Default: Create 7zipped image."
  847. echo
  848. echo " --write|-w DEV Write image to an SD card after bootstrap."
  849. echo " DEV must be the /dev/mmcblkX path to the card."
  850. echo
  851. echo " --write-only|-W DEV Write an existing image to an SD card"
  852. echo " without bootstrap and image generation."
  853. echo
  854. echo " --skip-debootstrap1|-1 Skip debootstrap first stage."
  855. echo " --skip-debootstrap2|-2 Skip debootstrap second stage."
  856. echo
  857. echo " --quick|-q Quick build. This is a shortcut for:"
  858. echo " --no-cython --no-zimg"
  859. echo
  860. echo " --rpiver|-R VERSION Raspberry Pi version to build for."
  861. echo " Can be either 0, 1, 2, 3, 4 or generic"
  862. echo " 0 and 1 are equivalent."
  863. echo " generic runs on any Raspberry Pi 0-4."
  864. echo " Default: generic"
  865. }
  866. # canonicalize basedir
  867. basedir="$(readlink -e "$basedir")"
  868. [ -n "$basedir" ] || die "Failed to canonicalize base directory."
  869. # Directory containing the PiLC bootstrapping files.
  870. basedir_pilc="$basedir/pilc"
  871. # Mountpoints. Will be umounted on cleanup.
  872. mp_shm=
  873. mp_proc=
  874. mp_proc_binfmt_misc=
  875. mp_sys=
  876. mp_bootimgfile=
  877. mp_rootimgfile=
  878. trap term_signal TERM INT
  879. if [ -z "$__PILC_BOOTSTRAP_SECOND_STAGE__" ]; then
  880. # First stage
  881. export _NPROCESSORS_ONLN="$(getconf _NPROCESSORS_ONLN)"
  882. [ -n "$_NPROCESSORS_ONLN" ] || die "Failed to get # of online CPUs"
  883. default_branch="master"
  884. default_suite="$DEFAULT_SUITE"
  885. default_arch="armhf"
  886. default_qemu="/usr/bin/qemu-arm-static"
  887. default_imgsuffix="-$(date '+%Y%m%d')"
  888. default_imgsize=4
  889. default_img=1
  890. default_zimg=1
  891. default_writedev=
  892. default_writeonly=0
  893. default_rpiver="generic"
  894. opt_target_dir=
  895. opt_branch="$default_branch"
  896. opt_cython=1
  897. opt_suite="$default_suite"
  898. opt_arch="$default_arch"
  899. opt_qemu="$default_qemu"
  900. opt_skip_debootstrap1=0
  901. opt_skip_debootstrap2=0
  902. opt_imgsuffix="$default_imgsuffix"
  903. opt_imgsize="$default_imgsize"
  904. opt_img="$default_img"
  905. opt_zimg="$default_zimg"
  906. opt_writedev="$default_writedev"
  907. opt_writeonly="$default_writeonly"
  908. opt_rpiver="$default_rpiver"
  909. while [ $# -ge 1 ]; do
  910. case "$1" in
  911. --help|-h)
  912. usage
  913. exit 0
  914. ;;
  915. --branch|-b)
  916. shift
  917. opt_branch="$1"
  918. [ -n "$opt_branch" ] || die "No branch given"
  919. ;;
  920. --no-cython|-C)
  921. opt_cython=0
  922. ;;
  923. --suite|-s)
  924. shift
  925. opt_suite="$1"
  926. [ -n "$opt_suite" ] || die "No suite given"
  927. ;;
  928. --arch|-a)
  929. shift
  930. opt_arch="$1"
  931. [ -n "$opt_arch" ] || die "No arch given"
  932. ;;
  933. --qemu-bin|-Q)
  934. shift
  935. opt_qemu="$1"
  936. [ -x "$opt_qemu" ] || die "No valid qemu binary given"
  937. ;;
  938. --skip-debootstrap1|-1)
  939. opt_skip_debootstrap1=1
  940. ;;
  941. --skip-debootstrap2|-2)
  942. opt_skip_debootstrap2=1
  943. ;;
  944. --img-suffix|-X)
  945. shift
  946. opt_imgsuffix="$1"
  947. ;;
  948. --img-size|-S)
  949. shift
  950. opt_imgsize="$(expr "$1" \* 1)"
  951. [ -n "$opt_imgsize" ] || die "--img-size|-S is invalid"
  952. ;;
  953. --no-zimg|-Z)
  954. opt_zimg=0
  955. ;;
  956. --no-img|-I)
  957. opt_img=0
  958. ;;
  959. --quick|-q)
  960. opt_cython=0
  961. opt_zimg=0
  962. ;;
  963. --write|-w|--write-only|-W)
  964. if [ "$1" = "--write" -o "$1" = "-w" ]; then
  965. opt_writeonly=0
  966. else
  967. opt_writeonly=1
  968. fi
  969. shift
  970. opt_writedev="$1"
  971. [ -b "$opt_writedev" ] || die "Invalid SD card block device"
  972. ;;
  973. --rpiver|-R)
  974. shift
  975. opt_rpiver="$1"
  976. [ "$opt_rpiver" = "generic" -o\
  977. "$opt_rpiver" = "0" -o\
  978. "$opt_rpiver" = "1" -o\
  979. "$opt_rpiver" = "2" -o\
  980. "$opt_rpiver" = "3" -o\
  981. "$opt_rpiver" = "4" ] || die "Invalid --rpiver|-R"
  982. ;;
  983. *)
  984. opt_target_dir="$*"
  985. break
  986. ;;
  987. esac
  988. shift
  989. done
  990. [ -n "$opt_target_dir" ] ||\
  991. die "No TARGET_DIR"
  992. opt_target_dir="$(readlink -m "${opt_target_dir}")"
  993. [ -n "$opt_target_dir" ] || die "Failed to resolve target dir."
  994. [ -d "$opt_target_dir" -o ! -e "$opt_target_dir" ] ||\
  995. die "$opt_target_dir is not a directory"
  996. trap cleanup EXIT
  997. if [ -n "$opt_writedev" -a $opt_writeonly -ne 0 ]; then
  998. # Just write the image to the SD card, then exit.
  999. write_image "${opt_target_dir}${opt_imgsuffix}.img" "$opt_writedev"
  1000. exit 0
  1001. fi
  1002. # Run first stage.
  1003. pilc_bootstrap_first_stage
  1004. info "Starting second stage."
  1005. # Export options for use by second stage.
  1006. export opt_target_dir
  1007. export opt_branch
  1008. export opt_cython
  1009. export opt_suite
  1010. export opt_arch
  1011. export opt_qemu
  1012. export opt_skip_debootstrap1
  1013. export opt_skip_debootstrap2
  1014. export opt_imgsuffix
  1015. export opt_zimg
  1016. export opt_img
  1017. export opt_writedev
  1018. export opt_writeonly
  1019. export opt_rpiver
  1020. export __PILC_BOOTSTRAP_SECOND_STAGE__=1
  1021. setarch linux32 \
  1022. chroot "$opt_target_dir" "/pilc-bootstrap.sh" ||\
  1023. die "Chroot failed."
  1024. # Run third stage.
  1025. pilc_bootstrap_third_stage
  1026. info ""
  1027. info "Successfully bootstrapped PiLC."
  1028. exit 0
  1029. else
  1030. # Run second stage
  1031. pilc_bootstrap_second_stage
  1032. exit 0
  1033. fi