Эх сурвалжийг харах

contrib: Merge dependency scripts into a single one.

Luther Blissett 3 жил өмнө
parent
commit
9ec99c4401

+ 15 - 13
README.md

@@ -5,9 +5,10 @@
 [![Manifesto - unsystem](https://img.shields.io/badge/Manifesto-unsystem-informational?logo=minutemailer&logoColor=white&style=flat-square)](https://dark.fi/manifesto.html)
 [![Book - mdbook](https://img.shields.io/badge/Book-mdbook-orange?logo=gitbook&logoColor=white&style=flat-square)](https://darkrenaissance.github.io/darkfi)
 
-## Connect to darkfi IRC
+## Connect to DarkFi IRC
 
-Follow [installation instructions](https://darkrenaissance.github.io/darkfi/misc/ircd.html#installation) for the p2p IRC daemon.
+Follow the [installation instructions](https://darkrenaissance.github.io/darkfi/misc/ircd.html#installation)
+for the P2P IRC daemon.
 
 ## Build
 
@@ -30,8 +31,8 @@ The following dependencies are also required:
 | freetype2 libs               | libfreetype6-dev |
 | expat xml lib                | libexpat1-dev    |
 
-Users of Debian-based systems (e.g. Ubuntu) can simply run the following 
-to install the required dependencies:
+Users of Debian-based systems (e.g. Ubuntu) can simply run the
+following to install the required dependencies:
 
 ```shell
 # apt-get update
@@ -40,20 +41,21 @@ to install the required dependencies:
     libexpat1-dev
 ```
 
-Alternatively, users can chose one of the automated scripts 
-under `contrib` folder by executing:
+Alternatively, users can try using the automated script under `contrib`
+folder by executing:
 
 ```shell
-% bash contrib/*_setup.sh
+% sh contrib/dependency_setup.sh
 ```
 
-The following setup script are provided:
-* **mac_setup.sh**: installation using brew (brew will be installed if not present).
-* **void_setup.sh**: Xbps dependencies for Void Linux.
+The script will try to recognize which system you are running,
+and install dependencies accordingly. In case it does not find your
+package manager, please consider adding support for it into the script
+and sending a patch.
 
-To build the necessary binaries, we can just clone the repo, and use the 
-provided Makefile to build the project. This will download the trusted 
-setup params, and compile the source code.
+To build the necessary binaries, we can just clone the repo, and use
+the provided Makefile to build the project. This will download the
+trusted setup params, and compile the source code.
 
 ```shell
 % git clone https://github.com/darkrenaissance/darkfi

+ 79 - 0
contrib/dependency_setup.sh

@@ -0,0 +1,79 @@
+#!/bin/sh
+set -e
+
+if [ "$UID" != 0 ]; then
+	SUDO="$(command -v sudo)"
+else
+	SUDO=""
+fi
+
+brew_sh="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
+
+setup_mac() {
+	if ! command -v brew >/dev/null; then
+		echo "brew not found, installing..." >&2
+		bash -c "$(curl -fL "${brew_sh}")" || return 1
+	fi
+
+	for i in cmake gcc jq pkgconf llvm@13 freetype expat; do
+		echo "Installing $i with brew..." >&2
+		brew install "$i" || return 1
+	done
+}
+
+setup_apt() {
+	APTGET="$SUDO $1"
+
+	$APTGET update || return 1
+	$APTGET install -y build-essential cmake jq wget pkg-config \
+		clang libclang-dev llvm-dev libudev-dev libfreetype6-dev \
+		libexpat1-dev || return 1
+}
+
+setup_xbps() {
+	XBPS="$SUDO $1"
+
+	$XBPS -S base-devel cmake wget expat-devel freetype-devel \
+		fontconfig-devel jq openssl-devel clang libclang llvm \
+		libllvm12 libgudev-devel
+}
+
+case "$(uname -s)" in
+Linux)
+	if command -v apt >/dev/null; then
+		echo "Setting up for apt" >&2
+		setup_apt "$(command -v apt)" || exit 1
+		echo "Dependencies installed!" >&2
+		exit 0
+	fi
+
+	if command -v apt-get >/dev/null; then
+		echo "Setting up for apt-get" >&2
+		setup_apt "$(command -v apt-get)" || exit 1
+		echo "Dependencies installed!" >&2
+		exit 0
+	fi
+
+	if command -v xbps-install; then
+		echo "Setting up for xbps" >&2
+		setup_xbps "$(command -v xbps-install)" || exit 1
+		echo "Dependencies installed!" >&2
+		exit 0
+	fi
+
+	echo "Error: Could not recognize your package manager." >&2
+	exit 1
+	;;
+
+Darwin)
+	echo "Setting up for OSX" >&2
+	setup_mac || exit 1
+	echo "Dependencies installed!" >&2
+	exit 0
+	;;
+
+*|"")
+	echo "Unsupported OS, sorry." >&2
+	exit 1
+	;;
+esac

+ 0 - 13
contrib/mac_setup.sh

@@ -1,13 +0,0 @@
-#!/bin/bash
-
-if ! command -v brew &> /dev/null ; then
-   /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-fi
-
-brew install cmake
-brew install gcc
-brew install jq
-brew install pkgconf
-brew install llvm@13
-brew install freetype
-brew install expat

+ 2 - 0
contrib/update_pkg_versions.py

@@ -1,4 +1,6 @@
 #!/usr/bin/env python3
+# Update the version in the toplevel Cargo.toml for DarkFi, and then run this
+# script to update all the other Cargo.toml files.
 import subprocess
 
 from os import chdir

+ 0 - 16
contrib/void_setup.sh

@@ -1,16 +0,0 @@
-#!/bin/bash
-
-sudo xbps-install -S \
-    base-devel \
-    cmake \
-    wget \
-    expat-devel \
-    freetype-devel \
-    fontconfig-devel \
-    jq \
-    openssl-devel \
-    clang \
-    libclang \
-    llvm \
-    libllvm12 \
-    libgudev-devel \