Statistics
| Branch: | Tag: | Revision:

one / share / onetoken / onetoken.sh @ f7d34f2d

History | View | Annotate | Download (1.45 KB)

1
onetokenset(){
2
    local PASSWORD
3

    
4
    if [ -n "$PASSWORD_ARG" ]; then
5
        PASSWORD=$1
6
        shift
7
    fi
8

    
9
    USER=$1
10
    shift
11

    
12
    if [ -z "$USER" -o "${USER:0:1}" = "-" ]; then
13
        echo "Usage: onetokenset <user> [options]" >&2
14
        echo "  Any option understood by 'oneuser token-set' is valid." >&2
15
        return 1
16
    fi
17

    
18
    if [ -z "$PASSWORD" ]; then
19
        echo -n "Password: "
20
        stty -echo
21
        read PASSWORD
22
        stty echo
23
        echo
24
    fi
25

    
26
    OUT=$(echo "$PASSWORD" | oneuser token-set --stdin_password $USER $*)
27

    
28
    if echo $OUT | grep -q export; then
29
        eval "$OUT"
30

    
31
        echo "Token loaded."
32
        return 0
33
    else
34
        echo $OUT
35
        return 1
36
    fi
37
}
38

    
39
onetokencreate(){
40
    local PASSWORD PASSWORD_ARG
41

    
42
    USER=$1
43

    
44
    if [ -z "$USER" ]; then
45
        echo "Usage: onetokencreate <user> [options]" >&2
46
        echo "  Any option understood by 'oneuser token-create' is valid." >&2
47
        return 1
48
    fi
49

    
50
    shift
51

    
52
    echo -n "Password: "
53
    stty -echo
54
    read PASSWORD
55
    stty echo
56
    echo
57

    
58
    OUT=$(echo "$PASSWORD" | oneuser token-create --stdin_password $USER $*)
59
    echo $OUT
60

    
61
    if echo $OUT | grep -q "Authentication Token"; then
62
        TOKEN=$(echo $OUT|tail -n1|cut -d: -f2)
63
        if [ -n "$TOKEN" ]; then
64
            PASSWORD_ARG=true onetokenset $PASSWORD $USER --token $TOKEN
65
        else
66
            echo "Invalid token."
67
            return 1
68
        fi
69
    else
70
        return 1
71
    fi
72
}