summaryrefslogtreecommitdiff
path: root/archinstall.sh
blob: 283cbe122dbaf4c9690c81db154c3329cde15eb8 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash


#  archinstall - A minimal Installation Script for Arch Linux
#  Copyright (C) 2019  xengineering

#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.

#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.


#################################################################
#                  _                 _        _ _       _       #
#    __ _ _ __ ___| |__ (_)_ __  ___| |_ __ _| | |  ___| |__    #
#   / _` | '__/ __| '_ \| | '_ \/ __| __/ _` | | | / __| '_ \   #
#  | (_| | | | (__| | | | | | | \__ \ || (_| | | |_\__ \ | | |  #
#   \__,_|_|  \___|_| |_|_|_| |_|___/\__\__,_|_|_(_)___/_| |_|  #
#                                                               #
#################################################################


# Settings for the Script:

DELAY=0.5
CLONE_BRANCH="master"
BASE_URL="https://github.com/xengineering/archinstall/"
RAW_BASE_URL="https://raw.githubusercontent.com/xengineering/archinstall/"


# Greetings and settings

cat << EOF

#################################################################
#                                                               #
#                Arch Linux Installation Script                 #
#                                                               #
# archinstall  Copyright (C) 2019  xengineering                 #
# This program comes with ABSOLUTELY NO WARRANTY.               #
# This is free software, and you are welcome to redistribute it #
# under certain conditions. See                                 #
# <https://www.gnu.org/licenses/gpl-3.0.en.html> for details.   #
#                                                               #
#################################################################

EOF


echo "Here is a list of available hard disks on your computer:"
echo ""
lsblk -o NAME,SIZE,TYPE | grep -v part
echo ""
echo "Please type in the 'NAME' of the hard disk on which you want to"
echo "install Arch Linux:"
read disk
disk_path="/dev/$disk"
echo ""


echo "Please type in the hostname of your new machine:"
read hostname
echo ""


locales[1]="German / Germany"
cat << EOF
Please select one of the available localizations:

[1] ${locales[1]}
EOF
read locale_id
echo ""


cat << EOF
#################################################################

                            Summary

    Hard disk:     -  $disk
    Hostname:      -  $hostname
    Localization:  -  ${locales[$locale_id]}

#################################################################

EOF

echo "All data on disk '$disk' will be finally lost!"
echo "Are you SURE that you want to install Arch Linux to '$disk'?!"
echo "Type 'Yes' for installation and 'No' for abort."
read answer
if [ $answer == "Yes" ]; then
    echo ""
    echo "Starting installation process - OK"
    echo ""
else
    echo ""
    echo "Abort of installation process!"
    exit
fi


# Check if booted with UEFI

if [ -d "/sys/firmware/efi/efivars" ]; then
    echo "Booted with UEFI - OK"
    echo ""
    sleep $DELAY
else
    echo "Not booted with UEFI. Please enable it in your mainboard settings. - FAILED"
    exit
fi


# Check internet connection

TESTSERVER="8.8.8.8"  # hostnames will not work properly

if ping -w 1 -c 1 $TESTSERVER > /dev/null; then
    echo "Internet connection is ready - OK"
    echo ""
    sleep $DELAY
else
    echo "Could not reach testserver '$TESTSERVER' - FAILED"
    exit
fi


# Update the system clock

timedatectl set-ntp true
if [ $? -eq 0 ]; then
    echo "Updated system clock - OK"
    echo ""
    sleep $DELAY
else
    echo "Could not update system clock - FAILED"
    exit
fi


# Partitioning

wipefs -a $disk_path > /dev/null  # make sure that fdisk does not ask for
                                  # removing signatures which breaks the script
fdisk $disk_path > /dev/null 2> /dev/null << EOF
g
n
1

+512M
n
2


p
w
EOF
boot_partition_path="${disk_path}1"
root_partition_path="${disk_path}2"
echo "Partitioning finished - OK"
sleep $DELAY
echo ""


# Create Filesystems

mkfs.fat -F32 $boot_partition_path > /dev/null 2> /dev/null
mkfs.ext4 $root_partition_path > /dev/null 2> /dev/null
fatlabel $boot_partition_path "BOOT" > /dev/null
e2label $root_partition_path "ROOT" > /dev/null
echo "Created filesystems - OK"
sleep $DELAY
echo ""


# Mount Root Filesystem

mount $root_partition_path /mnt
echo "Mounted root partition - OK"
sleep $DELAY
echo ""


# Install basic Packages

echo "Going to install basic packages ..."
sleep $DELAY
echo ""
pacstrap /mnt base linux dhcpcd
echo ""
echo "Installed basic packages - OK"
sleep $DELAY
echo ""


# Generate /etc/fstab file

genfstab -U /mnt >> /mnt/etc/fstab
echo "Generated /etc/fstab - OK"
sleep $DELAY
echo ""


# Install git in live environment and clone archinstall repository

pacman --noconfirm -Sy git
cd /mnt/opt && git clone $BASE_URL
cd /root
mv /mnt/opt/archinstall /mnt/opt/archinstall.git
cd /mnt/opt/archinstall.git && git checkout $CLONE_BRANCH
cd /root
echo "bash /opt/archinstall.git/bin/second_stage.sh $hostname ${disk_path}1" | arch-chroot /mnt

cd /root && umount $root_partition_path
echo "Unmounted root partition - OK"
sleep $DELAY
echo ""


# Final Messages

cat << EOF
#################################################################
#                                                               #
#     The default login is user root with password 'root'.      #
#     You can now power off your machine with 'poweroff',       #
#     remove the installation media and boot your new           #
#     Arch Linux machine!                                       #
#                                                               #
#################################################################

EOF