Temat: Uniwersalne środowisko własne
Stanisław Pitucha:
Hej,
chciałem się dowiedzieć, czy macie jakieś ciekawe własne patenty na $HOME, który jest taki sam na każdym hoście? Nie mówię tutaj o hostach w obrębie firmy, czy innego małego środowiska, gdzie można to zsynchronizować przez nfs, czy inny gfs. Chodzi mi o całkiem niezależne hosty.
Czy robicie coś podobnego? Jeśli tak, to czy pominąłem coś ciekawego co jest w waszych rozwiązaniach?
Hmm.. kiedys jak sie bawilem to napisalem takie 2 skrypty na ustawienie wlasnego environment w home directory. Szukalem czegos co mi stworzy moje przenosne home i jak skoncze prace to bede mogl swoje zmiany wziac ze soba.
Ta wersja jest troche okrojona, bo to jest co napisalem jakies 3 lata temu:
#!/bin/ksh
banner EG - ENV
echo "Ernest Environment Started"
## Vars
#
E='/home/'
F='/.kshrc'
G=$(whoami)
IAP=$E$G$F # Invoked Admin Profile
HOME=$E$G
date
## Checking Who am i
#
# check if in sudoers if user
## Checking permissions of current directory #
#
if [ ! -w $PWD ]; then
echo " Error, you don't have permissions to write to this directory."
echo " Please contact Administrator or change permissions of $PWD."
echo " Operations Aborted.."
exit 1
else
echo "Permissions for current directory............. OK"
fi
## setup ENV - dirs
#
echo " Preparing dirs.."
mkdir ~/EGscripts
mkdir ~/var
mkdir ~/exe
mkdir ~/dat
mkdir ~/bin
mkdir ~/test
mkdir ~/alias
## setup aliases
#
echo " Setting up script with alliases.."
touch ~/alias/EGaliases.ksh
echo "alias h='cd ~'" >> $HOME/alias/EGaliases.ksh
echo "alias show='pwd;ls'" >> $HOME/alias/EGaliases.ksh
echo "alias c='clear'" >> $HOME/alias/EGaliases.ksh
echo "alias d='date'" >> $HOME/alias/EGaliases.ksh
echo "alias lr='ls -R'" >> $HOME/alias/EGaliases.ksh
chmod +x $HOME/alias/EGaliases.ksh
## record profile
#
echo " Recording current profile.."
cat /etc/profile >> $HOME/EGscripts/EGprofile
sleep 2
## check & setup .bashrc file - direct aliases
# for all terminals
#
if [ -f $IAP ]; then
if [ -w $IAP ]; then
echo " bashrc file exists and is ready for Admin updates"
cp $IAP $IAP_`date | awk '{print $1 $2 $3 $6}'`.bkp
## Invoking kshrc file
#
echo "Adding new section to your bash profile file.."
echo " ############# ADMIN ALIASES AND FUNCTIONS ##########" >> $IAP
echo "" >> $IAP
echo " alias p='cd -' >> $IAP
echo " alias ifc='ifconfig' >> $IAP
echo " alias ll='ls -l' >> $IAP
echo " alias vib='sudo vi ~/.bashrc' >> $IAP
echo " alias h='cd ~' >> $IAP
echo " alias c='clear' >> $IAP
echo " pinggoogle='ping -c 3
http://google.com' >> $IAP
echo " quit='sudo init 0' >> $IAP
echo "" >> $IAP
echo "" >> $IAP
echo " datef() {
echo `date` | awk '{ print \$1 \$2 \$3 \$6}'
}" >> $IAP
echo "showips() {
ifconfig | grep encap | awk '{print \$1}' | uniq -u | grep -v \"encap\" >> file1dev.txt;ifconfig | grep \"inet addr\" | awk -F: '{print \$2}' | awk '{print \$1}' >> file1ips.txt;paste file1dev.txt file1ips.txt > listdevips.txt;rm -rf file1ips.txt file1dev.txt;cat listdevips.txt
}" >> $IAP
echo " killfirefox() {
sudo kill `ps -ax |grep \"firefox\"| awk '{print $1}'|head -n 2| head -n 1`
}" >> $IAP
echo "terminals() {
gnome-terminal --geometry=87x21 |gnome-terminal --geometry=87x21 |gnome-terminal --geometry=87x21 |gnome-terminal --geometry=87x21
}" >> $IAP
## terminal cmd will work if font is Monospace 9 ##
echo "looplist() {
echo \"Provide directory: \"
read directory
TEXT1=\"Long list for files in $directory\"
while : ;do date; echo $TEXT1; ls -l $directory; sleep 4; clear;done
}" >> $IAP
echo "pingh() {
echo \"type ip or hostname: \"
read ip
ping -c 3 $ip
}" >> $IAP
echo " checkversion() {
if [ -f /etc/debian_version ]; then
echo \"Version from debian_version file:\"
cat /etc/debian_version
echo \"-----------------------------------\"
else
echo \" Info from lsb_release\"
lsb_release
fi
echo \"-----------------------------------\"
echo \"Info from /etc/issue file: \"
cat /etc/issue
echo \"-----------------------------------\"
echo \"Info from /etc/*-release:\"
cat /etc/*-release
}" >> $IAP
echo " showfunctions() {
cat ~/.bashrc | grep \"()\" |grep -v \"grep\" | awk '{print $1}'
}" >> $IAP
echo "setupip() {
printf \"Provide interface: \"
read int
printf \"Provide ip address: \"
read ipad
printf \"Provide netmask: \"
read mask
printf \"Provide broadcast: \"
read broad
/sbin/ifconfig $int $ipad netmask $mask broadcast $broad
}" >> $IAP
## PUT MORE FUNCTIONS/ALIASES HERE AS NEEDED ##
echo " set -o vi" >> $IAP
"Profile file exist but you can't write to it"
fi
else
echo " bashrc does not exist"
echo " commands will be saved only to current session"
echo " and to your alias files"
fi
## MESSAGES
#
echo "Modify your alias/EGaliases.ksh script !!! & run it with . ./"
sleep 2
echo "You are in: "
pwd
sleep 1
echo "This is list of the files in current directory: "
ls
----------------------------------------------------------------- done.ksh
#!/bin/ksh
banner EG-ENV SAVE
echo "Ernest Environment is saving all files"
## Vars
#
E='/home/'
F='/.kshrc'
G=$(whoami)
IAP=$E$G$F # Invoked Admin Profile
HOME=$E$G
## Cleanup files and directories
#
# Add functions to ask if there are Admin files in other dirs then
# $HOME or different dirs
#
tar cvf EnvEG.tar $HOME/*
echo .;sleep 1; echo ..;sleep 1;echo ...;
echo "File EnvEG.tar created/updated succesfully !!! "
sleep 3
## Cleanup Aliases/Functions, Cleanup bash profile
#
touch $HOME/removealiases.ksh
echo "Removing aliases..."
unalias "d"
unalias "show"
unalias "c"
unalias "h"
unalias "lr"
sleep 1
echo "Done"
banner EG-ENV STOP
echo "Ernest Environment is deleting all files from Home directory"
date
echo .; echo . ; echo .;echo ..;echo ...;sleep 1;
rm -rf bin exe var alias dat test EGscripts
echo "Done"
sleep 1
echo "Thank you, for using EG-ENV "
banner BYE
pwd;ls