From 05cf83c6f864d42a3b3d8a8d9bc9c42fab523070 Mon Sep 17 00:00:00 2001 From: b1ek Date: Tue, 13 Feb 2024 18:55:29 +1000 Subject: [PATCH] init repo --- README.md | 9 +++ brick.sh | 165 ++++++++++++++++++++++++++++++++++++++++++++++ bricks/.gitignore | 1 + bricks/omz.brick | 11 ++++ 4 files changed, 186 insertions(+) create mode 100644 README.md create mode 100755 brick.sh create mode 100644 bricks/.gitignore create mode 100644 bricks/omz.brick diff --git a/README.md b/README.md new file mode 100644 index 0000000..38382f8 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# blek!OS +hiii and welcome to the blek! OS install place + +now, first of all it is not actually an OS but more like my customization rices for arch (aka dotfiles) +also some install scripts for stuff like `paru` + +oh yeah also it has a (kind of) a package manager which is called `brick.sh` which is used to install some stuff + +## have fun ^^ diff --git a/brick.sh b/brick.sh new file mode 100755 index 0000000..c5010b8 --- /dev/null +++ b/brick.sh @@ -0,0 +1,165 @@ +#!/bin/sh +# brick - a simple userspace package manager for blek!OS +# also built on top of pacman +# +# made by alice +# also it is GPL3 only uwu + +# settings +set -e + +# functions +errcho() { + # now this was stolen from https://stackoverflow.com/a/2990533 + # uwu + echo "$@" 1>&2; +} + +err() { + printf "\x1b[1;31m[!]\x1b[0m $@\n" 1>&2; +} + +inf() { + printf " $@\n" +} + +getbrick() { + echo $BRICKS_DIR/$1.brick +} + +brickdb() { + mkdir -p $BRICKS_DIR/.db + + if ! [ -f $BRICKS_DIR/.db/installed ]; then + touch $BRICKS_DIR/.db/installed + fi + + echo $BRICKS_DIR/.db +} + +pkg_installed() { + if [ ! -z $(echo "$BRICKS_INSTALLED" | grep "$1") ]; then + return 0 + fi + return 1 +} + +user_confirm() { + # base function was stolen from https://stackoverflow.com/a/32708121 + if [ "$AUTOMATIC" == "true" ]; then + return 0 + fi + + while true; do + read -r -n 1 -p "${1:-Continue?} [Y/n]: " REPLY + case $REPLY in + [yY]) echo ; return 0 ;; + [nN]) echo ; return 1 ;; + *) return 0 ;; + esac + done +} + +# some vars +BRICKS_DIR=${BRICKS_DIR:-} +PKGS=() +ERRORED=false +AUTOMATIC=false + +# settings the PKGS var +# lets grab those from argv +while [[ $# -gt 0 ]]; do + case $1 in + -y|--noconfirm) + AUTOMATIC=true + shift;; + -*) + # meh domt need unkonw args + shift;; + *) + # everything else is a package name however + PKGS+=("$1") + shift;; + esac +done + +# setting the BRICKS_DIR var + +BRICKS_PWD=$(pwd) + +while :; do + # lets jump to the parent dir until we find the bricks dir + if [ -d $BRICKS_PWD/bricks ]; then + # yay we found it ^^ + BRICKS_DIR=$BRICKS_PWD/bricks + break + fi + if [ $BRICKS_PWD = "/" ]; then + err "Didnt find the bricksdir in this or any parent directory (excluding root)" + exit 1 + fi +done + +unset BRICKS_PWD + +BRICKS_DB=$(brickdb) +BRICKS_INSTALLED=$(cat $BRICKS_DB/installed) + +PPKGS=() + +# now step 1 is to check that all packages are there +for pkg in "${PKGS[@]}"; do + if ! [ -f $(getbrick $pkg) ]; then + err "Oh no! Brick $pkg is not found in $BRICKS_DIR" + ERRORED=true + fi + + if pkg_installed "$pkg"; then + echo $pkg is installed, skipping + else + PPKGS=("${PPKGS[@]}" $pkg) + fi +done + +PKGS=("${PPKGS[@]}") + +if [ "$ERRORED" == "true" ]; then + exit 1 +fi + +if [ "${#PKGS[@]}" == "0" ]; then + inf "nothing to do" + exit +else + echo "Packages to install: ${PKGS[@]}" + user_confirm +fi + +PACDEPS=() + +# so now lets install! yay +for pkg in "${PKGS[@]}"; do + source $(getbrick $pkg) + IFS=' ' read -ra DEPS <<< $(pkgs) + PACDEPS=("${PACDEPS[@]}" "${DEPS[@]}") +done + +if [ "${#PACDEPS[@]}" != "0" ]; then + # welp lets install those + sudo pacman -S --needed --noconfirm $(printf "%s\n" "${PACDEPS[@]}" | sort -u) + inf "installed all pacman deps" +else + inf "no pacman deps to install" +fi + +i=1 +# pacman deps installed, lets install the actual shit +for pkg in "${PKGS[@]}"; do + inf "installing $pkg [$i/${#PKGS[@]}]" + source $(getbrick $pkg) + install > $BRICKS_DB/.$pkg-install-log + i=$(($i + 1)) +done + +inf "done" + diff --git a/bricks/.gitignore b/bricks/.gitignore new file mode 100644 index 0000000..d11b198 --- /dev/null +++ b/bricks/.gitignore @@ -0,0 +1 @@ +.db diff --git a/bricks/omz.brick b/bricks/omz.brick new file mode 100644 index 0000000..f266712 --- /dev/null +++ b/bricks/omz.brick @@ -0,0 +1,11 @@ +#!/bin/sh +# omz brick (pacakge is GPL3 only, omz itself is MIT (as of jan 2024)) +# made by alice + +pkgs() { + echo sh curl git zsh +} + +install() { + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +}