dependencies
This commit is contained in:
11
packages/libncurses.shrap
Normal file
11
packages/libncurses.shrap
Normal file
@@ -0,0 +1,11 @@
|
||||
(package
|
||||
(name "ncurses")
|
||||
(version "6.6")
|
||||
(homepage "https://invisible-island.net/ncurses/")
|
||||
(src (tar
|
||||
(url "https://invisible-mirror.net/archives/ncurses/ncurses-6.6.tar.gz")
|
||||
(dir "ncurses-6.6")
|
||||
(blake3 "")))
|
||||
(build
|
||||
(configure_make
|
||||
(configure_flags "--disable-widec --without-tests --without-progs --without-manpages"))))
|
||||
11
packages/vim.shrap
Normal file
11
packages/vim.shrap
Normal file
@@ -0,0 +1,11 @@
|
||||
(package
|
||||
(name "vim")
|
||||
(version "9.1.2148")
|
||||
(homepage "https://www.vim.org/")
|
||||
(dependencies "libncurses")
|
||||
(src (tar
|
||||
(url "https://github.com/vim/vim/archive/refs/tags/v9.1.2148.tar.gz")
|
||||
(dir "vim-9.1.2148")
|
||||
(blake3 "")))
|
||||
(build
|
||||
(configure_make)))
|
||||
10
packages/zlib.shrap
Normal file
10
packages/zlib.shrap
Normal file
@@ -0,0 +1,10 @@
|
||||
(package
|
||||
(name "zlib")
|
||||
(version "1.3.1")
|
||||
(homepage "https://zlib.net/")
|
||||
(src (tar
|
||||
(url "https://zlib.net/zlib-1.3.1.tar.gz")
|
||||
(dir "zlib-1.3.1")
|
||||
(blake3 "207c3b0862cb4e3686f8405f76a98c38dbad9c94bcf4be4b9efca0716aba51ec")))
|
||||
(build
|
||||
(configure_make)))
|
||||
61
src/main.cc
61
src/main.cc
@@ -2,28 +2,31 @@
|
||||
#include "util.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <sys/stat.h>
|
||||
#include <thread>
|
||||
|
||||
int main() {
|
||||
if (geteuid() != 0) {
|
||||
std::cerr << "This program needs to be ran as root.\n";
|
||||
return 1;
|
||||
}
|
||||
mkdir("/tmp/shrap", 0777);
|
||||
|
||||
std::ifstream file("zlib.shrap");
|
||||
void install_package(const std::string &name) {
|
||||
std::ifstream file("packages/" + name + ".shrap");
|
||||
if (!file) {
|
||||
std::cerr << "Error opening file\n";
|
||||
return 1;
|
||||
std::cerr << "Package " << name << "not found.\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
Expr pkg = Expr::parse(file);
|
||||
|
||||
try {
|
||||
for (const auto &dep : pkg.get("dependencies").children) {
|
||||
install_package(dep.value);
|
||||
}
|
||||
} catch (std::out_of_range &) {
|
||||
}
|
||||
|
||||
Expr src = pkg.get("src").children[0];
|
||||
std::string src_type = src.children[0].value;
|
||||
std::string src_url = src.children[1].value;
|
||||
std::string src_path = "/tmp/shrap/" + src.children[2].value;
|
||||
std::string src_url = src.get("url").children[0].value;
|
||||
std::string src_path = "/tmp/shrap/" + src.get("dir").children[0].value;
|
||||
|
||||
if (src_type == "tar") {
|
||||
std::string archive_path = "/tmp/shrap/" + Util::basename(src_url);
|
||||
@@ -31,12 +34,11 @@ int main() {
|
||||
// TODO: replace wget with a library for zero runtime dependencies
|
||||
Util::shell_command("wget -O " + archive_path + " " + src_url);
|
||||
|
||||
// TODO: check archive hash from src.children[3].value
|
||||
// TODO: check archive hash from src.get("blake3").children[0].value
|
||||
|
||||
Util::shell_command("tar xf " + archive_path + " -C /tmp/shrap/");
|
||||
} else {
|
||||
std::cerr << "ERROR: unrecognized src type: " << src_type << "\n";
|
||||
return 1;
|
||||
throw std::runtime_error("unrecognized src type");
|
||||
}
|
||||
|
||||
std::string jobs = std::to_string(std::thread::hardware_concurrency());
|
||||
@@ -45,12 +47,35 @@ int main() {
|
||||
std::string step_type = step.children[0].value;
|
||||
|
||||
if (step_type == "configure_make") {
|
||||
Util::shell_command("./configure --prefix=/usr", src_path);
|
||||
std::string configure_flags;
|
||||
try {
|
||||
configure_flags = step.get("configure_flags").children[0].value;
|
||||
} catch (std::out_of_range &) {
|
||||
}
|
||||
|
||||
Util::shell_command("./configure --prefix=/usr " + configure_flags,
|
||||
src_path);
|
||||
Util::shell_command("make -j " + jobs, src_path);
|
||||
Util::shell_command("make install", src_path);
|
||||
} else {
|
||||
std::cerr << "ERROR: unrecognized step type: " << step_type << "\n";
|
||||
return 1;
|
||||
throw std::runtime_error("unrecognized step type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
auto args = std::span(argv, static_cast<size_t>(argc));
|
||||
|
||||
if (geteuid() != 0) {
|
||||
std::cerr << "This program needs to be ran as root.\n";
|
||||
return 1;
|
||||
}
|
||||
Util::shell_command("mkdir -p /tmp/shrap");
|
||||
|
||||
try {
|
||||
install_package(args[1]);
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("key not found: " + key);
|
||||
throw std::out_of_range("key not found: " + key);
|
||||
}
|
||||
|
||||
static Expr parse(std::istream &in) { return parse_expr(in); }
|
||||
|
||||
14
src/util.h
14
src/util.h
@@ -1,16 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace Util {
|
||||
|
||||
static int shell_command(const std::string &cmd, const std::string &dir = ".") {
|
||||
static void shell_command(const std::string &cmd,
|
||||
const std::string &dir = ".") {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork failed");
|
||||
return -1;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
@@ -27,9 +29,13 @@ static int shell_command(const std::string &cmd, const std::string &dir = ".") {
|
||||
int status = 0;
|
||||
if (waitpid(pid, &status, 0) < 0) {
|
||||
perror("waitpid failed");
|
||||
return -1;
|
||||
std::exit(1);
|
||||
}
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
|
||||
std::cerr << "Command failed with exit code " << WEXITSTATUS(status)
|
||||
<< "\n";
|
||||
std::exit(1);
|
||||
}
|
||||
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
(package
|
||||
(name "zlib")
|
||||
(version "1.3.1")
|
||||
(homepage "https://zlib.net/")
|
||||
(src (tar "https://zlib.net/zlib-1.3.1.tar.gz" "zlib-1.3.1" "207c3b0862cb4e3686f8405f76a98c38dbad9c94bcf4be4b9efca0716aba51ec"))
|
||||
(build
|
||||
(configure_make)))
|
||||
Reference in New Issue
Block a user