Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 46 additions & 43 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,59 @@ OS="unknown"
# detect OS
KERNEL=$(uname -s)
case $KERNEL in
Darwin)
OS=mac ;;
Linux)
OS="$(grep "^ID=" /etc/os-release | sed 's/ID=//;s/^"//;s/"$//')" ;;
*)
echo "unsupported system ($KERNEL)"
exit 1
Darwin)
OS=mac
;;
Linux)
OS="$(grep "^ID=" /etc/os-release | sed 's/ID=//;s/^"//;s/"$//')"
;;
*)
echo "unsupported system ($KERNEL)"
exit 1
;;
esac

# update package manager and install just
# refresh package index and install just
case "$OS" in
mac)
if ! command -v nix &>/dev/null; then
sh <(curl -L https://nixos.org/nix/install) --daemon
if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
fi
fi
mkdir -p "$HOME/.config/nix"
if ! grep -q "experimental-features" "$HOME/.config/nix/nix.conf" 2>/dev/null; then
echo "experimental-features = nix-command flakes" >> "$HOME/.config/nix/nix.conf"
fi
;;
fedora)
sudo dnf update -y
;;
opensuse-tumbleweed)
sudo zypper dup -y
;;
cachyos)
sudo pacman -Syu --noconfirm
;;
ubuntu|debian)
sudo apt-get update
sudo apt-get upgrade -y
;;
*)
echo "unsupported system ($OS)"
exit 1
mac)
if ! command -v nix &>/dev/null; then
sh <(curl -L https://nixos.org/nix/install) --daemon
if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
fi
fi
mkdir -p "$HOME/.config/nix"
if ! grep -q "experimental-features" "$HOME/.config/nix/nix.conf" 2>/dev/null; then
echo "experimental-features = nix-command flakes" >>"$HOME/.config/nix/nix.conf"
fi
;;
fedora)
sudo dnf makecache
;;
opensuse-tumbleweed)
sudo zypper refresh
;;
cachyos)
sudo pacman -Sy --noconfirm
;;
ubuntu | debian)
sudo apt-get update
;;
*)
echo "unsupported system ($OS)"
exit 1
;;
esac

# install just if not present
if ! command -v just &>/dev/null; then
case "$OS" in
mac) nix profile add nixpkgs#just ;;
fedora) sudo dnf install -y just ;;
opensuse-tumbleweed) sudo zypper in -y just ;;
cachyos) sudo pacman -S --noconfirm just ;;
ubuntu|debian) sudo apt-get install -y just ;;
esac
case "$OS" in
mac) nix profile add nixpkgs#just ;;
fedora) sudo dnf install -y just ;;
opensuse-tumbleweed) sudo zypper in -y just ;;
cachyos) sudo pacman -S --noconfirm just ;;
ubuntu | debian) sudo apt-get install -y just ;;
esac
fi

# hand off to justfile
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
root := justfile_directory()

os := if os() == "macos" { "mac" } else { `grep "^ID=" /etc/os-release | sed 's/ID=//;s/^"//;s/"$//'` }
update := "true"
update := "false"

# Show available recipes
help:
Expand Down