2023-05-29 21:37:17 +08:00
|
|
|
#!/bin/ash
|
2023-05-29 16:38:07 +08:00
|
|
|
#
|
|
|
|
# Alpine Linux use "ash" as default shell.
|
2023-05-28 14:03:19 +08:00
|
|
|
|
|
|
|
exec >/dev/tty0 2>&1
|
|
|
|
|
2023-05-29 16:38:07 +08:00
|
|
|
addCommunityRepo() {
|
|
|
|
alpineVer=$(cut -d. -f1,2 </etc/alpine-release)
|
2023-05-29 21:41:03 +08:00
|
|
|
echo $LinuxMirror/v$alpineVer/community >>/etc/apk/repositories
|
2023-05-28 14:03:19 +08:00
|
|
|
}
|
|
|
|
|
2023-05-29 22:10:52 +08:00
|
|
|
# Delete the initial script itself to prevent to be executed in the new system.
|
|
|
|
rm -f /etc/local.d/alpineConf.start
|
|
|
|
rm -f /etc/runlevels/default/local
|
|
|
|
|
2023-05-29 21:41:03 +08:00
|
|
|
# Install necessary components.
|
|
|
|
apk update
|
2023-05-29 22:10:52 +08:00
|
|
|
apk add bash bash bash-doc bash-completion coreutils sed
|
2023-05-29 21:41:03 +08:00
|
|
|
|
|
|
|
# Get Alpine Linux configurations.
|
|
|
|
confFile="/root/alpine.config"
|
|
|
|
|
|
|
|
# Read configs from initial file.
|
|
|
|
AllDisks=$(grep "AllDisks" $confFile | awk '{print $2}')
|
|
|
|
LinuxMirror=$(grep "LinuxMirror" $confFile | awk '{print $2}')
|
|
|
|
TimeZone=$(grep "TimeZone" $confFile | awk '{print $2}')
|
|
|
|
tmpWORD=$(grep "tmpWORD" $confFile | awk '{print $2}')
|
|
|
|
sshPORT=$(grep "sshPORT" $confFile | awk '{print $2}')
|
|
|
|
AlpineTestRepository=$(grep "AlpineTestRepository" $confFile | awk '{print $2}')
|
|
|
|
|
2023-05-29 21:11:13 +08:00
|
|
|
# Setting Alpine Linux by "setup-alpine" will enable the following services
|
|
|
|
# https://github.com/alpinelinux/alpine-conf/blob/c5131e9a038b09881d3d44fb35e86851e406c756/setup-alpine.in#L189
|
|
|
|
# acpid | default
|
|
|
|
# crond | default
|
|
|
|
# seedrng | boot
|
|
|
|
|
|
|
|
# Add virt-what to community repository
|
|
|
|
addCommunityRepo
|
|
|
|
|
|
|
|
# Use kernel "virt" if be executed on virtual machine
|
|
|
|
cp /etc/apk/world /tmp/world.old
|
|
|
|
[[ -n "$(virt-what)" ]] && kernelOpt="-k virt"
|
|
|
|
|
|
|
|
# Reset configurations of repositories
|
|
|
|
true >/etc/apk/repositories
|
|
|
|
setup-apkrepos -1
|
|
|
|
setup-apkcache /var/cache/apk
|
|
|
|
|
|
|
|
# Delete comment in the repositories
|
|
|
|
sed -i 's/#//' /etc/apk/repositories
|
2023-05-28 14:03:19 +08:00
|
|
|
|
2023-05-29 21:32:53 +08:00
|
|
|
# Add edge testing to the repositories
|
2023-05-29 21:57:11 +08:00
|
|
|
sed -i '$a\'${AlpineTestRepository}'' /etc/apk/repositories
|
2023-05-29 21:32:53 +08:00
|
|
|
|
2023-05-29 16:38:07 +08:00
|
|
|
# Synchronize time from hardware
|
2023-05-28 14:03:19 +08:00
|
|
|
hwclock -s
|
|
|
|
|
2023-05-29 16:38:07 +08:00
|
|
|
# Install and enable ssh
|
2023-05-29 21:11:13 +08:00
|
|
|
echo root:${tmpWORD} | chpasswd
|
2023-05-28 14:03:19 +08:00
|
|
|
printf '\nyes' | setup-sshd
|
2023-05-29 21:57:11 +08:00
|
|
|
sed -ri 's/^#?Port.*/Port '${sshPORT}'/g' /etc/ssh/sshd_config
|
2023-05-28 14:03:19 +08:00
|
|
|
|
2023-05-29 16:52:06 +08:00
|
|
|
# Network configurations.
|
|
|
|
# Setup adapter.
|
|
|
|
setup-interfaces -a
|
|
|
|
# Generate network file of "/etc/network/interfaces"
|
|
|
|
rc-update add networking boot
|
|
|
|
# Delete network file and replace it by us.
|
2023-05-29 22:24:24 +08:00
|
|
|
rm -rf /etc/network/interfaces
|
|
|
|
mv /etc/network/tmp_interfaces /etc/network/interfaces
|
|
|
|
chmod a+x /etc/network/interfaces
|
2023-05-29 16:52:06 +08:00
|
|
|
|
2023-05-29 16:38:07 +08:00
|
|
|
# Localization
|
2023-05-28 14:03:19 +08:00
|
|
|
setup-keymap us us
|
2023-05-29 21:11:13 +08:00
|
|
|
setup-timezone -i ${TimeZone}
|
2023-05-28 14:03:19 +08:00
|
|
|
setup-ntp chrony
|
|
|
|
|
2023-05-29 16:38:07 +08:00
|
|
|
# In arm netboot initramfs init,
|
|
|
|
# If rtc hardware is detected, add hwclock for system, otherwise add swclock
|
|
|
|
# This settings will be copied to the new system
|
|
|
|
# But the new system boot from initramfs chroot can detect rtc hardwa1 correctly
|
|
|
|
# So we use hwclock manually to fix it
|
2023-05-28 14:03:19 +08:00
|
|
|
rc-update del swclock boot
|
|
|
|
rc-update add hwclock boot
|
|
|
|
|
2023-05-29 17:30:47 +08:00
|
|
|
# Replace "ash" to "bash" as the default shell of the Alpine Linux.
|
2023-05-29 22:10:52 +08:00
|
|
|
sed -ri 's/ash/bash/g' /etc/passwd
|
|
|
|
|
2023-05-29 22:24:24 +08:00
|
|
|
# Insall more components.
|
|
|
|
apk update
|
2023-05-29 22:10:52 +08:00
|
|
|
apk add axel bind-tools cpio curl e2fsprogs figlet grep grub gzip hdparm lsblk net-tools parted python3 py3-pip udev util-linux vim virt-what wget
|
2023-05-29 17:30:47 +08:00
|
|
|
|
2023-05-29 22:24:24 +08:00
|
|
|
# Install to hard drive.
|
|
|
|
export BOOTLOADER="grub"
|
|
|
|
printf 'y' | setup-disk -m sys $kernelOpt -s 0 $AllDisks
|
|
|
|
|
2023-05-29 16:38:07 +08:00
|
|
|
# Reboot, the system in the memory will all be written to the hard drive.
|
|
|
|
exec reboot
|