Zhiyi Zhang | 915aa45 | 2020-10-17 17:20:58 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | echo "What is the CA Prefix (eg. /example) you want to deploy?" |
| 4 | read CA_PREFIX |
| 5 | echo "" |
| 6 | |
| 7 | echo "Do you want to compile and build NDNCERT? [Y/N]" |
| 8 | read NDNCERT_COMPILE |
| 9 | echo "" |
| 10 | |
| 11 | case $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 | ;; |
| 25 | esac |
| 26 | |
| 27 | echo "===================================================================" |
| 28 | echo "==" |
| 29 | echo "== Deploying NDNCERT" |
| 30 | echo "==" |
| 31 | echo "===================================================================" |
| 32 | echo "" |
| 33 | echo "Are you sure [Y/n] ?" |
| 34 | read DEPLOY |
| 35 | |
| 36 | case $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 | ;; |
| 47 | esac |
| 48 | |
| 49 | echo "" |
| 50 | echo "===================================================================" |
| 51 | echo "==" |
| 52 | echo "== Deployment started" |
| 53 | echo "==" |
| 54 | echo "===================================================================" |
| 55 | |
| 56 | echo "Do you want to install ndncert CA for systemd on this machine? [Y/N]" |
| 57 | echo "" |
| 58 | read SYSTEMD_INSTALL |
| 59 | |
| 60 | case $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 | ;; |
| 76 | esac |
| 77 | |
| 78 | echo "ndncert-ca service requires user ndn. Will check it now :D" |
| 79 | if id ndn &>/dev/null; then |
| 80 | echo 'ndn user account found, GOOD!' |
| 81 | echo "" |
| 82 | else |
| 83 | echo 'ndn user not found; adding ndn user as root' |
| 84 | echo "" |
| 85 | sudo useradd ndn |
| 86 | fi |
| 87 | |
| 88 | echo "ndncert-ca service requires /var/lib/ndncert-ca. Will check or create the keychain in /var/lib/ndncert-ca" |
| 89 | echo "" |
| 90 | sudo mkdir -p /var/lib/ndncert-ca |
| 91 | sudo chown ndn /var/lib/ndncert-ca |
| 92 | echo '/var/lib/ndncert-ca is ready, GOOD!' |
| 93 | |
| 94 | echo "Do you want to import an exisitng safebag for ${CA_PREFIX}? [Y/N]" |
| 95 | echo "" |
| 96 | read USE_SAFE_BAG |
| 97 | |
| 98 | case $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 | ;; |
| 119 | esac |
| 120 | |
| 121 | echo "Do you want to start the service now? [Y/N]" |
| 122 | read START_NOW |
| 123 | case $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 | ;; |
| 141 | esac |