forked from mk-fg/fgtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
can-strap
executable file
·56 lines (46 loc) · 1.51 KB
/
can-strap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
usage() {
bin=$(basename $0)
echo >&2 "Usage: $bin [-x] [-c pacman.conf] name [can-set...] [-- pacstrap-opts...]"
echo >&2
echo >&2 "Bootstraps arch chroot in /var/lib/machines from"
echo >&2 " a can-* meta-package (default: base) using pacstrap."
echo >&2 "pacman.conf should have a repo where can-* packages will be available."
echo >&2 "See can-base package here:"
echo >&2 " https://github.com/mk-fg/archlinux-pkgbuilds/blob/master/can-base/PKGBUILD"
echo >&2
echo >&2 "Example: $bin -c pacman.i686.conf mymachine tools py -- -i"
exit ${1:-0}
}
[[ -z "$1" || "$1" = -h || "$1" = --help ]] && usage
pacman_conf=/etc/pacman.conf
[[ "$1" = -x ]] && { set -x; shift; }
[[ "$1" = -c ]] && { shift; pacman_conf=$(realpath "$1"); shift; }
[[ -z "$1" ]] && usage 1
can=$1
shift
can_sets=()
[[ -z "$1" ]]\
&& can_sets+=( can-base )\
|| while :; do
can_set=$1; shift
[[ -z "$can_set" || "$can_set" = -- ]] && break
can_sets+=( can-"$can_set" )
done
set -e -o pipefail
export LC_ALL=C
cd /var/lib/machines
mkdir -p "$can"
pacstrap "$@" -c -C "$pacman_conf" -d "$can" "${can_sets[@]}"
for conf in \
/etc/{localtime,profile,locale.gen,locale.conf} \
/etc/{screenrc,nanorc,gitconfig,pacman.d/mirrorlist}
do [[ ! -e "$conf" ]] || rsync -aL "$conf" "$can$conf"
done
chsh_cmd=true
[[ "${SHELL##*/}" != zsh || ! -e "$can"/etc/zsh/ ]] || {
cp /etc/zsh/* "$can"/etc/zsh/
[[ ! -e /root/.zshrc ]] || cp /root/.zshrc "$can"/root/
chsh_cmd="chsh -s $SHELL"
}
systemd-nspawn -D "$can" sh -c "locale-gen && $chsh_cmd"