blob: 9477af2e7cac2df02654103ce2862e231cd33ebc [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
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -07007echo "Do you want to (re) compile and build NDNCERT? [Y/N]"
Zhiyi Zhang915aa452020-10-17 17:20:58 -07008read NDNCERT_COMPILE
9echo ""
10
11case $NDNCERT_COMPILE in
12 N|n)
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070013 echo "Okay, we'll skip compilation and build."
Zhiyi Zhang915aa452020-10-17 17:20:58 -070014 ;;
15 Y|y)
16 cd ../ && CXXFLAGS="-O2" ./waf configure
17 ./waf
Zhiyi Zhang915aa452020-10-17 17:20:58 -070018 ;;
19 *)
20 echo "Unknown option, build and install is cancelled"
21 exit
22 ;;
23esac
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070024echo "Need sudo to install NDNCERT CLI tools"
25sudo ./waf install
26echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -070027
28echo "==================================================================="
29echo "=="
30echo "== Deploying NDNCERT"
31echo "=="
32echo "==================================================================="
33echo ""
34echo "Are you sure [Y/n] ?"
35read DEPLOY
36
37case $DEPLOY in
38 N|n)
39 echo "Deployment cancelled"
40 exit
41 ;;
42 Y|y)
43 ;;
44 *)
45 echo "Unknown option, deployment cancelled"
46 exit
47 ;;
48esac
49
50echo ""
51echo "==================================================================="
52echo "=="
53echo "== Deployment started"
54echo "=="
55echo "==================================================================="
56
57echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070058read SYSTEMD_INSTALL
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070059echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -070060
61case $SYSTEMD_INSTALL in
62 N|n)
63 echo "We will not install systemd CA on this machine"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070064 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"
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070069 sudo cp $(pwd)/../build/systemd/ndncert-ca.service /etc/systemd/system
Zhiyi Zhang915aa452020-10-17 17:20:58 -070070 sudo chmod 644 /etc/systemd/system/ndncert-ca.service
71 ;;
72 *)
73 echo "Unknown option, deployment cancelled"
74 exit
75 ;;
76esac
77
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070078echo ""
Zhiyi Zhang915aa452020-10-17 17:20:58 -070079echo "ndncert-ca service requires user ndn. Will check it now :D"
80if id ndn &>/dev/null; then
81 echo 'ndn user account found, GOOD!'
Zhiyi Zhang915aa452020-10-17 17:20:58 -070082else
83 echo 'ndn user not found; adding ndn user as root'
Zhiyi Zhang915aa452020-10-17 17:20:58 -070084 sudo useradd ndn
85fi
86
Zhiyi Zhang915aa452020-10-17 17:20:58 -070087echo ""
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070088echo "ndncert-ca service requires /var/lib/ndncert-ca. Will check or create the keychain in /var/lib/ndncert-ca"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070089sudo mkdir -p /var/lib/ndncert-ca
90sudo chown ndn /var/lib/ndncert-ca
91echo '/var/lib/ndncert-ca is ready, GOOD!'
92
Zhiyi Zhang915aa452020-10-17 17:20:58 -070093echo ""
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -070094echo "Do you want to import an exisitng safebag for ${CA_PREFIX}? [Y/N]"
Zhiyi Zhang915aa452020-10-17 17:20:58 -070095read USE_SAFE_BAG
96
97case $USE_SAFE_BAG in
98 N|n)
99 echo "Generating new NDN identity for ${CA_PREFIX}"
100 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-keygen $CA_PREFIX
101 ;;
102 Y|y)
103 echo "Reading the safebag."
104 echo "What is the safebag file name?"
105 read SAFE_BAG_PATH
106 echo ""
107
108 echo "What is the password of the safebag?"
109 read SAFE_BAG_PWD
110 echo ""
111
112 sudo HOME=/var/lib/ndncert-ca -u ndn ndnsec-import -i $SAFEBAG_FILE -P $PWD
113 ;;
114 *)
115 echo "Unknown option, deployment cancelled"
116 exit
117 ;;
118esac
119
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700120echo "Load the new configuration file for the CA"
121echo -e "{\n\"ca-prefix\": \"${CA_PREFIX}\",\n\"ca-info\": \"NDNCERT CA for ${CA_PREFIX}\",\n\"max-validity-period\": \"1296000\",\n\"max-suffix-length\": \"2\",\n\"supported-challenges\":\n[\n{ \"challenge\": \"pin\" }\n]\n}" > /usr/local/etc/ndncert/ca.conf
122echo ""
123
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700124echo "Do you want to start the service now? [Y/N]"
125read START_NOW
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700126case $START_NOW in
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700127 N|n)
128 echo "Successfully finish the deployment of NDNCERT. You can run sudo systemctl start ndncert-ca when you want to start the service"
129 exit
130 ;;
131 Y|y)
132 echo "Starting the service ndncert-ca"
133 sudo systemctl start ndncert-ca
Zhiyi Zhangc318a7a2020-10-17 17:41:19 -0700134 sleep 2
Zhiyi Zhang915aa452020-10-17 17:20:58 -0700135 echo "Reading the status of service ndncert-ca"
136 sudo systemctl status ndncert-ca
137 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"
138 exit
139 ;;
140 *)
141 echo "Unknown option, deployment cancelled"
142 exit
143 ;;
144esac