чување df56c0e6c8d1173600fcaac278357ae79d40a72a
родитељ df1f81891659036e84c2ed566bf9d41cef354918
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 4 Jul 2022 17:22:36 +0200
Chroot development
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 4, додавања: 115(+), брисања: 30(-)
diff --git a/02-prep-chroot.sh b/02-prep-chroot.sh
@@ -10,14 +10,29 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1
fi
+check_dir ${GR}/bin
+check_dir ${GR}/boot
check_dir ${GR}/dev
check_dir ${GR}/etc
+check_dir ${GR}/home
+check_dir ${GR}/include
+check_dir ${GR}/lib
+check_dir ${GR}/mnt
check_dir ${GR}/proc
-check_dir ${GR}/sys
check_dir ${GR}/run
+link_if_ne bin ${GR}/sbin
+check_dir ${GR}/share
+check_dir ${GR}/sucks/bin
+check_dir ${GR}/sucks/lib
+link_if_ne bin ${GR}/sucks/sbin
+check_dir ${GR}/sys
check_dir ${GR}/tmp
chmod +t ${GR}/tmp
+link_if_ne . ${GR}/usr
+check_dir ${GR}/var/cache
+check_dir ${GR}/var/log
check_dir ${GR}/var/run
+check_dir ${GR}/var/spool
check_mknod ${GR}/dev/console c 5 1 -m 600
check_mknod ${GR}/dev/null c 1 3 -m 666
@@ -33,15 +48,72 @@ if [ -h ${GR}/dev/shm ]; then
check_dir ${GR}/$(readlink ${GR}/dev/shm)
fi
-cat <<! >${GR}/etc/passwd
-root:x:0:0::/root:/bin/mksh
-galeb:x:${GUID}:${GGID}::/src:/bin/mksh
+if [ -e ${GR}/etc/passwd ]; then
+ msg info "%s exists" "${GR}/etc/passwd"
+else
+ msg info "Generating %s" "${GR}/etc/passwd"
+ cat <<! >${GR}/etc/passwd
+root:x:0:0:root:/root:/bin/mksh
+galeb:x:${GUID}:${GGID}:Temporary User Account:/src:/bin/mksh
+!
+fi
+
+if [ -e ${GR}/etc/group ]; then
+ msg info "%s exists" "${GR}/etc/group"
+else
+ msg info "Generating %s" "${GR}/etc/group"
+ cat <<! >${GR}/etc/group
+root:x:0:root
+galeb:x:${GGID}:galeb
!
+fi
+
+if [ -e ${GR}/etc/profile ]; then
+ msg info "%s exists" "${GR}/etc/profile"
+else
+ msg info "Generating %s" "${GR}/etc/profile"
+ cat <<! >${GR}/etc/profile
+PATH=/${TLD}/bin:/bin:/sbin:/sucks/bin:/sucks/sbin
+export PATH
+
+# A more familiar ls
+lc()
+{
+ /bin/ls \$* | cols
+}
+
+[ -e /etc/mkshrc ] && . /etc/mkshrc
+!
+fi
+
+if [ -e ${GR}/etc/mkshrc ]; then
+ msg info "%s exists" "${GR}/etc/mkshrc"
+else
+ msg info "Generating %s" "${GR}/etc/mkshrc"
+ cat <<'!' >${GR}/etc/mkshrc
+if [ "${KSHUID}" -eq 0 ]; then
+ PS1=$'\1\r\1\e]0;\1${PWD/#${HOME/\//\\\/}/\\~}\1\b\e[97m\1='\
+$'${HOSTNAME:=$(hostname)}=${PWD/#${HOME/\//\\\/}/\\~}= \1\e[1m\e[2m\e[31m\1\#\1\e[0m\1 '
+else
+ PS1=$'\1\r\1\e]0;\1${PWD/#${HOME/\//\\\/}/\\~}\1\b\e[97m\1='\
+$'${HOSTNAME:=$(hostname)}=${PWD/#${HOME/\//\\\/}/\\~}= \1\e[93m\1\$\1\e[0m\1 '
+fi
+
+bind '^L=clear-screen'
+bind -m ^U='^[0^K'
+
+set -U
+!
+fi
msg info "Next run 03-chroot.sh"
-PATH=/cross-tools/bin:/bin:/sbin:/sucks/bin \
-chroot ${GR} /bin/mksh -l +h
+msg query "Run as root [y/N]?"
+read -r run_as_root
+case "${run_as_root}" in
+ y|Y) chroot ${GR} /bin/mksh -l +h;;
+ *) chroot --userspec=${GUID}:${GGID} ${GR} /bin/mksh -l +h;;
+esac
#umount ${GR}/tmp
umount ${GR}/run
diff --git a/README b/README
@@ -24,17 +24,17 @@ Q: What license applies here?
A: License for each individual program is its own. License for files in this
repository is GPLv3, unless otherwise noted.
- musl-libc is licensed under Expat ("MIT") license, which doesn't restrict
+ musl-libc is licensed under the Expat ("MIT") license, which doesn't restrict
statically linking non-copylefted software.
- In contrast, glibc (not used here) is mainly licensed under LGPL v2.1+, which
- requires software using it to provide means for it to be potentially combined
- with modified versions of glibc (eg. have *.o files and Makefiles or just
- full source code available[2]).
+ In contrast, glibc (not used here) is mainly licensed under the LGPL v2.1+,
+ which requires software using it to provide means for it to be potentially
+ combined with modified versions of glibc (eg. have *.o files and Makefiles or
+ just full source code available[2]).
Scripts used to build the binary form of Galeb are publicly available, and
they use publicly available source code for all the constituent parts, so the
- requirements of GPL and LGPL are satisfied. Everyone can create modified
+ requirements of GPL and LGPL are satisfied. Anyone can create modified
versions of those scripts and the software they operate on according to their
respective licenses. Furthermore, Expat license is considered compatible with
the GPL by the FSF.[3]
diff --git a/galeb.session b/galeb.session
@@ -59,11 +59,10 @@ if &shortmess =~ 'A'
else
set shortmess=aoO
endif
-badd +45 01-cross.sh
-badd +99 lib/fun.sh
+badd +587 01-cross.sh
+badd +1 lib/fun.sh
badd +38 02-prep-chroot.sh
-badd +27 lib/env.sh
-badd +1 02-chroot.sh
+badd +25 lib/env.sh
argglobal
%argdel
$argadd 02-chroot.sh
@@ -94,7 +93,7 @@ exe 'vert 2resize ' . ((&columns * 95 + 95) / 191)
exe '3resize ' . ((&lines * 24 + 26) / 52)
exe 'vert 3resize ' . ((&columns * 95 + 95) / 191)
argglobal
-balt 02-chroot.sh
+balt lib/env.sh
setlocal keymap=
setlocal noarabic
setlocal noautoindent
@@ -224,11 +223,11 @@ setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
-let s:l = 179 - ((0 * winheight(0) + 25) / 50)
+let s:l = 587 - ((24 * winheight(0) + 25) / 50)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
-keepjumps 179
+keepjumps 587
normal! 0
wincmd w
argglobal
@@ -528,6 +527,7 @@ if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
+nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
diff --git a/lib/fun.sh b/lib/fun.sh
@@ -224,7 +224,7 @@ mount_or_fail()
msg()
{
- local fmt icon icon_plain kind tstamp
+ local fmt icon icon_plain kind log newline tstamp
icon=
icon_plain=
@@ -234,20 +234,33 @@ msg()
shift
tstamp=$(date +%T)
+ log=1
+ newline=1
case ${kind} in
- err) icon_plain="=E="
- icon="${bold}${white}${bgred}${icon_plain}";;
- info) icon_plain="=I="
- icon="${bold}${faint}${green}${icon_plain}";;
- warn) icon_plain="=W="
- icon="${bold}${yellow}${icon_plain}";;
- *) ;;
+ err) icon_plain="=E="
+ icon="${bold}${white}${bgred}${icon_plain}";;
+ info) icon_plain="=I="
+ icon="${bold}${faint}${green}${icon_plain}";;
+ query) icon_plain="=Q="
+ icon="${bold}${yellow}${icon_plain}"
+ log=0
+ newline=0;;
+ warn) icon_plain="=W="
+ icon="${bold}${yellow}${icon_plain}";;
+ *) ;;
esac
printf "%s %s " "${icon}" ${tstamp}
printf "%s %s " "${icon_plain}" ${tstamp} >>${G_LOG}
- printf "${fmt}${norm}\n" "$@"
- printf "$(echo "${fmt}" | sed 's/'$(printf '\033')'\[[0-9]\+m//g')\n" \
- "$@" >>${G_LOG}
+ printf "${fmt}${norm}" "$@"
+ if [ ${newline} -eq 1 ]; then
+ echo
+ else
+ printf ' '
+ fi
+ [ ${log} -eq 1 ] && \
+ printf "$(echo "${fmt}" | \
+ sed 's/'$(printf '\033')'\[[0-9]\+m//g')\n" \
+ "$@" >>${G_LOG}
}
mv_or_fail()