Commit ebb47093 authored by HgO's avatar HgO
Browse files

create neutrinet.cube with jq --arg to escape special chars

parent 22a20ecb
The script `./faire_un_point_cube.sh` generates a `neutrinet.cube` file that is required to install a Internet Cube with a VPN connection provided by Neutrinet.
## Requirements
You need the following tools to run this script:
- jq
- tree
You will need your VPN credentials, your VPN client key and the VPN certificates which you can download from https://user.neutrinet.be
## Usage
```bash
./faire_un_point_cube.sh
```
The script will look for the VPN credentials, the VPN client key and the VPN certificates.
In addition, the script will display which files couldn't be found. Make sure you correctly named the files, otherwise the `neutrinet.cube` file won't be generated.
The `neutrinet.cube` file can then be used to install your Internet Cube.
......@@ -55,7 +55,7 @@ do
else
echo "fichier $candidat trouvé, il sera utilisé pour le .cube"
ca_crt=$(<$candidat)
ca_crt="${ca_crt//$'\n'/\\|}"
ca_crt="${ca_crt//$'\n'/\|}"
((count--))
fi
done
......@@ -71,7 +71,7 @@ do
else
echo "fichier $candidat trouvé, il sera utilisé pour le .cube"
client_crt=$(<$candidat)
client_crt="${client_crt//$'\n'/\\|}"
client_crt="${client_crt//$'\n'/\|}"
((count--))
fi
done
......@@ -86,25 +86,25 @@ do
else
echo "fichier $candidat trouvé, il sera utilisé pour le .cube"
client_key=$(<$candidat)
client_key="${client_key//$'\n'/\\|}"
client_key="${client_key//$'\n'/\|}"
((count--))
fi
done
# Modèle pour le fichier neutrinet.cube
cat > neutrinet.cube << EOF
cube_template=$(cat << "EOF"
{
"server_name": "vpn.neutrinet.be",
"server_port": "1195",
"server_proto": "udp",
"ip6_net": "",
"ip4_addr": "",
"crt_server_ca": "CA-SERVER-CRT",
"crt_client": "CLIENT-CRT",
"crt_client_key": "CLIENT-KEY",
"crt_server_ca": $CA_SERVER_CRT,
"crt_client": $CLIENT_CRT,
"crt_client_key": $CLIENT_KEY,
"crt_client_ta": "",
"login_user": "VPN-LOGIN",
"login_passphrase": "VPN-PASS",
"login_user": $VPN_LOGIN,
"login_passphrase": $VPN_PASS,
"dns0": "89.234.141.66",
"dns1": "2001:913::8",
"openvpn_rm": [
......@@ -119,16 +119,18 @@ cat > neutrinet.cube << EOF
]
}
EOF
)
# Remplacement des éléments du modèle par les informations trouvées dans les fichiers
if [ ! $count -eq 0 ]; then
echo "Il manque au moins $count fichier(s) !"
else
sed -i "s/VPN-LOGIN/$vpn_login/g" neutrinet.cube
sed -i "s/VPN-PASS/$vpn_pass/g" neutrinet.cube
sed -i "s~\"CA-SERVER-CRT\"~\"$ca_crt\"~" neutrinet.cube
sed -i "s~\"CLIENT-CRT\"~\"$client_crt\"~" neutrinet.cube
sed -i "s~\"CLIENT-KEY\"~\"$client_key\"~" neutrinet.cube
jq -n "$cube_template" \
--arg VPN_LOGIN "$vpn_login" \
--arg VPN_PASS "$vpn_pass" \
--arg CA_SERVER_CRT "$ca_crt" \
--arg CLIENT_CRT "$client_crt" \
--arg CLIENT_KEY "$client_key" > neutrinet.cube
echo "Le fichier neutrinet.cube est prêt !"
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment