@Lee-Rowlett Thanks for the base scripts and ideas behind them.
@Tom-Elliott Thanks for helping me adjusting them for my needs.
@Junkhacker Thanks for the fog log script, you dont know how many time I have forgotten to delete the damn fog.log
Here are the scripts that @Tom-Elliott helped me with.
fog.postdownload:
#!/bin/bash
. /usr/share/fog/lib/funcs.sh
[[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
case $osid in
5|6|7|9)
clear
[[ ! -d /ntfs ]] && mkdir -p /ntfs
getHardDisk
if [[ -z $hd ]]; then
handleError "Could not find hdd to use"
fi
getPartitions $hd
for part in $parts; do
true
done
dots "Mounting partition $part"
ntfs-3g -o force,rw $part /ntfs >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Failed"
debugPause
handleError "Failed to mount $part ($0)\n Args: $*"
fi
echo "Done"
debugPause
. ${postdownpath}fog.log
. ${postdownpath}fog.drivers
. ${postdownpath}fog.ad
umount /ntfs
;;
*)
echo "Invalid OS"
debugPause
return
;;
esac
fog.ad :
#!/bin/bash
hostadpwd="ADPASSWDHERRE"; #only downside to this method- this is the plain ad password
unattend="/ntfs/Windows/Panther/unattend.xml";
[[ ! -f $unattend ]] && return
dots "Preparing Sysprep File"
rm -f /ntfs/Windows/System32/sysprep/unattend.xml >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Failed"
debugPause
handleError "Failed to remove original unattend file"
fi
echo "Done"
debugPause
dots "Writing Computer Name"
sed -i "/ComputerName/s/*/$hostname/g" $unattend >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Failed"
debugPause
handleError "Failed to update originating unattend file"
fi
echo "Done"
echo "ComputerName set to $hostname"
debugPause
[[ -z $addomain ]] && return
dots "Set PC to join the domain"
sed -i "/<JoinWorkgroup>/d" $unattend >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Failed"
debugPause
handleError "Failed to remove the Workgroup setter"
fi
sed -i \
-e "s|<Password></Password>|<Password>${hostadpwd}</Password>|g" \
-e "s|<Username></Username>|<Username>${addomain}\\\\${aduser}</Username>|g" \
-e "s|<MachineObjectOU></MachineObjectOU>|<MachineObjectOU>${adou}</MachineObjectOU>|g" \
-e "s|<JoinDomain></JoinDomain>|<JoinDomain>${addomain}</JoinDomain>|g" $unattend >/dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
echo "Failed"
debugPause
handleError "Failed to update user, pass, ou, and domain setter"
fi
echo "Done"
debugPause
fog.drivers:
For some reason Lenovo doesn’t play like most PC manufactures. I had to use the dmidecode variable of system-version to populate what the actual model of the PC was, with system-product-name it was returning the numerical machine type or serial number?
#!/bin/bash
ceol=`tput el`;
manu=`dmidecode -s system-manufacturer`;
case $manu in
[Ll][Ee][Nn][Oo][Vv][Oo])
machine=$(dmidecode -s system-version)
;;
*[Dd][Ee][Ll][Ll]*)
machine=$(dmidecode -s system-product-name) #pruduct is typo, just realized sorry :(
;;
*)
machine=$(dmidecode -s system-product-name) # Technically, we can remove the dell one as it's the "default"
;;
esac
[[ -z $machine ]] && return #assuming you want it to break if it is not lenovo or dell?
machine="${machine%"${machine##*[![:space:]]}"}" #Removes Trailing Spaces
system64="/ntfs/Windows/SysWOW64/regedit.exe" # sloppy detect if 64bit or not
[[ ! -f $system64 ]] && setarch="x86" || setarch="x64"
#############################################
#this is not section necessary needed, it's just to make the path "human readable"
#rather than using osid for filepath
case $osid in
5) osn="Win7" ;;
6) osn="Win8" ;;
7) osn="Win8.1" ;;
9) osn="Win10" ;;
esac
#############################################
dots "Preparing Drivers"
# below creates local folder on imaged pc
# this can be anywhere you want just remember
# to make sure it matches throughout!
clientdriverpath="/ntfs/Windows/DRV"
remotedriverpath="/images/drivers/$osn/$machine"
[[ ! -d $clientdriverpath ]] && mkdir -p "$clientdriverpath" >/dev/null 2>&1
echo -n "In Progress"
#there's 3 ways you could handle this,
#driver cab file, extracted driver files or both
#so on the server put extracted driver files to match below folder tree
#i.e. Model Latitude E5410, Windows 7 x86 image would be:
#/fog/Drivers/Win7/Latitude E5410/x86
rsync -aqz "$remotedriverpath" "$clientdriverpath" >/dev/null 2>&1
[[ ! $? -eq 0 ]] && handleError "Failed to download driver information"
#if you wanted to use driver.cab use this line below.
#i.e. /fog/Drivers/Win7/Latitude E5410/E5410-Win7-A07-KTT4G.CAB
#cabextract -d "$clientdriverpath" "$remotedriverpath/*.CAB" >/dev/null 2>&1
#if you wanted to mix both cab and extracted use these:
#rsync -aqz --exclude='*.CAB' "$remotedriverpath" "$clientdriverpath" >/dev/null 2>&1
#[[ ! $? -eq 0 ]] && handleError "Failed to sync cab and non-cab drivers"
#cabextract -d "$clientdriverpath" "$remotedriverpath/*.CAB" >/dev/null 2>&1
#[[ ! $? -eq 0 ]] && handleError "Failed to extract cab files"
#this next bit adds driver location on pc to devicepath in registry (so sysprep uses it to reference)
# remember to make devicepath= match the path you've used locally
#also do not remove %SystemRoot%\inf
#and to add more locations just use ; in between each location
regfile="/ntfs/Windows/System32/config/SOFTWARE"
key="\Microsoft\Windows\CurrentVersion\DevicePath"
devpath="%SystemRoot%\inf;%SystemRoot%\DRV";
reged -e "$regfile" &>/dev/null <<EOFREG
ed $key
$devpath
q
y
EOFREG
echo -e "\b\b\b\b\b\b\b\b\b\b\b${ceol}Done"; # this just removes "In Progress and replaces it with done :-)"
fog.log:
#!/bin/bash
#deletes fog.log for Windows 7, 8, or 8.1 or 10
#Greg Grammon (Junkhacker)
#
#funcs.sh allows us to use the functions that are used in the rest of
#fog i.e. "dots" and use the vars already in place i.e. "$part" and "$osid"
. /usr/share/fog/lib/funcs.sh;
case $osid in
[5-7]|9)
[[ -f /ntfs/fog.log ]] && rm /ntfs/fog.log >/dev/null 2>&1 || true
if [[ ! $? -eq 0 ]]; then
echo "Failed"
debugPause
handleError "Failed to remove original fog.log file"
fi
;;
*) return ;;
esac
Thanks For all the Help Tom and Lee