-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinstall-in-chroot.sh
executable file
·143 lines (119 loc) · 2.7 KB
/
install-in-chroot.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
CPUCoreCount=$(grep -c processor /proc/cpuinfo)
jobCount=$((CPUCoreCount + 1))
Color_Red='\033[0;31m' # Red
Color_Green='\033[0;32m' # Green
Color_Yellow='\033[0;33m' # Yellow
Color_Purple='\033[0;35m' # Purple
Color_Cyan='\033[0;36m' # Cyan
Color_Off='\033[0m' # Reset
msg() {
printf "%b\n" "$1"
}
info() {
msg "${Color_Purple}[🌺] $1$2${Color_Off}"
}
warn() {
msg "${Color_Yellow}[🔥] $1$2${Color_Off}"
}
prompt() {
msg "${Color_Cyan}[🍎] $1$2:${Color_Off}"
}
error() {
msg "${Color_Red}[✘] $1$2${Color_Off}"
exit 1
}
errorOnly() {
msg "${Color_Red}[✘] $1$2${Color_Off}"
}
success() {
msg "${Color_Green}[✔] $1$2${Color_Off}"
}
#step19
syncPortageTree() {
emerge --sync
}
#step20
selectProfile() {
eselect profile set default/linux/amd64/17.1/systemd
}
#step21
updateWorldSet() {
emerge --ask --verbose --update --deep --newuse @world
}
#step22
setTimeZone() {
echo "Asia/Shanghai" > /etc/timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
}
#step23
genLocales() {
sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen &&
locale-gen &&
eselect locale set en_US.UTF-8 &&
env-update && . /etc/profile
}
#step24
configfstab() {
curl -o /sbin/genfstab https://raw.githubusercontent.com/YangMame/Gentoo-Installer/master/genfstab
chmod o+x /sbin/genfstab
genfstab -U / >> /etc/fstab
}
#step24
downloadLinuxKernelSources() {
emerge sys-kernel/gentoo-sources
emerge sys-kernel/genkernel
emerge sys-kernel/linux-firmware
emerge sys-apps/pciutils
}
#step25
compileLinuxKernelSources() {
[ -d /usr/src/linux ] || error "sys-kernel/gentoo-sources not installed"
#cd /usr/src/linux
genkernel all
}
#step26
configHostname() {
prompt "please set hostname:"
read -r hostname
sed -i "s/127.0.0.1\slocalhost/127.0.0.1\\tlocalhost ${hostname}/g" /etc/hosts
sed -i "s@hostname=\"localhost\"@hostname=\"${hostname}\"@g" /etc/conf.d/hostname
}
#step27
setRootPassword() {
print "%s" "set root "
passwd
}
#step28
newUserAndSetPassword() {
prompt "please set none-root username:"
read -r username
useradd -m -G wheel -s /bin/bash "$username"
passwd "$username"
}
#step29
installAndConfigGrub2() {
emerge sys-boot/grub:2
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg
}
#step30
exitChroot() {
exit
}
main() {
syncPortageTree
selectProfile
updateWorldSet
setTimeZone
genLocales
configfstab
downloadLinuxKernelSources
compileLinuxKernelSources
configHostname
setRootPassword
newUserAndSetPassword
installAndConfigGrub2
exitChroot
}
main "$@"