Compare commits
4 Commits
f578383b63
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
ead88b2a38
|
|||
|
5c29367857
|
|||
|
1270925d3f
|
|||
|
bd880608c5
|
10
copy-files.sh
Normal file → Executable file
10
copy-files.sh
Normal file → Executable file
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
usage() {
|
||||
echo "Usage: copy-files.sh <file> <output directory>"
|
||||
echo "<file>: file that contains the files to copy, each on a different line"
|
||||
echo "Usage: copy-files.sh <input directory> <output directory>"
|
||||
echo "<input directory>: directory where the files are located"
|
||||
echo "<output directory>: directory where the files are copied to"
|
||||
exit 1
|
||||
}
|
||||
@@ -11,9 +11,7 @@ if [ $# != 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
filename=$1
|
||||
input=$1
|
||||
output=$2
|
||||
|
||||
while read -r p; do
|
||||
cp "$p" "$output"
|
||||
done <"$filename"
|
||||
find "$input" -type f -iregex '.*\.\(pdf\|doc\|docx\|xlsx\|accdb|\mdb\)' -print0 | xargs -0 cp -t "$output"
|
||||
|
||||
39
vpn-client.sh
Executable file
39
vpn-client.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
usage() {
|
||||
echo "Usage: vpn-client.sh <hostname>"
|
||||
echo "hostname: Name of the new host"
|
||||
exit 1
|
||||
}
|
||||
|
||||
get_last_ip() {
|
||||
last_ocurrence=$(grep '10.9.0' "$networking_file" | tail -1)
|
||||
last_digit=$(echo "$last_ocurrence" | cut -d . -f 4 | cut -c 1)
|
||||
}
|
||||
|
||||
generate_certificates() {
|
||||
mkdir "$certificates_directory/$hostname"
|
||||
cd "$certificates_directory/$hostname" || exit
|
||||
wg genkey | tee "$hostname".key | wg pubkey >"$hostname".pub
|
||||
}
|
||||
|
||||
generate_config() {
|
||||
private_key=$(cat "$hostname.key")
|
||||
get_last_ip
|
||||
last_ip=$((last_digit + 1))
|
||||
cd "$config_directory" || exit
|
||||
sed -e "s/private_key_placeholder/$private_key/g" -e "s/ip_placeholder/$last_ip/g" "$config_file" >"$hostname".conf
|
||||
}
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
hostname=$1
|
||||
networking_file="/etc/nixos/modules/networking.nix"
|
||||
certificates_directory="/home/coace/.wg"
|
||||
config_directory="/vault/config/wireguard"
|
||||
config_file="$config_directory/placeholder.conf"
|
||||
|
||||
generate_certificates
|
||||
generate_config
|
||||
Reference in New Issue
Block a user