Zdalne-systemy-z-kit-uVPN/configs/create.sh

102 lines
2.4 KiB
Bash
Raw Normal View History

2023-04-07 06:56:31 +00:00
#!/bin/bash
2023-04-13 10:54:28 +00:00
kitcrypto_version="0.0.3"
uvpn3_version="3.0.3"
2023-04-07 06:56:31 +00:00
2023-04-13 10:54:28 +00:00
usage() { echo "Usage: [-a <root ssh authorized_keys>] [-b add executable to output] [-c <conf file>] [-d <sshd_config>] [-i <ini config>] [-k <pub server key>] [-l <priv key lenght>] [-m <msmtp script>] [-n <name>] [-s <dir with scripts>]" 1>&2; exit 1; }
while getopts "a:b:c:d:e:i:k:l:m:n:s:" option
do
2023-04-07 06:56:31 +00:00
case "${option}"
in
2023-04-13 10:54:28 +00:00
a)akeys=${OPTARG};;
b)build="yes";;
c)conf=${OPTARG};;
d)sshconf=${OPTARG};;
2023-04-07 06:56:31 +00:00
i)ini=${OPTARG};;
k)key=${OPTARG};;
l)keylen=${OPTARG};;
2023-04-13 10:54:28 +00:00
m)msmtp=${OPTARG};;
2023-04-07 06:56:31 +00:00
n)name=${OPTARG};;
s)scripts=${OPTARG};;
*)usage;;
esac
done
shift $((OPTIND-1))
CONFIGS=$(pwd)
echo "${CONFIGS}"
2023-04-13 10:54:28 +00:00
2023-04-07 06:56:31 +00:00
sudo apt update
sudo apt install cmake make g++ gcc libssl-dev libgmp-dev
cd /tmp
2023-04-13 10:54:28 +00:00
wget -O uVPN.tar.xz https://opensource.krypto-it.pl/uVPN/uVPN-$uvpn3_version.tar.xz
2023-04-07 06:56:31 +00:00
mkdir uVPN
tar -xvf uVPN.tar.xz -C uVPN
rm uVPN.tar.xz
mv uVPN/*/* uVPN/
2023-04-13 10:54:28 +00:00
wget -O kit-crypto.tar.xz https://opensource.krypto-it.pl/kit-crypto-c/kit-crypto-c-$kitcrypto_version.tar.xz
2023-04-07 06:56:31 +00:00
mkdir kit-crypto
tar -xvf kit-crypto.tar.xz -C kit-crypto
rm kit-crypto.tar.xz
mv kit-crypto/*/* kit-crypto/
cd kit-crypto
cmake .
make
mkdir ../uVPN.bin
cd ../uVPN.bin
cmake ../uVPN -DKIT_CRYPTO_INCLUDES=/tmp/kit-crypto/include -DKIT_CRYPTO_LIB=/tmp/kit-crypto/libkitcryptoc_static.a
make
mkdir /tmp/output
2023-04-13 10:54:28 +00:00
mkdir /tmp/output/vpn
mkdir /tmp/output/ssh
./uVPN_rsagen $keylen > /tmp/output/vpn/uVPN.priv
head -2 /tmp/output/vpn/uVPN.priv > /tmp/output/vpn/$name.pub
if [ -n "$build" ]; then
mv uVPN3 /tmp/output/vpn
fi
2023-04-07 06:56:31 +00:00
cd $CONFIGS
2023-04-13 10:54:28 +00:00
cp $conf /tmp/output/vpn
cp $ini /tmp/output/vpn
cp $key /tmp/output/vpn
2023-04-07 07:46:07 +00:00
if [ -n "$scripts" ]; then
2023-04-13 10:54:28 +00:00
cp -r $scripts /tmp/output/vpn
fi
if [ -n "$akeys" ]; then
cp $akeys /tmp/output/ssh
2023-04-07 06:56:31 +00:00
fi
2023-04-13 10:54:28 +00:00
if [ -n "$sshconf" ]; then
cp $sshconf /tmp/output/ssh
fi
mkdir /tmp/output/msmtp
if [ -n "$msmtp" ]; then
cp $msmtp /tmp/output/msmtp
fi
sed -i '/^private_key/c\private_key uVPN.priv' /tmp/output/vpn/$conf
sed -i '/^name/c\name '"$name" /tmp/output/vpn/$conf
sed -i '/^servers_config/c\servers_config '"$ini" /tmp/output/vpn/$conf
sed -i '1s/.*/['"$name"']/' /tmp/output/vpn/$ini
2023-04-07 06:56:31 +00:00
cd /tmp/output
2023-04-13 10:54:28 +00:00
mkdir configs
mv * configs
2023-04-07 07:46:07 +00:00
mkdir -t $CONFIGS/squash
mkdir -t $CONFIGS/squash/$name
2023-04-07 06:56:31 +00:00
mksquashfs . $CONFIGS/squash/$name.squashfs
2023-04-13 10:54:28 +00:00
cp /tmp/output/configs/vpn/$name.pub $CONFIGS/squash/$name.pub
2023-04-07 06:56:31 +00:00
rm -rf /tmp/kit-crypto
rm -rf /tmp/uVPN*
rm -rf /tmp/output