packages feed

hifi 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+84/−16 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Templating: instance Text.Mustache.Types.ToMustache Templating.DataSpec
- Templating: instance Text.Mustache.Types.ToMustache Templating.ScriptSpec
+ Templating: instance Text.Mustache.Internal.Types.ToMustache Templating.DataSpec
+ Templating: instance Text.Mustache.Internal.Types.ToMustache Templating.ScriptSpec

Files

+ README.md view
@@ -0,0 +1,67 @@+hifi+====++A tool for generating wifi connection scripts. Uses wpa_supplicant to connect.++# Prerequisites++You will need to have `wpa_supplicant`, `wpa_passphrase` and `dhcpcd` installed,+as that is what is used in the connection scripts generated by hifi.++# Installation+To install, simply do either:++`stack install hifi`++or++`git clone https://gitlab.com/gonz/hifi ./hifi && cd hifi && stack install`++# Usage+`hifi <filename> <interface> <ssid> <passphrase>`++The filename parameter determines what your data and script files will be called.+They are stored in your XDG data directory, which by default (in most distros)+will mean your files will end up in `$HOME/.local/share/hifi/...`.++The SSID and passphrase parameters should be obvious enough. They are simply+the connection information you would use to connect to your network.++When a script has been generated once it will not have to be generated again.+Instead, you should simply run the generated script.++Typical usage looks as follows, for a first run:++```shell+$ hifi wifi-home wlp7s0 MyWLANsSSID MyPassphrase+Created /home/yourusername/.local/share/hifi/data/wifi-home and /home/yourusername/.local/share/hifi/scripts/wifi-home+$ wifi-home+```++## Your $PATH variable and connect scripts+If you want to be able to run the scripts without issuing their full path you+will need to add your scripts folder to your path. You can do this in several+ways, but the most common one is to add the following to your+`bash_profile`, `zsh_profile`, `zsh_env` file or the like:++`PATH=".local/share/hifi/scripts:$PATH"` where $PATH can either refer to the rest+of your $PATH environment variable or simply a literal containing all your+specified directories.++# Folders, templates++hifi will generate a script for connecting and a data portion that will be used+in the script.++The scripts are located in `$HOME/.local/share/hifi/scripts` and the data+portion in the `data` directory of that same hifi root folder.++hifi uses templates that are located in the `templates` directory, so you can+change the template being used to generate both the data files and the scripts.++The templates are copied on `cabal install` and `stack install`, so any changes+made will carry on to the installed version.++The `templateDir` function will return the directory where the files end up+being stored. This varies, so that is why it uses `getDataFileName` and the+`data-files` entry in the cabal-file.
hifi.cabal view
@@ -1,16 +1,16 @@ name:                hifi-version:             0.1.0.0-synopsis:            Initial project template from stack-description:         Please see README.md+version:             0.1.1.0+synopsis:            WiFi connection script generator+description:         A CLI tool generating scripts for connecting to WiFi, circumventing big WiFi management tools. homepage:            https://gitlab.com/gonz/hifi license:             BSD3 license-file:        LICENSE author:              Rickard Andersson maintainer:          gonz@severnatazvezda.com-copyright:           2016 Rickard Andersson+copyright:           2017 Rickard Andersson category:            CLI build-type:          Simple--- extra-source-files:+extra-source-files:  README.md cabal-version:       >=1.10 data-files:          templates/*.mustache 
src/Templating.hs view
@@ -3,21 +3,21 @@ module Templating (createFiles) where  import qualified Config-import qualified Data.Text.IO      as TextIO-import           System.FilePath   ((</>))+import qualified Data.Text.IO       as TextIO+import           System.FilePath    ((</>))+import qualified System.IO          as IO import           System.Posix.Files-import qualified System.IO         as IO import           System.Process import           Text.Mustache-import           Text.Parsec.Error (ParseError)+import           Text.Parsec.Error  (ParseError) -data ScriptSpec = ScriptSpec { interface :: String, dataFilename :: String}+data ScriptSpec = ScriptSpec { interface :: String, dataFilename :: String }  instance ToMustache ScriptSpec where   toMustache spec = object ["interface" ~> interface spec,                             "data_filename" ~> dataFilename spec] -data DataSpec = DataSpec { wpaPassphraseOutput :: String}+newtype DataSpec = DataSpec { wpaPassphraseOutput :: String}  instance ToMustache DataSpec where   toMustache spec = object ["wpa_passphrase_output" ~> wpaPassphraseOutput spec]@@ -25,8 +25,9 @@ type Interface = String type SSID = String type Passphrase = String+type FileResult = Either ParseError FilePath -createScript :: FilePath -> Interface -> FilePath -> IO (Either ParseError FilePath)+createScript :: FilePath -> Interface -> FilePath -> IO FileResult createScript filename iface dataFile =   createFile filename Config.scriptDir scriptSpec "script.mustache"   where scriptSpec = ScriptSpec { interface = iface, dataFilename = dataFile }@@ -36,15 +37,15 @@   (_, Just hout, _, _) <- createProcess wpa_passphrase_process                           { std_out = CreatePipe }   IO.hGetContents hout-  where wpa_passphrase_process = (proc "wpa_passphrase" [ssid, passphrase])+  where wpa_passphrase_process = proc "wpa_passphrase" [ssid, passphrase] -createData :: FilePath -> String -> IO (Either ParseError FilePath)+createData :: FilePath -> String -> IO FileResult createData filename wpaPPoutput =   createFile filename Config.dataDir dataSpec "data.mustache"   where dataSpec = DataSpec {wpaPassphraseOutput = wpaPPoutput} -createFile :: ToMustache a => FilePath -> IO FilePath -> a -> FilePath-  -> IO (Either ParseError FilePath)+createFile ::+  ToMustache a => FilePath -> IO FilePath -> a -> FilePath -> IO FileResult createFile filename outputDirFunc spec templateFile = do   templateDir <- Config.templateDir   outputDir <- outputDirFunc