initial commit

This commit is contained in:
Djeeberjr 2022-05-05 19:42:51 +02:00
commit 8f331bacc3
3 changed files with 179 additions and 0 deletions

24
install.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
PASS="mediabox"
HOSTNAME="mediabox"
# get the directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Enter the ip address of the server:"
read ip
# if ip is not empty
if [ ! -z "$ip" ]; then
# write the ip to the inventory file
echo "$ip" > "$DIR/inventory"
fi
echo "run 'passwd' on the archiso and chage the root password to something"
ansible-playbook -v -i "inventory" playbook.yml --ask-pass --user root \
--extra-vars user_password="$(openssl passwd -crypt $PASS)" \
--extra-vars hostname="$HOSTNAME"

21
kodi.service Normal file
View File

@ -0,0 +1,21 @@
# Stolen from here: https://github.com/graysky2/kodi-standalone-service
[Unit]
Description=Kodi standalone
After=remote-fs.target systemd-user-sessions.service network-online.target nss-lookup.target sound.target bluetooth.target polkit.service upower.service mysqld.service lircd.service
Wants=network-online.target polkit.service upower.service
Conflicts=getty@tty1.service
[Service]
User=mediabox
Group=mediabox
PAMName=login
TTYPath=/dev/tty1
ExecStart=/usr/bin/kodi-standalone
ExecStop=/usr/bin/killall --user mediabox --exact --wait kodi.bin
Restart=on-abort
StandardInput=tty
StandardOutput=journal
[Install]
Alias=display-manager.service

134
playbook.yml Normal file
View File

@ -0,0 +1,134 @@
---
- hosts: all
vars:
install_drive: /dev/sda
boot_partition_suffix: 1
timezone: Europe/Berlin
user_name: mediabox
tasks:
- name: Abort if the host is not booted from the Arch install media
fail:
msg: "This host is not booted from the Arch install media!"
when: ansible_nodename != 'archiso'
- name: Synchronize clock via NTP
command: timedatectl set-ntp true
- name: Repartition install drive
block:
- name: Wipe install drive and all its partitions
command: find /dev -wholename "{{ install_drive }}*" -exec wipefs --force --all {} \;
- name: Create boot partition
parted:
device: '{{ install_drive }}'
label: gpt
number: 1
part_end: 512MB
name: boot
flags: [boot, esp]
state: present
- name: Create root partition
parted:
device: '{{ install_drive }}'
label: gpt
number: 2
part_start: 512MB
name: root
flags: []
state: present
- name: Create filesystems
block:
- name: Create FAT32 filesystem in boot partition
filesystem:
dev: '{{ install_drive }}1'
fstype: vfat
opts: -F32
force: yes
- name: Create ext4 filesystem in root volume
filesystem:
dev: '{{ install_drive }}2'
fstype: ext4
force: yes
- name: Get UUID for boot filesystem
command: blkid -s UUID -o value '{{ install_drive }}1'
register: boot_uuid
changed_when: false
- name: Get UUID for root filesystem
command: blkid -s UUID -o value '{{ install_drive }}2'
register: root_uuid
changed_when: false
- name: Mount filesystems
block:
- name: Mount root filesystem
mount:
path: /mnt
src: UUID={{ root_uuid.stdout }}
fstype: ext4
state: mounted
- name: Create mountpoint for boot volume
file:
path: /mnt/boot
state: directory
- name: Mount boot filesystem
mount:
path: /mnt/boot
src: UUID={{ boot_uuid.stdout }}
fstype: vfat
state: mounted
- name: Run pacstrap
command: pacstrap /mnt base base-devel efibootmgr grub linux linux-firmware openssh python reflector sudo networkmanager kodi lzo polkit vim
- name: Generate fstab
command: genfstab -U /mnt >> /mnt/etc/fstab
- name: Set local timezone
command: arch-chroot /mnt ln -sf /usr/share/zoneinfo/{{ timezone }} /etc/localtime
- name: Generate adjtime file
command: arch-chroot /mnt hwclock --systohc
- name: Setup locales
block:
- name: Configure locale.gen
lineinfile:
dest: /mnt/etc/locale.gen
regexp: '{{ item.regex }}'
line: '{{ item.line }}'
loop:
- {regex: en_US\.UTF-8 UTF-8, line: en_US.UTF-8 UTF-8}
- {regex: en_US ISO-8859-1, line: en_US ISO-8859-1}
- name: Create locale.conf
copy:
content: "LANG=en_US.UTF-8"
dest: /mnt/etc/locale.conf
- name: Generate locales
command: arch-chroot /mnt locale-gen
- name: Set hostname
copy:
content: '{{ hostname }}'
dest: /mnt/etc/hostname
- name: Set up initramfs
command: arch-chroot /mnt mkinitcpio -p linux
- name: Set up grub
block:
- name: Install grub
command: arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
- name: Create grub config
command: arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
- name: Setup user account
block:
- name: Create user account
command: arch-chroot /mnt useradd --create-home --user-group --groups wheel,input {{ user_name }} --password {{ user_password }}
- name: Give passwordless sudo access to wheel group
copy:
content: '%wheel ALL=(ALL) NOPASSWD: ALL'
dest: /mnt/etc/sudoers.d/wheel
validate: /usr/sbin/visudo --check --file=%s
- name: Change root pw
command: arch-chroot /mnt echo "root:{{user_password}}" | chpasswd
- name: Enable NetworkManager
command: arch-chroot /mnt systemctl enable NetworkManager
- name: Enable SSH server
command: arch-chroot /mnt systemctl enable sshd
- name: Insert Kodi service
block:
- name: Create systemd service file
copy:
src: "{{playbook_dir}}/kodi.service"
dest: /mnt/etc/systemd/system/kodi.service
- name: Enable kodi service
command: arch-chroot /mnt systemctl enable kodi.service