Skip to content

Instantly share code, notes, and snippets.

@koiralakiran1
Last active September 17, 2023 14:41
Show Gist options
  • Save koiralakiran1/a7b0faae0a5c00d05e8a96576ae15469 to your computer and use it in GitHub Desktop.
Save koiralakiran1/a7b0faae0a5c00d05e8a96576ae15469 to your computer and use it in GitHub Desktop.
My device setup process

My device setup process

Base system: Manjaro

Installation

  • Install with MANJARO_ENCRYPTED_INSTALL.md guide

After installation

  • Run setup_device.py
$ curl https://gist.githubusercontent.com/koiralakiran1/a7b0faae0a5c00d05e8a96576ae15469/raw/3647c29a99e04e0e6e50ad1a46f5d454ce7d74d2/setup_device.py | python -

Use Calamares to install encrypted root

From https://forum.manjaro.org/t/root-tip-how-to-use-calamares-to-install-encrypted-root-using-unencrypted-boot/117304

Calamares EFI system encryption guide

Ensure your system is using EFI mode by entering your system firmware and disable Legacy or Ccmpatibility mode.

Boot the live ISO and start the Calamares installer.

In the installer - move along with the installer until you reach the Partitions section

Partitions section.

  1. Choose Manual partitioning option
  2. Do Not tick the Encrypt system box
  3. Click > Next button

image

  1. Click the New Parition Table button
  2. The GPT partition scheme should be preselected (if it's not something's not right - cancel and fix it)
  3. Click the OK button

image

Select the Free space and click the Create button

  1. Size -> 512M
  2. File system -> fat32
  3. Mount Point -> /boot/efi
  4. FS Label -> efi system
  5. Flags -> boot
  6. Click the OK button

image

Select the Free space and click the Create button

  1. Size -> 1024M
  2. File system -> ext4
  3. Mount Point -> /boot
  4. FS Label -> linux boot
  5. Flags -> No flags
  6. Click the OK button

image

Select the Free space and click the Create button

  1. Size -> remaining
  2. File system -> ext4
  3. Tick Encrypt
  4. Fill in encryption phrase
  5. Confirm encryption phrase
  6. Mount Point -> /
  7. FS Label -> linux root
  8. Flags -> root
  9. Click the OK button

image

When you continue the remainder of the installation you will be notified by the installer, the installation is considered unsafe. You already know that - so acknowledge the warning and continue.

image

ℹ️ After you finalize your installation and reboot - consider creating a swapfile following the instructions on the wiki page at https://wiki.manjaro.org/index.php/Swap#Using_a_Swapfile

ℹ️ Hibernate functionality is not initially setup using this kind of installation. It is likely possible to setup but beyond the scope of this guide.

#!/usr/bin/env python
# pylint: disable=line-too-long,missing-module-docstring
import os
import sys
import logging
import platform
import subprocess
class SetupDevice():
"""Executes my new device setup flows"""
logger: logging.Logger
ssh_setup_script = 'https://gist.githubusercontent.com/koiralakiran1/fd33f2b6162f827a0a90a7c45011df53/raw/8dca96fcf5ea49b3c353fa6f437da28bb1c7baef/setup_github_ssh_keys.sh'
default_browser_preference = 'brave-bin' # Pacman's "brave-browser" doesn't work for some reason
# Dotfiles specific config
clone_directory = os.path.expanduser('~/dotfiles')
link_files_script_path_in_dotfiles = 'v2/home/.scripts/link_files.py'
def __init__(self) -> None:
self.logger = self._get_logger()
def _get_logger(self):
handler = logging.StreamHandler()
handler.setLevel(logging.NOTSET)
handler.setFormatter(self._CustomFormatter())
logger = logging.getLogger('SetupDevice')
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
return logger
def _ask_yes_no(self, question: str, defaultValue = 'no'):
answer = input(f'{question} (y/n/yes/no, default = {defaultValue}): ') or defaultValue
return answer.lower() == 'yes' or answer.lower() == 'y'
def _exec_full(self, filepath):
global_namespace = {
"__file__": filepath,
"__name__": "__main__",
}
with open(filepath, 'rb') as file:
exec(compile(file.read(), filepath, 'exec'), global_namespace)
def _sync_packages(self):
if self._ask_yes_no('Sync packages?', 'y'):
self.logger.info('Syncing pacman package list. (sudo pacman -Sy)')
subprocess.run(['sudo', 'pacman', '-Sy'], check=True)
def _instal_necessary_utilities(self):
self.logger.info('Installing yay and necessary utilities using pacman..')
subprocess.run(['sudo', 'pacman', '-S', '--needed', 'curl', 'wget', 'bash', 'git', 'base-devel', 'yay'], check=True)
def _install_preferred_browser(self):
preferred_browser = input(f'Enter preferred browser (default = {self.default_browser_preference}): ') or self.default_browser_preference
self.logger.info('Installing %s...', preferred_browser)
subprocess.run(['yay', '-S', '--needed', preferred_browser], check=True)
self.logger.info('Now open %s and sync it; Setup password manager, accounts etc.', preferred_browser)
input('Press any key to continue...')
def _setup_github_ssh_access(self):
"""
Setup ssh access to github. Using existing shell file from gist
TODO: Make python version of the shell file
"""
if not self._ask_yes_no('Do you have git ssh setup already?'):
self.logger.info('Setting up new github ssh access')
self.logger.info('Running "%s"', self.ssh_setup_script)
os.system(f'bash <(curl -s {self.ssh_setup_script})')
self.logger.info('Github ssh access setup complete!')
else:
self.logger.info('Skipping ssh setup...')
def _clone_dotfiles(self):
dotfiles_profile = input('Enter github profile to clone "dotfiles" repo from: ')
dotfiles_link = f'git@github.com:{dotfiles_profile}/dotfiles.git'
# Backup existing dotfiles if any
self.logger.info('Backing up existing dotfiles if exists')
subprocess.run(['mv', '-f', self.clone_directory, f'{self.clone_directory}.bkp'], check=False)
# Clone dotfiles
self.logger.info('Cloning dotfiles from %s to %s', dotfiles_link, self.clone_directory)
subprocess.run(['git', 'clone', dotfiles_link, self.clone_directory], check=True)
self.logger.info('Dotfiles cloned!')
def _execute_link_files(self):
if self._ask_yes_no('Link files?'):
self.logger.info('Executing link-files')
self._exec_full(os.path.expanduser(f'{self.clone_directory}/{self.link_files_script_path_in_dotfiles}'))
self.logger.info('Linked files!')
def _install_package_list(self):
if self._ask_yes_no('Install ~/.packagelist?', 'yes'):
subprocess.run(['install-packagelist'], check=True)
self.logger.info('All packages from packagelist are installed!')
class _CustomFormatter(logging.Formatter):
"""Custom log formatter"""
grey = "\x1b[38m"
green = "\x1B[32m"
yellow = "\x1b[33m"
red = "\x1b[31m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
message_format = "%(asctime)s - %(name)s - %(levelname)s -> %(message)s (%(filename)s:%(lineno)d)"
FORMATS = {
logging.DEBUG: grey + message_format + reset,
logging.INFO: green + message_format + reset,
logging.WARNING: yellow + message_format + reset,
logging.ERROR: red + message_format + reset,
logging.CRITICAL: bold_red + message_format + reset
}
def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)
def main(self):
"""Main function to run setup device flow"""
self.logger.info('Setting up new system: %s', platform.node())
self._sync_packages()
self._instal_necessary_utilities()
self._install_preferred_browser()
self._setup_github_ssh_access()
self._clone_dotfiles()
self._execute_link_files()
self.logger.info('Now install packagelist. Run `install-packagelist`')
self._install_package_list()
self.logger.info('Setup Complete!')
if __name__ == "__main__":
obj = SetupDevice()
sys.exit(obj.main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment