Skip to content

Instantly share code, notes, and snippets.

@dsana123
Created February 18, 2016 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsana123/bdc9a5d8ceb0f683fd36 to your computer and use it in GitHub Desktop.
Save dsana123/bdc9a5d8ceb0f683fd36 to your computer and use it in GitHub Desktop.
#!/bin/bash --noprofile
# Bash script to perform installation of a base Arch Linux system within
# the arch-chroot environment. A normal user is created as specified by
# the 'user' variable.
set -o nounset
export readonly hostname=insert_amusing_hostname_here
export readonly user=insert_username_here
install() {
# We don't want to inherit the TERM type in case it's not suitable.
export TERM=linux
echo "Setting up the locale"
sed -i -e "s/^#en_GB.UTF-8 UTF-8/en_GB.UTF8 UTF-8/" /etc/locale.gen
locale-gen
echo "LANG=en_GB.UTF-8" > /etc/locale.conf
echo "Setting up the virtual console configuration."
pacman -S --needed terminus-font
cat >/etc/vconsole.conf <<EOF
KEYMAP=us
FONT=ter-132n
EOF
echo "Setting the time zone."
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
echo "Setting the time standard to UTC."
hwclock --systohc --utc
echo "Installing grub."
pacman -S --needed intel-ucode grub
grub-install --target=x86_64-efi --efi-directory=/boot --no-nvram
echo "Copying the grub EFI program to the location expected by the Apple boot loader."
mkdir -p /boot/EFI/BOOT
cp /boot/EFI/arch/grubx64.efi /boot/EFI/BOOT/BOOTX64.EFI
echo "Configuring grub (start ASAP, add hid-apple module parameter)."
sed -i \
-e 's/#\?GRUB_TIMEOUT=[0-9]*/GRUB_TIMEOUT=0/' \
-e 's/#\?GRUB_HIDDEN_TIMEOUT=[0-9]*/GRUB_HIDDEN_TIMEOUT=0/' \
-e 's/#\?GRUB_HIDDEN_TIMEOUT_QUIET=[a-zA-Z]*/GRUB_HIDDEN_TIMEOUT_QUIET=true/' \
-e 's/\(GRUB_CMDLINE_LINUX_DEFAULT="[^"]*\)/\1 hid_apple.iso_layout=0/' \
/etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
echo "Installing git and rsync."
pacman -S --needed git rsync
echo "Cloning the config repo."
local readonly git_parent_dir=/tmp
local readonly git_repo=config-macbook-pro-13-2015
pushd ${git_parent_dir}
if [[ ! -d ${git_repo} ]]; then
git clone https://xxx@xxx.xxx/path/to/${git_repo}.git
else
echo " The directory already exists, assuming it has already been cloned."
fi
popd
local readonly git_dir=${git_parent_dir}/${git_repo}
echo "Adding Arch Linux icon for Apple boot loader display."
cp ${git_dir}/other/.VolumeIcon.icns /boot
echo "Adding Arch Linux volume label for Apple boot loader display."
cp ${git_dir}/other/.disk_label /boot
cp ${git_dir}/other/.disk_label_2x /boot
echo "Setting the hostname."
echo "${hostname}" > /etc/hostname
sed -i -e "s/localhost$/localhost ${hostname}/" /etc/hosts
echo "Installing wireless packages for netctl."
pacman -S --needed iw wpa_supplicant dialog
echo "Setting root passwd."
passwd
echo "Creating a user: ${user}."
useradd -m -G wheel -s /bin/bash ${user}
echo "Setting a password for ${user}"
passwd ${user}
echo "Inhibiting last login message for user."
touch /home/${user}/.hushlogin
echo "Installing sudo and adding user to sudoers list."
pacman -S --needed sudo
echo "${user} ALL=(ALL) ALL" > /etc/sudoers.d/user_${user}
echo "Copying over /etc/modprobe.d files."
rsync -av --no-o --no-g ${git_dir}/system/modprobe.d/ /etc/modprobe.d
echo "Copying over /etc/udev/rules.d files."
rsync -av --no-o --no-g ${git_dir}/system/rules.d/ /etc/udev/rules.d
echo "Copying over /etc/sysctl.d files."
rsync -av --no-o --no-g ${git_dir}/system/sysctl.d/ /etc/sysctl.d
echo "Copying over /etc/systemd/coredump.conf.d files."
rsync -av --no-o --no-g ${git_dir}/system/coredump.conf.d /etc/systemd
echo "Copying over /etc/systemd/journald.conf.d files."
rsync -av --no-o --no-g ${git_dir}/system/journald.conf.d /etc/systemd
echo "Copying over /etc/systemd/logind.conf.d files."
rsync -av --no-o --no-g ${git_dir}/system/logind.conf.d /etc/systemd
echo "Disable IP ARP checking in /etc/dhcpcd.conf."
cat >>/etc/dhcpcd.conf <<EOF
# Disable IP ARP checking
noarp
EOF
echo "Increasing the file limit in /etc/security/limits.conf"
cat >>/etc/security/limits.conf <<EOF
* soft nofile 8192
* hard nofile 8192
EOF
}
install "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment