First version
This commit is contained in:
parent
9612bab73d
commit
ba0c29f4a8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
cowtool
|
11
Makefile
Normal file
11
Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
all:
|
||||
g++ src/cowtool.cpp -o ./cowtool
|
||||
|
||||
install:
|
||||
mv ./cowtool /sbin/cowtool
|
||||
cp -r ./structure/* /etc/
|
||||
mkdir /sources/
|
||||
mkdir /sources/cowtool/
|
||||
mkdir /sources/cowtool/buildspace/
|
||||
|
||||
|
@ -18,9 +18,8 @@ When installing a package, you are prompted to create a bash script from a templ
|
||||
|
||||
Commands:
|
||||
|
||||
- cowtool lick < name > : Create/edit a package script
|
||||
- cowtool lick < name > < editor > : Create/edit a package script
|
||||
- cowtool milk < name > : Install package
|
||||
- cowtool herd : List package scripts
|
||||
- cowtool graze < name / empty for all > : Update packages, if empty do only autoupdate
|
||||
- cowtool steak < name > : Uninstalls a package
|
||||
- cowtool butcher < name > : Removes package script
|
||||
- cowtool graze : Update packages, if empty do only autoupdate
|
||||
- cowtool butcher < name > : Uninstalls a package
|
||||
|
142
src/cowtool.cpp
Normal file
142
src/cowtool.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <cstring>
|
||||
|
||||
/*
|
||||
* File structure:
|
||||
* /etc/cowtool/
|
||||
* |- enabled
|
||||
* |- disabled
|
||||
* \- install_template.sh
|
||||
*
|
||||
*
|
||||
* /sources/cowtool/buildspace/
|
||||
*
|
||||
* lick will load a template via a text editor of choice.
|
||||
* milk will run a script from Disabled, and if autoupdate, copy it to Enabled
|
||||
* herd will list both Enabled and Disabled
|
||||
* graze will run all the scripts in Enabled
|
||||
* Butcher will run in uninstall version of the script and remove it from Enabled
|
||||
*/
|
||||
|
||||
bool ask(std::string prompt) {
|
||||
std::cout << prompt << " (Y/n) ";
|
||||
std::string response;
|
||||
std::cin >> response;
|
||||
|
||||
if (response == "y" || response == "yes") {
|
||||
return true;
|
||||
} else if (response == "n" || response == "no") {
|
||||
return false;
|
||||
} else {
|
||||
// default to yes
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if( !getuid() ) {
|
||||
std::cout << "Must be root!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( argc == 1 ) {
|
||||
std::cout << " Cowtool 0.0 :" << std::endl;
|
||||
std::cout << " - cowtool lick < name > < editor > : Create/edit a package script" << std::endl;
|
||||
std::cout << " - cowtool milk < name > : Install package" << std::endl;
|
||||
std::cout << " - cowtool herd : List package scripts" << std::endl;
|
||||
std::cout << " - cowtool graze < name / empty for all > : Update packages, if empty do only autoupdate" << std::endl;
|
||||
std::cout << " - cowtool butcher < name > : Uninstalls a package" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string firstArg = argv[1];
|
||||
|
||||
if ( firstArg == "lick") {
|
||||
|
||||
if (argc < 3) {
|
||||
std::cout << "Package name required!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string name = argv[2];
|
||||
std::string editor;
|
||||
if (argc < 4) {
|
||||
editor = "vim";
|
||||
} else {
|
||||
editor = argv[3];
|
||||
}
|
||||
|
||||
|
||||
if (!std::filesystem::exists("/etc/cowtool/disabled/install_"+name+".sh")) {
|
||||
system(("cp -v /etc/cowtool/install_template.sh /etc/cowtool/disabled/install_"+name+".sh").c_str());
|
||||
system(("cp -v /etc/cowtool/disabled/install_"+name+".sh /etc/cowtool/disabled/remove_"+name+".sh").c_str());
|
||||
system(("echo #### ADD UNINSTALLATION #### >> /etc/cowtool/disabled/remove_"+name+".sh").c_str());
|
||||
}
|
||||
|
||||
system((editor+"/etc/cowtool/disabled/install_"+name+".sh").c_str());
|
||||
system((editor+"/etc/cowtool/disabled/remove_"+name+".sh").c_str());
|
||||
std::cout << "Remember to `milk` to install/update `"+ name << "`!" << std::endl;
|
||||
|
||||
} else if (firstArg == "milk") {
|
||||
|
||||
if (argc < 3) {
|
||||
std::cout << "Package name required!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string name = argv[2];
|
||||
|
||||
if (ask("Should this package be updated when `graze` is run?")) {
|
||||
system(("cp -v /etc/cowtool/disabled/install_" + name + ".sh /etc/cowtool/enabled/install_" + name + ".sh").c_str());
|
||||
}
|
||||
|
||||
system(("bash /etc/cowtool/disabled/install_" + name + ".sh").c_str());
|
||||
|
||||
} else if (firstArg == "herd") {
|
||||
|
||||
std::cout << "List of package scripts:" << std::endl << std::endl;
|
||||
system("ls /etc/cowtool/disabled/install_");
|
||||
|
||||
std::cout << std::endl << "List of package scripts marked as autoupdate:" << std::endl << std::endl;
|
||||
system("ls /etc/cowtool/enabled/install_");
|
||||
|
||||
} else if (firstArg == "graze") {
|
||||
|
||||
// Loads directory
|
||||
std::filesystem::path dir("/etc/cowtool/enabled");
|
||||
for (const auto& entry : std::filesystem::directory_iterator(dir)) {
|
||||
if (entry.is_regular_file()) {
|
||||
system(("bash /etc/cowtool/enabled/" + entry.path().filename().string()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} else if (firstArg == "butcher") {
|
||||
|
||||
if (argc < 3) {
|
||||
std::cout << "Package name required!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string name = argv[2];
|
||||
|
||||
system(("rm -f /etc/cowtool/enabled/install_"+name+".sh").c_str());
|
||||
system(("bash /etc/cowtool/disabled/remove_"+name+".sh").c_str());
|
||||
|
||||
} else {
|
||||
|
||||
std::cout << "Unknown argument!" << std::endl;
|
||||
std::cout << "Run without arguments for help menu." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user