Skripta za linkat datoteke in mape iz ene lokacije na drugo.

t3ch Član
uredil/-a 27. November, 2009 v Programiranje
Skripta ki linka datoteke iz lokacije na lokacijo. Meni je uporabna pri installiranju sourcev na druge lokacije torej z drugacnim --prefix om. Npr.: Ti installas ffmpeg:

# mkdir /home/user/ffmpeg
# ./configure --prefix=/home/user/ffmpeg
# make
# make install
# cd /home/user/ffmpeg
# ./skripta --link $(pwd)/bin /usr/bin

To bo linkalo vse binarne datoteke iz lokaciji /home/user/ffmpeg/bin na lokacijo /usr/bin/...
( to ponovis z direktoriji /lib, /share, /sbin, itd... )

Lahko tudi unlinkas z --unlink argumentom. Če se radi igrate s kompajlanjem sourcov bo vam mogoče prisla prav.

Skripta:

#!/bin/bash
##############################################
# Script for linking files and directories
# from one location to other.
# by m5itteam at gmail.com
##############################################

CHKERROR=0;

FROM=\"\";
TO=\"\";
ARGC=$#; # Number of 'ARGV' in $@

function usage {
echo
echo \"# Usage: \"
echo \"# Example for linking.\"
echo \"$1 --link /home/user/php-install/lib /usr/lib/php\"
echo \"# Example for unlinking.\"
echo \"$1 --unlink /home/user/php-install/lib /usr/lib/php\"
}
######################## MAIN ###########################
if [[ ARGC -eq 3 ]]; then
FROM=$2;
TO=$3;

if [ ! -d $FROM ]; then # Checking if directory missing
echo \"ERROR Directory $FROM missing!\"
usage $0
exit;
fi
if [ ! -d $TO ]; then # Checking if directory missing
echo \"ERROR Directory $TO missing!\"
usage $0
exit
fi

LCHAR=${FROM#${FROM%?}}; # Get last char of string
if [ $LCHAR != '/' ]; then
FROM=\"$FROM/\";
fi
LCHAR=${TO#${TO%?}}; # Get last char of string
if [ $LCHAR != '/' ]; then
TO=\"$TO/\";
fi

if [ $1 = \"--link\" ]; then
for FileName in `dir -d $FROM*`; do
echo \"Link ${FileName} => $TO\";
ln -sf $FileName $TO
done
exit
fi

if [ $1 = \"--unlink\" ]; then
for FileName in `dir -d $FROM*`; do
FileName=$(basename $FileName)
UnlinkPath=$TO$FileName
echo \"Unlink $UnlinkPath\"
rm $UnlinkPath
done
exit
fi

usage $0
exit
else
usage $0
exit
fi
######################## END ############################


lp
Za komentiranje se prijavite ali pa se vpišite.