Você poderia usar o comando source
, colocar os comandos criar arquivo de opções em linha de fluxo em um arquivo separado, e fonte no script principal quando todos os as variáveis utilizadas foram atribuídas,
# USER.ovpn
### create stream-lined option file ###
cat > $OVPN/$USER.ovpn <<EOF
client
;dev tap
dev tun
;proto tcp
proto udp
remote SERVER 1194
remote SERVER 1194
remote-random
resolv-retry infinite
nobind
;user nobody
;group nogroup
persist-key
persist-tun
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
;mute-replay-warnings
ca ca.crt
cert $USER.crt
key $USER.key
ns-cert-type server
;tls-auth ta.key 1
;cipher x
comp-lzo
verb 3
;mute 20
<ca>
$BASECA
</ca>
<cert>
$BASECRT
</cert>
<key>
$BASEKEY
</key>
EOF
Seu script principal poderia ser feito,
#!/bin/bash
### Set PATH ###
BACKUP=/var/BACKUPS
OVPN=/etc/openvpn/
CA=/etc/openvpn/ca.crt
RSA=/etc/openvpn/easy-rsa
KEYS=/etc/openvpn/easy-rsa/keys
HTML=/var/dir/for/user/dl
### Move to working directory ###
cd $RSA
### Trial/30 day/90 day/365 day ###
PS3='What kind of subscriber is being created?: '
options=("7 Day Trial" "30 Day Subscriber" "90 Day Subscriber" "1 Year Subscriber" "Quit")
select opt in "${options[@]}"
do
case $opt in
"7 Day Trial")
echo -e "You have selected 7 day trial.\nUsing vars7."
source ./vars7
break
;;
"30 Day Subscriber")
echo -e "You have selected 30 day subscriber.\nUsing vars30."
source ./vars30
break
;;
"90 Day Subscriber")
echo -e "You have selected 90 day subscriber.\nUsing vars90."
source ./vars90
break
;;
"1 Year Subscriber")
echo -e "You have selected 1 year subscriber.\nUsing vars365."
source ./vars365
break
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
### Catch input for user and build/sign keys and certificates ###
echo "Please enter the user's name:"
read USER
echo "Starting process now..."
./build-key $USER
### Set new PATHs ###
BASECRT=$(sed -n 68,97p $KEYS/$USER.crt)
BASECA=$(cat $CA)
BASEKEY=$(cat $KEYS/$USER.key)
### create stream-lined option file ###
source USER.ovpn # ". USER.ovpn" also works
### Make Directories needed ###
mkdir $HTML/$USER
mkdir $BACKUP/$USER
mkdir $HTML/$USER/keys
### Store Backups ###
cp $KEYS/$USER.* $BACKUP/$USER
cp $OVPN/$USER.ovpn $BACKUP/$USER
tar -czvf $BACKUP/$USER.tar.gz $BACKUP/$USER
### Move keys and options to user's directory for download ###
cp $KEYS/$USER.* $HTML/$USER/keys
cp $OVPN/$USER.ovpn $HTML/$USER
cp $CA $HTML/$USER/keys
chmod 755 $HTML/$USER/*
I had used cat > $OVPN/$USER.ovpn