Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR 2 Init #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CXX := g++
CXX_FLAGS := -std=c++17 -ggdb

BIN := bin
SRC := src
INCLUDE :=
LIB := lib
LIBRARIES :=
EXECUTABLE := main


all: $(BIN)/$(EXECUTABLE)

run: clean all
@echo "run called"
./$(BIN)/$(EXECUTABLE)

$(BIN)/$(EXECUTABLE): $(SRC)/*.cpp
$(CXX) $(CXX_FLAGS) -I$(INCLUDE) -L$(LIB) $^ -o $ ~/imperium/$(BIN)/$(EXECUTABLE) $(LIBRARIES) -lssl -lcrypto

clean:
@echo "clean called"
@rm -rf -d ~/imperium/$(BIN)/*
16 changes: 16 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
sudo apt-get update
sudo apt-get install openssl -y
sudo apt-get install libssl-dev -y
mkdir -p ~/imperium/bin
cp imperium.sh ~/imperium
cd ..
make
cd ~/imperium/bin || echo "error"
chmod +x main
cd ..
if grep -q "source $PWD/imperium.sh" "$PWD/../.bashrc" ; then
echo 'already installed bash source';
else
echo "source $PWD/imperium.sh" >> ~/.bashrc;
fi
8 changes: 8 additions & 0 deletions scripts/imperium.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
function imperium(){
DIR=$PWD
export dir=$DIR
cd ~/imperium/bin || echo "Error"
./main "$@"
cd "$DIR" || echo "Error"
}
72 changes: 72 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <iostream>
#include <string.h>
#include <cstring>
#include <fstream>
#include <sys/stat.h>
#include <filesystem>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <openssl/sha.h>
#include <chrono>
#include <ctime>

namespace fs = std::filesystem;

std::string root = "";

void init(std::string path)
{
struct stat buffer;

if (stat((path + "/.imperium").c_str(), &buffer) == 0)
{
std::cout << "Already initialized as imperium repository"
<< "\n";
}
else
{
std::string imperiumIgnore = path + "/.imperiumIgnore";
std::ofstream ignore(imperiumIgnore.c_str());
path += "/.imperium";
ignore << ".imperium/\n"
<< ".git/\n"
<< "/.imperiumIgnore\n"
<< ".node_modules/\n"
<< "/.env\n";
int created = mkdir(path.c_str(), 0777);
if (created == 0)
{
std::string commitLog = path + "/commit.log";
std::ofstream commit(commitLog.c_str());
std::string addLog = path + "/add.log";
std::string conflictLog = path + "/conflict";
std::ofstream conflict(conflictLog.c_str());
std::ofstream add(addLog.c_str());
add.close();
commit.close();
conflict << "false\n";
conflict.close();
std::cout << "Initialised imperium repository"
<< "\n";
}
else
{
std::cout << "Error with creation"
<< "\n";
}
}
}

int main(int argc, const char **argv)
{
const char *dir = getenv("dir");
root = dir;

if (strcmp(argv[1], "init") == 0)
{
init(dir);
}
return 0;
}