blob: 77b3115f209e6b157bfee13f930bc77c11ec6b1c [file] [log] [blame]
Zhiyi Zhang915aa452020-10-17 17:20:58 -07001#!/usr/bin/env bash
2
3echo "What is the CA Prefix (eg. /example) you want to deploy?"
4read CA_PREFIX
5echo ""
6
7echo "Do you want to compile and build NDNCERT? [Y/N]"
8read NDNCERT_COMPILE
9echo ""
10
11case $NDNCERT_COMPILE in
12 N|n)
13 echo "Okay, we'll continue with the setup"
14 ;;
15 Y|y)
16 cd ../ && CXXFLAGS="-O2" ./waf configure
17 ./waf
18 echo "Need sudo to install NDNCERT CLI tools"
19 sudo ./waf install
20 ;;
21 *)
22 echo "Unknown option, build and install is cancelled"
23 exit
24 ;;
25esac
26
27echo "==================================================================="
28echo "=="
29echo "== Deploying NDNCERT"
30echo "=="
31echo "==================================================================="
32echo ""
33echo "Are you sure [Y/n] ?"
34read DEPLOY
35
36case $DEPLOY in
37 N|n)
38 echo "Deployment cancelled"
39 exit
40 ;;
41 Y|y)
42 ;;
43 *)
44 echo "Unknown option, deployment cancelled"
45 exit
46 ;;
47esac
48
49echo ""
50echo "==================================================================="
51echo "=="
52echo "== Deployment started"
53echo "=="
54echo "==================================================================="
55
56echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]"
57echo ""
58read SYSTEMD_INSTALL
59
60case $SYSTEMD_INSTALL in
61 N|n)
62 echo "We will not install systemd CA on this machine"
63 echo ""
64 echo "Successfully finish the deployment of NDNCERT. To run NDNCERT, please use CLI ndncert-ca-server"
65 exit
66 ;;
67 Y|y)
68 echo "Copying NDNCERT-CA systemd service on this machine"
69 sudo cp ../build/systemd/ndncert-ca.service /etc/systemd/system
70 sudo chmod 644 /etc/systemd/system/ndncert-ca.service
71 ;;
72 *)
73 echo "Unknown option, deployment cancelled"
74 exit
75 ;;
76esac
77
78echo "ndncert-ca service requires user ndn. Will check it now :D"
79if id ndn &>/dev/null; then
80 echo 'ndn user account found, GOOD!'
81 echo ""
82else
83 echo 'ndn user not found; adding ndn user as root'
84 echo ""
85 sudo useradd ndn
86fi
87
88echo "ndncert-ca service requires /var/lib/ndncert-ca. Will check or create the keychain in /var/lib/ndncert-ca"
89echo ""
90sudo mkdir -p /var/lib/ndncert-ca
91sudo chown ndn /var/lib/ndncert-ca
92echo '/var/lib/ndncert-ca is ready, GOOD!'
93
94echo "Do you want to import an exisitng safebag for ${CA_PREFIX}? [Y/N]"
95echo ""
96read USE_SAFE_BAG
97
98case $USE_SAFE_BAG in
99 N|n)
100 echo "Generating new NDN identity for ${CA_PREFIX}"
101 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-keygen $CA_PREFIX
102 ;;
103 Y|y)
104 echo "Reading the safebag."
105 echo "What is the safebag file name?"
106 read SAFE_BAG_PATH
107 echo ""
108
109 echo "What is the password of the safebag?"
110 read SAFE_BAG_PWD
111 echo ""
112
113 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-import -i $SAFEBAG_FILE -P $PWD
114 ;;
115 *)
116 echo "Unknown option, deployment cancelled"
117 exit
118 ;;
119esac
120
121echo "Do you want to start the service now? [Y/N]"
122read START_NOW
123case $USE_SAFE_BAG in
124 N|n)
125 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl start ndncert-ca when you want to start the service"
126 exit
127 ;;
128 Y|y)
129 echo "Starting the service ndncert-ca"
130 sudo systemctl start ndncert-ca
131 sleep(2)
132 echo "Reading the status of service ndncert-ca"
133 sudo systemctl status ndncert-ca
134 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl status ndncert-ca when you want to check the status of the service"
135 exit
136 ;;
137 *)
138 echo "Unknown option, deployment cancelled"
139 exit
140 ;;
141esac