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

remove usage of sudo #44

Merged
merged 1 commit into from
Feb 27, 2024
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
60 changes: 30 additions & 30 deletions backend/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ unordered_map<string, string> proxy_list;

void set_environment_variables() {
// Setting up Environment Variables
string command = "echo https_proxy=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/environment";
string command = "echo https_proxy=" + proxy_list["https_proxy"] + " | tee -a /etc/environment";
system(command.c_str());
command = "echo HTTPS_PROXY=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/environment";

command = "echo HTTPS_PROXY=" + proxy_list["https_proxy"] + " | tee -a /etc/environment";
system(command.c_str());
command = "echo HTTP_PROXY=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/environment";

command = "echo HTTP_PROXY=" + proxy_list["https_proxy"] + " | tee -a /etc/environment";
system(command.c_str());
command = "echo http_proxy=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/environment";

command = "echo http_proxy=" + proxy_list["https_proxy"] + " | tee -a /etc/environment";
system(command.c_str());
command = "echo ftp_proxy=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/environment";

command = "echo ftp_proxy=" + proxy_list["https_proxy"] + " | tee -a /etc/environment";
system(command.c_str());
command = "echo FTP_PROXY=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/environment";

command = "echo FTP_PROXY=" + proxy_list["https_proxy"] + " | tee -a /etc/environment";
system(command.c_str());
command = "echo no_proxy=" + proxy_list["no_proxy"] + " | sudo tee -a /etc/environment";

command = "echo no_proxy=" + proxy_list["no_proxy"] + " | tee -a /etc/environment";
system(command.c_str());

setenv("https_proxy",proxy_list["https_proxy"].c_str(),1);
setenv("http_proxy",proxy_list["https_proxy"].c_str(),1);
setenv("ftp_proxy",proxy_list["https_proxy"].c_str(),1);
Expand All @@ -45,46 +45,46 @@ void set_environment_variables() {

void apply_docker_proxy() {
// Create /etc/systemd/system/docker.service.d directory structure
if(system("sudo mkdir -p /etc/systemd/system/docker.service.d") == -1){
if(system("mkdir -p /etc/systemd/system/docker.service.d") == -1){
cout << "Failed to create directory structure for docker proxies" << endl;
exit(0);
}

// Write the docker proxy setting
string apply_systemd_proxy = "echo [Service] | sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf";
string apply_systemd_proxy = "echo [Service] | tee /etc/systemd/system/docker.service.d/http-proxy.conf";
system(apply_systemd_proxy.c_str());
apply_systemd_proxy = "echo Environment=HTTPS_PROXY=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf";

apply_systemd_proxy = "echo Environment=HTTPS_PROXY=" + proxy_list["https_proxy"] + " | tee -a /etc/systemd/system/docker.service.d/http-proxy.conf";
system(apply_systemd_proxy.c_str());
apply_systemd_proxy = "echo Environment=HTTP_PROXY=" + proxy_list["https_proxy"] + " | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf";

apply_systemd_proxy = "echo Environment=HTTP_PROXY=" + proxy_list["https_proxy"] + " | tee -a /etc/systemd/system/docker.service.d/http-proxy.conf";
system(apply_systemd_proxy.c_str());
apply_systemd_proxy = "echo Environment=NO_PROXY=" + proxy_list["no_proxy"] + " | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf";

apply_systemd_proxy = "echo Environment=NO_PROXY=" + proxy_list["no_proxy"] + " | tee -a /etc/systemd/system/docker.service.d/http-proxy.conf";
system(apply_systemd_proxy.c_str());

// Flush changes, Re-load Daemon and Re-Start Docker
string str = "sudo systemctl daemon-reload";
string str = "systemctl daemon-reload";
const char *command = str.c_str();
system(command);
str = "sudo systemctl restart docker";

str = "systemctl restart docker";
command = str.c_str();
system(command);
}

void Settings::set_proxy(QString https_proxy, QString no_proxy) {
Settings::_https_proxy=https_proxy;
Settings::_no_proxy=no_proxy;

cout << "Setting https_proxy to " << https_proxy.toStdString() << endl;
cout << "Setting no_proxy to " << no_proxy.toStdString() << endl;

proxy_list["https_proxy"] = https_proxy.toStdString();
proxy_list["no_proxy"] = no_proxy.toStdString();

apply_docker_proxy();
set_environment_variables();

cout << "Applied Proxy Settings!" << endl;
}
4 changes: 2 additions & 2 deletions backend/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

QString stats::getgpuload() {
QProcess process;
process.start("sudo cat /sys/kernel/debug/pvr/status");
process.start("cat /sys/kernel/debug/pvr/status");
process.waitForFinished(-1);
QString output = process.readAllStandardOutput();
return output.mid(output.indexOf("GPU Utilisation")+17,output.indexOf("%")-output.indexOf("GPU Utilisation")-17);
Expand All @@ -31,7 +31,7 @@ QString stats::get_soc_temp() {
QString output;
float temp = 0;

process.start("sudo cat /sys/class/thermal/thermal_zone0/temp");
process.start("cat /sys/class/thermal/thermal_zone0/temp");
process.waitForFinished(-1);
temp = process.readAllStandardOutput().toFloat();

Expand Down