示例#1
0
def request_pass(depth: int) -> str:
    pass1 = getpass(prompt=format_with_depth(depth, "Enter password: "******"Enter password again: "))
    if pass1 != pass2:
        print_on_depth(depth, "Password doesn't match.")
        exit(-1)
    return pass1
示例#2
0
def install():
    depth = 0
    print_on_depth(depth, "Starting installation run")
    data = gather_info(depth + 1)
    install_all(depth + 1, data)
    fix_git_settings(depth + 1, data)
    init_dirs_and_config(depth, data)
    prep_system(depth, data)
示例#3
0
def abs_copy(depth: int, src: str, dest: str):
    if os.path.exists(dest):
        if confirm(depth, "A file exists at %s continue and backup?\n" % dest):
            shutil.copy(dest, dest + ".bak.cfg")
            shutil.copy(src, dest)
        else:
            print_on_depth(depth, "Skipped copy of %s to %s" % (src, dest))
    else:
        shutil.copy(src, dest)
示例#4
0
def copy_corresponding(depth: int, dest_root, cfg, data: InstallData):
    for root, dirs, files in os.walk(cfg):
        cor = str(root).replace(
            data.system_data.append_to_config_location("/"), "")
        dest = dest_root + cor
        if not os.path.exists(dest):
            os.makedirs(dest, mode=0o700, exist_ok=True)
        for f in files:
            src = os.path.join(root, f)
            dst = os.path.join(dest, f)
            abs_copy(depth, src, dst)
            print_on_depth(depth, "Copied %s")
示例#5
0
def install_yay(depth: int):
    print_on_depth(depth, "Installing Yay")
    tmp = tempfile.mkdtemp()
    cur = os.getcwd()
    os.chdir(tmp)
    run_cmd(depth, "git clone https://aur.archlinux.org/yay.git").get_or_throw()
    print_on_depth(depth, "Successfully cloned")
    os.chdir(os.path.join(tmp, "yay"))
    run_cmd(depth, "makepkg -si --noconfirm").get_or_throw()
    print_on_depth(depth, "Successfully installed")
    print_on_depth(depth, "Cleaning up dirs")
    shutil.rmtree(tmp)
    os.chdir(cur)
    print_on_depth(depth, "Success")
示例#6
0
def prep_env():
    depth = 0
    print_on_depth(depth, "Prepping env as chroot")
    opts = UserOpts.prompt_for_opts(depth + 1)
    print_on_depth(depth, "Creating user %s" % opts.user_name)
    run_cmd(depth, "useradd %s" % opts.user_name)
    hostname = "/etc/hostname"
    create_with_content(depth, hostname, [opts.host_name])

    hosts = "/etc/hosts"
    create_with_content(depth, hosts,
                        ["127.0.0.1    localhost", "::1          localhost"])

    append_lines_to_end("/etc/locale.gen", ["en_US.UTF-8 UTF-8"])
    create_with_content(depth, "/etc/locale.conf", ["LANG=en_US.UTF-8"])
    run_cmd(depth, "locale-gen").get_or_throw()
    run_cmd(depth, "ln -s /usr/share/zoneinfo/Europe/Stockholm /etc/localtime"
            ).get_or_throw()
    run_cmd(depth, "timedatectl set-timezone Europe/Stockholm").get_or_throw()
    run_cmd(depth, "hwclock --systohc --utc").get_or_throw()

    run_cmd(depth, "useradd -m %s" % opts.user_name).get_or_throw()
    append_lines_to_end("/etc/sudoers",
                        ["%s    ALL=(ALL) NOPASSWD:ALL" % opts.user_name])
    run_cmd(depth,
            "systemctl --now enable systemd-networkd systemd-resolved iwd"
            ).or_print_err()
    run_cmd(depth, "systemctl --now enable dhcpcd").or_print_err()
    tmpl = ToTmpl(template_path="/opts.tmpl",
                  props=opts.__dict__).to_tmpl_fmt()
    save = "/home/setup/arch_config/opts"
    with open(save, "w+") as f:
        f.write(tmpl)
    print_on_depth(depth, "Done prepping env, saved opts to %s" % save)
    print_on_depth(depth, "Remember to run: passwd %s" % opts.user_name)
示例#7
0
def copy_dirs(depth: int, data: InstallData):
    for d in USER_COPY_DIRS:
        dest = data.system_data.append_to_base("/")
        cfg = data.system_data.append_to_config_location(d)
        if not os.path.exists(dest):
            mkdir(depth, dest, username=data.user_opts.user_name)
        copy_corresponding(depth, dest, cfg, data)
        print_on_depth(depth, "Copied contents of dir %s" % d)
    for d in SYS_DIRS:
        dest = d
        cfg = data.system_data.append_to_config_location(d)
        if not os.path.exists(dest):
            mkdir(depth, dest)
        copy_corresponding(
            depth, dest, cfg,
            data)  # TODO: Fix bug where it tries to copy to /etcetc
        print_on_depth(depth, "Copied contents of dir %s" % d)
示例#8
0
def prep_system(depth: int, data: InstallData):
    if data.user_opts.programming:
        run_cmd(depth, "rustup toolchain install stable").or_print_err()

    # Start services
    print_on_depth(depth, "Enabling services now")
    run_cmd(depth, "sudo systemctl enable --now bluetooth").or_print_err()
    run_cmd(depth, "sudo systemctl enable --now cronie").or_print_err()
    run_cmd(depth, "sudo systemctl enable --now dhcpcd").or_print_err()
    run_cmd(depth, "sudo systemctl enable --now ntpd").or_print_err()
    run_cmd(depth, "sudo pulseaudio -D").or_print_err()

    # Set bluetooth agent on
    print_on_depth(depth, "Setting up default BT agent")
    run_cmd(depth, "sudo bluetoothctl -- default-agent").or_print_err()
    run_cmd(depth, "sudo bluetoothctl -- power on").or_print_err()
    update_bt_conf()
    print(depth, "Successfully prepped system")
示例#9
0
def fix_git_settings(depth: int, data: InstallData):
    print_on_depth(depth, "Configuring git and generating keys.")
    run_cmd(depth, "git config --global user.email %s" %
            data.user_opts.email).get_or_throw()
    run_cmd(depth, "git config --global user.name %s" %
            data.user_opts.user_name).get_or_throw()
    run_cmd(depth, "git config --global pull.rebase true").get_or_throw()
    run_cmd(depth, "git config --global push.default current").get_or_throw()
    run_cmd(depth, "git config --global rerere.enabled true").get_or_throw()

    rsa = data.system_data.append_to_base("/.ssh/id_rsa")
    if not os.path.exists(rsa):
        print_on_depth(depth, "Creating SSH key")
        run_cmd(depth, "ssh-keygen -t rsa -b 4096 -C %s" %
                data.user_opts.email).get_or_throw()
        run_cmd(depth, "ssh-add %s" % rsa).get_or_throw()
        print_on_depth(
            depth,
            "Add the key from ~/.ssh/id_rsa to github to finish git install")
    else:
        print_on_depth(depth, "Skipping key generation as it already exists.")
    print_on_depth(depth, "Success.")
示例#10
0
def install_all(depth: int, data: InstallData) -> [str]:
    print_on_depth(depth, "Preparing packag install")
    to_install = base
    if bool(data.user_opts.xmonad):
        print_on_depth(depth, "Include xmonad deps")
        to_install += xmonad
    if bool(data.user_opts.programming):
        print_on_depth(depth, "Include programming deps")
        to_install += programming
    if bool(data.user_opts.nvidia):
        print_on_depth(depth, "Include nvidia drivers")
        to_install += nvidia
    else:
        print_on_depth(depth, "Exclude nvidia drivers")
        to_install += non_nvidia
    print_on_depth(depth, "Installing %s packages" % len(to_install))
    for pkg in to_install:
        res = pacman_install(depth + 1, pkg)
        if not res.was_successful():
            print_on_depth(depth, "Failed to install pkg: %s" % pkg)
    print_on_depth(depth, "Successfully installed pacman packages")

    if bool(data.user_opts.yay):
        install_yay(depth + 1)
        for pkg in yay:
            if confirm(depth + 1, "Install package %s with yay? " % pkg):
                yay_install(depth + 1, pkg).or_print_err()
def install():
    depth = 0
    print_on_depth(depth, "Starting install script")
    pw = request_pass(depth)

    # Add boot deps
    print_on_depth(depth, "Installing boot deps")
    run_cmd(depth, "pacman -S grub --noconfirm --needed")
    run_cmd(depth, "pacman -S efibootmgr --noconfirm --needed")
    run_cmd(depth, "pacman -S sudo --noconfirm --needed")
    run_cmd(depth, "pacman -S iwd --noconfirm --needed")
    run_cmd(depth, "pacman -S dhcpcd --noconfirm --needed")

    print_on_depth(depth, "Generating root keyfile...")
    root_key_file = "/root/croot.keyfile"
    if mkfile(depth, root_key_file):
        run_cmd(
            depth, "dd bs=512 count=4 if=/dev/random of=%s iflag=fullblock" %
            root_key_file).get_or_throw()
        run_cmd(depth, "chmod 000 %s" % root_key_file).get_or_throw()
        run_cmd(depth,
                "cryptsetup -v luksAddKey %s %s" % (ROOT, root_key_file),
                piped_input=pw).get_or_throw()

    print_on_depth(depth, "Generating home keyfile...")
    home_key_dir = "/etc/cryptsetup-keys.d"
    mkdir(depth, home_key_dir, 644).get_or_throw()
    home_key_file = "%s/home.key" % home_key_dir
    if mkfile(depth, home_key_file):
        run_cmd(
            depth, "dd bs=512 count=4 if=/dev/random of=%s iflag=fullblock" %
            home_key_file).get_or_throw()
        run_cmd(depth, "chmod 000 %s" % home_key_file).get_or_throw()
        run_cmd(depth,
                "cryptsetup -v luksAddKey %s %s" % (HOME, home_key_file),
                piped_input=pw).get_or_throw()

    print_on_depth(depth, "Generating swap keyfile...")
    swap_key_file = "%s/swap.key" % home_key_dir
    if mkfile(depth, swap_key_file):
        run_cmd(
            depth, "dd bs=512 count=4 if=/dev/random of=%s iflag=fullblock" %
            home_key_file).get_or_throw()
        run_cmd(depth, "chmod 000 %s" % swap_key_file).get_or_throw()
        run_cmd(depth,
                "cryptsetup -v luksAddKey %s %s" % (SWAP, swap_key_file),
                piped_input=pw).get_or_throw()
    print_on_depth(depth, "Done generating keyfiles")

    print_on_depth(depth, "Fixing crypt conf")
    fix_conf(root_key_file, home_key_file, swap_key_file, get_lsblk(depth))
    print_on_depth(depth, "Executing grub install")
    run_cmd(
        depth,
        "grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB --recheck"
    ).get_or_throw()
    run_cmd(depth, "grub-install --target=i386-pc --recheck %s" %
            DISK).get_or_throw()
    print_on_depth(depth, "Executing mkinitcpio")
    run_cmd(depth, "mkinitcpio -P").get_or_throw()
    print_on_depth(depth, "Creating grub cfg")
    run_cmd(depth, "grub-mkconfig -o /boot/grub/grub.cfg").get_or_throw()
    prep_env()
    run_cmd(depth, "mkdir /home/gramar")
    run_cmd(depth, "chown -R gramar /home/gramar")
    run_cmd(depth, "chgrp -R gramar /home/gramar")
    run_cmd(depth, "mv /home/setup/arch_config /home/gramar/code")
    run_cmd(depth, "chown -R gramar /home/gramar/code")
    run_cmd(depth, "chgrp -R gramar /home/gramar/code")
    print_on_depth(
        depth, "Done, enter root password then exit chroot, umount -a, reboot,"
        " and run install/user_install.sh")
示例#12
0
def create_dirs(depth: int, data: InstallData):
    for d in BASE:
        os.makedirs(data.system_data.append_to_base(d),
                    mode=0o700,
                    exist_ok=True)
        print_on_depth(depth, "Created dir: %s" % d)
示例#13
0
def init_dirs_and_config(depth: int, data: InstallData):
    print_on_depth(depth, "Initialising dirs")
    create_dirs(depth, data)
    copy_user_files(depth, data)
    copy_dirs(depth, data)