From e254d8dba1fef5d05a90308228ef58817ecc34e6 Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Wed, 11 Sep 2024 22:56:50 +0530 Subject: [PATCH] feat(install): Do distro specific setup before installing os-packages --- scripts/bootstrap-dotfiles.sh | 115 --------------------------------- scripts/install-os-packages.sh | 41 ++++++++---- scripts/install.sh | 5 +- scripts/package-list-os | 1 - scripts/test/.dockerignore | 1 + scripts/test/Dockerfile | 13 ++-- scripts/test/run-test.sh | 6 +- 7 files changed, 41 insertions(+), 141 deletions(-) delete mode 100755 scripts/bootstrap-dotfiles.sh diff --git a/scripts/bootstrap-dotfiles.sh b/scripts/bootstrap-dotfiles.sh deleted file mode 100755 index 3c62b81..0000000 --- a/scripts/bootstrap-dotfiles.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/sh - -# TODO: Use this to better manage dotfiles -# https://github.com/dylanirlbeck/dotfiles/blob/master/scripts/bootstrap.sh - -################################## -# Parse script arguments -################################## - -# defaults -QUIET="n" -CREATE_LINKS="y" - -usage() { - if [ "$1" != "" ]; then - echo "" - echo -e "${CRED}$1${CEND}\n" - fi - - echo "Applies all settings stored in the script's directory to your home directory" - echo "" - echo "Usage: $0 [-q|--quiet] [-l|--create-links]" - echo " -q, --quiet No screen outputs" - echo " -l, --create-links Applied by default. Creates soft-links to files in the current directory instead of copying them" - - echo "" - echo "Example: $0 -q --create-links" -} - -place_dotfile_at_target_location() { - source_file_location="$1" - file_target_location="$2" - TS="$3" - - # To avoid over writing existing dot file, we rename them - # Appending the timestamp to file name - if [ -f "$file_target_location" ] || [ -L "$file_target_location" ]; then - # echo "mv ${file_target_location} ${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing dotfile renamed to ${file_target_location}_${TS}" - mv "$file_target_location" "${file_target_location}_${TS}" && [ "$QUIET" = "n" ] && echo "Existing setting renamed to ${file_target_location}_${TS}" - fi - - target_directory=$(dirname "$file_target_location") - if [ ! -d "$target_directory" ]; then - mkdir -p "$target_directory" && [ "$QUIET" = "n" ] && echo "Directory ${target_directory} created" - fi - - if [ "$CREATE_LINKS" = "y" ]; then - # echo "ln -s ${source_file_location} ${target_directory}" - ln -sf "$source_file_location" "$target_directory" && [ "$QUIET" = "n" ] && echo "Linked ${file_target_location}" - else - # echo "cp ${source_file_location} ${target_directory}" - cp "$source_file_location" "$target_directory" && [ "$QUIET" = "n" ] && echo "Copied ${file_target_location}" - fi -} - -main() { - while [ "${#}" -gt 0 ]; do - case $1 in - -q | --quiet) - QUIET="y" - shift - ;; - -l | --create-links) - CREATE_LINKS="y" - shift - ;; - -h | --help) - echo - usage - echo - exit 0 - ;; - *) - usage "Unknown parameter passed: $1" "h" - exit 1 - ;; - esac - done - - case $(uname -a) in - Linux*) - # TODO: Make it less KDE-Neon specific and more towards general Linux - OS="kde-neon" - - [ "$XDG_CURRENT_DESKTOP" = "KDE" ] && OS="kde-neon" - ;; - Darwin*) - OS="macos" - ;; - *) - OS="UNSUPPORTED" - ;; - esac - - TS=$(date '+%d_%m_%Y-%H_%M_%S') - - # Switch inside dotfile repository directory - cd -P "$(dirname "$0")" || exit - - # Copy all files in "Common" dotfiles to $HOME directory ("~") - find "./common" -type f -not -path '*.DS_Store' -not -path '*.directory' | while read -r file; do - file_target_location="${HOME}${file#./common}" - source_file_location="${PWD}${file#.}" - place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" - done - - # Copy platform specific files to $HOME directory ("~") - find "./${OS}" -type f -not -path '*.DS_Store' -not -path '*.directory' | while read -r file; do - file_target_location="${HOME}${file#./"${OS}"}" - source_file_location="${PWD}${file#.}" - place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" - done -} - -main "$@" diff --git a/scripts/install-os-packages.sh b/scripts/install-os-packages.sh index cfc6b1c..2e1b777 100755 --- a/scripts/install-os-packages.sh +++ b/scripts/install-os-packages.sh @@ -2,29 +2,48 @@ OS_PACKAGE_FILE=package-list-os -OS_INSTALL_COMMAND="" -OS_PKG_CHECK_COMMAND="" +setup() { + OS_INSTALL_COMMAND="" + OS_PKG_CHECK_COMMAND="" -os_check() { - # TODO: Apply pre-processing to each. - # - Install apt specific things: apt-transport-https, sudo apt-get update && sudo apt-get upgrade -y - # - Improve dnf download speed by pre-applying required config # Detect package manager and set package manager commands if command -v apt-get > /dev/null 2>&1; then - OS_INSTALL_COMMAND="apt-get update && sudo apt-get upgrade -y && sudo apt-get" + OS_INSTALL_COMMAND="apt-get" OS_PKG_CHECK_COMMAND="apt-cache show" - elif command -v yum > /dev/null 2>&1; then - OS_INSTALL_COMMAND="yum" - OS_PKG_CHECK_COMMAND="yum list available" + + apt_setup elif command -v dnf > /dev/null 2>&1; then OS_INSTALL_COMMAND="dnf" OS_PKG_CHECK_COMMAND="dnf list available" + + dnf_setup + elif command -v yum > /dev/null 2>&1; then + OS_INSTALL_COMMAND="yum" + OS_PKG_CHECK_COMMAND="yum list available" else log "Unsupported package manager. This script supports apt, yum, and dnf." exit 1 fi } +dnf_setup() { + # Faster dnf installs + echo "fastestmirror=True" | sudo tee -a /etc/dnf/dnf.conf > /dev/null + echo "max_parallel_downloads=10" | sudo tee -a /etc/dnf/dnf.conf > /dev/null + echo "defaultYes=True" | sudo tee -a /etc/dnf/dnf.conf > /dev/null + echo "keepcache=True" | sudo tee -a /etc/dnf/dnf.conf > /dev/null + + # Enable RPM Fusion & Install media codecs + sudo dnf install -y https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm && sudo dnf groupupdate -y core multimedia --setop="install_weak_deps=False" --exclude=PackageKit-gstreamer-plugin sound-and-video + + sudo dnf update -y +} + +apt_setup() { + sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y apt-transport-https + # Add PPAs here +} + input_file_check() { if [ ! -f "$OS_PACKAGE_FILE" ]; then echo "File not found: $OS_PACKAGE_FILE" @@ -69,8 +88,8 @@ print_summary() { } main() { - os_check input_file_check + setup install_os_packages print_summary "OS" "$os_not_found_packages" } diff --git a/scripts/install.sh b/scripts/install.sh index 09b5236..7fe46a9 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,11 +1,8 @@ #!/usr/bin/env sh # TODO: -# - Update `bootstrap-dotfiles.sh` to work from its parent directory & ignore "scripts" directory -# - Integrate with `bootstrap-dotfiles.sh` -> do dotfiles 1st, then install -# - README.md # - Needs manual installation: appimagelauncher, firefox, brave, vs-code, cursor, kitty, mattermost-desktop, skypedesktop, ulauncher, dotnet8, dotnet8-sdk8.0, aspnetcore-runtime-8.0, Jetbrains Toolbox, Obsidian, Postman, firefox, zen, zoho, zoho-workdrive, nala -# - Available on some, not on others; may need manual installation: libreoffice, sublime-text, kitty-terminfo +# - Available on some, not on others; may need manual installation: libreoffice, sublime-text, kitty-terminfo, imagemagick main() { ./install-os-packages.sh diff --git a/scripts/package-list-os b/scripts/package-list-os index 5bc0f13..c5f9731 100644 --- a/scripts/package-list-os +++ b/scripts/package-list-os @@ -1,5 +1,4 @@ # Lines that start with # are ignored -apt-transport-https bash bleachbit build-essential diff --git a/scripts/test/.dockerignore b/scripts/test/.dockerignore index f722d46..7e88002 100644 --- a/scripts/test/.dockerignore +++ b/scripts/test/.dockerignore @@ -100,6 +100,7 @@ dist-ssr nvim_switch/ *kitty/*.py +.git/ README.md .gitignore .prettierrc diff --git a/scripts/test/Dockerfile b/scripts/test/Dockerfile index 2065eac..818a3fa 100644 --- a/scripts/test/Dockerfile +++ b/scripts/test/Dockerfile @@ -1,14 +1,13 @@ #FROM kdeneon/plasma -#FROM debian:11-slim +FROM debian:11-slim #FROM debian:12-slim #FROM ubuntu:20.04 #FROM ubuntu:22.04 -#FROM ubuntu:22.10 #FROM ubuntu:23.04 -FROM fedora:40 +#FROM fedora:40 #TODO: Arch -WORKDIR /scripts -#RUN apt-get update -y && apt-get install sudo -y # for debian distros -RUN dnf install sudo -y # for fedora and its derivatives +WORKDIR /dotfiles +RUN apt-get update && apt-get install sudo -y # for debian distros +#RUN dnf install sudo -y # for fedora and its derivatives COPY . . -CMD [ "sh", "install.sh" ] +CMD [ "sh", "setup.sh", "-i" ] diff --git a/scripts/test/run-test.sh b/scripts/test/run-test.sh index 5753cfd..788c904 100755 --- a/scripts/test/run-test.sh +++ b/scripts/test/run-test.sh @@ -2,10 +2,10 @@ # Prune, build and run docker main() { - cd .. # change docker build context to 1 directory up + cd ../.. # change docker context to dotfile repo docker container prune -f && echo "Removed old Docker containers" - docker build -t dotfile-install-test:latest -f test/Dockerfile . && echo "Docker build success" - docker run -it dotfile-install-test:latest + docker build -t dotfile-setup:latest -f scripts/test/Dockerfile . && echo "Docker build success" + docker run -it dotfile-setup:latest } main "$@"