3 # Copyright: the ARPA2 project. See LICENSE-USERSPACE.MD
5 # Quickstart: how to get a working instance of tlspool.
7 # The assumption is that you are using a shell environment.
8 # First we check for a few necessary programs.
10 PROGRAMS="nix-env git"
12 for requiredProg in $PROGRAMS
14 command -v $requiredProg >/dev/null && continue || { printf "$requiredProg is not available. Please install."; exit 1; }
17 # If you start with nix you can install git (if you don't have it) from there
18 # with "nix-env -i git".
20 # See: http://nixos.org/nix/manual/#chap-installation).
22 # Alternatively you can install git through your package manager.
23 # If you use a computer platform which doesn't have one, see:
24 # https://git-scm.com/downloads).
26 printf "QUICKSTART.sh from ARPA2 project's TLS Pool here.\n\n"
27 printf "Usage: QUICKSTART.sh /path/you/want subdirectory_name.\n\n"
29 # User can indicate where to install everything by providing the
30 # desired path and subfolder name as an argument to the script. By default
31 # everything is placed in a time-stamped folder located directly under the
32 # current folder or directory.
34 # First we check to see if there are any arguments, then we clean them up.
40 # Clean up trailing slashes etc
43 *[!/]*/) BASEDIR=${x%"${x##*[!/]}"};;
49 WORKINGDIR="$(date --iso-8601)-tlspool-environment";
55 # Ask the user if the settings are okay, and if she or he agrees with proceeding.
57 printf "I'm going to create a subdirectory called $WORKINGDIR in $BASEDIR and install tlspool using nix.\n"
58 printf "You'll get a local copy of ARPA2's nixpkgs for free.\nAre you okay with that (y/n)? "
60 old_stty_cfg=$(stty -g)
61 stty raw -echo ; answer=$(head -c 1) ; stty $old_stty_cfg
62 if printf "$answer" | grep -iq "^y" ;then
63 printf "\nGreat. I'll get to work in $BASEDIR/$WORKINGDIR. Big stuff, might take a while to download.\n"
65 printf "\nGood that you told me. \nIf you change your mind, let me know. \n"
71 # Let's make sure the working directory exists, and go there
73 if [ ! -d "$BASEDIR/$WORKINGDIR" ]; then
74 mkdir "$BASEDIR/$WORKINGDIR"
77 cd "$BASEDIR/$WORKINGDIR"
79 # By keeping the tlspool and nixpkgs repositories inside the same folder we can update
80 # tlspool with a simple "git pull" from the main repository and nix-build command.
82 if [ ! -d "tlspool" ]; then
83 git clone https://github.com/arpa2/tlspool
84 git checkout 49bf1157e3471ee15bc279d41c9492646a2bf44c
87 git pull https://github.com/arpa2/tlspool
88 git checkout 49bf1157e3471ee15bc279d41c9492646a2bf44c
92 if [ ! -d "nixpkgs" ]; then
93 git clone https://github.com/arpa2/nixpkgs
96 git pull https://github.com/arpa2/nixpkgs
100 if [ ! -d "steamworks" ]; then
101 git clone https://github.com/arpa2/steamworks
104 git pull https://github.com/arpa2/steamworks
108 # Go into the nixpkgs folder and switch to the tlspool branch:
111 export NIXPKGS="$BASEDIR/$WORKINGDIR/nixpkgs"
114 # Install tlspool and all the dependencies through nix:
116 nix-env -f "$NIXPKGS" -iA tlspool
120 # NB: for SoftHSM you will need to create a config file
121 CONFIGFILE="$HOME/.config/softhsm2/softhsm2.conf";
123 # This will have the following minimal contents
124 LINE1a="directories.tokendir = ";
125 LINE1b="/path/to/tokendir/";
126 LINE2="objectstore.backend = file";
127 LINE3="log.level = DEBUG";
129 # Does the user already have a SoftHSM2 config file?
131 if [ ! -e "$CONFIGFILE" ];
134 printf "Don't forget to create the config file for SoftHSM2\n"
135 printf "You can create a file named $CONFIGFILE"
136 printf "with the following suggested content:\n"
137 printf "%s\n--------\n";
138 printf "$LINE1a$LINE1b\n$LINE2\n$LINE3\n"
139 printf "%s\n--------\n";
140 printf "After that you can initiate a token with:\n\n"
141 printf "softhsm2-util --init-token --free --label 'TLS_Pool_dev_data'\n\n"
143 printf "Do you want me to create the config file for you, with tokendir pointing to ./$WORKINGDIR/token (y/n)? "
144 stty raw -echo ; answer=$(head -c 1) ; stty $old_stty_cfg
146 if echo "$answer" | grep -iq "^y" ; then
147 # Make sure config directory and token directory exist
148 if [ ! -d "$HOME/.config/softhsm2" ]; then
149 mkdir -p "$HOME/.config/softhsm2"
151 if [ ! -d "$BASEDIR/$WORKINGDIR/token" ]; then
152 mkdir -p "$BASEDIR/$WORKINGDIR/token"
154 # Create the config file and check wether it was created.
155 printf "$LINE1a$BASEDIR/$WORKINGDIR/token\n$LINE2\n$LINE3\n" >> "$CONFIGFILE"
156 if [ -a "$CONFIGFILE" ]; then
157 printf "\nSoftHSMv2 configuration file $CONFIGFILE created.\n"
159 # Now, given that there was no config, surely there will not be a token.
160 # So should we generate it? Let's ask.
161 printf "\nDo you want to generate a token (y/n)?"
162 stty raw -echo ; answer=$(head -c 1) ; stty $old_stty_cfg
163 if echo "$answer" | grep -iq "^y" ; then
164 printf "\nDon't forget to write down your PIN numbers.\n"
165 softhsm2-util --init-token --free --label 'TLS_Pool_dev_data'
168 printf "\nSoftHSM doesn't work without a config file. But you probably already got that.\n"
172 printf "You've already got a config file for SoftHSM2. Great."
175 printf "\n\nYou can now go into the ../tlspool directory and edit files "
176 printf "you want to edit. If you want to rebuild tlspool, just reexecute\n\n"
177 printf "nix-env -f $NIXPKGS -iA tlspool\n\n"
179 UPDATESCRIPT="$BASEDIR/$WORKINGDIR/update-tlspool.sh"
181 if [ ! -e $UPDATESCRIPT ]; then
182 printf "#! /usr/bin/env sh\n\n# Created by QUICKSTART.sh.\n$SHELL $BASEDIR/$WORKINGDIR/tlspool/QUICKSTART.sh '$BASEDIR' '$WORKINGDIR'\n" > $UPDATESCRIPT
183 chmod +x $UPDATESCRIPT;
186 printf "A simple git pull will update either.\n\nOr just copy $UPDATESCRIPT to wherever you want it to be.\n\n"
188 printf "You can run 'tlspool -c configfile'. There is an example config file at "
189 printf "~i/.nix-profile/etc/tlspool/tlspool.conf which you can modify for usage."