02-chroot.sh (4687B)
1 #!/bin/sh 2 3 . ./lib/env.sh 4 . ./lib/fun.sh 5 6 WD=${PWD} 7 8 usage() 9 { 10 cat <<! 11 Usage: ${0##*/} [-h|--help] [rootdir] 12 rootdir - If present, overrides GR 13 ! 14 } 15 16 case $1 in 17 -h|--help) usage; exit 0;; 18 *) ;; 19 esac 20 21 if [ -n "$1" ]; then 22 GR=$1 23 fi 24 25 HOST_COREUTILS=0 26 HOST_FIND=0 27 HOST_MD5SUM=0 28 HOST_SED=0 29 HOST_TAR=0 30 export HOST_COREUTILS HOST_FIND HOST_MD5SUM HOST_SED HOST_TAR 31 32 trap exit_cleanup HUP PIPE INT QUIT TERM EXIT 33 34 if [ "$(id -u)" -ne 0 ]; then 35 msg err "You must run this script as root" 36 exit 1 37 fi 38 39 cat art/galeb.ansi 40 41 msg info "Creating directories" 42 ./lib/createdirs 02-chroot.sh-start 43 44 check_mknod ${GR}/dev/console c 5 1 -m 600 45 check_mknod ${GR}/dev/null c 1 3 -m 666 46 47 mount_or_fail -B /dev ${GR}/dev 48 mount_or_fail -t devpts devpts ${GR}/dev/pts -o gid=5,mode=620 49 mount_or_fail -t proc proc ${GR}/proc 50 mount_or_fail -t sysfs sys ${GR}/sys 51 check_dir ${GR}/sys/firmware/efi/efivars 52 mount_or_fail -t efivarfs efivarfs ${GR}/sys/firmware/efi/efivars 53 mount_or_fail -t tmpfs -o nodev,nosuid,noatime,mode=0755 run ${GR}/run 54 mount_or_fail -t tmpfs -o nodev,nosuid,noatime,mode=1777 tmp ${GR}/tmp 55 56 rm -f ${GR}/dev/random ${GR}/dev/urandom 57 mknod -m 444 ${GR}/dev/random c 1 8 58 mknod -m 666 ${GR}/dev/urandom c 1 9 59 60 cp_or_fail ${WD}/art/galeb.ansi ${GR}/etc/issue 61 62 if [ -h ${GR}/dev/shm ]; then 63 check_dir ${GR}/$(readlink ${GR}/dev/shm) 64 fi 65 66 if [ -e ${GR}/etc/passwd ]; then 67 msg info "%s exists" "${GR}/etc/passwd" 68 else 69 msg info "Generating %s" "${GR}/etc/passwd" 70 cat <<! >${GR}/etc/passwd 71 root:x:0:0:root:/root:/tools/bin/mksh 72 galeb:x:${GUID}:${GGID}:Temporary User Account:/src:/tools/bin/mksh 73 ! 74 fi 75 76 if [ -e ${GR}/etc/group ]; then 77 msg info "%s exists" "${GR}/etc/group" 78 else 79 msg info "Generating %s" "${GR}/etc/group" 80 cat <<! >${GR}/etc/group 81 root:x:0:root 82 galeb:x:${GGID}:galeb 83 ! 84 fi 85 86 if [ -e ${GR}/etc/shells ]; then 87 msg info "%s exists" "${GR}/etc/shells" 88 else 89 msg info "Generating %s" "${GR}/etc/shells" 90 cat <<! >${GR}/etc/shells 91 /bin/sh 92 /bin/mksh 93 /plan9/bin/rc 94 ! 95 fi 96 97 msg info "Generating %s" "${GR}/etc/profile" 98 cat <<! >${GR}/etc/profile 99 LC_ALL= 100 LANG=C.UTF-8 101 PATH=/${TLD}/bin:/bin:/sbin:/sucks/bin:/sucks/sbin:/plan9/bin 102 export LC_ALL LANG PATH 103 104 [ -e /etc/mkshrc ] && . /etc/mkshrc 105 106 # More like GNU ls 107 lc() 108 { 109 if [ -x /tools/bin/ls ]; then 110 /tools/bin/ls \$* | cols 111 else 112 /bin/ls \$* | cols 113 fi 114 } 115 ! 116 117 link_if_ne /${TLD}/bin/lksh ${GR}/bin/sh 118 link_if_ne /${TLD}/bin/bash ${GR}/bin/bash 119 cp_or_fail ${WD}/03-packages.sh ${GR}/bin/ 120 cp_or_fail ${WD}/04-finale.sh ${GR}/bin/ 121 check_dir ${G_LIB} 122 cp_or_fail ${WD}/lib/env.sh ${GR}/lib/env.sh 123 /bin/sed -i 's,^\(GR=\).*,\1'\'\'',' ${GR}/lib/env.sh 124 cp_or_fail ${WD}/lib/fun.sh ${GR}/lib/fun.sh 125 cp_or_fail ${WD}/${FLD}/rc.d/g_fun.sh ${GR}/lib/g_fun.sh 126 cp_or_fail ${WD}/lib/createdirs ${GR}/lib/createdirs 127 cp_or_fail ${WD}/lib/dirs.tsv ${GR}/lib/dirs.tsv 128 cp_or_fail ${WD}/lib/createlinks ${GR}/lib/createlinks 129 cp_or_fail ${WD}/lib/symlinks.tsv ${GR}/lib/symlinks.tsv 130 cp_or_fail ${WD}/lib/setperms ${GR}/lib/setperms 131 cp_or_fail ${WD}/lib/perms.tsv ${GR}/lib/perms.tsv 132 cp_or_fail ${WD}/lib/rmfiles ${GR}/lib/rmfiles 133 cp_or_fail ${WD}/lib/rmlist.tsv ${GR}/lib/rmlist.tsv 134 135 cp_or_fail ${WD}/src/gettyc ${GR}/bin/gettyc 136 cp_or_fail -r ${WD}/${FLD}/man/* ${GR}/share/man/ 137 138 cp_or_fail ${WD}/${FLD}/rc.d/profile ${GR}/etc/profile.final 139 cp_or_fail ${WD}/${FLD}/rc.d/mkshrc ${GR}/etc/mkshrc 140 cp_or_fail ${WD}/${FLD}/rc.d/rc.conf ${GR}/etc/rc.conf 141 cp_or_fail ${WD}/${FLD}/rc.d/rc.inet ${GR}/bin/rc.inet 142 cp_or_fail ${WD}/${FLD}/rc.d/rc.init ${GR}/bin/rc.init 143 cp_or_fail ${WD}/${FLD}/rc.d/rc.shutdown ${GR}/bin/rc.shutdown 144 cp_or_fail ${WD}/${FLD}/rc.d/rc.local ${GR}/etc/rc.local 145 146 msg warn "Next run 03-packages.sh" 147 148 remove_file ${GR}/root/.profile 149 150 msg query "Run as root [Y/n]?" 151 read -r run_as_root 152 case "${run_as_root}" in 153 n|N) chroot --userspec=${GUID}:${GGID} ${GR} /${TLD}/bin/mksh -l +h;; 154 *) chroot ${GR} /${TLD}/bin/mksh -l +h;; 155 esac 156 157 umount ${GR}/tmp 158 umount ${GR}/run 159 umount ${GR}/sys/firmware/efi/efivars 160 umount ${GR}/sys 161 umount ${GR}/proc 162 umount -R ${GR}/dev 163 164 msg info "Generating %s" ${GR}/root/.profile 165 cat <<! >${GR}/root/.profile 166 #!/bin/sh 167 if [ -e ${HOME}/README.1st ]; then 168 clear 169 less ${HOME}/README.1st 170 rm /root/.profile 171 fi 172 ! 173 174 cd ${WD} 175 cp_or_fail ${WD}/${FLD}/README.1st ${GR}/root/README.1st 176 177 msg info "Creating directories" 178 ./lib/createdirs 179 180 msg info "Creating symlinks" 181 ./lib/createlinks 02-chroot.sh-end 182 183 msg info "Setting permissions" 184 ./lib/setperms 185 186 msg info "Cleaning up" 187 ./lib/rmfiles 02-chroot.sh-end 188 189 mv_or_fail ${GR}/etc/profile.final ${GR}/etc/profile 190 191 msg query "Run 05-mkbootimage.sh to generate a boot image [y/N]? " 192 read -r run_mkbootimage 193 case "${run_mkbootimage}" in 194 y|Y) ;; 195 *) exit;; 196 esac 197 198 ./05-mkbootimage.sh