CLI tool install script.
[UPDATED] Templates are now in ciphers.plist. [ADDED] Install script for Java-based mpw CLI tool. [UPDATED] Java tool is now bundled in a single executable self-containing JAR.
This commit is contained in:
parent
c0737de939
commit
33e25a5fed
0
MasterPassword/Java/.mvn-tools
Normal file
0
MasterPassword/Java/.mvn-tools
Normal file
@ -32,10 +32,16 @@ public class MPTemplates extends MetaObject {
|
|||||||
this.templates = templates;
|
this.templates = templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MPTemplates load() {
|
||||||
|
|
||||||
|
return loadFromPList( "ciphers.plist" );
|
||||||
|
}
|
||||||
|
|
||||||
public static MPTemplates loadFromPList(final String templateResource) {
|
public static MPTemplates loadFromPList(final String templateResource) {
|
||||||
|
|
||||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||||
InputStream templateStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( templateResource );
|
InputStream templateStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( templateResource );
|
||||||
|
Preconditions.checkNotNull( templateStream, "Not found: %s", templateResource );
|
||||||
try {
|
try {
|
||||||
NSObject plistObject = PropertyListParser.parse( templateStream );
|
NSObject plistObject = PropertyListParser.parse( templateStream );
|
||||||
Preconditions.checkState( NSDictionary.class.isAssignableFrom( plistObject.getClass() ) );
|
Preconditions.checkState( NSDictionary.class.isAssignableFrom( plistObject.getClass() ) );
|
||||||
@ -98,6 +104,6 @@ public class MPTemplates extends MetaObject {
|
|||||||
|
|
||||||
public static void main(final String... arguments) {
|
public static void main(final String... arguments) {
|
||||||
|
|
||||||
loadFromPList( "templates.plist" );
|
load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public abstract class MasterPassword {
|
|||||||
private static final ByteOrder MP_byteOrder = ByteOrder.BIG_ENDIAN;
|
private static final ByteOrder MP_byteOrder = ByteOrder.BIG_ENDIAN;
|
||||||
private static final MessageDigests MP_hash = MessageDigests.SHA256;
|
private static final MessageDigests MP_hash = MessageDigests.SHA256;
|
||||||
private static final MessageAuthenticationDigests MP_mac = MessageAuthenticationDigests.HmacSHA256;
|
private static final MessageAuthenticationDigests MP_mac = MessageAuthenticationDigests.HmacSHA256;
|
||||||
private static final MPTemplates templates = MPTemplates.loadFromPList( "templates.plist" );
|
private static final MPTemplates templates = MPTemplates.load();
|
||||||
|
|
||||||
public static byte[] keyForPassword(final String password, final String username) {
|
public static byte[] keyForPassword(final String password, final String username) {
|
||||||
|
|
||||||
|
@ -29,30 +29,49 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>prepare-package</id>
|
||||||
|
<phase>prepare-package</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<target>
|
||||||
<manifest>
|
<chmod file="${project.build.directory}/install" perm="755"/>
|
||||||
<mainClass>com.lyndir.lhunath.masterpassword.CLI</mainClass>
|
</target>
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>lib/</classpathPrefix>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy-dependencies</id>
|
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>copy-dependencies</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>com.lyndir.lhunath.masterpassword.CLI</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.SF</exclude>
|
||||||
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
1958
MasterPassword/Java/masterpassword-cli/src/main/scripts/bashlib
Executable file
1958
MasterPassword/Java/masterpassword-cli/src/main/scripts/bashlib
Executable file
File diff suppressed because it is too large
Load Diff
56
MasterPassword/Java/masterpassword-cli/src/main/scripts/install
Executable file
56
MasterPassword/Java/masterpassword-cli/src/main/scripts/install
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Install the Master Password CLI tool.
|
||||||
|
set -e
|
||||||
|
cd "${BASH_SOURCE%/*}"
|
||||||
|
source bashlib
|
||||||
|
|
||||||
|
inf "This will install the mpw tool."
|
||||||
|
|
||||||
|
# Try to guess then ask for the bin dir to install to.
|
||||||
|
IFS=: read -a paths <<< "$PATH"
|
||||||
|
if inArray ~/bin "${paths[@]}"; then
|
||||||
|
bindir=~/bin
|
||||||
|
elif inArray ~/.bin "${paths[@]}"; then
|
||||||
|
bindir=~/.bin
|
||||||
|
elif inArray /usr/local/bin "${paths[@]}"; then
|
||||||
|
bindir=/usr/local/bin
|
||||||
|
else
|
||||||
|
bindir=~/bin
|
||||||
|
fi
|
||||||
|
bindir=$(ask -d "$bindir" "What bin directory should I install to?")
|
||||||
|
[[ -d "$bindir" ]] || mkdir "$bindir" || ftl 'Cannot create missing bin directory: %s' "$bindir" || exit
|
||||||
|
[[ -w "$bindir" ]] || ftl 'Cannot write to bin directory: %s' "$bindir" || exit
|
||||||
|
|
||||||
|
# Try to guess then ask for the share dir to install to.
|
||||||
|
sharedir=$(cd -P "$bindir/.."; [[ $bindir = */.bin ]] && printf '%s/.share' "$PWD" || printf '%s/share' "$PWD")
|
||||||
|
sharedir=$(ask -d "$sharedir" "What share directory should I install to?")
|
||||||
|
[[ -d "$sharedir" ]] || mkdir "$sharedir" || ftl 'Cannot create missing share directory: %s' "$sharedir" || exit
|
||||||
|
[[ -w "$sharedir" ]] || ftl 'Cannot write to share directory: %s' "$sharedir" || exit
|
||||||
|
|
||||||
|
# Install Master Password.
|
||||||
|
sharepath=$sharedir/masterpassword
|
||||||
|
mkdir -p "$sharepath"
|
||||||
|
cp -a "masterpassword-cli-"*".jar" bashlib mpw "$sharepath"
|
||||||
|
ex -c "%s~%SHAREPATH%~$sharepath~g|x" "$sharepath/mpw"
|
||||||
|
ln -sf "$sharepath/mpw" "$bindir/mpw"
|
||||||
|
chmod +x "$sharepath/mpw"
|
||||||
|
[[ ! -e "$bindir/bashlib" ]] && ln -s "$sharepath/bashlib" "$bindir/bashlib" ||:
|
||||||
|
|
||||||
|
# Convenience bash function.
|
||||||
|
inf "Installation successful!"
|
||||||
|
echo
|
||||||
|
inf "To improve usability, you can install an mpw function in your bash shell."
|
||||||
|
inf "This function adds the following features:"
|
||||||
|
inf " - Ask the Master Password once, remember in the shell."
|
||||||
|
inf " - Automatically put the password in the clipboard (some platforms)."
|
||||||
|
echo
|
||||||
|
inf "To do this you need the following function in ~/.bashrc:\n%s" "$(<mpw.bashrc)"
|
||||||
|
echo
|
||||||
|
inf "We can do this for you automatically now."
|
||||||
|
if ask -c Y!n "Append the mpw function to your .bashrc?"; then
|
||||||
|
cat mpw.bashrc >> ~/.bashrc
|
||||||
|
inf "Done! Don't forget to run '%s' to apply the changes!" "source ~/.bashrc"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
inf "To begin using Master Password, type: mpw [site name]"
|
@ -5,5 +5,5 @@
|
|||||||
# Uncomment this to hardcode your master password. Make sure this file's permissions are tight. Master Password will not ask you for your master password anymore. This is probably not a good idea.
|
# Uncomment this to hardcode your master password. Make sure this file's permissions are tight. Master Password will not ask you for your master password anymore. This is probably not a good idea.
|
||||||
# export MP_PASSWORD="banana colored duckling"
|
# export MP_PASSWORD="banana colored duckling"
|
||||||
|
|
||||||
cd "${BASH_SOURCE[0]%/*}"
|
cd "%SHAREPATH%"
|
||||||
java -jar masterpassword-cli-GIT-SNAPSHOT.jar "$@"
|
exec java -jar masterpassword-cli-GIT-SNAPSHOT.jar "$@"
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
source bashlib
|
||||||
|
mpw() {
|
||||||
|
_nocopy() { echo >&2 "$(cat)"; }
|
||||||
|
_copy() { "$(type -P pbcopy || type -P xclip || echo _nocopy)"; }
|
||||||
|
|
||||||
|
# Empty the clipboard
|
||||||
|
:| _copy 2>/dev/null
|
||||||
|
|
||||||
|
# Ask for the user's name and password if not yet known.
|
||||||
|
MP_USERNAME=${MP_USERNAME:-$(ask -s 'Your Full Name:')}
|
||||||
|
MP_PASSWORD=${MP_PASSWORD:-$(ask -s 'Master Password:')}
|
||||||
|
|
||||||
|
# Start Master Password and copy the output.
|
||||||
|
printf %s "$(MP_USERNAME=$MP_USERNAME MP_PASSWORD=$MP_PASSWORD command mpw "$@")" | _copy
|
||||||
|
}
|
@ -21,7 +21,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>masterpassword-algorithm</module>
|
<module>masterpassword-algorithm</module>
|
||||||
<module>masterpassword-cli</module>
|
<module>masterpassword-cli</module>
|
||||||
<module>masterpassword-android</module>
|
<!--module>masterpassword-android</module-->
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<!-- REMOTE ARTIFACT REPOSITORIES -->
|
<!-- REMOTE ARTIFACT REPOSITORIES -->
|
||||||
|
Loading…
Reference in New Issue
Block a user