aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2016-05-15 20:42:08 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2016-05-15 20:42:08 +0200
commita673f920852a8a566f325b4cebe5cfe4b556aa1a (patch)
treee05e91ce25a5ae26cd6b14208e845cf161898f1e
parent5c4abeefb5fb5fc899dc698b5cc7005d77e3f918 (diff)
downloaddotfiles-a673f920852a8a566f325b4cebe5cfe4b556aa1a.tar.gz
dotfiles-a673f920852a8a566f325b4cebe5cfe4b556aa1a.zip
rework setup.py to handle sensible files
setup.py: + files ending with .gpg will be decrypted and stored in decrypted/ + detect if root privileges are requiered and request them with sudo + use argparse instead of manually parsing sys.argv add function to start the FAU Wlan and the requiered wpa_supplicant config
-rw-r--r--.gitignore3
-rw-r--r--config/fish/functions/start_uni_wlan.fish4
-rw-r--r--fau_stud.conf.gpgbin0 -> 833 bytes
-rwxr-xr-x[-rw-r--r--]setup.py61
4 files changed, 49 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 7027f37..e095d55 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
*~
i3/log
vim/.netrwhist
+
+# exclude private files
+decrypted/*
diff --git a/config/fish/functions/start_uni_wlan.fish b/config/fish/functions/start_uni_wlan.fish
new file mode 100644
index 0000000..0d17e69
--- /dev/null
+++ b/config/fish/functions/start_uni_wlan.fish
@@ -0,0 +1,4 @@
+function start_uni_wlan --description "starts wpa_supplicant and dhcpcd"
+ sudo wpa_supplicant -B -iwlp2s0 -D wext -c /etc/wpa_supplicant/fau_stud.conf
+ sudo dhcpcd wlp2s0
+end
diff --git a/fau_stud.conf.gpg b/fau_stud.conf.gpg
new file mode 100644
index 0000000..fa93ec6
--- /dev/null
+++ b/fau_stud.conf.gpg
Binary files differ
diff --git a/setup.py b/setup.py
index 6833dde..1338902 100644..100755
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,11 @@
+#!/bin/env python3
+
"""Interactively install fischerlings dotfiles"""
+import argparse
import os
import sys
+import subprocess
home_dir = os.getenv("HOME")
cwd = os.getcwd()
@@ -10,7 +14,6 @@ def fish_config(quiet):
"""install and run fisherman"""
# download fisherman
import urllib.request
- import subprocess
if not quiet:
print("Installing fisherman, see: https://github.com/fisherman/fisherman")
@@ -27,7 +30,7 @@ def fish_config(quiet):
file.write(fisher)
else:
if not quiet:
- print("fisherman all ready installed")
+ print("fisherman already installed")
return
if not quiet:
@@ -47,7 +50,8 @@ targets = {"vimrc": [("vimrc", home_dir + "/.vimrc")],
"i3-config": [("i3", home_dir + "/.i3")],
"dir_colors": [("dir_colors", home_dir + "/.dir_colors")],
"fish-config": [("config/fish/config.fish", home_dir + "/.config/fish/config.fish"),
- ("config/fish/fishfile", home_dir + "/.config/fish/fishfile"), fish_config],
+ ("config/fish/fishfile", home_dir + "/.config/fish/fishfile"), fish_config,
+ ("fau_stud.conf.gpg", "/etc/wpa_supplicant/fau_stud.conf")],
"terminator-config": [("config/terminator/config", home_dir + "/.config/terminator/config")]}
git_submodules_for = ["vim.d"]
@@ -63,10 +67,32 @@ def install_target(target, quiet):
if not quiet:
print("Installing", instruction[0], "to", instruction[1])
if os.path.exists(instruction[0]):
+ # check if file is encrypted
+ if instruction[0][-4:] == ".gpg":
+ if subprocess.run(["gpg", "--output", "decrypted/" +
+ instruction[0][:-4], "-d", instruction[0]]):
+ instruction = ("decrypted/" + instruction[0][:-4],
+ instruction[1])
+
+ # set privacy friendly file permissions
+ if not subprocess.run(["chmod", "660", instruction[0]]):
+ print("Skipping because changing permissions of",
+ instruction[1], "failed. This could be a privacy risk!")
+ continue
+ else:
+ print("Decrypting failed", file=sys.stderr)
+ continue
+
try:
os.symlink(cwd + "/" + instruction[0], instruction[1])
- except FileExistsError as e:
- print(e, file=sys.stderr)
+ except Exception as e:
+ if isinstance(e, PermissionError):
+ subprocess.run(["sudo", "ln", "-s",
+ cwd + '/' + instruction[0], instruction[1]])
+ elif isinstance(e, FileExistsError):
+ print("File already exists")
+ else:
+ print(e, file=sys.stderr)
else:
print("Can't find", instruction[0] +
". Please make sure you are in the right directory.", file=sys.stderr)
@@ -87,23 +113,21 @@ def install_target(target, quiet):
if target in git_submodules_for:
choice = input(target + " uses git submodules want to pull them ? (Y/n) ")
if choice in ["Y", "y", ""]:
- import subprocess
subprocess.run(["git", "submodule", "update", "--init"])
def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-q", "--quiet", action="store_true")
+ parser.add_argument("targets", type=str, nargs='*')
- quiet = False
- if "-q" in sys.argv:
- quiet = True
- del(sys.argv[sys.argv.index("-q")])
+ args = parser.parse_args()
- if len(sys.argv) > 1:
- for arg in sys.argv[1:]:
- if arg in targets:
- install_target(arg, quiet)
+ if args.targets:
+ for t in args.targets:
+ install_target(t, args.quiet)
else:
- if not quiet:
+ if not args.quiet:
print("Welcome to the installation script of fischerlings dotfiles.")
print("Located at: https://github.com/fischerling/dotfiles")
print()
@@ -118,15 +142,14 @@ def main():
pass
elif "all" in choice:
for target in targets:
- install_target(target, quiet)
+ install_target(target, args.quiet)
else:
for n in choice.strip().split(" "):
- install_target(targets_ord[int(n)], quiet)
+ install_target(targets_ord[int(n)], args.quiet)
- if not quiet:
+ if not args.quiet:
print("Good Bye. Have fun with your new configuration")
if __name__ == "__main__":
main()
-