Skip to content
This repository has been archived by the owner on Oct 16, 2022. It is now read-only.

Added Slackware support (no mail support) #783

Open
wants to merge 1 commit 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
20 changes: 13 additions & 7 deletions src/Core/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4168,15 +4168,21 @@ public class Main : GLib.Object{

if (scheduled){

//hourly
CronTab.add_script_file("timeshift-hourly", "d", "0 * * * * root timeshift --check --scripted", stop_cron_emails);

//boot
if (schedule_boot){
CronTab.add_script_file("timeshift-boot", "d", "@reboot root sleep 10m && timeshift --create --scripted --tags B", stop_cron_emails);
if (this.current_distro.dist_id == "slackware"){
//hourly
CronTab.add_script_file("timeshift-hourly", "hourly", "/usr/bin/timeshift --check --scripted", stop_cron_emails);
}
else{
CronTab.remove_script_file("timeshift-boot", "d");
//hourly
CronTab.add_script_file("timeshift-hourly", "d", "0 * * * * root timeshift --check --scripted", stop_cron_emails);

//boot
if (schedule_boot){
CronTab.add_script_file("timeshift-boot", "d", "@reboot root sleep 10m && timeshift --create --scripted --tags B", stop_cron_emails);
}
else{
CronTab.remove_script_file("timeshift-boot", "d");
}
}
}
else{
Expand Down
26 changes: 20 additions & 6 deletions src/Utility/CronTab.vala
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,19 @@ public class CronTab : GLib.Object {
string file_path = "/etc/cron.%s/%s".printf(cron_dir_type, file_name.replace(".","-")); // dot is not allowed in file name

string sh = "";
sh += "SHELL=/bin/bash" + "\n";
sh += "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" + "\n";
if (stop_cron_emails){
sh += "MAILTO=\"\"" + "\n";
LinuxDistro info = LinuxDistro.get_dist_info("/");

if (info.dist_id == "slackware"){
sh += "#!/bin/sh\n\n";
}
else{
sh += "SHELL=/bin/bash" + "\n";
sh += "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" + "\n";
if (stop_cron_emails){
sh += "MAILTO=\"\"" + "\n";
}
sh += "\n";
}
sh += "\n";
sh += text + "\n";

if (file_exists(file_path) && (file_read(file_path) == sh)){
Expand All @@ -307,7 +314,14 @@ public class CronTab : GLib.Object {

file_write(file_path, sh);
chown(file_path, "root", "root");
chmod(file_path, "644");

// As this is a script in Slackware, make it executable
if (info.dist_id == "slackware"){
chmod(file_path, "755");
}
else{
chmod(file_path, "644");
}

log_msg(_("Added cron task") + ": %s".printf(file_path));

Expand Down
113 changes: 75 additions & 38 deletions src/Utility/LinuxDistro.vala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class LinuxDistro : GLib.Object{

LinuxDistro info = new LinuxDistro();

/* Ubuntu distribution */

string dist_file = root_path + "/etc/lsb-release";
var f = File.new_for_path(dist_file);
if (f.query_exists()){
Expand Down Expand Up @@ -105,50 +107,82 @@ public class LinuxDistro : GLib.Object{
break;
}
}

return info;
}
else{

dist_file = root_path + "/etc/os-release";
f = File.new_for_path(dist_file);
if (f.query_exists()){

/*
NAME="Ubuntu"
VERSION="13.04, Raring Ringtail"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 13.04"
VERSION_ID="13.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
*/

foreach(string line in file_read(dist_file).split("\n")){

if (line.split("=").length != 2){ continue; }

string key = line.split("=")[0].strip();
string val = line.split("=")[1].strip();

switch (key){
case "ID":
info.dist_id = val;
break;
case "VERSION_ID":
info.release = val;
break;
//case "DISTRIB_CODENAME":
//info.codename = val;
//break;
case "PRETTY_NAME":
info.description = val;
break;
}
/* Ubuntu distribution again */

dist_file = root_path + "/etc/os-release";
f = File.new_for_path(dist_file);
if (f.query_exists()){

/*
NAME="Ubuntu"
VERSION="13.04, Raring Ringtail"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 13.04"
VERSION_ID="13.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
*/

foreach(string line in file_read(dist_file).split("\n")){

if (line.split("=").length != 2){ continue; }

string key = line.split("=")[0].strip();
string val = line.split("=")[1].strip();

switch (key){
case "ID":
info.dist_id = val;
break;
case "VERSION_ID":
info.release = val;
break;
//case "DISTRIB_CODENAME":
//info.codename = val;
//break;
case "PRETTY_NAME":
info.description = val;
break;
}
}

return info;
}

/* Slackware distribution */

dist_file = root_path + "/etc/slackware-version";
f = File.new_for_path(dist_file);
if (f.query_exists()){

/*
DISTRIB_ID=Slackware
DISTRIB_RELEASE=14.2
DISTRIB_DESCRIPTION="Slackware 14.2"
*/

string line = file_read(dist_file);

if (line.split(" ").length == 2)
{
string name = line.split(" ")[0];
string version = line.split(" ")[1];

info.dist_id = "slackware";
info.codename = name;
info.description = line;
info.release = version;

return info;
}
}

return info;
}

Expand Down Expand Up @@ -209,6 +243,9 @@ public class LinuxDistro : GLib.Object{
else if (dist_id.down().contains("ubuntu") || dist_id.down().contains("debian")){
return "debian";
}
else if (dist_id.down().contains("slackware")){
return "slackware";
}
else{
return "";
}
Expand Down