summaryrefslogtreecommitdiff
path: root/netzbon/functions.sh
blob: b4c265deb7519296e84aaf93d36e5f7a50bd9c58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

# Message

function say()
{
    echo "TALER: " "$@"
}


# Check user if the user is root

function check_user()
{

    if [ $(whoami) != "root" ]; then
        say "Please run this script as root"
        exit 1
    fi
}

# Create users "exchange" and "merchant"
# Deprecated: should be done by Debian!
function create_users()
{
    say "Creating users"
    for n in exchange merchant
    do
	    # Only setup use if it does not yet exist
        if test ! -d /home/$n
        then
	        adduser --disabled-password $n
        fi
    done
}

# Assign group and permissions to users
# Deprecated: should be done by Debian!
function assign_user_permissions()
{
    for n in exchange merchant
    do
	    adduser www-data $n
	    mkdir -p /home/$n/.config/
	    # FIXME
	    # cp -r $n/* /home/$n/
	    # TODO: No taler.conf is provided
	    # mv /home/$n/taler.conf /home/$n/.config/taler.conf
	    chmod 600 /home/$n/.config/taler.conf
	    chown -R $n:$n /home/$n/
	    su - postgres -c "createuser $n"
	    su - postgres -c "createdb -O $n taler-$n"
    done
}

# Set DISTRO to the detected distro or return non-zero
# status if distro not supported.
function detect_distro()
{
  unset DISTRO
  uname -a | grep Ubuntu >/dev/null && DISTRO=ubuntu && return 0
  uname -a | grep Debian >/dev/null && DISTRO=debian && return 0
  return 1
}