aboutsummaryrefslogtreecommitdiff
path: root/buildtools/freebsd-skeleton/rpki-rp/pkg-install
blob: 8c55201621ad6e42eaed315a15cf2f0b558e3c14 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh -

case $2 in

PRE-INSTALL)
    if /usr/sbin/pw groupshow "rcynic" 2>/dev/null
    then
        echo "You already have a group \"rcynic\", so I will use it."
    elif /usr/sbin/pw groupadd rcynic
    then
        echo "Added group \"rcynic\"."
    else
        echo "Adding group \"rcynic\" failed..."
        echo "Please create it, then try again."
        exit 1
    fi
    if /usr/sbin/pw usershow "rcynic" 2>/dev/null
    then
        echo "You already have a user \"rcynic\", so I will use it."
    elif /usr/sbin/pw useradd rcynic -g rcynic -h - -d /nonexistant -s /usr/sbin/nologin -c "RPKI validation system"
    then
        echo "Added user \"rcynic\"."
    else
        echo "Adding user \"rcynic\" failed..."
        echo "Please create it, then try again."
        exit 1
    fi
    if /usr/sbin/pw groupshow "rpkirtr" 2>/dev/null
    then
        echo "You already have a group \"rpkirtr\", so I will use it."
    elif /usr/sbin/pw groupadd rpkirtr
    then
        echo "Added group \"rpkirtr\"."
    else
        echo "Adding group \"rpkirtr\" failed..."
        echo "Please create it, then try again."
        exit 1
    fi
    if /usr/sbin/pw usershow "rpkirtr" 2>/dev/null
    then
        echo "You already have a user \"rpkirtr\", so I will use it."
    elif /usr/sbin/pw useradd rpkirtr -g rpkirtr -h - -d /nonexistant -s /usr/sbin/nologin -c "RPKI router server"
    then
        echo "Added user \"rpkirtr\"."
    else
        echo "Adding user \"rpkirtr\" failed..."
        echo "Please create it, then try again."
        exit 1
    fi
    ;;

POST-INSTALL)
    if ! test -d /var/rcynic
    then
	echo "Creating /var/rcynic"
	/usr/bin/install -o root -g wheel -d /var/rcynic
    fi
    for dir in /var/rcynic/data /var/rcynic/rpki-rtr
    do
	if ! test -d $dir
	then
	    echo "Creating $dir"
	    /usr/bin/install -o rcynic -g rcynic -d /var/rcynic
	fi
    done
    if ! test -d /var/rcynic/rpki-rtr/sockets
    then
	echo "Creating /var/rcynic/rpki-rtr/sockets"
	/usr/bin/install -o rpkirtr -g rcynic -m 775 -d /var/rcynic/rpki-rtr/sockets
    fi
    if test ! -f /usr/local/etc/rcynic.conf
    then
	/bin/cp -p /usr/local/etc/rcynic.conf.sample /usr/local/etc/rcynic.conf
    fi
    htmldir=/usr/local/www/apache22/data/rcynic
    if ! test -d $htmldir
    then
        echo "Creating $htmldir"
        /usr/bin/install -o rcynic -g rcynic -d $htmldir
    fi
    if test "X`/usr/bin/crontab -l -u rcynic 2>/dev/null`" != "X"
    then
	echo "rcynic user already has a crontab, leaving it alone"
    else
	echo "Setting up rcynic's crontab to run rcynic-cron script"
	/usr/bin/awk -v t=`/usr/bin/hexdump -n 2 -e '"%u\n"' /dev/random` '
            BEGIN {printf "MAILTO=root\n%u * * * *\texec  /usr/local/bin/rcynic-cron\n", t % 60}' |
	/usr/bin/crontab -u rcynic -
    fi
    echo "Setting up rpki-rtr listener under inetd"
    if /usr/bin/egrep -q '^rpki-rtr' /etc/services
    then
        echo "You already have a /etc/services entry for rpki-rtr, so I will use it."
    elif echo >>/etc/services "rpki-rtr	43779/tcp  #RFC 6810"
    then
        echo "Added rpki-rtr to /etc/services."
    else
        echo "Adding rpki-rtr to /etc/services failed, please fix this, then try again."
        exit 1
    fi
    if /usr/bin/egrep -q "rpki-rtr[ 	]+stream[ 	]+tcp[ 	]" /etc/inetd.conf
    then
        echo "You already have an inetd.conf entry for rpki-rtr on TCPv4, so I will use it."
    elif echo >>/etc/inetd.conf "rpki-rtr	stream	tcp	nowait	rpkirtr	/usr/local/bin/rtr-origin	rtr-origin --server /var/rcynic/rpki-rtr"
    then
        echo "Added rpki-rtr for TCPv4 to /etc/inetd.conf."
    else
        echo "Adding rpki-rtr for TCPv4 to /etc/inetd.conf failed, please fix this, then try again."
        exit 1
    fi
    if /usr/bin/egrep -q "rpki-rtr[ 	]+stream[ 	]+tcp6[ 	]" /etc/inetd.conf
    then
        echo "You already have an inetd.conf entry for rpki-rtr on TCPv6, so I will use it."
    elif echo >>/etc/inetd.conf "rpki-rtr	stream	tcp6	nowait	rpkirtr	/usr/local/bin/rtr-origin	rtr-origin --server /var/rcynic/rpki-rtr"
    then
        echo "Added rpki-rtr for TCPv6 to /etc/inetd.conf."
    else
        echo "Adding rpki-rtr for TCPv6 to /etc/inetd.conf failed, please fix this, then try again."
        exit 1
    fi
    ;;

*)
    echo "No clue what this script is meant to do when invoked with arguments \"$*\".  Punting."
    exit 1
    ;;

esac