Created
October 17, 2019 16:05
-
-
Save rikka0w0/b447070157b906ab8bdf4c194ff0b9b8 to your computer and use it in GitHub Desktop.
A bash script to duplicate a newly installed l4d2 server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# $1 - Return Variable, $2 - input relative path | |
function get_full_path() { | |
local __resultvar=$1 | |
local myresult="$(cd "$(dirname "$2")"; pwd -P)/$(basename "$2")" | |
eval $__resultvar="'$myresult'" | |
} | |
# $1 src, $2 dst, $3 and so on are blacklisted filename | |
function process_dir() { | |
local d='' | |
for d in $1/* ; do | |
local DIRNAME=$(basename $d) | |
local LNSRC=$d | |
local LNDST=$2/$(basename $d) | |
# Check if the item is in the blacklist | |
local i=3 | |
local exec_ln=1; | |
while [ $i -le $# ]; do | |
local not_inc=$(eval "echo \${$i}") | |
if [ $DIRNAME == $not_inc ]; then | |
exec_ln=0 | |
fi | |
((i++)) | |
done | |
local hintstr='' | |
# Create symbolic link if it is not in the blacklist | |
if [ $exec_ln -eq "1" ]; then | |
if [ -d $LNSRC ]; then | |
hintstr='\e[34mLinkD\e[39m: ' | |
else | |
hintstr='LinkF: ' | |
fi | |
ln -s $LNSRC $LNDST | |
elif [ -d $LNSRC ]; then | |
hintstr='\e[93mMKDir\e[39m: ' | |
mkdir $LNDST | |
else | |
hintstr='\e[92mCopy \e[39m: ' | |
cp $LNSRC $2 | |
fi | |
echo -e $hintstr$LNSRC" \e[93m<--->\e[39m "$LNDST | |
done | |
} | |
get_full_path L4D2SRC $1 | |
get_full_path DESTDIR $2 | |
echo 'Source Dir = '"$L4D2SRC" | |
echo 'Dest Dir = '$DESTDIR | |
echo -e "\e[91mProcessing: $L4D2SRC\e[39m" | |
process_dir $L4D2SRC $DESTDIR left4dead2 update | |
echo -e "\e[91mProcessing: $L4D2SRC/update \e[39m" | |
process_dir $L4D2SRC/update $DESTDIR/update | |
echo -e "\e[91mProcessing: $L4D2SRC/left4dead2 \e[39m" | |
process_dir $L4D2SRC/left4dead2 $DESTDIR/left4dead2 addons cfg downloads host.txt mapcycle.txt maplist.txt missioncycle.txt missions.cache modelsounds.cache stats.txt whitelist.cfg motd.txt | |
echo -e "\e[91mCopy Dir: $L4D2SRC/cfg \e[39m" | |
cp -r $L4D2SRC/left4dead2/cfg/* $DESTDIR/left4dead2/cfg/ | |
echo $L4D2SRC/left4dead2/cfg/\*" ==> "$DESTDIR/left4dead2/cfg/\* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment