aboutsummaryrefslogtreecommitdiff
path: root/scripts/setup.sh
blob: 5ca421145b3b173f6e65fc1ef03af12c496a69c2 (plain)
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
#!/bin/sh
set -e

while [ $# -gt 0 ]; do
	case "$1" in
		-h|--help)
			echo "Multiconfig system setup script"
			echo "Usage: setup.sh"
			exit 0
			;;
	esac
	shift
done

# Move to multiconfig root
cd "$(dirname "$(dirname "$(readlink -f "$1")")")"

PREFIX="/root/.multiconfig"

echo "Creating directory $PREFIX"
sudo mkdir -p "$PREFIX"

# Manage new key
echo "Generating new key for this host"
KEY="$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 128 | xargs)"
sudo -- sh -c "echo -n '$KEY' > '$PREFIX/key'"
# TODO setup access rights

echo -n "$KEY" > wkey
FKEY="files/keys/$(hostname)"
echo "Writing key to repository"
gpg2 --decrypt files/keys/primary.gpg | \
	openssl aes-192-cbc -e -a -kfile wkey -out "$FKEY"
rm -f wkey
echo "Don't forget to add key to git!"

# Deploy multiconfig script
sudo cp scripts/multiconfig.sh /usr/local/bin/multiconfig.sh