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

112 lines
2.8 KiB
Bash
Raw Normal View History

2023-04-07 06:56:31 +00:00
#!/bin/bash
2023-04-13 11:32:21 +00:00
echo "Parametry podane do skryptu: $@"
2023-04-07 06:56:31 +00:00
2023-04-13 10:54:28 +00:00
kitcrypto_version="0.0.3"
2023-04-25 09:10:31 +00:00
uvpn3_version="3.0.4"
2023-04-07 06:56:31 +00:00
2023-04-25 09:01:37 +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>] [-o <config for msmtp>] [-p <vpn ipaddress>] [-s <scripts folder>]" 1>&2; exit 1; }
2023-04-13 10:54:28 +00:00
2023-04-25 09:01:37 +00:00
while getopts "a:b:c:d:e:i:k:l:m:n:o:p:s:" option
2023-04-13 10:54:28 +00:00
do
2023-04-07 06:56:31 +00:00
case "${option}"
in
2023-04-13 11:32:21 +00:00
a)akeys=${OPTARG};;
b)build="yes";;
c)conf=${OPTARG};;
d)sshconf=${OPTARG};;
i)ini=${OPTARG};;
k)key=${OPTARG};;
l)keylen=${OPTARG};;
m)msmtp=${OPTARG};;
n)name=${OPTARG};;
o)msmtp_conf=${OPTARG};;
2023-04-19 11:46:25 +00:00
p)ip=${OPTARG};;
2023-04-25 09:01:37 +00:00
s)scripts=${OPTARG};;
2023-04-13 11:32:21 +00:00
*)usage;;
2023-04-07 06:56:31 +00:00
esac
done
shift $((OPTIND-1))
CONFIGS=$(pwd)
echo "${CONFIGS}"
2023-04-20 14:29:01 +00:00
squashfs
2023-04-13 12:02:32 +00:00
#sudo apt update
#sudo apt install cmake make g++ gcc libssl-dev libgmp-dev
2023-04-07 06:56:31 +00:00
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
2023-04-13 11:48:59 +00:00
head -2 /tmp/output/vpn/uVPN.priv > /tmp/output/vpn/"$name.pub"
if [ -n "$build" ]; then
mv uVPN3 /tmp/output/vpn
fi
cd $CONFIGS
cp $conf /tmp/output/vpn
cp $ini /tmp/output/vpn
cp $key /tmp/output/vpn
if [ -n "$akeys" ]; then
cp $akeys /tmp/output/ssh
2023-04-13 11:48:59 +00:00
fi
if [ -n "$sshconf" ]; then
cp $sshconf /tmp/output/ssh
2023-04-13 11:48:59 +00:00
fi
mkdir /tmp/output/msmtp
if [ -n "$msmtp" ]; then
cp $msmtp /tmp/output/msmtp
fi
if [ -n "$msmtp_conf" ]; then
cp $msmtp_conf /tmp/output/msmtp
2023-04-13 11:48:59 +00:00
fi
2023-04-25 09:01:37 +00:00
if [ -n "$scripts" ]; then
2023-04-25 09:06:13 +00:00
cp -r $scripts /tmp/output/vpn
2023-04-25 09:01:37 +00:00
fi
2023-04-19 11:46:25 +00:00
2023-04-25 09:25:41 +00:00
sed -i 's/ip/'$ip'/g' starttap.sh
2023-04-19 11:46:25 +00:00
sed -i '/^private_key/c\private_key uVPN.priv' /tmp/output/vpn/$(basename "$conf")
sed -i '/^tap_name/c\tap_name uvpnT2' /tmp/output/vpn/$(basename "$conf")
2023-04-13 11:48:59 +00:00
sed -i '/^name/c\name '"$name" /tmp/output/vpn/$(basename "$conf")
sed -i '/^servers_config/c\servers_config '"$(basename "$ini")" /tmp/output/vpn/$(basename "$conf")
sed -i '1s/.*/['"$name"']/' /tmp/output/vpn/$(basename "$ini")
cd /tmp/output
mkdir configs
mv * configs
2023-04-13 11:51:32 +00:00
mkdir "$CONFIGS/squash"
2023-04-13 11:52:52 +00:00
mksquashfs . $CONFIGS/squash/"$name.squashfs"
cp /tmp/output/configs/vpn/"$name.pub" $CONFIGS/squash/"$name.pub"
2023-04-13 11:48:59 +00:00
echo "$name"
rm -rf /tmp/kit-crypto
rm -rf /tmp/uVPN*
rm -rf /tmp/output