Compare commits
7 Commits
d2108276a0
...
3903498d40
Author | SHA1 | Date | |
---|---|---|---|
3903498d40 | |||
59beb10404 | |||
d99bb94c52 | |||
c9f979a0ad | |||
db3c705376 | |||
d5e219dbf5 | |||
bd586e4c67 |
@@ -418,7 +418,7 @@ In order to generate a new master key after you've changed your user key as ment
|
|||||||
--large-block \
|
--large-block \
|
||||||
--compressed \
|
--compressed \
|
||||||
'zpool/root/archlinux-sxu@rekey' | \
|
'zpool/root/archlinux-sxu@rekey' | \
|
||||||
|
\
|
||||||
zfs receive \
|
zfs receive \
|
||||||
-Fvu \
|
-Fvu \
|
||||||
-o 'encryption=on' \
|
-o 'encryption=on' \
|
||||||
|
151
setup.sh
151
setup.sh
@@ -36,6 +36,17 @@ trap '[ "$?" -ne 77 ] || exit 77' ERR
|
|||||||
|
|
||||||
declare zpool_drive efi_drive boot_drive part_schema
|
declare zpool_drive efi_drive boot_drive part_schema
|
||||||
|
|
||||||
|
function calculate_prefix_from_netmask () {
|
||||||
|
# https://stackoverflow.com/a/50419919
|
||||||
|
c='0'
|
||||||
|
x='0'"$(printf -- '%o' ${1//./ })"
|
||||||
|
while [ "${x}" -gt '0' ]; do
|
||||||
|
# Modulo then bitwise-shift x and store as new x
|
||||||
|
let c+="$(( x % 2 ))" 'x>>=1'
|
||||||
|
done
|
||||||
|
printf -- '%s' '/'"${c}";
|
||||||
|
}
|
||||||
|
|
||||||
function setup_env_vars () {
|
function setup_env_vars () {
|
||||||
printf -- '%s\n' \
|
printf -- '%s\n' \
|
||||||
'We will go over a series of questions to create an answer file with' \
|
'We will go over a series of questions to create an answer file with' \
|
||||||
@@ -57,7 +68,7 @@ function setup_env_vars () {
|
|||||||
echo '----------------------------------------'
|
echo '----------------------------------------'
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "Do you want compressed datasets?"
|
echo 'Do you want compressed datasets?'
|
||||||
select arg_compressed in "Compressed" "Uncompressed"; do
|
select arg_compressed in "Compressed" "Uncompressed"; do
|
||||||
case "${arg_compressed}" in
|
case "${arg_compressed}" in
|
||||||
Compressed)
|
Compressed)
|
||||||
@@ -70,7 +81,7 @@ function setup_env_vars () {
|
|||||||
esac
|
esac
|
||||||
done <&3 && echo
|
done <&3 && echo
|
||||||
|
|
||||||
echo "Do you want encrypted datasets?"
|
echo 'Do you want encrypted datasets?'
|
||||||
select arg_encrypted in "Encrypted" "Unencrypted"; do
|
select arg_encrypted in "Encrypted" "Unencrypted"; do
|
||||||
case "${arg_encrypted}" in
|
case "${arg_encrypted}" in
|
||||||
Encrypted)
|
Encrypted)
|
||||||
@@ -84,7 +95,7 @@ function setup_env_vars () {
|
|||||||
done <&3 && echo
|
done <&3 && echo
|
||||||
|
|
||||||
if [[ "${arg_encrypted}" = 'Encrypted' ]]; then
|
if [[ "${arg_encrypted}" = 'Encrypted' ]]; then
|
||||||
echo "Do you want a custom dataset decryption password?"
|
echo 'Do you want a custom dataset decryption password?'
|
||||||
select arg_custom_dataset_pw in "Yes" "No"; do
|
select arg_custom_dataset_pw in "Yes" "No"; do
|
||||||
case "${arg_custom_dataset_pw}" in
|
case "${arg_custom_dataset_pw}" in
|
||||||
Yes)
|
Yes)
|
||||||
@@ -104,7 +115,7 @@ function setup_env_vars () {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Do you want a custom 'root' user password?"
|
echo 'Do you want a custom '"'"'root'"'"' user password?'
|
||||||
select arg_custom_root_pw in "Yes" "No"; do
|
select arg_custom_root_pw in "Yes" "No"; do
|
||||||
case "${arg_custom_root_pw}" in
|
case "${arg_custom_root_pw}" in
|
||||||
Yes)
|
Yes)
|
||||||
@@ -123,7 +134,7 @@ function setup_env_vars () {
|
|||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Do you want an SSH daemon in ZFSBootMenu?"
|
echo 'Do you want an SSH daemon in ZFSBootMenu?'
|
||||||
select arg_ssh_in_zbm in "Yes" "No"; do
|
select arg_ssh_in_zbm in "Yes" "No"; do
|
||||||
case "${arg_ssh_in_zbm}" in
|
case "${arg_ssh_in_zbm}" in
|
||||||
Yes)
|
Yes)
|
||||||
@@ -137,7 +148,7 @@ function setup_env_vars () {
|
|||||||
done <&3 && echo
|
done <&3 && echo
|
||||||
|
|
||||||
if [[ "${want_ssh_in_zbm}" ]]; then
|
if [[ "${want_ssh_in_zbm}" ]]; then
|
||||||
echo "How do you want to assign an IP address in ZFSBootMenu?"
|
echo 'How do you want to assign an IP address in ZFSBootMenu?'
|
||||||
select arg_ip_autoconf_method in "Statically" "Dynamically, DHCP" "Dynamically, BOOTP" "Dynamically, RARP"; do
|
select arg_ip_autoconf_method in "Statically" "Dynamically, DHCP" "Dynamically, BOOTP" "Dynamically, RARP"; do
|
||||||
case "${arg_ip_autoconf_method}" in
|
case "${arg_ip_autoconf_method}" in
|
||||||
'Statically')
|
'Statically')
|
||||||
@@ -173,7 +184,7 @@ function setup_env_vars () {
|
|||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Do you want a custom SSH listening port?"
|
echo 'Do you want a custom SSH listening port?'
|
||||||
select arg_custom_ssh_port in "Yes (let me specify)" "No (keep port 22)"; do
|
select arg_custom_ssh_port in "Yes (let me specify)" "No (keep port 22)"; do
|
||||||
case "${arg_custom_ssh_port}" in
|
case "${arg_custom_ssh_port}" in
|
||||||
'Yes (let me specify)')
|
'Yes (let me specify)')
|
||||||
@@ -191,7 +202,7 @@ function setup_env_vars () {
|
|||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Do you want the SSH daemon to use a custom keepalive send interval?"
|
echo 'Do you want the SSH daemon to use a custom keepalive send interval?'
|
||||||
select arg_custom_ssh_keepalive_intvl in "Yes (let me specify)" "No (keep 1)"; do
|
select arg_custom_ssh_keepalive_intvl in "Yes (let me specify)" "No (keep 1)"; do
|
||||||
case "${arg_custom_ssh_keepalive_intvl}" in
|
case "${arg_custom_ssh_keepalive_intvl}" in
|
||||||
'Yes (let me specify)')
|
'Yes (let me specify)')
|
||||||
@@ -213,7 +224,84 @@ function setup_env_vars () {
|
|||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for env_var in 'ARCHZBM_ZFSPROPS_NO_COMPRESSION' 'ARCHZBM_ZFSPROPS_NO_ENCRYPTION' 'ARCHZBM_ZPOOL_PASSWORD' 'ARCHZBM_ROOT_PASSWORD' 'ARCHZBM_NET_AUTOCONF' 'ARCHZBM_NET_DEVICE' 'ARCHZBM_NET_CLIENT_IP' 'ARCHZBM_NET_NETMASK' 'ARCHZBM_NET_GATEWAY_IP' 'ARCHZBM_SSH_PORT' 'ARCHZBM_SSH_KEEPALIVE_INTVL' 'ARCHZBM_SSH_AUTH_KEYS'; do
|
if [[ "${want_ssh_in_zbm}" ]]; then
|
||||||
|
echo 'Do you want to define operating system'"'"'s IP address?'
|
||||||
|
select arg_os_ip in 'Yes (let me specify)' 'Yes (use ZBM addresses)' 'No (DHCP is fine)'; do
|
||||||
|
case "${arg_os_ip}" in
|
||||||
|
'Yes (let me specify)')
|
||||||
|
want_custom_ip_in_os='true'
|
||||||
|
want_dns_and_ntp='true'
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
'Yes (use ZBM addresses)')
|
||||||
|
ARCHZBM_OS_CLIENT_IP="${ARCHZBM_NET_CLIENT_IP}"
|
||||||
|
ARCHZBM_NET_CLIENT_IP_PREFIX="$(calculate_prefix_from_netmask "${ARCHZBM_NET_NETMASK}")"
|
||||||
|
ARCHZBM_OS_CLIENT_IP+="${ARCHZBM_NET_CLIENT_IP_PREFIX}"
|
||||||
|
ARCHZBM_OS_GATEWAY_IP="${ARCHZBM_NET_GATEWAY_IP}"
|
||||||
|
want_dns_and_ntp='true'
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
'No (DHCP is fine)')
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done <&3 && echo
|
||||||
|
|
||||||
|
if [[ "${want_custom_ip_in_os}" ]]; then
|
||||||
|
read -u3 -p 'Interface IP address with CIDR prefix (a.b.c.d/nn): ' ARCHZBM_OS_CLIENT_IP
|
||||||
|
echo
|
||||||
|
|
||||||
|
read -u3 -p 'Gateway IP address: ' ARCHZBM_OS_GATEWAY_IP
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo 'Do you want to define operating system'"'"'s IP address?'
|
||||||
|
select arg_os_ip in 'Yes (let me specify)' 'No (DHCP is fine)'; do
|
||||||
|
case "${arg_os_ip}" in
|
||||||
|
'Yes (let me specify)')
|
||||||
|
want_own_ip_in_os='true'
|
||||||
|
want_dns_and_ntp='true'
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
'No (DHCP is fine)')
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done <&3 && echo
|
||||||
|
|
||||||
|
if [[ "${want_own_ip_in_os}" ]]; then
|
||||||
|
read -u3 -p 'Interface IP address with CIDR prefix (a.b.c.d/nn): ' ARCHZBM_OS_CLIENT_IP
|
||||||
|
echo
|
||||||
|
|
||||||
|
read -u3 -p 'Gateway IP address: ' ARCHZBM_OS_GATEWAY_IP
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${want_dns_and_ntp}" ]]; then
|
||||||
|
read -u3 -p 'Specify one or more comma-separated DNS IPs: ' ARCHZBM_OS_DNS_IP
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo 'Do you want to override Arch Linux'"'"' NTP servers?'
|
||||||
|
select arg_custom_ntp in 'Yes' 'No'; do
|
||||||
|
case "${arg_custom_ntp}" in
|
||||||
|
'Yes')
|
||||||
|
want_own_ntp='true'
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
'No')
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done <&3 && echo
|
||||||
|
|
||||||
|
if [[ "${want_own_ntp}" ]]; then
|
||||||
|
read -u3 -p 'Specify one or more comma-separated NTP hostnames or IPs: ' ARCHZBM_OS_NTP_IP
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
for env_var in 'ARCHZBM_ZFSPROPS_NO_COMPRESSION' 'ARCHZBM_ZFSPROPS_NO_ENCRYPTION' 'ARCHZBM_ZPOOL_PASSWORD' 'ARCHZBM_ROOT_PASSWORD' 'ARCHZBM_NET_AUTOCONF' 'ARCHZBM_NET_DEVICE' 'ARCHZBM_NET_CLIENT_IP' 'ARCHZBM_NET_NETMASK' 'ARCHZBM_NET_GATEWAY_IP' 'ARCHZBM_SSH_PORT' 'ARCHZBM_SSH_KEEPALIVE_INTVL' 'ARCHZBM_SSH_AUTH_KEYS' 'ARCHZBM_OS_CLIENT_IP' 'ARCHZBM_OS_GATEWAY_IP' 'ARCHZBM_OS_DNS_IP' 'ARCHZBM_OS_NTP_IP'; do
|
||||||
if [[ "${!env_var}" ]]; then
|
if [[ "${!env_var}" ]]; then
|
||||||
printf -- '%s='"'"'%s'"'"'\n' \
|
printf -- '%s='"'"'%s'"'"'\n' \
|
||||||
"${env_var}" "${!env_var}" \
|
"${env_var}" "${!env_var}" \
|
||||||
@@ -1207,11 +1295,54 @@ function set_root_pw () {
|
|||||||
|
|
||||||
function configure_networking () {
|
function configure_networking () {
|
||||||
#3.3
|
#3.3
|
||||||
|
local -a dns_addresses ntp_addresses
|
||||||
|
|
||||||
|
# Begin network unit file with a default top section
|
||||||
cat > '/mnt/etc/systemd/network/50-wired.network' <<"EOF"
|
cat > '/mnt/etc/systemd/network/50-wired.network' <<"EOF"
|
||||||
[Match]
|
[Match]
|
||||||
Name=en*
|
Name=en*
|
||||||
|
|
||||||
[Network]
|
[Network]
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Decide on what comes next in network unit file
|
||||||
|
if [[ "${ARCHZBM_OS_CLIENT_IP}" ]] || \
|
||||||
|
[[ "${ARCHZBM_OS_GATEWAY_IP}" ]] || \
|
||||||
|
[[ "${ARCHZBM_OS_DNS_IP}" ]] || \
|
||||||
|
[[ "${ARCHZBM_OS_NTP_IP}" ]]; then
|
||||||
|
|
||||||
|
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
|
||||||
|
Address="${ARCHZBM_OS_CLIENT_IP}"
|
||||||
|
Gateway="${ARCHZBM_OS_GATEWAY_IP}"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [[ "${ARCHZBM_OS_DNS_IP}" ]]; then
|
||||||
|
mapfile -t dns_addresses < <(<<<"${ARCHZBM_OS_DNS_IP}" tr ',' '\n' | sed '/^$/d')
|
||||||
|
else
|
||||||
|
dns_addresses+=('8.8.8.8')
|
||||||
|
dns_addresses+=('8.8.4.4')
|
||||||
|
fi
|
||||||
|
for dns_addr in "${dns_addresses[@]}"; do
|
||||||
|
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
|
||||||
|
DNS="${dns_addr}"
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "${ARCHZBM_OS_NTP_IP}" ]]; then
|
||||||
|
mapfile -t ntp_addresses < <(<<<"${ARCHZBM_OS_NTP_IP}" tr ',' '\n' | sed '/^$/d')
|
||||||
|
for ntp_addr in "${ntp_addresses[@]}"; do
|
||||||
|
cat >> '/mnt/etc/systemd/network/50-wired.network' <<EOF
|
||||||
|
NTP="${ntp_addr}"
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat >> '/mnt/etc/systemd/network/50-wired.network' <<"EOF"
|
||||||
|
IPForward=yes
|
||||||
|
Domains=~.
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
cat >> '/mnt/etc/systemd/network/50-wired.network' <<"EOF"
|
||||||
DHCP=ipv4
|
DHCP=ipv4
|
||||||
IPForward=yes
|
IPForward=yes
|
||||||
|
|
||||||
@@ -1219,6 +1350,8 @@ IPForward=yes
|
|||||||
UseDNS=yes
|
UseDNS=yes
|
||||||
RouteMetric=10
|
RouteMetric=10
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
systemctl enable 'systemd-networkd' --root='/mnt'
|
systemctl enable 'systemd-networkd' --root='/mnt'
|
||||||
systemctl disable 'systemd-networkd-wait-online' --root='/mnt'
|
systemctl disable 'systemd-networkd-wait-online' --root='/mnt'
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user