]> Git repositories of Lucie Scarlet - dotfiles.git/commitdiff
Accounted for uptime script
authorLucie Scarlet <lucie@scarlet.moe>
Wed, 3 Jul 2024 22:45:32 +0000 (00:45 +0200)
committerLucie Scarlet <lucie@scarlet.moe>
Wed, 3 Jul 2024 22:45:32 +0000 (00:45 +0200)
Install now installs the uptime python3 script to /opt and adds the
script to crontab

i3/install.sh
i3/uptime.py [new file with mode: 0644]

index dbf4a81f5a885d9fbf5f11cdae6214b4f448b57c..7c6ea542a18e7fbb6e91ea81301b199827a38849 100755 (executable)
@@ -1,6 +1,20 @@
 #!/bin/bash
 
+echo "Installing i3 config"
 mkdir -p ~/.config/i3
 cp ./i3config ~/.config/i3/config
+echo  "Installing i3status config"
 mkdir -p ~/.config/i3status
 cp ./i3status ~/.config/i3status/config
+
+echo "Installing uptime script"
+sudo -s <<EOF
+cp ./uptime.py /opt/uptime.py
+EOF
+
+ct=`mktemp`
+crontab -l | tee $ct
+echo "* * * * * python3 /opt/uptime.py > /tmp/uptime" | tee -a $ct
+echo "@reboot python3 /opt/uptime.py > /tmp/uptime" | tee -a $ct
+
+crontab $ct
diff --git a/i3/uptime.py b/i3/uptime.py
new file mode 100644 (file)
index 0000000..d263030
--- /dev/null
@@ -0,0 +1,18 @@
+from datetime import timedelta
+
+
+def main() -> int:
+    raw_uptime: str = ""
+    with open("/proc/uptime", "r") as uptime:
+        raw_uptime = uptime.read()
+    text_uptime: str = raw_uptime.split()[0]
+    raw_formatted = timedelta(seconds=(float(text_uptime)))
+    well_formatted: str = str(raw_formatted).split(".")[0][:-3]
+    fmt = well_formatted.split(".")[0]
+    hours = fmt.split(":")[0]
+    mins = fmt.split(":")[1]
+    print(f"Uptime: {hours}h {mins}m")
+
+
+if __name__ == "__main__":
+    raise SystemExit(main())