Skip to content

Instantly share code, notes, and snippets.

@andreaseger
Last active September 13, 2016 07:40
Show Gist options
  • Save andreaseger/5653983 to your computer and use it in GitHub Desktop.
Save andreaseger/5653983 to your computer and use it in GitHub Desktop.
prepares and installs an archlinux installation with btrfs on dm_crypt with gnome and one user. Partionining has to be done beforehand
#!/bin/bash
TMP_DIR=/opt/tmp
cd $TMP_DIR
tar -xvzf $1.tar.gz
cd $1
makepkg --asroot -si
#!/bin/bash
user=$1
DIR=/opt/dot-files
git clone -b fish --single-branch https://[email protected]/sch1zo/dot-files.git $DIR
cd $DIR
git submodule update --init
cp $DIR/.* /home/$user -r
chown $user:users /home/$user -R
#!/bin/bash
tmp=`dirname $0`
BASE=`realpath $tmp/..`
echo $BASE
pause(){
read -p "$*"
}
refresh_pacman() {
echo "refresh pacman"
pacman -Sy
pacman -S --noconfirm reflector
reflector -f 6 -l 6 --save /etc/pacman.d/mirrorlist
pacman -Syy
}
setup_LUKS(){
local device=$1
echo $device
cryptsetup luksFormat $device
cryptsetup luksOpen $device cryptroot
}
setup_btrfs(){
local device=$1 ; shift 1
# format and mount btrfs root
mkfs.btrfs -f -L btrfs-root $device
mount -o noatime,compress=lzo $device /mnt
# setup btrfs layout/subvolumes
cd /mnt
mkdir __snapshot
btrfs subvolume create __active
cd __active
for sub in "$@" ; do
btrfs subvolume create $sub
chmod 755 ../\__active $sub
done
cd /
umount $device
mount -o noatime,compress=lzo,subvol=__active $device /mnt
cd /mnt
}
setup_boot(){
# format and mount /boot
mkfs.ext4 $1
mkdir /mnt/boot
mount $1 /mnt/boot
}
make_fs(){
echo "make_fs"
setup_btrfs $2 home var usr data
setup_boot $1
}
bootstrap_arch(){
echo "bootstrap"
pacstrap /mnt base base-devel syslinux gptfdisk
genfstab -p /mnt >> /mnt/etc/fstab
read -p "hostname:(arch)" hostname
if [[ -z "$hostname" ]]; then
hostname='arch'
fi
echo $hostname > /mnt/etc/hostname
#enable en_US.UTF-8
vi /mnt/etc/locale.gen
arch-chroot /mnt locale-gen
echo LANG=en_US.UTF-8 > /mnt/etc/locale.conf
#arch-chroot /mnt export LANG=en_US.UTF-8
arch-chroot /mnt ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
arch-chroot /mnt hwclock --systohc --utc
}
add_encrypt_hook(){
sed -i '/^HOOKS/ s/filesystems/encrypt filesystems/' /mnt/etc/mkinitcpio.conf
arch-chroot /mnt mkinitcpio -p linux
}
setup_syslinux(){
local encrypt=$1 root=$2
arch-chroot /mnt syslinux-install_update -i -a -m
if $encrypt ; then
sed -i 's/APPEND root=[a-z\/0-9]*/APPEND cryptdevice=\/dev\/sda2:cryptroot root=\/dev\/mapper\/cryptroot rootflags=subvol=__active/' /mnt/boot/syslinux/syslinux.cfg
else
sed -i 's/APPEND root=[a-z\/0-9]*/APPEND root=\/dev\/sda2 rootflags=subvol=__active/' /mnt/boot/syslinux/syslinux.cfg
fi
}
setup_aur(){
local tmp_dir=/opt/tmp
mkdir -p /mnt/$tmp_dir
cp /root/meh/install/aur.sh /mnt/$tmp_dir
#wget -O /mnt/$tmp_dir/aur.sh https://gist.github.com/sch1zo/5653983/raw/0d1041f400e590ddd020c3337156aa30b9c2af7a/aur.sh
arch-chroot /mnt pacman -S --noconfirm expac yajl
wget -O /mnt/$tmp_dir/cower.tar.gz https://aur.archlinux.org/packages/co/cower/cower.tar.gz
arch-chroot /mnt sh $tmp_dir/aur.sh cower
wget -O /mnt/$tmp_dir/pacaur.tar.gz https://aur.archlinux.org/packages/pa/pacaur/pacaur.tar.gz
arch-chroot /mnt sh $tmp_dir/aur.sh pacaur
rm -r /mnt/$tmp_dir
}
setup_pacman(){
arch-chroot /mnt pacman -S --noconfirm reflector
arch-chroot /mnt reflector -f 6 -l 6 --save /etc/pacman.d/mirrorlist
arch-chroot /mnt pacaur -S powerpill --asroot
arch-chroot /mnt pacman -Syy
}
install_base_apps(){
arch-chroot /mnt powerpill -S --noconfirm sudo git fish gvim curl tmux zsh htop \
openssh wget bc rsync
}
install_x(){
# install xserver, common stuff
read -p "video-driver(xf86-video-intel)" VIDEO
if [[ -z "$VIDEO" ]]; then
VIDEO='xf86-video-intel'
fi
arch-chroot /mnt powerpill -S --noconfirm xorg-server xorg-server-utils xorg-xinit \
mesa xf86-input-synaptics $VIDEO ttf-ubuntu-font-family
}
install_x_amd(){
arch-chroot /mnt powerpill -S --noconfirm xorg-server xorg-server-utils xorg-xinit \
mesa ttf-ubuntu-font-family xf86-video-ati
}
install_gnome(){
read -p "amd? (y/N)?"
if [[ $REPLY == [yY] ]] ; then
install_x_amd
else
install_x
fi
arch-chroot /mnt powerpill -S --noconfirm eog evince gdm gnome-backgrounds \
gnome-calculator gnome-contacts gnome-desktop gnome-dictionary gnome-control-center \
gnome-disk-utility gnome-font-viewer gnome-icon-theme gnome-icon-theme-extras \
gnome-icon-theme-symbolic gnome-keyring gnome-screenshot gnome-session \
gnome-settings-daemon gnome-shell gnome-system-log gnome-system-monitor \
gnome-terminal gnome-themes-standard gnome-user-docs gnome-user-share \
mousetweaks mutter nautilus sushi totem tracker xdg-user-dirs-gtk networkmanager \
network-manager-applet ntp
}
install_apps(){
arch-chroot /mnt powerpill -S --noconfirm evolution evolution-ews cpupower \
virtualbox chromium rdesktop nss libreoffice-impress libreoffice-calc \
libreoffice-writer libreoffice-gnome pidgin vlc
}
get_dotfiles(){
local tmp_dir=/opt/tmp
mkdir -p /mnt/$tmp_dir
cp /root/meh/install/fetch_dotfiles.sh /mnt/$tmp_dir
#wget -O /mnt/$tmp_dir/fetch_dotfiles.sh https://gist.github.com/sch1zo/5653983/raw/a718ff3f79979d4b16a5540e132bcaeb7f172d44/fetch_dotfiles.sh
arch-chroot /mnt sh $tmp_dir/fetch_dotfiles.sh $1
rm -r /mnt/$tmp_dir
}
setup_users(){
echo "set rootpw:"
arch-chroot /mnt passwd
read -p "default user:(sch1zo)" user
if [[ -z "$user" ]]; then
user='sch1zo'
fi
echo "create user $user"
arch-chroot /mnt useradd -m -g users -G wheel,adm,audio,optical,video,storage,lp,disk -s /usr/bin/fish $user
echo "set user pw:"
arch-chroot /mnt passwd $user
arch-chroot /mnt visudo
# get_dotfiles $user
}
enable_services(){
# enable systemd stuff
arch-chroot /mnt systemctl enable gdm
arch-chroot /mnt systemctl enable NetworkManager
arch-chroot /mnt systemctl enable cpupower
}
# get some stuff from aur
install_aur_pkgs(){
arch-chroot /mnt pacaur -S --asroot sublime-text-nightly spotify dropbox keepass
}
install_zramswap(){
arch-chroot /mnt pacaur -S --asroot zramswap
arch-chroot /mnt systemctl enable zramswap.service
}
# optimize performance
# swappiness
#echo "vm.swappiness=20" >> /mnt/etc/sysctl.conf
#echo "vm.vfs_cache_pressure=50" >> /mnt/etc/sysctl.conf
read -p "boot device(/dev/sda1):" boot_device
if [[ -z "$boot_device" ]]; then
boot_device='/dev/sda1'
fi
read -p "root device(/dev/sda2):" root_device
if [[ -z "$root_device" ]]; then
root_device='/dev/sda2'
fi
read -p "encrypt? (y/N)?"
if [[ $REPLY == [yY] ]] ; then
echo "use encrypt"
encrypt=true
else
echo "no encryption"
encrypt=false
fi
if $encrypt ; then
setup_LUKS $root_device
root_device=/dev/mapper/cryptroot
fi
echo "boot: $boot_device | root: $root_device"
make_fs $boot_device $root_device
refresh_pacman
bootstrap_arch
if $encrypt ; then
add_encrypt_hook
fi
setup_syslinux $encrypt
setup_aur
setup_pacman
install_base_apps
setup_users
read -p "gnome? (y/N)"
if [[ $REPLY == [yY] ]] ; then
install_gnome
install_apps
install_aur_pkgs
enable_services
else
arch-chroot /mnt systemctl enable sshd.service
# arch-chroot /mnt systemctl enable dhcpcd.service
fi
read -p "zramswap? (y/N)?"
if [[ $REPLY == [yY] ]] ; then
install_zramswap
fi
read -p "umount?(Y/n)?"
if [[ $REPLY == [nN] ]] ; then
exit 0
fi
umount /mnt/boot
umount /mnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment