You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

872 lines
20 KiB

  1. #!/bin/bash
  2. #
  3. set -e
  4. echo (){
  5. /bin/echo "#########################################"
  6. /bin/echo "$@"
  7. /bin/echo "#########################################"
  8. }
  9. #LICENSE#{{{
  10. # Copyright (c) 2012 Tom Wambold
  11. #
  12. # Permission is hereby granted, free of charge, to any person obtaining a copy
  13. # of this software and associated documentation files (the "Software"), to deal
  14. # in the Software without restriction, including without limitation the rights
  15. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. # copies of the Software, and to permit persons to whom the Software is
  17. # furnished to do so, subject to the following conditions:
  18. #
  19. # The above copyright notice and this permission notice shall be included in
  20. # all copies or substantial portions of the Software.
  21. #
  22. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. # SOFTWARE.
  29. #}}}
  30. #ABOUT#{{{
  31. # This script will set up an Arch installation with a 100 MB /boot partition
  32. # and an encrypted LVM partition with swap and / inside. It also installs
  33. # and configures systemd as the init system.
  34. #
  35. # You should read through this script before running it in case you want to
  36. # make any modifications, in particular, the variables just below, and the
  37. # following functions:
  38. #
  39. # partition_drive - Customize to change partition sizes (/boot vs LVM)
  40. # setup_lvm - Customize for partitions inside LVM
  41. # install_packages - Customize packages installed in base system
  42. # (desktop environment, etc.)
  43. # install_aur_packages - More packages after packer (AUR helper) is
  44. # installed
  45. # set_netcfg - Preload netcfg profiles
  46. #}}}
  47. # CONFIGURE THESE VARIABLES{{{
  48. # Drive to install to.
  49. DRIVE='/dev/sda'
  50. # Hostname of the installed machine.
  51. HOSTNAME='arch'
  52. # Encrypt everything (except /boot). true or false
  53. ENCRYPT_DRIVE=true
  54. # Passphrase used to encrypt the drive (leave blank to be prompted).
  55. DRIVE_PASSPHRASE=''
  56. # Root password (leave blank to be prompted).
  57. ROOT_PASSWORD=''
  58. # Main user to create (by default, added to wheel group, and others).
  59. USER_NAME='lelgenio'
  60. # Link to users dotfiles repo(git)
  61. # Assumed to have stow-able modules on its root(cd .dotfiles;stow*/)
  62. DOTFILES_URL="https://gitlab.com/$USER_NAME/dotfiles"
  63. USER_SHELL='fish'
  64. # The main user's password (leave blank to be prompted).
  65. USER_PASSWORD=''
  66. # System timezone.
  67. TIMEZONE='America/Sao_Paulo'
  68. # Country code for pacman repos
  69. COUNTRY='brazil'
  70. # Have /tmp on a tmpfs or not. Leave blank to disable.
  71. # Only leave this blank on systems with very little RAM.
  72. TMP_ON_TMPFS='TRUE'
  73. KEYMAP='br-abnt2'
  74. # KEYMAP='dvorak'
  75. LANG=pt_BR.UTF-8
  76. # Choose your video driver
  77. # For Intel
  78. VIDEO_DRIVER="i915"
  79. # For nVidia
  80. #VIDEO_DRIVER="nouveau"
  81. # For ATI
  82. #VIDEO_DRIVER="radeon"
  83. # For generic stuff
  84. #VIDEO_DRIVER="vesa"
  85. REMOVE_PKGS=false
  86. FULL_INSTALL=false
  87. #}}}
  88. # PACKAGES{{{
  89. set_pkgs() {
  90. # pkgs_base -> Are on the official repo are are mandatory to use the system
  91. # pkgs -> Basic packages for a simple desktop, may be from AUR
  92. # FULL_INSTALL -> Install extra stuff, completely optional
  93. # sudo to allow to run as a user later
  94. sudo pacman -Sy
  95. pkgs_base+=' base linux-zen linux-firmware intel-ucode lvm2 '
  96. pkgs_base+=' fish bluez cronie git man-db'
  97. # netctl
  98. pkgs_base+=' netctl dhcpcd ifplugd wpa_supplicant dialog'
  99. pkgs_base+=" $(pacman -Sgq base-devel)"
  100. if $IS_BIOS;then
  101. pkgs_base+=' grub'
  102. fi
  103. pkgs+=" $pkgs_base"
  104. # DE
  105. pkgs+=' ly sway waybar ruby-fusuma light mako udiskie dotdrop yay'
  106. pkgs+=' bemenu wofi-hg j4-dmenu-desktop'
  107. # passwords and auth
  108. pkgs+=' pass gnupg pam-gnupg'
  109. # pkgs+=' i3 termite scrot pamixer'
  110. pkgs+=' nemo cinnamon-translations thunar redshift-wlr-gamma-control-git '
  111. pkgs+=' pkgfile alacritty neovim moreutils htop-vim-git'
  112. # Audio
  113. pkgs+=' pulseaudio pavolume-git'
  114. # Fonts
  115. pkgs+=' ttf-hack inter-font otf-fira-code ttf-material-wifi-icons-git'
  116. if $FULL_INSTALL; then
  117. # Screenshot
  118. pkgs+=' grim slurp wl-clipboard wf-recorder-git'
  119. pkgs+=' httpie jq'
  120. # Theme
  121. pkgs+=' materia-custom-accent papirus-icon-theme'
  122. pkgs+=' papirus-folders-git capitaine-cursors '
  123. # Terminal
  124. pkgs+=' tmux ranger atool p7zip tree'
  125. pkgs+=' neofetch powerline-fonts'
  126. pkgs+=' exa bat lolcat cmatrix'
  127. # extra font for ranger
  128. pkgs+=' otf-nerd-fonts-fira-code'
  129. # Network
  130. pkgs+=' wget curl bluez-utils rsync rclone nmap gnu-netcat tor mtr speedtest-cli'
  131. pkgs+=' openssh sshfs fail2ban'
  132. # Browser
  133. pkgs+=' qutebrowser youtube-dl'
  134. # Email
  135. pkgs+=' neomutt isync'
  136. # Files
  137. pkgs+=' syncthing nextcloud-client '
  138. pkgs+=' deluge deezloader-remix-git smloadr'
  139. # Media
  140. pkgs+=' imv mpv mpd mpc ncmpcpp mpv-mpris mpdris2 playerctl'
  141. pkgs+=' blender gimp kdenlive picard image_optim'
  142. # Office
  143. pkgs+=' libreoffice-fresh libreoffice-fresh-pt-br hunspell-pt-br papirus-libreoffice-theme'
  144. # Programing
  145. pkgs+=' code neovim python-pynvim neovim-symlinks ipython how2'
  146. pkgs+=' gdb clang'
  147. # Virt
  148. pkgs+=' qemu'
  149. # Gtk
  150. pkgs+=' gtk3-nocsd-git'
  151. # Qt
  152. pkgs+=' qt5-base qt5-wayland qt5ct kvantum-qt5'
  153. # Chat
  154. pkgs+=' discord telegram-desktop telegram-cli-git'
  155. # Gaming
  156. pkgs+=' steam lutris gamemode lutris-wine-meta wine wine-mono winetricks'
  157. if [ "$VIDEO_DRIVER" == "i915" ];then
  158. pkgs+=' xf86-video-intel '
  159. pkgs+=' lib32-mesa vulkan-intel lib32-vulkan-intel vulkan-icd-loader lib32-vulkan-icd-loader'
  160. elif [ "$VIDEO_DRIVER" == "radeon" ];then
  161. pkgs+=' xf86-video-ati'
  162. pkgs+=' lib32-mesa vulkan-radeon lib32-vulkan-radeon vulkan-icd-loader lib32-vulkan-icd-loader'
  163. elif [ "$VIDEO_DRIVER" == "nouveau" ];then
  164. pkgs+=' xf86-video-nouveau'
  165. pkgs+=' nvidia nvidia-utils lib32-nvidia-utils nvidia-settings vulkan-icd-loader lib32-vulkan-icd-loader'
  166. elif [ "$VIDEO_DRIVER" == "vesa" ];then
  167. packages+=' xf86-video-vesa'
  168. fi
  169. fi
  170. }
  171. #}}}
  172. # Initial Setup{{{
  173. # Base install{{{
  174. setup() {
  175. local boot_dev="$DRIVE"1
  176. if "$ENCRYPT_DRIVE"
  177. then
  178. local crypt_dev="$DRIVE"2
  179. local lvm_dev="/dev/mapper/lvm"
  180. else
  181. local lvm_dev="$DRIVE"2
  182. fi
  183. echo 'Cleaning disk'
  184. disk_clean "$lvm_dev" "$DRIVE"2
  185. echo 'Creating partitions'
  186. partition_drive "$DRIVE"
  187. if "$ENCRYPT_DRIVE"
  188. then
  189. if [ -z "$DRIVE_PASSPHRASE" ];then
  190. echo 'Enter a passphrase to encrypt the disk:'
  191. read -s DRIVE_PASSPHRASE
  192. fi
  193. echo 'Encrypting partition'
  194. encrypt_drive "$crypt_dev" "$DRIVE_PASSPHRASE" lvm
  195. fi
  196. echo 'Setting up LVM'
  197. setup_lvm "$lvm_dev" vg00
  198. echo 'Formatting filesystems'
  199. format_filesystems "$boot_dev"
  200. echo 'Mounting filesystems'
  201. mount_filesystems "$boot_dev"
  202. echo 'Setting repos'
  203. set_repos
  204. echo 'Installing base system'
  205. install_base
  206. echo 'Setting fstab'
  207. set_fstab
  208. echo 'Chrooting into installed system to continue setup...'
  209. cp "$0" "/mnt/setup.sh"
  210. chmod +x "/mnt/setup.sh"
  211. arch-chroot /mnt "./setup.sh"
  212. if [ -f "/mnt/setup.sh" ];then
  213. echo 'ERROR: Something failed inside the chroot, not unmounting filesystems so you can investigate.'
  214. echo 'Make sure you unmount everything before you try to run this script again.'
  215. else
  216. echo 'Unmounting filesystems'
  217. unmount_filesystems
  218. echo 'Done! Reboot system.'
  219. fi
  220. }
  221. #}}}
  222. # Remove old LVMs{{{
  223. disk_clean(){
  224. local lvm_dev="$1"
  225. local disk="$2"
  226. echo 'cleaning disk'
  227. umount --recursive --quiet /mnt || true
  228. swapoff -a
  229. pvs "$lvm_dev" || return 0
  230. for vg in $(pvs -o vg_name --nohead "$lvm_dev")
  231. do
  232. vgremove "$vg" --yes
  233. done
  234. pvremove "$lvm_dev"
  235. if "$ENCRYPT_DRIVE"
  236. then
  237. cryptsetup close lvm
  238. fi
  239. wipefs -a "$disk"
  240. }
  241. #}}}
  242. # Partition Drive{{{
  243. partition_drive() {
  244. local dev="$1"; shift
  245. # 100 MB /boot partition, everything else under LVM
  246. if $IS_BIOS;then
  247. parted \
  248. --align optimal \
  249. --script "$dev" \
  250. mklabel msdos \
  251. mkpart primary fat32 1M 100M \
  252. mkpart primary ext4 100M 100% \
  253. set 1 boot on \
  254. set 2 lvm on
  255. else
  256. parted \
  257. --align optimal \
  258. --script "$dev" \
  259. mklabel gpt \
  260. mkpart boot 1 100M \
  261. mkpart lvm 100M 100% \
  262. set 1 boot on \
  263. set 2 lvm on
  264. fi
  265. }
  266. #}}}
  267. # Encrypt_drive {{{
  268. encrypt_drive() {
  269. local dev="$1"; shift
  270. local passphrase="$1"; shift
  271. local name="$1"; shift
  272. /bin/echo -en "$passphrase" | cryptsetup luksFormat "$dev"
  273. /bin/echo -en "$passphrase" | cryptsetup luksOpen "$dev" lvm
  274. }
  275. #}}}
  276. # setup_lvm{{{
  277. setup_lvm() {
  278. local partition="$1"; shift
  279. local volgroup="$1"; shift
  280. local d_size=$(lsblk --noheadings --nodeps --bytes --raw --output SIZE $DRIVE)
  281. local swap_size=$(free -b | awk '/^Mem/ { printf "%.0fG", 2*$2*10**-9}')
  282. pvcreate "$partition"
  283. vgcreate "$volgroup" "$partition"
  284. # Create a swap partition that is twice the amount of RAM
  285. lvcreate --yes -L$swap_size "$volgroup" -n swap
  286. # if the disk has more than 100Gb
  287. if [ "$d_size" -gt $( echo "100*10^9" | bc ) ]
  288. then
  289. # Create a 50GB root partition
  290. lvcreate --yes -L '50G' "$volgroup" -n root
  291. else
  292. # Create root partition on 50% of free space
  293. lvcreate --yes -l '+50%FREE' "$volgroup" -n root
  294. fi
  295. # Use the rest of the space for home
  296. lvcreate --yes -l '+100%FREE' "$volgroup" -n home
  297. # Enable the new volumes
  298. vgchange -ay
  299. }
  300. #}}}
  301. # format_filesystems #{{{
  302. format_filesystems() {
  303. local boot_dev="$1"; shift
  304. mkfs.fat "$boot_dev"
  305. mkfs.ext4 -L root /dev/vg00/root
  306. mkfs.ext4 -L home /dev/vg00/home
  307. mkswap /dev/vg00/swap
  308. }
  309. #}}}
  310. # mount_filesystems #{{{
  311. mount_filesystems() {
  312. local boot_dev="$1"; shift
  313. mount /dev/vg00/root /mnt
  314. mkdir /mnt/home
  315. mount /dev/vg00/home /mnt/home
  316. mkdir /mnt/boot
  317. mount "$boot_dev" /mnt/boot
  318. swapon /dev/vg00/swap
  319. }
  320. #}}}
  321. # set_repos() {{{{
  322. set_repos() {
  323. # /etc/pacman.conf{{{
  324. cat > /etc/pacman.conf <<EOF
  325. #
  326. # GENERAL OPTIONS
  327. #
  328. [options]
  329. HoldPkg = pacman glibc
  330. Architecture = auto
  331. # Misc options
  332. #UseSyslog
  333. Color
  334. ILoveCandy
  335. #TotalDownload
  336. CheckSpace
  337. #VerbosePkgLists
  338. SigLevel = Required DatabaseOptional
  339. LocalFileSigLevel = Optional
  340. #RemoteFileSigLevel = Required
  341. #
  342. # REPOSITORIES
  343. #
  344. #[testing]
  345. #Include = /etc/pacman.d/mirrorlist
  346. [core]
  347. Include = /etc/pacman.d/mirrorlist
  348. [extra]
  349. Include = /etc/pacman.d/mirrorlist
  350. #[community-testing]
  351. #Include = /etc/pacman.d/mirrorlist
  352. [community]
  353. Include = /etc/pacman.d/mirrorlist
  354. #[multilib-testing]
  355. #Include = /etc/pacman.d/mirrorlist
  356. [multilib]
  357. Include = /etc/pacman.d/mirrorlist
  358. EOF
  359. #}}}
  360. # /etc/pacman.d/mirrorlist{{{
  361. pacman -Sy reflector --noconfirm --needed
  362. reflector -c $COUNTRY -f 10 -p http -p https
  363. #}}}
  364. mkdir -p /mnt/etc/pacman.d
  365. cp -r /mnt/etc/pacman* /etc/
  366. }
  367. #}}}
  368. # install_base #{{{
  369. install_base() {
  370. pacstrap /mnt $pkgs_base
  371. }
  372. #}}}
  373. # Set fstab {{{
  374. set_fstab() {
  375. genfstab -Up /mnt > /mnt/etc/fstab
  376. }
  377. #}}}
  378. # Unmount filesystems #{{{
  379. unmount_filesystems() {
  380. umount -R /mnt
  381. swapoff /dev/vg00/swap
  382. vgchange -an
  383. if $ENCRYPT_DRIVE
  384. then
  385. cryptsetup luksClose lvm
  386. fi
  387. }
  388. #}}}
  389. # is_bios{{{
  390. if ls /sys/firmware/efi/efivars/ &> /dev/null
  391. then
  392. IS_BIOS=false
  393. else
  394. IS_BIOS=true
  395. fi
  396. #}}}
  397. #}}}
  398. # Configuration{{{
  399. # configure() {#{{{
  400. configure() {
  401. local boot_dev="$DRIVE"1
  402. local lvm_dev="$DRIVE"2
  403. echo 'Setting hostname'
  404. set_hostname "$HOSTNAME"
  405. echo 'Setting timezone'
  406. set_timezone "$TIMEZONE"
  407. echo 'Setting locale'
  408. set_locale
  409. echo 'Setting console keymap'
  410. set_inputs
  411. echo 'Configuring initial ramdisk'
  412. set_initcpio
  413. echo 'Configuring Bluetooth'
  414. set_bluetooth
  415. echo 'Configuring bootloader'
  416. set_bootctl "$boot_dev" "$lvm_dev"
  417. echo 'Configuring sudo'
  418. set_sudoers
  419. echo 'Configuring PAM'
  420. set_pam
  421. echo 'Configuring logind'
  422. set_logind
  423. if [ -z "$ROOT_PASSWORD" ];then
  424. echo 'Enter the root password:'
  425. read -s ROOT_PASSWORD
  426. fi
  427. echo 'Setting root password'
  428. set_root_password "$ROOT_PASSWORD"
  429. if [ -z "$USER_PASSWORD" ];then
  430. echo "Enter the password for user $USER_NAME"
  431. read -s USER_PASSWORD
  432. fi
  433. echo 'Creating initial user'
  434. create_user "$USER_NAME" "$USER_PASSWORD"
  435. echo 'setting up user'
  436. cp $0 "/home/$USER_NAME/setup.sh"
  437. chown $USER_NAME "/home/$USER_NAME/setup.sh"
  438. su $USER_NAME -c "/home/$USER_NAME/setup.sh"
  439. shred "/home/$USER_NAME/setup.sh"
  440. rm "/home/$USER_NAME/setup.sh"
  441. echo 'Setting initial daemons'
  442. set_daemons "$TMP_ON_TMPFS"
  443. echo 'Updating pkgfile database'
  444. update_pkgfile
  445. }
  446. #}}}
  447. # set_hostname() {#{{{
  448. set_hostname() {
  449. local hostname="$1"; shift
  450. /bin/echo "$hostname" > /etc/hostname
  451. cat > /etc/hosts <<EOF
  452. 127.0.0.1 localhost.localdomain localhost $hostname
  453. ::1 localhost.localdomain localhost $hostname
  454. EOF
  455. }
  456. #}}}
  457. # set_timezone() {#{{{
  458. set_timezone() {
  459. local timezone="$1"; shift
  460. ln -sfT "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
  461. timedatectl set-ntp on
  462. hwclock --systohc || echo FAILED TO SET HW CLOCK
  463. }
  464. #}}}
  465. # set_locale() {#{{{
  466. set_locale() {
  467. cat > /etc/locale.conf <<EOF
  468. LANG=$LANG
  469. LC_COLLATE=C
  470. EOF
  471. cat > /etc/locale.gen <<EOF
  472. en_US.UTF-8 UTF-8
  473. $LANG UTF-8
  474. EOF
  475. locale-gen
  476. }
  477. #}}}
  478. # set_inputs() {#{{{
  479. set_inputs() {
  480. localectl set-keymap $KEYMAP
  481. mkdir -p /etc/X11/xorg.conf.d/
  482. cat > /etc/X11/xorg.conf.d/30-touchpad.conf <<EOF
  483. Section "InputClass"
  484. MatchIsTouchpad "on"
  485. Identifier "devname"
  486. Driver "libinput"
  487. Option "Tapping" "on"
  488. Option "ClickMethod" "clickfinger"
  489. Option "NaturalScrolling" "true"
  490. EndSection
  491. EOF
  492. }
  493. #}}}
  494. # set_initcpio() {#{{{
  495. set_initcpio() {
  496. local vid
  497. if [ "$VIDEO_DRIVER" = "i915" ];then
  498. vid='i915'
  499. elif [ "$VIDEO_DRIVER" = "nouveau" ];then
  500. vid='nouveau'
  501. elif [ "$VIDEO_DRIVER" = "radeon" ];then
  502. vid='radeon'
  503. fi
  504. local encrypt=""
  505. if $ENCRYPT_DRIVE
  506. then
  507. encrypt="encrypt keyboard"
  508. fi
  509. cat > /etc/mkinitcpio.conf <<EOF
  510. # vim:set ft=sh
  511. MODULES=(ext4 $vid)
  512. BINARIES=()
  513. FILES=()
  514. HOOKS=(base udev autodetect block $encrypt lvm2 filesystems fsck)
  515. EOF
  516. # Intall kernel, if necessary
  517. [ -f /boot/vmlinuz-linux-zen ] ||
  518. mkinitcpio -P
  519. }
  520. #}}}
  521. # set_daemons() {#{{{
  522. set_daemons() {
  523. local tmp_on_tmpfs="$1"; shift
  524. if [ -z "$tmp_on_tmpfs" ];then
  525. systemctl mask tmp.mount
  526. fi
  527. systemctl enable \
  528. cronie.service \
  529. netctl.service \
  530. ly.service
  531. # Netctl{{{
  532. cat > /etc/netctl/ethernet-dhcp <<EOF
  533. Description='A basic dhcp ethernet connection'
  534. Interface=en-any
  535. Connection=ethernet
  536. IP=dhcp
  537. EOF
  538. mkdir -p /etc/netctl/interfaces/
  539. cat > /etc/netctl/interfaces/en-any <<EOF
  540. #!/bin/bash
  541. for interface in /sys/class/net/en*; do
  542. break;
  543. done
  544. Interface=\$(basename \$interface)
  545. echo "en-any: using interface \$Interface";
  546. EOF
  547. chmod +x /etc/netctl/interfaces/en-any
  548. cd /sys/class/net/
  549. for interface in $(ls -d en*);do
  550. systemctl enable netctl-ifpluged@$interface
  551. done
  552. for interface in $(ls -d wl*);do
  553. systemctl enable netctl-auto@$interface
  554. done
  555. cd -
  556. #}}}
  557. # Ly{{{
  558. mkdir -p /etc/ly/
  559. cat > /etc/ly/config.ini << EOF
  560. animate = true
  561. blank_box = true
  562. hide_borders = true
  563. lang = br
  564. EOF
  565. #}}}
  566. }
  567. #}}}
  568. # set_bluetooth{{{
  569. set_bluetooth() {
  570. mkdir -p /etc/bluetooth/
  571. cat > /etc/bluetooth/main.conf <<EOF
  572. [General]
  573. DiscoverableTimeout = 0
  574. Discoverable = true
  575. AlwaysPairable = true
  576. [Policy]
  577. AutoEnable=true
  578. EOF
  579. }
  580. #}}}
  581. # set_boot_loader() {{{
  582. set_bootctl() {
  583. local boot_dev="$1"; shift
  584. local lvm_dev="$1"; shift
  585. local lvm_uuid=$(get_uuid "/dev/vg00/root")
  586. local k_args="root=UUID=$lvm_uuid"
  587. if $IS_BIOS;then
  588. cat >> /etc/default/grub <<EOF
  589. GRUB_CMDLINE_LINUX_DEFAULT="$k_args"
  590. # GRUB_CMDLINE_LINUX_DEFAULT="quiet splash loglevel=3 vga=current rd.udev.log_priority=3 rd.systemd.show_status=auto vt.global_cursor_default=0 nmi_watchdog=0 $k_args"
  591. EOF
  592. grub-install "$DRIVE"
  593. grub-mkconfig -o /boot/grub/grub.cfg
  594. else
  595. bootctl install
  596. cat > /boot/loader/entries/arch.conf <<EOF
  597. title arch
  598. linux vmlinuz-linux-zen
  599. initrd intel-ucode.img
  600. initrd initramfs-linux-zen.img
  601. options $k_args
  602. # options quiet splash loglevel=3 vga=current rd.udev.log_priority=3 rd.systemd.show_status=auto vt.global_cursor_default=0 nmi_watchdog=0
  603. EOF
  604. fi
  605. }
  606. #}}}
  607. # set_sudoers() {#{{{
  608. set_sudoers() {
  609. cat > /etc/sudoers <<EOF
  610. ##
  611. ## User privilege specification
  612. ##
  613. root ALL=(ALL) ALL
  614. ## Uncomment to allow members of group wheel to execute any command
  615. # %wheel ALL=(ALL) ALL
  616. ## Same thing without a password
  617. %wheel ALL=(ALL) NOPASSWD: ALL
  618. ## Read drop-in files from /etc/sudoers.d
  619. ## (the '#' here does not indicate a comment)
  620. #includedir /etc/sudoers.d
  621. EOF
  622. chmod 440 /etc/sudoers
  623. }
  624. #}}}
  625. # set_pam{{{
  626. set_pam() {
  627. cat > /etc/pam.d/system-local-login <<EOF
  628. auth include system-login
  629. account include system-login
  630. password include system-login
  631. session include system-login
  632. auth optional pam_gnupg.so
  633. session optional pam_gnupg.so
  634. EOF
  635. }
  636. #}}}
  637. # set_logind{{{
  638. set_logind(){
  639. mkdir -p /etc/systemd
  640. cat > /etc/systemd/logind.conf <<EOF
  641. [Login]
  642. HandlePowerKey=suspend
  643. HandleSuspendKey=suspend
  644. HandleLidSwitch=ignore
  645. EOF
  646. }
  647. #}}}
  648. # set_root_password() {#{{{
  649. set_root_password() {
  650. local password="$1"; shift
  651. /bin/echo -en "$password\n$password" | passwd
  652. }
  653. #}}}
  654. # create_user() {#{{{
  655. create_user() {
  656. local name="$1"; shift
  657. local password="$1"; shift
  658. grep "^$name" /etc/passwd ||
  659. useradd -m -s /usr/bin/$USER_SHELL -G adm,systemd-journal,wheel,rfkill,games,network,video,audio,optical,floppy,storage,scanner,power,input "$name"
  660. /bin/echo -en "$password\n$password" | passwd "$name"
  661. }
  662. #}}}
  663. # update_pkgfile() {#{{{
  664. update_pkgfile() {
  665. pkgfile -u
  666. }
  667. #}}}
  668. # get_uuid() {#{{{
  669. get_uuid() {
  670. lsblk --noheadings --nodeps --output UUID "$1"
  671. }
  672. #}}}
  673. # is_chroot(){{{{
  674. is_chroot(){
  675. test "$(ls -id / | cut -d' ' -f1)" == "2"
  676. }
  677. #}}}
  678. #}}}
  679. # User setup{{{
  680. user_setup() {
  681. echo 'Installing packages'
  682. install_aur_packages
  683. if $REMOVE_PKGS;then
  684. echo 'Cleaning packages'
  685. clean_packages
  686. fi
  687. echo 'Stowing dotfiles'
  688. stow_dots
  689. }
  690. # Install AUR packages #{{{
  691. install_aur_packages() {
  692. sudo pacman -S --needed git
  693. # getting yay
  694. if ! command -v yay
  695. then
  696. git clone http://aur.archlinux.org/yay.git ~/yay
  697. cd ~/yay
  698. makepkg -si --noconfirm
  699. cd -
  700. fi
  701. yay -Syu --needed --noconfirm $pkgs || true
  702. }
  703. #}}}
  704. # Clean up packages #{{{
  705. clean_packages() {
  706. # Mark every package as dependency
  707. yay -D --asdeps $(yay -Qqe) > /dev/null
  708. # Mark some packages as explicit
  709. yay -D --asexplicit $pkgs > /dev/null
  710. # Query orphan dependencies
  711. TO_REMOVE=$(yay -Qtdq)
  712. if [ -n "$TO_REMOVE" ];then
  713. # Remove queried packages
  714. yay -Rns --noconfirm $TO_REMOVE
  715. fi
  716. }
  717. #}}}
  718. # Install dotfiles{{{
  719. stow_dots() {
  720. if [ ! -d ~/.dotfiles ];then
  721. git clone $DOTFILES_URL ~/.dotfiles
  722. fi
  723. test -f ~/.dotfiles/config.y*ml &&
  724. dotdrop --cfg ~/.dotfiles/config.y*ml install --force --no-banner
  725. }
  726. #}}}
  727. #}}}
  728. set_pkgs
  729. if [ ! "$USER" == "root" ];then
  730. user_setup
  731. elif is_chroot;then
  732. configure
  733. else
  734. setup
  735. fi
  736. # vim:foldmethod=marker