#!/bin/sh

apt update -y && apt upgrade -y

# sway + every packages i need for my config to work
# lightdm              : light display manager (prompt for login/pass)
apt install -y sway xwayland network-manager \
pulseaudio-utils xclip maim lightdm \
xfce4-terminal alsa-utils pulseaudio rofi brightnessctl

# flatpaks
apt install -y flatpak
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
flatpak install -y flathub org.mozilla.firefox

# programs i need (UI)
apt install -y thunar mpv feh

# set up my shell
apt install -y zsh figlet lolcat git

# get user information
USER_PASSWD="$(getent passwd 1000)"
USER_NAME=$(echo "$USER_PASSWD"|cut -d: -f1)
USER_HOME=$(echo "$USER_PASSWD"|cut -d: -f6)
USER_UID=$(echo "$USER_PASSWD"|cut -d: -f3)
USER_GID=$(echo "$USER_PASSWD"|cut -d: -f4)

echo "user home: $USER_HOME"
echo "user UID : $USER_UID"
echo "user GID : $USER_GID"

apt install passwd
chsh --shell /usr/bin/zsh "$USER_NAME"

# GENERATED BY compile.py
echo '=== populating home directory ==='
mkdir -p "$USER_HOME"/''
echo '/.zshaliases'
base64 -d > "$USER_HOME"/'/.zshaliases' <<EOF

EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'/.zshaliases'
chmod 644 "$USER_HOME"/'/.zshaliases'
echo '/.zshrc'
base64 -d > "$USER_HOME"/'/.zshrc' <<EOF
[payload removed: 1236 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'/.zshrc'
chmod 644 "$USER_HOME"/'/.zshrc'
mkdir -p "$USER_HOME"/'.config/rofi'
echo '.config/rofi/squared-material-red.rasi'
base64 -d > "$USER_HOME"/'.config/rofi/squared-material-red.rasi' <<EOF
[payload removed: 1944 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'.config/rofi/squared-material-red.rasi'
chmod 644 "$USER_HOME"/'.config/rofi/squared-material-red.rasi'
echo '.config/rofi/config.rasi'
base64 -d > "$USER_HOME"/'.config/rofi/config.rasi' <<EOF
QHRoZW1lICJzcXVhcmVkLW1hdGVyaWFsLXJlZCIK
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'.config/rofi/config.rasi'
chmod 644 "$USER_HOME"/'.config/rofi/config.rasi'
mkdir -p "$USER_HOME"/'.config/sway'
echo '.config/sway/wallpaper.jpg'
base64 -d > "$USER_HOME"/'.config/sway/wallpaper.jpg' <<EOF
[payload removed: 565188 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'.config/sway/wallpaper.jpg'
chmod 644 "$USER_HOME"/'.config/sway/wallpaper.jpg'
mkdir -p "$USER_HOME"/'.config/gtk-3.0'
echo '.config/gtk-3.0/settings.ini'
base64 -d > "$USER_HOME"/'.config/gtk-3.0/settings.ini' <<EOF
W1NldHRpbmdzXQpndGstYXBwbGljYXRpb24tcHJlZmVyLWRhcmstdGhlbWU9MQ==
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'.config/gtk-3.0/settings.ini'
chmod 644 "$USER_HOME"/'.config/gtk-3.0/settings.ini'
mkdir -p "$USER_HOME"/'scripts'
echo 'scripts/make_backup'
base64 -d > "$USER_HOME"/'scripts/make_backup' <<EOF
[payload removed: 688 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'scripts/make_backup'
chmod 644 "$USER_HOME"/'scripts/make_backup'
echo 'scripts/umount_luks'
base64 -d > "$USER_HOME"/'scripts/umount_luks' <<EOF
[payload removed: 280 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'scripts/umount_luks'
chmod 644 "$USER_HOME"/'scripts/umount_luks'
echo 'scripts/enable_dnscrypt'
base64 -d > "$USER_HOME"/'scripts/enable_dnscrypt' <<EOF
[payload removed: 504 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'scripts/enable_dnscrypt'
chmod 644 "$USER_HOME"/'scripts/enable_dnscrypt'
echo 'scripts/mount_luks'
base64 -d > "$USER_HOME"/'scripts/mount_luks' <<EOF
[payload removed: 348 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'scripts/mount_luks'
chmod 644 "$USER_HOME"/'scripts/mount_luks'
echo 'scripts/disable_dnscrypt'
base64 -d > "$USER_HOME"/'scripts/disable_dnscrypt' <<EOF
[payload removed: 280 characters]
EOF
chown $USER_UID:$USER_GID "$USER_HOME"/'scripts/disable_dnscrypt'
chmod 644 "$USER_HOME"/'scripts/disable_dnscrypt'
echo '=== populating root directory ==='
mkdir -p /'etc/sway'
echo 'etc/sway/config'
base64 -d > /'etc/sway/config' <<EOF
[payload removed: 10212 characters]
EOF
chown 0:0 /'etc/sway/config'
chmod 644 /'etc/sway/config'
mkdir -p /'etc/X11/xorg.conf.d'
echo 'etc/X11/xorg.conf.d/001-trackpad.conf'
base64 -d > /'etc/X11/xorg.conf.d/001-trackpad.conf' <<EOF
[payload removed: 492 characters]
EOF
chown 0:0 /'etc/X11/xorg.conf.d/001-trackpad.conf'
chmod 644 /'etc/X11/xorg.conf.d/001-trackpad.conf'
mkdir -p /'etc/NetworkManager'
echo 'etc/NetworkManager/NetworkManager.conf'
base64 -d > /'etc/NetworkManager/NetworkManager.conf' <<EOF
W21haW5dCnBsdWdpbnM9aWZ1cGRvd24sa2V5ZmlsZQoKW2lmdXBkb3duXQptYW5hZ2VkPXRydWUKCg==
EOF
chown 0:0 /'etc/NetworkManager/NetworkManager.conf'
chmod 644 /'etc/NetworkManager/NetworkManager.conf'

# set home owner
chown -R "$USER_UID:$USER_GID" "$USER_HOME"

# reboot
systemctl reboot
