SHARE
TWEET

Untitled

a guest Nov 14th, 2018 365 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std.process;
  2. import std.stdio;
  3. import std.range;
  4. import std.string;
  5. import std.algorithm.searching;
  6. import std.format;
  7. import std.conv;
  8. import std.file;
  9. import std.parallelism;
  10. import core.thread;
  11.  
  12. //    pkexec dd if=/run/media/user1101/portable_drive/software/os/manjaro-kde-18.0-stable-x86_64.iso of=/dev/sdd bs=4M status=progress 2>&1 && sync
  13. //    pkexec dd if=/home/user1101/Downloads/mini.iso of=/dev/sdd bs=4M status=progress 2>&1 && sync
  14.  
  15. int ddOp(in string logFileName, ref bool started) {
  16.     started = true;
  17.     immutable string fileName = "/run/media/user1101/portable_drive/software/os/archlinux-2018.11.01-x86_64.iso";
  18.     immutable string device = "/dev/sdd";
  19.     immutable string command = format("pkexec dd if=/%s of=%s bs=4M status=progress 2>%s && sync",
  20.             fileName, device, logFileName);
  21.  
  22.     return executeShell(command).status;
  23. }
  24.  
  25. uint parseLog(string logFileName) {
  26.     try {
  27.         if (!(logFileName.exists))
  28.             return 0;
  29.         auto text = logFileName.readText();
  30.         if (text.splitLines().length == 0)
  31.             return 0;
  32.         if (text.text.splitLines().back.split.front.isNumeric)
  33.             return text.splitLines().back.split.front.to!uint;
  34.     }
  35.     catch (Exception e) {
  36.         return 0;
  37.     }
  38.     return 0;
  39. }
  40.  
  41. void main() {
  42.     auto logFileName = "/tmp/.dd_op.txt";
  43.     bool ddStarted = false;
  44.     auto invokedd = task!ddOp(logFileName, ddStarted);
  45.     invokedd.executeInNewThread();
  46.     while (!(invokedd.done)) {
  47.         Thread.sleep(500.msecs);
  48.         writeln(parseLog(logFileName));
  49.  
  50.     }
  51.     if (logFileName.exists()) {
  52.         logFileName.remove;
  53.         ddStarted = false;
  54.     }
  55.  
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top