diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 8ea12a7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -#FROM kdeneon/plasma -FROM debian:11-slim -#FROM debian:12-slim -#FROM ubuntu:20.04 -#FROM ubuntu:22.04 -#FROM ubuntu:22.10 -#FROM ubuntu:23.04 -#TODO: Fedora -#TODO: openSUSE -#TODO: Arch -WORKDIR /scripts -RUN apt-get update -y && apt-get install sudo -y -COPY scripts . -CMD [ "bash", "install.sh" ] diff --git a/scripts/bootstrap.sh b/scripts/bootstrap-dotfiles.sh similarity index 100% rename from scripts/bootstrap.sh rename to scripts/bootstrap-dotfiles.sh diff --git a/scripts/install-brew-packages.sh b/scripts/install-brew-packages.sh new file mode 100755 index 0000000..58ab91b --- /dev/null +++ b/scripts/install-brew-packages.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env sh + +BREW_PACKAGE_FILE=package-list-brew + +input_file_check() { + if [ ! -f "$BREW_PACKAGE_FILE" ]; then + echo "File not found: $BREW_PACKAGE_FILE" + exit 1 + fi +} + +install_brew() { + yes | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + + # Required for installing fonts + brew tap homebrew/linux-fonts +} + +# Install packages listed on "brew-package-list" file +install_brew_packages() { + not_found_packages="" + found_packages="" + + # Read the package names from the file + while IFS= read -r brew_package; do + # Skip lines that start with # + case "$brew_package" in + \#*) continue ;; + esac + + # Check if the package exists in the Homebrew repository + if brew search "$brew_package" | grep -q "^$brew_package\$"; then + echo "Available: $brew_package" + found_packages="$found_packages $brew_package" + else + not_found_packages="$not_found_packages $brew_package" + echo "Unavailable: $brew_package" + fi + done < "$BREW_PACKAGE_FILE" + + brew install $found_packages +} + +print_summary() { + # Print the list of packages that were not found + echo + if [ -n "$2" ]; then + echo "The following $1 packages were not found in the repository:" + echo "$2" + fi +} + +main() { + input_file_check + install_brew + install_brew_packages + print_summary "Brew" "$not_found_packages" +} + +main "$@" diff --git a/scripts/install-os-packages.sh b/scripts/install-os-packages.sh new file mode 100755 index 0000000..cfc6b1c --- /dev/null +++ b/scripts/install-os-packages.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env sh + +OS_PACKAGE_FILE=package-list-os + +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_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" + elif command -v dnf > /dev/null 2>&1; then + OS_INSTALL_COMMAND="dnf" + OS_PKG_CHECK_COMMAND="dnf list available" + else + log "Unsupported package manager. This script supports apt, yum, and dnf." + exit 1 + fi +} + +input_file_check() { + if [ ! -f "$OS_PACKAGE_FILE" ]; then + echo "File not found: $OS_PACKAGE_FILE" + exit 1 + fi +} + +# Install packages listed on "os-package-list" file +install_os_packages() { + os_not_found_packages="" + os_found_packages="" + + echo "Checking package availability..." + + # Loop through each package name in the file + while IFS= read -r os_package; do + # Skip lines that start with # + case "$os_package" in + \#*) continue ;; + esac + + # Check if the package exists in the APT repository + if eval "$OS_PKG_CHECK_COMMAND" "$os_package" > /dev/null 2>&1; then + echo "Available: $os_package" + os_found_packages="$os_found_packages $os_package" + else + echo "Unavailable: $os_package" + os_not_found_packages="$os_not_found_packages $os_package" + fi + done < "$OS_PACKAGE_FILE" + + eval sudo "$OS_INSTALL_COMMAND" install -y "$os_found_packages" +} + +print_summary() { + # Print the list of packages that were not found + echo + if [ -n "$2" ]; then + echo "The following $1 packages were not found in the repository:" + echo "$2" + fi +} + +main() { + os_check + input_file_check + install_os_packages + print_summary "OS" "$os_not_found_packages" +} + +main "$@" diff --git a/scripts/install.sh b/scripts/install.sh index 91e3f26..09b5236 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,34 +1,15 @@ #!/usr/bin/env sh # TODO: -# - brave, vs-code, cursor, kitty, libreoffice, mattermost-desktop, skypedesktop, ulauncher, code, dotnet8, dotnet8-sdk8.0, aspnetcore-runtime-8.0, sublime-text, AppImage Launcher Settings, Jetbrains Toolbox, Obsidian, Postman, firefox, zen, zoho, zoho-workdrive -# - `tee` logs to a file +# - 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 -# - Integrate with `bootstrap.sh` - -# Install packages listed on "os-package-list" file -install_os_packages() { - # Ignore lines that start with # - OS_PACKAGES=$(sed "/^#/d" os-package-list | tr "\n\r" " ") - sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get install $OS_PACKAGES -y -} - -# Install packages listed on "brew-package-list" file -install_brew_packages() { - yes | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - - # Required for installing fonts - brew tap homebrew/linux-fonts - - # Ignore lines that start with # - BREW_PACKAGES=$(sed "/^#/d" brew-package-list | tr "\n\r" " ") - brew install $BREW_PACKAGES -} +# - 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 main() { - install_os_packages - install_brew_packages + ./install-os-packages.sh + ./install-brew-packages.sh } main "$@" diff --git a/scripts/brew-package-list b/scripts/package-list-brew similarity index 100% rename from scripts/brew-package-list rename to scripts/package-list-brew diff --git a/scripts/os-package-list b/scripts/package-list-os similarity index 77% rename from scripts/os-package-list rename to scripts/package-list-os index 8446433..5bc0f13 100644 --- a/scripts/os-package-list +++ b/scripts/package-list-os @@ -1,5 +1,4 @@ # Lines that start with # are ignored -# TODO: use apt to check if the package is available. if not, remove them from list before installing apt-transport-https bash bleachbit @@ -17,9 +16,12 @@ gdb git gparted htop -imagemagick +#imagemagick kde-spectacle kdeconnect +kitty +kitty-terminfo +libreoffice llvm make net-tools diff --git a/scripts/run-test.sh b/scripts/run-test.sh deleted file mode 100755 index e564f92..0000000 --- a/scripts/run-test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# Prune, build and run docker -main() { - docker container prune -f && echo "Removed old Docker containers" - docker build -f ../Dockerfile -t dotfile-install-test:latest .. && echo "Docker build success" - docker run -it dotfile-install-test:latest -} - -main "$@" diff --git a/.dockerignore b/scripts/test/.dockerignore similarity index 99% rename from .dockerignore rename to scripts/test/.dockerignore index c819b05..f722d46 100644 --- a/.dockerignore +++ b/scripts/test/.dockerignore @@ -104,3 +104,5 @@ README.md .gitignore .prettierrc LICENSE + +test/ diff --git a/scripts/test/Dockerfile b/scripts/test/Dockerfile new file mode 100644 index 0000000..2065eac --- /dev/null +++ b/scripts/test/Dockerfile @@ -0,0 +1,14 @@ +#FROM kdeneon/plasma +#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 +#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 +COPY . . +CMD [ "sh", "install.sh" ] diff --git a/scripts/test/run-test.sh b/scripts/test/run-test.sh new file mode 100755 index 0000000..5753cfd --- /dev/null +++ b/scripts/test/run-test.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Prune, build and run docker +main() { + cd .. # change docker build context to 1 directory up + 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 +} + +main "$@"