diff -Nru aptik-18.5.2/debian/changelog aptik-18.6/debian/changelog --- aptik-18.5.2/debian/changelog 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/debian/changelog 2018-06-30 09:38:00.000000000 +0000 @@ -1,8 +1,19 @@ -aptik (18.5.2-0~201805120407~ubuntu18.04.1) bionic; urgency=low +aptik (18.6-0~201806300917~ubuntu18.04.1) bionic; urgency=low * Auto build. - -- Tony George Sat, 12 May 2018 05:04:13 +0000 + -- Tony George Sat, 30 Jun 2018 09:38:00 +0000 + +aptik (18.6) xenial; urgency=medium + + * ArchLinux: Show admin prompt for listing crypttab entries + + * ArchLinux: Unselect 'base' and 'base-devel' packages by default + + * Themes: Show theme type 'openbox-3' in list if existing + + -- Tony George Sat, 30 Jun 2018 10:00:00 +0530 + aptik (18.5.2) xenial; urgency=medium diff -Nru aptik-18.5.2/debian/git-build-recipe.manifest aptik-18.6/debian/git-build-recipe.manifest --- aptik-18.5.2/debian/git-build-recipe.manifest 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/debian/git-build-recipe.manifest 2018-06-30 09:38:00.000000000 +0000 @@ -1,2 +1,2 @@ -# git-build-recipe format 0.4 deb-version {debupstream}-0~201805120407 -lp:aptik-github git-commit:bcb792618838ceef05bb4dcbbab7b2f0d2b1202f +# git-build-recipe format 0.4 deb-version {debupstream}-0~201806300917 +lp:aptik-github git-commit:7c0b20eb464cae5e3108db0830b55e0bab2099b7 diff -Nru aptik-18.5.2/release/sanity.config aptik-18.6/release/sanity.config --- aptik-18.5.2/release/sanity.config 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/release/sanity.config 2018-06-30 09:38:00.000000000 +0000 @@ -1,7 +1,7 @@ app_name: Aptik depends_debian: libgee-0.8-2 libjson-glib-1.0-0 apt aptitude apt-transport-https pv xz-utils depends_redhat: libgee json-glib pv xz-utils -depends_arch: libgee json-glib pv xz +depends_arch: libgee json-glib pv xz depends_generic: libgee json-glib pv xz-utils assume_yes: 0 exec_line: aptik diff -Nru aptik-18.5.2/src/Console/AptikConsole.vala aptik-18.6/src/Console/AptikConsole.vala --- aptik-18.5.2/src/Console/AptikConsole.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/AptikConsole.vala 2018-06-30 09:38:00.000000000 +0000 @@ -32,7 +32,7 @@ public const string AppName = "Aptik"; public const string AppShortName = "aptik"; -public const string AppVersion = "18.5.2"; +public const string AppVersion = "18.6"; public const string AppAuthor = "Tony George"; public const string AppAuthorEmail = "teejeetech@gmail.com"; @@ -250,12 +250,6 @@ } } - public void print_backup_path(){ - - log_msg("Backup path: %s".printf(basepath)); - log_msg(string.nfill(70,'-')); - } - public string help_message() { string fmt = " %-30s %s\n"; @@ -644,7 +638,8 @@ case "--backup-repos": case "--restore-repos": case "--import-missing-keys": - + + case "--list-available": case "--list-installed": case "--list-installed-dist": case "--list-installed-user": @@ -821,6 +816,9 @@ case "--list-installed": return list_packages_installed(); + + case "--list-available": + return list_packages_available(); case "--list-installed-dist": return list_packages_installed_dist(); diff -Nru aptik-18.5.2/src/Console/DconfManager.vala aptik-18.6/src/Console/DconfManager.vala --- aptik-18.5.2/src/Console/DconfManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/DconfManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -42,16 +42,21 @@ var mgr = new UserManager(distro, current_user, basepath, dry_run, redist, apply_selections); mgr.query_users(false); + + read_selections(); foreach(var user in mgr.users_sorted){ if (user.is_system) { continue; } + + bool selected = true; + if (exclude_list.contains(user.name)){ selected = false; } txt += "NAME='%s'".printf(user.name); txt += ",DESC='%s'".printf(user.full_name); - txt += ",ACT='%s'".printf("1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); @@ -73,11 +78,16 @@ var mgr = new UserManager(distro, current_user, basepath, dry_run, redist, apply_selections); mgr.query_users(false); + + read_selections(); foreach(var user in mgr.users_sorted){ if (user.is_system) { continue; } + bool selected = true; + if (exclude_list.contains(user.name)){ selected = false; } + string bkup_file = path_combine(files_path, "%s.dconf-settings".printf(user.name)); if (!file_exists(bkup_file)){ continue; } @@ -86,7 +96,7 @@ txt += ",DESC='%s'".printf(user.full_name); - txt += ",ACT='%s'".printf("1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); diff -Nru aptik-18.5.2/src/Console/GroupManager.vala aptik-18.6/src/Console/GroupManager.vala --- aptik-18.5.2/src/Console/GroupManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/GroupManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -209,16 +209,21 @@ public void dump_info(){ string txt = ""; + + read_selections(); foreach(var group in groups_sorted){ if (group.is_system) { continue; } + + bool selected = true; + if (exclude_list.contains(group.name)){ selected = false; } txt += "NAME='%s'".printf(group.name); //txt += ",DESC='%s'".printf(""); - txt += ",ACT='%s'".printf("1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); @@ -242,6 +247,8 @@ var mgr = new GroupManager(distro, current_user, basepath, dry_run, redist, apply_selections); mgr.read_groups_from_folder(files_path); + + read_selections(); foreach(var group in mgr.groups_sorted){ @@ -252,11 +259,14 @@ is_installed = true; } + bool selected = true; // true even if installed + if (exclude_list.contains(group.name)){ selected = false; } + txt += "NAME='%s'".printf(group.name); //txt += ",DESC='%s'".printf(""); - txt += ",ACT='%s'".printf(is_installed ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf(is_installed ? "0" : "1"); diff -Nru aptik-18.5.2/src/Console/MountEntryManager.vala aptik-18.6/src/Console/MountEntryManager.vala --- aptik-18.5.2/src/Console/MountEntryManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/MountEntryManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -284,6 +284,8 @@ string txt = ""; + read_selections(); + foreach(var entry in fstab){ bool is_system = false; @@ -297,6 +299,9 @@ break; } + bool selected = !is_system; + if (exclude_list.contains(entry.mount_point)){ selected = false; } + txt += "NAME='%s'".printf(entry.mount_point); txt += ",DEV='%s'".printf(entry.device); txt += ",MPATH='%s'".printf(entry.mount_point); @@ -304,7 +309,7 @@ txt += ",OPT='%s'".printf(entry.options); txt += ",DUMP='%s'".printf(entry.dump); txt += ",PASS='%s'".printf(entry.pass); - txt += ",ACT='%s'".printf(is_system ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf(is_system ? "0" : "1"); txt += ",TYPE='%s'".printf("fstab"); txt += "\n"; @@ -312,11 +317,14 @@ foreach(var entry in crypttab){ + bool selected = true; + if (exclude_list.contains(entry.name)){ selected = false; } + txt += "NAME='%s'".printf(entry.name); txt += ",DEV='%s'".printf(entry.device); txt += ",PASSWORD='%s'".printf(entry.password); txt += ",OPT='%s'".printf(entry.options); - txt += ",ACT='%s'".printf("1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); txt += ",TYPE='%s'".printf("crypttab"); txt += "\n"; @@ -337,6 +345,8 @@ var mgr = new MountEntryManager(distro, current_user, basepath, dry_run, redist, apply_selections); mgr.read_mount_entries_from_folder(files_path); + + read_selections(); var fstab_bkup = mgr.fstab; var crypttab_bkup = mgr.crypttab; @@ -364,6 +374,9 @@ } } + bool selected = !is_system && !is_installed; + if (exclude_list.contains(entry.mount_point)){ selected = false; } + txt += "NAME='%s'".printf(entry.mount_point); txt += ",DEV='%s'".printf(entry.device); txt += ",MPATH='%s'".printf(entry.mount_point); @@ -371,8 +384,8 @@ txt += ",OPT='%s'".printf(entry.options); txt += ",DUMP='%s'".printf(entry.dump); txt += ",PASS='%s'".printf(entry.pass); - txt += ",ACT='%s'".printf((is_system || is_installed) ? "0" : "1"); - txt += ",SENS='%s'".printf((is_system || is_installed) ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); + txt += ",SENS='%s'".printf((!is_system && !is_installed) ? "1" : "0"); txt += ",INST='%s'".printf(is_installed ? "1" : "0"); txt += ",TYPE='%s'".printf("fstab"); txt += "\n"; @@ -387,12 +400,15 @@ break; } } + + bool selected = !is_installed; + if (exclude_list.contains(entry.name)){ selected = false; } txt += "NAME='%s'".printf(entry.name); txt += ",DEV='%s'".printf(entry.device); txt += ",PASSWORD='%s'".printf(entry.password); txt += ",OPT='%s'".printf(entry.options); - txt += ",ACT='%s'".printf(is_installed ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf(is_installed ? "0" : "1"); txt += ",INST='%s'".printf(is_installed ? "1" : "0"); txt += ",TYPE='%s'".printf("crypttab"); diff -Nru aptik-18.5.2/src/Console/PackageManager.vala aptik-18.6/src/Console/PackageManager.vala --- aptik-18.5.2/src/Console/PackageManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/PackageManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -216,6 +216,24 @@ var pkg = packages[name]; pkg.is_user = true; } + + exec_script_sync("pacman -Qgq base base-devel", out std_out, out std_err); + + foreach(string line in std_out.split("\n")){ + + string[] arr = line.split(" "); + if (arr.length == 0) { continue; } + string name = arr[0].strip(); + + if (!packages.has_key(name)){ + packages[name] = new Package(name); + } + + var pkg = packages[name]; + pkg.is_dist = true; + } + + dist_installed_known = true; } private void check_packages_debian(){ @@ -319,7 +337,7 @@ string temp_file = get_temp_file_path(); string std_out, std_err; - exec_script_sync("aptitude search --disable-columns -F '%p|%v|%C|%M|%d' '?true'", out std_out, out std_err); + exec_script_sync("aptitude search --disable-columns -F '%p|%v|%C|%M|%d|%s' '?true'", out std_out, out std_err); file_write(temp_file, std_out); try { @@ -335,7 +353,7 @@ while ((line = dis.read_line (null)) != null) { string[] arr = line.split("|"); - if (arr.length != 5) { continue; } + if (arr.length != 6) { continue; } string name = arr[0].strip(); @@ -360,6 +378,11 @@ string state = arr[2].strip(); string auto = arr[3].strip(); string desc = arr[4].strip(); + string section = arr[5].strip(); + + if (section.contains("/")){ + section = section.split("/")[1]; + } if (!packages.has_key(name)){ packages[name] = new Package(name); @@ -373,6 +396,7 @@ pkg.is_auto = (auto == "A"); pkg.is_foreign = is_foreign; pkg.version_installed = version; + pkg.section = section; } auto_installed_known = true; // is_automatic flag is available @@ -557,6 +581,8 @@ string txt = ""; log_msg("O:icon:%s".printf(exclude_icons.to_string())); + + read_selections(); foreach(var pkg in packages_sorted){ @@ -575,10 +601,14 @@ if (auto_installed_known && pkg.is_auto){ selected = false; } if (dist_installed_known && pkg.is_dist){ selected = false; } - if (!include_foreign && pkg.is_foreign){ selected = false; } - if (exclude_icons && pkg.name.contains("-icon-theme")){ selected = false; } - if (exclude_themes && pkg.name.contains("-theme") && !pkg.name.contains("-icon-theme")){ selected = false; } - if (exclude_fonts && pkg.name.has_prefix("fonts-")){ selected = false; } + if (!include_list.contains(pkg.name)){ + if (!include_foreign && pkg.is_foreign){ selected = false; } + if (exclude_icons && pkg.name.contains("-icon-theme")){ selected = false; } + if (exclude_themes && pkg.name.contains("-theme") && !pkg.name.contains("-icon-theme")){ selected = false; } + if (exclude_fonts && pkg.name.has_prefix("fonts-")){ selected = false; } + } + + if (exclude_list.contains(pkg.name)){ selected = false; } txt += "NAME='%s'".printf(pkg.name); txt += ",ARCH='%s'".printf(pkg.arch); @@ -591,6 +621,7 @@ txt += ",USER='%s'".printf((pkg.is_user || (!pkg.is_dist && !pkg.is_auto)) ? "1" : "0"); txt += ",FOR='%s'".printf(pkg.is_foreign ? "1" : "0"); txt += ",MAN='%s'".printf(pkg.is_manual ? "1" : "0"); + txt += ",SEC='%s'".printf(pkg.section); txt += "\n"; } @@ -612,6 +643,8 @@ log_error(msg); return; } + + read_selections(); string txt = ""; @@ -625,18 +658,25 @@ string desc = line.split("#",2)[1].strip(); bool is_available = false; bool is_installed = false; - + bool selected = true; + string section = ""; + if (packages.has_key(name)){ is_available = true; is_installed = packages[name].is_installed; + section = packages[name].section; } + selected = is_available && !is_installed; + if (exclude_list.contains(name)){ selected = false; } + txt += "NAME='%s'".printf(name); txt += ",DESC='%s'".printf(desc); - txt += ",ACT='%s'".printf((is_available && !is_installed) ? "1" : "0"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf((is_available && !is_installed) ? "1" : "0"); txt += ",AVAIL='%s'".printf(is_available ? "1" : "0"); txt += ",INST='%s'".printf(is_installed ? "1" : "0"); + txt += ",SEC='%s'".printf(section); txt += "\n"; } diff -Nru aptik-18.5.2/src/Console/RepoManager.vala aptik-18.6/src/Console/RepoManager.vala --- aptik-18.5.2/src/Console/RepoManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/RepoManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -273,16 +273,21 @@ public void dump_info(){ string txt = ""; + + read_selections(); foreach(var repo in repos_sorted){ if (!repo.is_installed){ continue; } + + bool selected = !repo.is_disabled; + if (exclude_list.contains(repo.name)){ selected = false; } txt += "NAME='%s'".printf(repo.name); txt += ",DESC='%s'".printf(repo.description); - txt += ",ACT='%s'".printf(repo.is_disabled ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); @@ -303,6 +308,8 @@ string txt = ""; var list = dir_list_names(files_path, true); + + read_selections(); foreach(string file_path in list) { @@ -313,7 +320,7 @@ string name = file_basename(file_path); string desc = ""; bool disabled = false; - + if (name == "CODENAME"){ continue; } if (name == "apt.keys"){ continue; } @@ -377,13 +384,16 @@ is_installed = repos[name].is_installed; } + bool selected = !is_installed && !disabled; + if (exclude_list.contains(name)){ selected = false; } + txt += "NAME='%s'".printf(name); txt += ",DESC='%s'".printf(desc); txt += ",INST='%s'".printf(is_installed ? "1" : "0"); - txt += ",ACT='%s'".printf(is_installed ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf(is_installed ? "0" : "1"); diff -Nru aptik-18.5.2/src/Console/ThemeManager.vala aptik-18.6/src/Console/ThemeManager.vala --- aptik-18.5.2/src/Console/ThemeManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/ThemeManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -263,10 +263,15 @@ public void dump_info(){ string txt = ""; + + read_selections(); foreach(var theme in themes_sorted){ if (!theme.is_installed){ continue; } + + bool selected = !theme.is_dist; + if (exclude_list.contains(theme.name)){ selected = false; } txt += "NAME='%s',DESC='%s'".printf(theme.name, theme.subtypes_desc); @@ -274,7 +279,7 @@ txt += ",DIST='%s'".printf(theme.is_dist ? "1" : "0"); - txt += ",ACT='%s'".printf(theme.is_dist ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); // always sensitive @@ -294,7 +299,12 @@ string txt = ""; + read_selections(); + foreach(var theme in themes_sorted){ + + bool selected = !theme.is_installed; + if (exclude_list.contains(theme.name)){ selected = false; } txt += "NAME='%s'".printf(theme.name); @@ -302,7 +312,7 @@ txt += ",INST='%s'".printf(theme.is_installed ? "1" : "0"); - txt += ",ACT='%s'".printf(theme.is_installed ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf(theme.is_installed ? "0" : "1"); @@ -600,6 +610,11 @@ if (subtypes_desc.length > 0){ subtypes_desc += ","; } subtypes_desc += dir_name.down(); break; + case "openbox-3": + subtypes.add(ThemeType.OPENBOX3); + if (subtypes_desc.length > 0){ subtypes_desc += ","; } + subtypes_desc += dir_name.down(); + break; case "actions": case "apps": case "categories": @@ -751,10 +766,12 @@ map[ThemeType.UNITY] = "unity"; map[ThemeType.XFCENOTIFY40] = "xfce-notify-4.0"; map[ThemeType.XFWM4] = "xfwm4"; + map[ThemeType.OPENBOX3] = "openbox-3"; theme_type_map = map; } public static void fix_nested_folders(){ + fix_nested_folders_in_path("/usr/share/themes"); fix_nested_folders_in_path("/usr/share/icons"); fix_nested_folders_in_path("/root/.themes"); @@ -844,7 +861,8 @@ METACITY1, UNITY, XFCENOTIFY40, - XFWM4 + XFWM4, + OPENBOX3 } diff -Nru aptik-18.5.2/src/Console/UserManager.vala aptik-18.6/src/Console/UserManager.vala --- aptik-18.5.2/src/Console/UserManager.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Console/UserManager.vala 2018-06-30 09:38:00.000000000 +0000 @@ -271,16 +271,21 @@ string txt = ""; query_users(false); + + read_selections(); foreach(var user in users_sorted){ if (user.is_system) { continue; } + + bool selected = true; + if (exclude_list.contains(user.name)){ selected = false; } txt += "NAME='%s'".printf(user.name); txt += ",DESC='%s'".printf(user.full_name); - txt += ",ACT='%s'".printf("1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf("1"); @@ -305,6 +310,8 @@ var mgr = new UserManager(distro, current_user, basepath, dry_run, redist, apply_selections); mgr.read_users_from_folder(files_path); + read_selections(); + foreach(var user in mgr.users_sorted){ bool is_installed = false; @@ -314,11 +321,14 @@ is_installed = true; } + bool selected = true; // true, even if installed + if (exclude_list.contains(user.name)){ selected = false; } + txt += "NAME='%s'".printf(user.name); txt += ",DESC='%s'".printf(user.full_name); - txt += ",ACT='%s'".printf(is_installed ? "0" : "1"); + txt += ",ACT='%s'".printf(selected ? "1" : "0"); txt += ",SENS='%s'".printf(is_installed ? "0" : "1"); diff -Nru aptik-18.5.2/src/makefile aptik-18.6/src/makefile --- aptik-18.5.2/src/makefile 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/makefile 2018-06-30 09:38:00.000000000 +0000 @@ -17,7 +17,7 @@ aptik-console: - valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" --thread \ + valac -X -D'GETTEXT_PACKAGE="${app_name}"' --Xcc="-lm" --Xcc="-Os" --thread \ *.vala Console/*.vala Utility/Console/*.vala \ -o ${app_name} \ --pkg glib-2.0 \ diff -Nru aptik-18.5.2/src/Utility/Console/AsyncTask.vala aptik-18.6/src/Utility/Console/AsyncTask.vala --- aptik-18.5.2/src/Utility/Console/AsyncTask.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Utility/Console/AsyncTask.vala 2018-06-30 09:38:00.000000000 +0000 @@ -415,6 +415,7 @@ } public string stat_time_remaining{ + owned get{ if (progress > 0){ long elapsed = (long) timer_elapsed(timer); diff -Nru aptik-18.5.2/src/Utility/Console/TeeJee.FileSystem.vala aptik-18.6/src/Utility/Console/TeeJee.FileSystem.vala --- aptik-18.5.2/src/Utility/Console/TeeJee.FileSystem.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Utility/Console/TeeJee.FileSystem.vala 2018-06-30 09:38:00.000000000 +0000 @@ -238,17 +238,6 @@ return true; } - public bool file_shred(string file_path){ - - /* Check and delete file */ - - var file = File.new_for_path (file_path); - if (file.query_exists ()) { - Posix.system("shred -u '%s'".printf(escape_single_quote(file_path))); - } - return true; - } - public int64 file_line_count (string file_path){ /* Count number of lines in text file */ string cmd = "wc -l '%s'".printf(escape_single_quote(file_path)); @@ -374,30 +363,6 @@ } } - public bool file_gzip (string src_file){ - - string dst_file = src_file + ".gz"; - file_delete(dst_file); - - string cmd = "gzip '%s'".printf(escape_single_quote(src_file)); - string std_out, std_err; - exec_sync(cmd, out std_out, out std_err); - - return file_exists(dst_file); - } - - public bool file_gunzip (string src_file){ - - string dst_file = src_file; - file_delete(dst_file); - - string cmd = "gunzip '%s'".printf(escape_single_quote(src_file)); - string std_out, std_err; - exec_sync(cmd, out std_out, out std_err); - - return file_exists(dst_file); - } - public string file_checksum(string file_path, GLib.ChecksumType checksum_type = ChecksumType.MD5){ var checksum = new Checksum (ChecksumType.MD5); @@ -515,77 +480,6 @@ return (status == 0); } - public bool dir_move_to_trash (string dir_path){ - return file_move_to_trash(dir_path); - } - - public bool dir_is_empty (string dir_path){ - - /* Check if directory is empty */ - - try{ - bool is_empty = true; - var dir = File.parse_name (dir_path); - if (dir.query_exists()) { - FileInfo info; - var enu = dir.enumerate_children ("%s".printf(FileAttribute.STANDARD_NAME), 0); - while ((info = enu.next_file()) != null) { - is_empty = false; - break; - } - } - return is_empty; - } - catch (Error e) { - log_error (e.message); - return false; - } - } - - public bool filesystem_supports_hardlinks(string path, out bool is_readonly){ - bool supports_hardlinks = false; - is_readonly = false; - - var test_file = path_combine(path, random_string() + "~"); - - if (file_write(test_file,"")){ - - var test_file2 = path_combine(path, random_string() + "~"); - - var cmd = "ln '%s' '%s'".printf( - escape_single_quote(test_file), - escape_single_quote(test_file2)); - - log_debug(cmd); - - int status = exec_sync(cmd, null, null); - - cmd = "stat --printf '%%h' '%s'".printf( - escape_single_quote(test_file)); - - log_debug(cmd); - - string std_out, std_err; - status = exec_sync(cmd, out std_out, out std_err); - log_debug("stdout: %s".printf(std_out)); - - int64 count = 0; - if (int64.try_parse(std_out, out count)){ - if (count > 1){ - supports_hardlinks = true; - } - } - - file_delete(test_file2); // delete if exists - file_delete(test_file); - } - else{ - is_readonly = true; - } - - return supports_hardlinks; - } - public Gee.ArrayList dir_list_names(string path, bool full_path){ var list = new Gee.ArrayList(); @@ -669,69 +563,6 @@ return list; } - public bool dir_tar (string src_dir, string tar_file, bool recursion = true){ - if (dir_exists(src_dir)) { - - if (file_exists(tar_file)){ - file_delete(tar_file); - } - - var src_parent = file_parent(src_dir); - var src_name = file_basename(src_dir); - - string cmd = "tar cvf '%s' --overwrite --%srecursion -C '%s' '%s'\n".printf( - escape_single_quote(tar_file), - (recursion ? "" : "no-"), - escape_single_quote(src_parent), - escape_single_quote(src_name)); - - log_debug(cmd); - - string stdout, stderr; - int status = exec_script_sync(cmd, out stdout, out stderr); - if (status == 0){ - return true; - } - else{ - log_msg(stderr); - } - } - else{ - log_error(_("Dir not found") + ": %s".printf(src_dir)); - } - - return false; - } - - public bool dir_untar (string tar_file, string dst_dir){ - if (file_exists(tar_file)) { - - if (!dir_exists(dst_dir)){ - dir_create(dst_dir); - } - - string cmd = "tar xvf '%s' --overwrite --same-permissions -C '%s'\n".printf( - escape_single_quote(tar_file), - escape_single_quote(dst_dir)); - - log_debug(cmd); - - string stdout, stderr; - int status = exec_script_sync(cmd, out stdout, out stderr); - if (status == 0){ - return true; - } - else{ - log_msg(stderr); - } - } - else{ - log_error(_("File not found") + ": %s".printf(tar_file)); - } - - return false; - } - public bool chown(string file_path, string username, string group){ // Note: chown is recursive, chmod is not. use chmod_dir_contents() for recursive chmod() @@ -773,64 +604,9 @@ return (status == 0); } - // dir info ------------------- - - // dep: find wc TODO: rewrite - public long dir_count(string path){ - - /* Return total count of files and directories */ - - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - cmd = "find '%s' | wc -l".printf(escape_single_quote(path)); - ret_val = exec_script_sync(cmd, out std_out, out std_err); - return long.parse(std_out); - } - - // dep: du - public long dir_size(string path){ - - /* Returns size of files and directories in KB*/ - - string cmd = "du -s -b '%s'".printf(escape_single_quote(path)); - string std_out, std_err; - exec_sync(cmd, out std_out, out std_err); - return long.parse(std_out.split("\t")[0]); - } - - // dep: du - public long dir_size_kb(string path){ - - /* Returns size of files and directories in KB*/ - - return (long)(dir_size(path) / 1024.0); - } - - // hashing ----------- - - public string hash_md5(string path){ - Checksum checksum = new Checksum (ChecksumType.MD5); - FileStream stream = FileStream.open (path, "rb"); - - uint8 fbuf[100]; - size_t size; - while ((size = stream.read (fbuf)) > 0){ - checksum.update (fbuf, size); - } - - unowned string digest = checksum.get_string(); - - return digest; - } - // misc -------------------- - public string format_file_size ( - uint64 size, bool binary_units = false, - string unit = "", bool show_units = true, int decimals = 1){ + public string format_file_size (uint64 size, bool binary_units = false, string unit = "", bool show_units = true, int decimals = 1){ int64 unit_k = binary_units ? 1024 : 1000; int64 unit_m = binary_units ? 1024 * unit_k : 1000 * unit_k; @@ -876,42 +652,4 @@ public string escape_single_quote(string file_path){ return file_path.replace("'","'\\''"); } - - // dep: realpath - public string resolve_relative_path (string filePath){ - - /* Resolve the full path of given file using 'realpath' command */ - - string filePath2 = filePath; - if (filePath2.has_prefix ("~")){ - filePath2 = Environment.get_home_dir () + "/" + filePath2[2:filePath2.length]; - } - - try { - string output = ""; - string cmd = "realpath '%s'".printf(escape_single_quote(filePath2)); - Process.spawn_command_line_sync(cmd, out output); - output = output.strip (); - if (FileUtils.test(output, GLib.FileTest.EXISTS)){ - return output; - } - } - catch(Error e){ - log_error (e.message); - } - - return filePath2; - } - - public int rsync (string sourceDirectory, string destDirectory, bool updateExisting, bool deleteExtra){ - - /* Sync files with rsync */ - - string cmd = "rsync -avh"; - cmd += updateExisting ? "" : " --ignore-existing"; - cmd += deleteExtra ? " --delete" : ""; - cmd += " '%s'".printf(escape_single_quote(sourceDirectory) + "//"); - cmd += " '%s'".printf(escape_single_quote(destDirectory)); - return exec_sync (cmd, null, null); - } } diff -Nru aptik-18.5.2/src/Utility/Console/TeeJee.System.vala aptik-18.6/src/Utility/Console/TeeJee.System.vala --- aptik-18.5.2/src/Utility/Console/TeeJee.System.vala 2018-05-12 05:04:13.000000000 +0000 +++ aptik-18.6/src/Utility/Console/TeeJee.System.vala 2018-06-30 09:38:00.000000000 +0000 @@ -106,50 +106,100 @@ public int get_user_id_from_username(string username){ - int user_id = -1; + // check local user accounts in /etc/passwd ------------------- foreach(var line in file_read("/etc/passwd").split("\n")){ + var arr = line.split(":"); - if (arr.length < 3) { continue; } - if (arr[0] == username){ - user_id = int.parse(arr[2]); - break; + + if ((arr.length >= 3) && (arr[0] == username)){ + + return int.parse(arr[2]); } } - return user_id; + // check remote user accounts with getent ------------------- + + var arr = get_user_with_getent(username).split(":"); + + if ((arr.length >= 3) && (arr[0] == username)){ + + return int.parse(arr[2]); + } + + // not found -------------------- + + log_error("UserId not found for userName: %s".printf(username)); + + return -1; } public string get_username_from_uid(int user_id){ - - string username = ""; + // check local user accounts in /etc/passwd ------------------- + foreach(var line in file_read("/etc/passwd").split("\n")){ + var arr = line.split(":"); - if (arr.length < 3) { continue; } - if (int.parse(arr[2]) == user_id){ - username = arr[0]; - break; + + if ((arr.length >= 3) && (arr[2] == user_id.to_string())){ + + return arr[0]; } } - return username; + // check remote user accounts with getent ------------------- + + var arr = get_user_with_getent(user_id.to_string()).split(":"); + + if ((arr.length >= 3) && (arr[2] == user_id.to_string())){ + + return arr[0]; + } + + // not found -------------------- + + log_error("Username not found for uid: %d".printf(user_id)); + + return ""; } public string get_user_home(string username = get_username()){ - - string userhome = ""; + // check local user accounts in /etc/passwd ------------------- + foreach(var line in file_read("/etc/passwd").split("\n")){ + var arr = line.split(":"); - if (arr.length < 6) { continue; } - if (arr[0] == username){ - userhome = arr[5]; - break; + + if ((arr.length >= 6) && (arr[0] == username)){ + + return arr[5]; } } - return userhome; + // check remote user accounts with getent ------------------- + + var arr = get_user_with_getent(username).split(":"); + + if ((arr.length >= 6) && (arr[0] == username)){ + + return arr[5]; + } + + // not found -------------------- + + log_error("Home directory not found for user: %s".printf(username)); + + return ""; + } + + public string get_user_with_getent(string user_name_or_uid){ + + string cmd = "getent passwd " + user_name_or_uid; + string std_out, std_err; + exec_sync(cmd, out std_out, out std_err); + return std_out; } public string get_user_home_effective(){ @@ -186,74 +236,8 @@ // system ------------------------------------ - // dep: cat TODO: rewrite - public double get_system_uptime_seconds(){ - - /* Returns the system up-time in seconds */ - - string cmd = ""; - string std_out; - string std_err; - int ret_val; - - try{ - cmd = "cat /proc/uptime"; - Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val); - string uptime = std_out.split(" ")[0]; - double secs = double.parse(uptime); - return secs; - } - catch(Error e){ - log_error (e.message); - return 0; - } - } - - public string get_desktop_name(){ - - /* Return the names of the current Desktop environment */ - - int pid = -1; - - pid = get_pid_by_name("cinnamon"); - if (pid > 0){ - return "Cinnamon"; - } - - pid = get_pid_by_name("xfdesktop"); - if (pid > 0){ - return "Xfce"; - } - - pid = get_pid_by_name("lxsession"); - if (pid > 0){ - return "LXDE"; - } - - pid = get_pid_by_name("gnome-shell"); - if (pid > 0){ - return "Gnome"; - } - - pid = get_pid_by_name("wingpanel"); - if (pid > 0){ - return "Elementary"; - } - - pid = get_pid_by_name("unity-panel-service"); - if (pid > 0){ - return "Unity"; - } - - pid = get_pid_by_name("plasma-desktop"); - if (pid > 0){ - return "KDE"; - } - - return "Unknown"; - } - public Gee.ArrayList list_dir_names(string path){ + var list = new Gee.ArrayList(); try @@ -300,30 +284,6 @@ return (exit_code == 0); } - public bool check_internet_connectivity_test1(){ - int exit_code = -1; - string std_err; - string std_out; - - string cmd = "ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3`\n"; - cmd += "exit $?"; - exit_code = exec_script_sync(cmd, out std_out, out std_err, false); - - return (exit_code == 0); - } - - public bool check_internet_connectivity_test2(){ - int exit_code = -1; - string std_err; - string std_out; - - string cmd = "ping -q -w 1 -c 1 google.com\n"; - cmd += "exit $?"; - exit_code = exec_script_sync(cmd, out std_out, out std_err, false); - - return (exit_code == 0); - } - public bool shutdown (){ /* Shutdown the system immediately */ @@ -340,174 +300,6 @@ } } - public bool command_exists(string command){ - string path = get_cmd_path(command); - return ((path != null) && (path.length > 0)); - } - - // open ----------------------------- - - public bool xdg_open (string file, string user = ""){ - string path = get_cmd_path ("xdg-open"); - if ((path != null) && (path != "")){ - string cmd = "xdg-open '%s'".printf(escape_single_quote(file)); - if (user.length > 0){ - cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ".printf(user) + cmd; - } - log_debug(cmd); - int status = exec_script_async(cmd); - return (status == 0); - } - return false; - } - - public bool exo_open_folder (string dir_path, bool xdg_open_try_first = true){ - - /* Tries to open the given directory in a file manager */ - - /* - xdg-open is a desktop-independent tool for configuring the default applications of a user. - Inside a desktop environment (e.g. GNOME, KDE, Xfce), xdg-open simply passes the arguments - to that desktop environment's file-opener application (gvfs-open, kde-open, exo-open, respectively). - We will first try using xdg-open and then check for specific file managers if it fails. - */ - - string path; - int status; - - if (xdg_open_try_first){ - //try using xdg-open - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - string cmd = "xdg-open '%s'".printf(escape_single_quote(dir_path)); - status = exec_script_async (cmd); - return (status == 0); - } - } - - foreach(string app_name in - new string[]{ "nemo", "nautilus", "thunar", "pantheon-files", "marlin"}){ - - path = get_cmd_path (app_name); - if ((path != null)&&(path != "")){ - string cmd = "%s '%s'".printf(app_name, escape_single_quote(dir_path)); - status = exec_script_async (cmd); - return (status == 0); - } - } - - if (xdg_open_try_first == false){ - //try using xdg-open - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - string cmd = "xdg-open '%s'".printf(escape_single_quote(dir_path)); - status = exec_script_async (cmd); - return (status == 0); - } - } - - return false; - } - - public bool exo_open_textfile (string txt_file){ - - /* Tries to open the given text file in a text editor */ - - string path; - int status; - string cmd; - - path = get_cmd_path ("exo-open"); - if ((path != null)&&(path != "")){ - cmd = "exo-open '%s'".printf(escape_single_quote(txt_file)); - status = exec_script_async (cmd); - return (status == 0); - } - - path = get_cmd_path ("gedit"); - if ((path != null)&&(path != "")){ - cmd = "gedit --new-document '%s'".printf(escape_single_quote(txt_file)); - status = exec_script_async (cmd); - return (status == 0); - } - - return false; - } - - public bool exo_open_url (string url){ - - /* Tries to open the given text file in a text editor */ - - string path; - int status; - //string cmd; - - path = get_cmd_path ("exo-open"); - if ((path != null)&&(path != "")){ - status = exec_script_async ("exo-open \"" + url + "\""); - return (status == 0); - } - - path = get_cmd_path ("firefox"); - if ((path != null)&&(path != "")){ - status = exec_script_async ("firefox \"" + url + "\""); - return (status == 0); - } - - path = get_cmd_path ("chromium-browser"); - if ((path != null)&&(path != "")){ - status = exec_script_async ("chromium-browser \"" + url + "\""); - return (status == 0); - } - - return false; - } - - public bool using_efi_boot(){ - - /* Returns true if the system was booted in EFI mode - * and false for BIOS mode */ - - return dir_exists("/sys/firmware/efi"); - } - - public void open_terminal_window( - string terminal_emulator, - string working_dir, - string script_file_to_execute, - bool run_as_admin){ - - string cmd = ""; - if (run_as_admin){ - cmd += "pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY "; - } - - string term = terminal_emulator; - if (!command_exists(term)){ - term = "gnome-terminal"; - if (!command_exists(term)){ - term = "xfce4-terminal"; - } - } - - cmd += term; - - switch (term){ - case "gnome-terminal": - case "xfce4-terminal": - if (working_dir.length > 0){ - cmd += " --working-directory='%s'".printf(escape_single_quote(working_dir)); - } - if (script_file_to_execute.length > 0){ - cmd += " -e '%s\n; echo Press ENTER to exit... ; read dummy;'".printf(escape_single_quote(script_file_to_execute)); - } - break; - } - - log_debug(cmd); - exec_script_async(cmd); - } - // timers -------------------------------------------------- public GLib.Timer timer_start(){ @@ -516,11 +308,6 @@ return timer; } - public void timer_restart(GLib.Timer timer){ - timer.reset(); - timer.start(); - } - public ulong timer_elapsed(GLib.Timer timer, bool stop = true){ ulong microseconds; double seconds; @@ -544,21 +331,4 @@ } return "%.0f ms".printf((seconds * 1000 ) + microseconds/1000); } - - public void timer_elapsed_print(GLib.Timer timer, bool stop = true){ - ulong microseconds; - double seconds; - seconds = timer.elapsed (out microseconds); - if (stop){ - timer.stop(); - } - log_msg("%s %lu\n".printf(seconds.to_string(), microseconds)); - } - - - public void set_numeric_locale(string type){ - Intl.setlocale(GLib.LocaleCategory.NUMERIC, type); - Intl.setlocale(GLib.LocaleCategory.COLLATE, type); - Intl.setlocale(GLib.LocaleCategory.TIME, type); - } }