| 1 | #!bin/ysh
|
| 2 |
|
| 3 | #
|
| 4 | # Set up Debian Linux chroot.
|
| 5 | #
|
| 6 | # Usage:
|
| 7 | # regtest/debian-setup.ysh <function-name>
|
| 8 | # Examples:
|
| 9 | # regtest/debian-setup.ysh fetch-all
|
| 10 | # Download all the required files for the chroot.
|
| 11 | # Only has to be run again if a newer version must be downloaded
|
| 12 | # regtest/debian-setup.ysh prepare-all
|
| 13 | # Create a new chroot environment. Must run fetch-all first
|
| 14 | # Also sets up the osh-as-sh layer.
|
| 15 |
|
| 16 | proc download-oils() {
|
| 17 | var tarball_id=${1:-$TARBALL_ID}
|
| 18 |
|
| 19 | # var url="https://op.oilshell.org/uuu/github-jobs/$tarball_id/cpp-tarball.wwz/_release/oils-for-unix.tar"
|
| 20 | var url="https://op.oilshell.org/code/github-jobs/git-fd65318bebefcacf83f0ba8678575c4a8f56fa4b/oils-for-unix.tar"
|
| 21 |
|
| 22 | rm -f -v _tmp/oils-for-unix.tar
|
| 23 |
|
| 24 | #wget --no-clobber --directory-prefix _tmp "$url"
|
| 25 | wget --directory-prefix _tmp "$url"
|
| 26 | }
|
| 27 |
|
| 28 | proc make-user() {
|
| 29 | exec-chroot "useradd -m -s /bin/bash udu"
|
| 30 |
|
| 31 | # 'wheel' is for 'sudo'
|
| 32 | exec-chroot "groupadd -f wheel"
|
| 33 | exec-chroot "adduser udu wheel"
|
| 34 | }
|
| 35 |
|
| 36 | proc setup-doas() {
|
| 37 | sudo rm -f $CHROOT_DIR/etc/doas.conf
|
| 38 |
|
| 39 | # no password
|
| 40 | exec-chroot u'echo "permit nopass :wheel" >> /etc/doas.conf'
|
| 41 | }
|
| 42 |
|
| 43 | proc change-perms(path) {
|
| 44 | # pass any number of args
|
| 45 |
|
| 46 | # get uid from /home/udu
|
| 47 | var uid=$(stat -c '%u' $CHROOT_HOME_DIR)
|
| 48 | sudo chown --verbose --recursive $uid $path
|
| 49 | }
|
| 50 |
|
| 51 | # test-time-tsv() {
|
| 52 | # enter-rootfs-user sh -c '
|
| 53 | # cd oils
|
| 54 | # pwd
|
| 55 | # whoami
|
| 56 | # echo ---
|
| 57 |
|
| 58 | # build/py.sh time-helper
|
| 59 | # regtest/aports-guest.sh my-time-tsv-test
|
| 60 | # '
|
| 61 | # }
|
| 62 |
|
| 63 | proc oils-in-chroot() {
|
| 64 | # test-time-tsv
|
| 65 | copy-oils
|
| 66 | build-oils
|
| 67 | }
|
| 68 |
|
| 69 | proc copy-oils() {
|
| 70 | var dest=CHROOT_HOME_DIR
|
| 71 |
|
| 72 | var tar=$(pwd) ++ '/_tmp/oils-for-unix.tar'
|
| 73 | pushd $dest
|
| 74 | sudo tar -x < $tar
|
| 75 | popd
|
| 76 |
|
| 77 | change-perms "$dest/oils-for-unix-0.37.0"
|
| 78 | }
|
| 79 |
|
| 80 | proc build-oils() {
|
| 81 | exec-chroot-user 'cd oils-for-unix-*
|
| 82 | ./configure
|
| 83 | _build/oils.sh # do not --skip-rebuild
|
| 84 | doas ./install
|
| 85 | '
|
| 86 | }
|
| 87 |
|
| 88 | proc create-osh-overlay() {
|
| 89 | # _debian_chroot/
|
| 90 | # debian-build/ # chroot image
|
| 91 | # osh-as-sh.overlay/ # overlay
|
| 92 | # merged/ # permanently mounted
|
| 93 | # work/
|
| 94 | # layer/ # has the OSH symlink
|
| 95 |
|
| 96 |
|
| 97 | var osh_overlay=DEBIAN_ROOT ++ '/osh-as-sh.overlay'
|
| 98 |
|
| 99 | mkdir -v -p $osh_overlay/{merged,work,layer}
|
| 100 | cp regtest/sh_wrapper.sh $osh_overlay/layer/sh_wrapper.sh
|
| 101 | chmod +x $osh_overlay/layer/sh_wrapper.sh
|
| 102 |
|
| 103 | # -o index=off fixes this error: fsconfig() failed: Stale file handle
|
| 104 | # See also https://oilshell.zulipchat.com/#narrow/channel/522730-distros/topic/setting.20up.20regtest.2Faports-setup.2Esh/with/544318771
|
| 105 | sudo mount \
|
| 106 | -t overlay \
|
| 107 | osh-as-sh \
|
| 108 | -o index=off \
|
| 109 | -o "lowerdir=$CHROOT_DIR,upperdir=$osh_overlay/layer,workdir=$osh_overlay/work" \
|
| 110 | $osh_overlay/merged
|
| 111 |
|
| 112 | exec-chroot-osh '
|
| 113 | set -x
|
| 114 | if ! test -f /usr/local/bin/oils-for-unix; then
|
| 115 | echo "Build Oils first"
|
| 116 | exit
|
| 117 | fi
|
| 118 | ln -s -f /sh_wrapper.sh /bin/sh
|
| 119 | ln -s -f /usr/local/bin/oils-for-unix /bin/dash
|
| 120 | ln -s -f /usr/local/bin/oils-for-unix /bin/bash
|
| 121 | '
|
| 122 | }
|
| 123 |
|
| 124 | proc remove-osh-overlay() {
|
| 125 | var dir= DEBIAN_ROOT ++ '/osh-as-sh.overlay'
|
| 126 | sudo umount $dir/merged || true
|
| 127 | sudo rm -r -f $dir
|
| 128 | }
|
| 129 |
|
| 130 | # remove-shard-layers() {
|
| 131 | # sudo rm -r -f _chroot/shard*
|
| 132 | # }
|
| 133 |
|
| 134 | # make-distfiles-tar() {
|
| 135 | # local a_repo=$1 # 'main' or 'community'
|
| 136 |
|
| 137 | # local tar=_chroot/distfiles-${a_repo}.tar
|
| 138 | # tar --create --file $tar --directory $CHROOT_DIR/var/cache/distfiles .
|
| 139 |
|
| 140 | # tar --list < $tar
|
| 141 | # echo
|
| 142 | # ls -l --si $tar
|
| 143 | # echo
|
| 144 | # }
|
| 145 |
|
| 146 | # unpack-distfiles() {
|
| 147 | # local a_repo=$1 # 'main' or 'community'
|
| 148 |
|
| 149 | # local tar=_chroot/distfiles-${a_repo}.tar
|
| 150 | # sudo tar --verbose -x --directory $CHROOT_DIR/var/cache/distfiles < $tar
|
| 151 | # }
|
| 152 |
|
| 153 | . regtest/debian-common.ysh
|
| 154 |
|
| 155 | proc remove-all() {
|
| 156 | set -x
|
| 157 | remove-chroot
|
| 158 | remove-osh-overlay
|
| 159 | # remove-shard-layers || true
|
| 160 | }
|
| 161 |
|
| 162 | proc remove-chroot() {
|
| 163 | try {
|
| 164 | sudo umount -R $CHROOT_DIR 2>/dev/null
|
| 165 | }
|
| 166 | sudo rm -rf $CHROOT_DIR
|
| 167 | }
|
| 168 |
|
| 169 | proc clone-debootstrap() {
|
| 170 | var dir = '../debianlinux'
|
| 171 | mkdir -p $dir
|
| 172 | rm -rf "$dir/debootstrap"
|
| 173 | pushd $dir
|
| 174 |
|
| 175 | # Took 1m 13s, at 27 MiB /ssec
|
| 176 | git clone \
|
| 177 | https://salsa.debian.org/installer-team/debootstrap.git
|
| 178 |
|
| 179 | popd
|
| 180 | }
|
| 181 |
|
| 182 | proc make-chroot() {
|
| 183 | mkdir -p $DEBIAN_ROOT
|
| 184 | var dir = '../debianlinux/debootstrap'
|
| 185 | pushd $dir
|
| 186 | var debootstrap_dir = $(pwd)
|
| 187 |
|
| 188 | # This takes about 1m20s
|
| 189 | # need to pass --arch, automatic detection doesnt work on non-debian systems
|
| 190 | sudo DEBOOTSTRAP_DIR=$debootstrap_dir ./debootstrap --arch=amd64 stable $CHROOT_DIR http://deb.debian.org/debian/
|
| 191 | popd
|
| 192 | }
|
| 193 |
|
| 194 | proc add-build-deps() {
|
| 195 | # takes around 2 minutes
|
| 196 | exec-chroot "apt-get update; apt-get install doas dpkg-dev build-essential devscripts fakeroot apt-utils -y"
|
| 197 | }
|
| 198 |
|
| 199 | proc config-chroot() {
|
| 200 | exec-chroot 'echo "deb-src http://deb.debian.org/debian stable main" >> /etc/apt/sources.list'
|
| 201 | exec-chroot 'apt-get update' # else apt still doesnt know we added the deb-src line
|
| 202 | make-user
|
| 203 | setup-doas
|
| 204 | }
|
| 205 |
|
| 206 | proc fetch-all() {
|
| 207 | # Download the resources required for setting up a new chroot
|
| 208 | clone-debootstrap
|
| 209 |
|
| 210 | download-oils
|
| 211 | }
|
| 212 |
|
| 213 | proc prepare-all() {
|
| 214 | # Create a new chroot environment and set it up from scratch
|
| 215 | make-chroot
|
| 216 |
|
| 217 | add-build-deps
|
| 218 |
|
| 219 | # TODO: mount /proc etc?
|
| 220 | config-chroot
|
| 221 |
|
| 222 | oils-in-chroot
|
| 223 |
|
| 224 | create-osh-overlay
|
| 225 |
|
| 226 | # # makes a host file
|
| 227 | # apk-manifest
|
| 228 | }
|
| 229 |
|
| 230 | runproc @ARGV
|