MySql PHP Queries Cheat Sheet

Create Database

CREATE DATABASE `newdatabase` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

Grand Privileges

GRANT ALL PRIVILEGES ON `newdatabase`.* TO 'someone'@'localhost' WITH GRANT OPTION;

Connect to MySql

$con = new mysqli(host, user, password, newdatabase);
if ($con->connect_errno) {
    error_log('Failed to connect to MySQL: ['.$con->connect_errno.'] '.$con->connect_error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$con->set_charset("utf8")) {
    error_log('Mysql loading character set utf8: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
mysqli_close($con);

Drop Tables

$sql = 'DROP TABLE IF EXISTS `mytable`, `mytable2`';
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
$stmt->close();

Create Table

$sql = 'CREATE TABLE IF NOT EXISTS `mytable` (
    `Id` int unsigned AUTO_INCREMENT,
    `SomeInt` mediumint unsigned DEFAULT 0,
    `SomeFloat` decimal(5,2) DEFAULT 0,
    `SomeName` varchar(64) DEFAULT NULL,
    PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=1;';
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
$stmt->close();

Select Data

$sql = "SELECT `SomeInt`, `SomeFloat`, `SomeName` FROM `mytable` WHERE `Id` >= $some_value ORDER BY `Id` ASC";
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->bind_result($someint, $somefloat, $somename)) {
    $phperror = error_get_last();
    error_log('Bind Result Error: '.$phperror['message'].' in '.$phperror['file'].' on line '.$phperror['line']);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->store_result()) {
    $phperror = error_get_last();
    error_log('Store Result Error: '.$phperror['message'].' in '.$phperror['file'].' on line '.$phperror['line']);
    exit;
}
while ($stmt->fetch()) {
    // do somethng with the data
    $someint;
    $somefloat;
    $somename;
}
$stmt->close();

Select Data Fetch ASSOC

$sql = "SELECT * FROM `mytable` WHERE `Id` = $some_value ORDER BY `Id` DESC LIMIT 1";
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt_result = $stmt->get_result()) {
    $phperror = error_get_last();
    error_log('Get Result Error: '.$phperror['message'].' in '.$phperror['file'].' on line '.$phperror['line']);
    exit;
}
if ($stmt_result->num_rows > 0) {
    while ($row = $stmt_result->fetch_assoc()) {
        // do somethng with the data
        $row['Id'];
        $row['SomeInt'];
        $row['SomeFloat'];
        $row['SomeName'];
    }
}
$stmt->close();

Select Data INNER JOIN

$sql = "SELECT ne.`SomeInt`, ot.`OtherInt` FROM `mytable` AS `ne` INNER JOIN `othertable` AS `ot` ON ne.`somename` = ot.`othername`";
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->bind_result($someint, $otherint)) {
    $phperror = error_get_last();
    error_log('Bind Result Error: '.$phperror['message'].' in '.$phperror['file'].' on line '.$phperror['line']);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->store_result()) {
    $phperror = error_get_last();
    error_log('Store Result Error: '.$phperror['message'].' in '.$phperror['file'].' on line '.$phperror['line']);
    exit;
}
while ($stmt->fetch()) {
    // do somethng with the data
    $someint;
    $otherint;
}
$stmt->close();

Insert Data

$sql = "INSERT INTO `mytable` (`SomeInt`, `SomeFloat`, `SomeName`) VALUES ($someint, $somefloat, $somename)";
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
$stmt->close();

Insert With BindParam Data

$sql = 'INSERT INTO `mytable` (`SomeInt`, `SomeFloat`, `SomeName`) VALUES (?, ?, ?)';
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->bind_param('ids', $someint, $somefloat, $somename) {
    $phperror = error_get_last();
    error_log('Bind Param Error: '.$phperror['message'].' in '.$phperror['file'].' on line '.$phperror['line']);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
$stmt->close();

Update Data

$sql = "UPDATE `mytable` SET `SomeInt` = $someint, `SomeFloat` = $somefloat, `SomeName` = $somename WHERE `Id` = $some_value";
if (!($stmt =  $con->prepare($sql))) {
    error_log('Mysql Prepare failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
if (!$stmt->execute()) {
    error_log('Mysql Execute failed: ['.$con->errno.'] '.$con->error.' : in '.__FILE__.' on line '.__LINE__);
    exit;
}
$stmt->close();

Update a Column

$sql = "UPDATE `mytable` SET `SomeInt` = $newvalue WHERE `Id` = $somevalue";
prepare, execute, close.

Update a Column using same/other Column as input

$sql = "UPDATE `mytable` SET `SomeInt` = `SomeInt` + $newvalue WHERE `Id` = $somevalue";
prepare, execute, close.

Add a Column

$sql = 'ALTER TABLE `mytable` ADD COLUMN `NewInt` int unsigned DEFAULT 0 AFTER `SomeInt`';
$sql = 'ALTER TABLE `mytable` ADD COLUMN `NewFloat` decimal(5,2) 0 AFTER `SomeFloat`';
$sql = 'ALTER TABLE `mytable` ADD COLUMN `NewMame` varchar(64) DEFAULT NULL AFTER `Somename`';
prepare, execute, close.

Modify a Column

$sql = 'ALTER TABLE `mytable` MODIFY `SomeInt` mediumint unsigned DEFAULT 0';
prepare, execute, close.

Rename Column

$sql = 'ALTER TABLE `mytable` CHANGE `SomeInt` `OtherInt` int unsigned DEFAULT 0';
prepare, execute, close.

Notepad++ Setup Compiling Papyrus Scripts

Setting up Notepad++ for Compiling Papyrus Scripts.

  • Browse to your “..\Skyrim\Papyrus Compiler\” folder.
  • Right click “ScriptCompile.bat” and select “Edit with Notepad++”.
  • Delete all content it currently has.
  • Then copy paste the text below.
    (Check the file paths if they match your skyrim folder location)
"C:\Program Files (x86)\Steam\SteamApps\common\skyrim\Papyrus Compiler\PapyrusCompiler.exe" %1 -f="TESV_Papyrus_Flags.flg" -i="C:\Program Files (x86)\Steam\SteamApps\common\skyrim\Data\Scripts\Source" -o="C:\Program Files (x86)\Steam\SteamApps\common\skyrim\Data\Scripts"

pause

Save and close the file.
Now make a backup copy of that file. Because when you do a “Verify Integrity of Game Cache” it will replace it with the original default file as provided by Bethesda.

While still in notepad++ press ‘F5’
It’ll popup a dialogue.
Paste the line below in to it.
(Check the file path if it match your skyrim folder location)

"C:\Program Files (x86)\Steam\steamapps\common\skyrim\Papyrus Compiler\ScriptCompile.bat" "$(FILE_NAME)" "$(CURRENT_DIRECTORY)"

Click save and name it “Papyrus Compile” and set your favorite short cut key combo for the function.
Mine is ‘Shift’ ‘F7’
Although I usually click it from menu -> Run -> Papyrus Compile.


Next we’ll setup fancy syntax high lighting for papyrus script.

Download this papyrus style file and unzip the papyrus-style.xml to your “..\skyrim\Papyrus Compiler\” folder.

In notepad select from menu -> Language -> Define Your Language
From the Dialogue Click “Import” and browse to your “..\Skyrim\Papyrus Compiler\” folder and select the “papyrus-style.xml”
It should popup a message “Import successful”.

Set .psc file association with notepad++
Close Notepad++
Right click a .psc file and select “Open with” -> “Choose Default Program” -> Select Notepad++.
If the notepad++ does not show in the initial dialogue then click browse and browse to “C:\Program Files (x86)\Notepad++” folder and select notepad++.exe

Done 🙂

Anna NPC’s Outfit Management

How to Use the Outfit Management system.

If you are using SKSE and SkyUI then you are in luck !
Anna NPC’s now has a Outfit management system that can be enabled through the SkyUI Mod Configuration Menu.

Once the Outfit Management is enabled for a specific follower the options become available in the dialogue tree.

First!!  it is important to know not to use the outfit inventories as storage.
Only put items in there you want them to wear.
If you want the follower to carry loot and items for you then use the Carry Bag option. “Would you carry this in your bag?


 

The Outfit Management options are available under the topic:
Let’s talk about your clothes.

Available options are:
About your weapons and armor.” (All)
About your casual clothes.” (All)
About your fancy clothes.” (All)
About your sleep wear.” (All)
About your underwear.” (All)

About your mage clothes.” (Anduniel, Valyen)
About your thieves armor.” (Anduniel, Darion, Mareen)
About your imperial armor.” (Elyndra)
About your companions armor.” (Nadina)
About your daedric armor.” (Teryn)
About your Dibella robes.” (Zorya)


 

Now what do these inventories do?
Well there are a few options.
If you keep the default option (recommended) “You can wear what you like.” they will then automatically change outfits depending on where they are and if they are in combat or not. Below is a list what they will wear and where.


 

OptionYou can wear what you like.
Casual clothes will be equipped in following locations:
♦ Inns.
♦ Player Home.
♦ Walled Cities. (Markarth, Riften, Solitude, Whiterun, Windhelm)
♦ Most interiors in walled cities.

Fancy clothes will be equipped in:
♦ Jarls castles/homes.
♦ Custom locations with keyword LocTypeCastle.

Sleep wear will be equipped when:
♦ Sleeping.

Underwear will be equipped when:
♦ Swimming.

Mage Clothes will be equipped in:
♦ College of Winterhold.

Thieves outfit will be equipped in:
♦ Ragged Flagon.
♦ Thieves guild head quarters. (Cistern)

Imperial Armor will be equipped in:
♦ Castle Dour. (Solitude)

Companions armor will be equipped in:
♦ Jorvaskr.

Daedric armor will be equipped in:
♦ Jorvaskr.

Dibella Robe will be equipped in:
♦ Markarth.
♦ Most Markarth Interiors.

♦ If they are in one of the above locations and combat starts they will change to their armor.

♦ If they are not in one of the above locations they will wear their armor.


 

OptionWear your xxxxx outfit/armor please
♦ They will then equip that outfit and only change to their armor when combat is beginning and change back when combat has ended.
♦ Except for the Imperial, Thieves, Companions and Deadric options. (Because those are armor)
♦ They will not automatically change to casual, fancy, sleep or swim outfits.


 

Anduniels Main Script

Scriptname FOL_MonitorPlayerScript extends Quest Conditional

GlobalVariable Property FOL_ForceRideHorse Auto
GlobalVariable Property FOL_AndunielFollowState Auto
GlobalVariable Property FOL_AllowChat Auto
GlobalVariable Property FOL_ChatterPace Auto
ObjectReference Property FOL_AndunielHomeMarker Auto
Actor Property PlayerRef Auto
Actor Property GloryRef Auto  
Actor Property AndunielRef Auto
WorldSpace Property Tamriel Auto
WorldSpace Property WhiterunDragonsreachWorld Auto
Location Property KilkreathRuinsLocation Auto
float Property UpdateInterval auto
float Property SettleRadius auto
int Property IsOnHorse Auto Conditional
Bool Property IsSitting Auto Conditional
Bool Property IsUsingSpecial Auto Conditional
KeyWord Property LocTypePlayerHouse Auto
KeyWord Property LocTypeInn Auto
KeyWord Property LocTypeStore Auto
KeyWord Property LocTypeHouse Auto
KeyWord Property LocTypeCastle Auto
KeyWord Property LocTypeTemple Auto
KeyWord Property LocTypeCity Auto
KeyWord Property LocTypeTown Auto
KeyWord Property LocTypeSettlement Auto
Quest Property FOL_InnkeepScenes Auto
Quest Property FOL_BoyScenes Auto
Quest Property FOL_GirlScenes Auto
Location TmpLoc
Int DoSandbox

Actor theHorse
Bool DoSetup = TRUE
Bool SummonHorse
Bool SummonHorseInProgress
Bool SummonHorseReady
Bool WantsToRideHorse
Int AndunielFollowState
Bool PlayerSettled
int cTimer
float pDistance
int pdCount
int psCount
float pPosX
float pPosY
float pPosZ
float pAngleZ
Bool iSeeYou
Bool Property LocChanged Auto Hidden Conditional 

int __historySize = 8 ; remember to update the declarations if necessary
float[] __playerPosX
float[] __playerPosY
float[] __playerPosZ

Function OnInit()
	WantsToRideHorse = FALSE
	SummonHorse = FALSE
	SummonHorseReady = FALSE
	SummonHorseInProgress = FALSE
	PlayerSettled = FALSE
	cTimer = 0
	pdCount = 0
	psCount = 0
	DoSetup = TRUE
	DoSandbox = 0
	LocChanged = FALSE
	RegisterForLOS(PlayerRef, AndunielRef)
	;Debug.Trace("INIT monitorplayer")
endFunction

Function Setup()
	; float[x] size has to the same as __historySize = x
	__playerPosX = new float[8]
	__playerPosY = new float[8]
	__playerPosZ = new float[8]

	int count = 0
	while (count < __historySize)
		__playerPosX[count] = PlayerRef.X + 1000
		__playerPosY[count] = PlayerRef.Y + 1000
		__playerPosZ[count] = PlayerRef.Z + 1000
		count += 1
	endwhile
	DoSetup = FALSE
EndFunction

Function SetToNotMoving()
	int count = 0
	while (count < __historySize)
		__playerPosX[count] = PlayerRef.X
		__playerPosY[count] = PlayerRef.Y
		__playerPosZ[count] = PlayerRef.Z
		count += 1
	endwhile
EndFunction

Event OnGainLOS(Actor akViewer, ObjectReference akTarget)
	iSeeYou = TRUE
EndEvent

Event OnLostLOS(Actor akViewer, ObjectReference akTarget)
	iSeeYou = FALSE
EndEvent

;Event OnLocationChange(Location akOldLoc, Location akNewLoc)
;	LocChanged = TRUE
;	Debug.Trace("===: Location Change - function")
;	Debug.Notification("===: Location Change - function")
;endEvent

Event OnUpdate()
	;Debug.Notification("Updating MonitorPlayerScript ")
	;Debug.Trace("Updating MonitorPlayerScript ")
	;==================================
	;=== Reset the AllowChat global	===
	;==================================	
	if (FOL_AllowChat.GetValueInt() == 1)
		cTimer += 1
		if (cTimer >= FOL_ChatterPace.GetValueInt()) 
			FOL_AllowChat.SetValueInt(0)
			;Debug.Notification("Allowed to chatter again.. ")
			cTimer = 0
		endif
	endif

	AndunielFollowState = FOL_AndunielFollowState.GetValueInt()
	if ((AndunielFollowState >= 1) && (AndunielRef.GetAV("WaitingForPlayer") == 0))
		;Debug.Trace("===: Updating MonitorPlayerScript ")
		if (DoSetup)
			Setup()
		endif
		
		if (LocChanged)
			LocChanged = FALSE
			FOL_AndunielFollowState.SetValueInt(1)
			AndunielRef.EvaluatePackage()
			psCount = 0
			PlayerSettled = FALSE
			TmpLoc = PlayerRef.GetCurrentLocation()

			Bool StopInnQuest = FALSE
			Bool StopKidsQuest = FALSE
			if (FOL_InnkeepScenes.IsRunning())
				FOL_InnkeepScenes.Stop()
				StopInnQuest = TRUE
			endif					
            if (FOL_BoyScenes.IsRunning())
				FOL_BoyScenes.Stop()
				StopKidsQuest = TRUE
			endif					
			if (FOL_GirlScenes.IsRunning())
				FOL_GirlScenes.Stop()
				StopKidsQuest = TRUE
			endif
			if (TmpLoc != None)
				if (StopInnQuest == FALSE)
					if (TmpLoc.HasKeyWord(LocTypeInn))
						FOL_InnkeepScenes.Start()
					endif
				endif
				if (StopKidsQuest == FALSE)
					if  ((TmpLoc.HasKeyWord(LocTypeTown)) || (TmpLoc.HasKeyWord(LocTypeCity)) || (TmpLoc.HasKeyWord(LocTypeSettlement)))
						FOL_BoyScenes.Start()
						FOL_Girlscenes.Start()
					endif
				endif
			endif
			RegisterForSingleUpdate(1)
			Return
		endif
		;==============================================================
		;=== Setup Conditionals == No actual actions yet 			===
		;=== ONLY do this when she's in STANDARD follow mode "1"	===
		;=== even though she might be in follow sandbox mode,		===
		;=== she has to come out of that first by her self			===
		;==============================================================
		theHorse = Game.GetPlayersLastRiddenHorse()	
		if (theHorse && theHorse.GetPlayerControls())
			;=== Player IS on horse so anduniel wants to ride	===
			WantsToRideHorse = TRUE
		else
			;=== Player is NOT horse ===
			if (FOL_ForceRideHorse.GetValueInt() > 0)
				if (PlayerRef.IsInInterior())
					FOL_ForceRideHorse.SetValueInt(0)
					WantsToRideHorse = FALSE
					;Uh oH Player went indoors while she was on horse back the game does not move her to the interior
					;we have to do it manualy
					AndunielRef.MoveTo(PlayerRef)
				elseif (PlayerRef.GetWorldSpace() != Tamriel)
					;Debug.Notification("Not in tamriel")
					FOL_ForceRideHorse.SetValueInt(0)
					WantsToRideHorse = FALSE
					;Uh oH Player went out of tamriel while she was on horse back
				elseif (PlayerRef.IsInCombat())
					;Player is not on horse but is in combat
					WantsToRideHorse = FALSE
				else
					;Player is not on horse and not in combat but she was asked to ride so anduniel wants to ride
					WantsToRideHorse = TRUE
				endif
			else
				;player is not on horse and she was not asked to ride so anduniel does not want to ride
				WantsToRideHorse = FALSE
			endif
		endif
		;=== End Setup conditional

		if (WantsToRideHorse)
			if (GloryRef.IsBeingRidden())
				;... unreliable after fast travel ??
				;Debug.Notification("Glory is being ridden.")
				if (IsOnHorse == 0)
					;Debug.Notification("Glory is being ridden.")
					IsOnHorse = 1
					; switch to FOL_AndunielRideCombat AI package  
					AndunielRef.EvaluatePackage()
				endif
			else
				;Debug.Notification("Glory is NOT being ridden need mount")
				if (SummonHorseInProgress == FALSE)
					;Debug.Notification("NOT Summon Horse in progress")
					if (GloryRef.IsInInterior())
						;Horse is in dummy cell. ;need to summon horse.
						SummonHorse = TRUE
					elseif (AndunielRef.GetDistance(GloryRef) > 300)
						;horse is to far away. need a summon
						SummonHorse = TRUE
					endif
				else
					;Debug.Notification("Summon Horse in progress")
					if (GloryRef.Is3DLoaded())
						;Debug.Notification("Horse Model is loaded")
						; Wait for actual model to be loaded into game
						SummonHorseReady = TRUE
						SummonHorseInProgress = FALSE
					endif
				endif

				if (SummonHorse)
					;Debug.Notification("Andie Summon Horse")
					;Move the horse to anduniel
					GloryRef.MoveTo(AndunielRef, 32, 0, 0)
					SummonHorse = FALSE
					SummonHorseReady = FALSE
					SummonHorseInProgress = TRUE
				endif

				if (SummonHorseReady)
					;Debug.Notification("Andie mounting horse")
					; Horse is loaded and ready, Start mounting. (aka activate)
					GloryRef.Activate(AndunielRef, TRUE)
				endif
			endif
		else
			if (GloryRef.IsBeingRidden())
				;Debug.Notification("Glory is being ridden need DISmount")
				if (IsOnHorse == 1)
				;Debug.Notification("Andie Dismounting horse")
				;Dismount when on horse (aka activate again)
				GloryRef.Activate(AndunielRef, TRUE)
				endif
			else
				if (IsOnHorse == 1)
					SummonHorse = FALSE
					SummonHorseReady = FALSE
					SummonHorseInProgress = FALSE
					IsOnHorse = 0
					;switch to FOL_PlayerFollowerPackage AI package
					AndunielRef.EvaluatePackage()
				endif
			endif
		endif

		;==========================================
		;=== Setting up sand box conditional
		;===
		;==========================================
		TmpLoc = PlayerRef.GetCurrentLocation()
		if (TmpLoc != None)
			if (TmpLoc.HasKeyWord(LocTypePlayerHouse) || TmpLoc.HasKeyWord(LocTypeInn) || \
				TmpLoc.HasKeyWord(LocTypeStore) || (FOL_AndunielHomeMarker.GetParentCell() == PlayerRef.GetParentCell()))
				; Do SandBox even when player is moving or sneaking
				DoSandbox = 2
			elseif (TmpLoc.HasKeyWord(LocTypeHouse) || TmpLoc.HasKeyWord(LocTypeCastle) || TmpLoc.HasKeyWord(LocTypeTemple) || \
					TmpLoc.HasKeyWord(LocTypeCity) || TmpLoc.HasKeyWord(LocTypeTown) || TmpLoc.HasKeyWord(LocTypeSettlement))
				; Allow sandbox when idle.
				DoSandbox = 1
			else
				; Do not sandbox at all.
				DoSandbox = 0
			endif
		else
			;=== No location found ???
			; Do not sandbox at all.
			DoSandbox = 0
		endif
		
		
		if (PlayerRef.IsInCombat() == FALSE)
			bool switchedPackageConditions = FALSE
			if ((DoSandbox == 2) && (AndunielRef.GetParentCell() == PlayerRef.GetParentCell()))
				if (PlayerSettled == FALSE)
					switchedPackageConditions = TRUE
					FOL_AndunielFollowState.SetValueInt(3)
					psCount = 0
					;Debug.Trace("===: DoSandbox = 2 -> PlayerSettled - Sandbox")
				endif
				PlayerSettled = TRUE
			elseif (DoSandbox == 1)
				;==========================================
				;=== Trace players movement	for idle	===
				;=== Sandbox when player does not move	===
				;==========================================
				; cycle all positions down one notch in the history arrays
				int historyIndex = 0
				while (historyIndex < __historySize - 1)
					__playerPosX[historyIndex] = __playerPosX[historyIndex + 1]
					__playerPosY[historyIndex] = __playerPosY[historyIndex + 1]
					__playerPosZ[historyIndex] = __playerPosZ[historyIndex + 1]
					historyIndex += 1
				endwhile
				; set the most recent history as the current player position
				;Actor _player = Game.GetPlayer()
				pPosX = PlayerRef.X
				pPosY = PlayerRef.Y
				pPosZ = PlayerRef.Z
				__playerPosX[__historySize - 1] = pPosX
				__playerPosY[__historySize - 1] = pPosY
				__playerPosZ[__historySize - 1] = pPosZ
				
				; check current position against oldest history point if we're in follow mode
				; calculate distance between history start and present
				;    sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2)
				float xFactor = (__playerPosX[0] - pPosX)
				float yFactor = (__playerPosY[0] - pPosY)
				float zFactor = (__playerPosZ[0] - pPosZ)
				;float distance = Math.sqrt(xFactor + yFactor + zFactor)
				float distance = yFactor * yFactor
				distance += xFactor * xFactor
				distance += zFactor * zFactor
				; if the player has moved less than the defined settle radius,
				;   set the flag that the sandbox package is looking for.
				if (distance > SettleRadius)
					;Debug.Trace("===: PlayerMoving")
					if (PlayerSettled)
						IsUsingSpecial = FALSE
						switchedPackageConditions = TRUE
						FOL_AndunielFollowState.SetValueInt(1)
						psCount = 0
						;Debug.Trace("===: MPS-> PlayerMoving - Stop Sandbox")
					endif
					PlayerSettled = FALSE
				else
					;Debug.Trace("===: PlayerSettled")
					if (WantsToRideHorse || (IsSitting && IsUSingSpecial == FALSE) || (PlayerRef.IsSneaking()))
						if (PlayerSettled)
							;======================================================
							;=== Player is settled BUT, she wants to ride horse	===
							;=== or player is sitting. takes precedence			===
							;=== force back to follow state "1"					===
							;======================================================
							switchedPackageConditions = TRUE
							FOL_AndunielFollowState.SetValueInt(1)
							;Debug.Trace("===: MPS-> PlayerSettled when sitting")
						endif
						PlayerSettled = FALSE
					elseif ((PlayerRef.GetDistance(AndunielRef) < = 1024) && (PlayerRef.IsSneaking() == FALSE))
						;==============================================================
						;=== Sandbox when player doesn't move for a while			===
						;=== Only when NOT wants to ride horse, player NOT sitting	===
						;==============================================================
						if (PlayerSettled == FALSE)
							switchedPackageConditions = TRUE
							FOL_AndunielFollowState.SetValueInt(3)
							psCount = 0
							;Debug.Trace("===: MPS-> PlayerSettled - Sandbox")
						endif
						PlayerSettled = TRUE
					endif
				endif
			else
				if (PlayerSettled)
					IsUsingSpecial = FALSE
					switchedPackageConditions = TRUE
					FOL_AndunielFollowState.SetValueInt(1)
					psCount = 0
					;Debug.Trace("===: DoSandbox = 0 - Stop Sandbox")
				endif
				PlayerSettled = FALSE
			endif
	
			; only do the EVP if we've actually changed the value
			if (switchedPackageConditions)
				AndunielRef.EvaluatePackage()
			endif
		
			;==========================================
			;=== Keep track of distance to player	===
			;=== And teleport when to far away		===
			;==========================================
			if ((PlayerRef.GetCurrentScene() == None) && (IsOnHorse == FALSE) && (AndunielFollowState == 1))
				pDistance = PlayerRef.GetDistance(AndunielRef)
				if (PlayerRef.IsInInterior())
					if (pDistance > 1024)
						pdCount += 1
					else
						pdCount = 0
					endif
				else
					if (PlayerRef.GetAnimationVariableBool("bIsRiding") && (WantsToRideHorse == FALSE))
						;debug.notification("IS RIDING A DRAGON")
						pdCount = 0
					elseif (PlayerRef.GetWorldSpace() == WhiterunDragonsreachWorld )
						pdCount = 0
					elseif (PlayerRef.GetCurrentLocation() == KilkreathRuinsLocation)
						pdCount = 0					
					else
						if (pDistance > 1200)
							pdCount += 1
						else
							pdCount = 0
						endif
					endif
				endif
			endif
			if (pdCount > 3)
				if (iSeeYou == FALSE)
					pAngleZ = PlayerRef.GetAngleZ()
					pPosX = -256 * math.sin(pAngleZ)
					pPosY = -256 * math.cos(pAngleZ)
					AndunielRef.MoveTo(PlayerRef, pPosX, pPosY)
					;debug.notification("teleport")
					pdCount = 0
				endif
			endif

			;======================================================================
			;=== Sit when player sits after 2 iterations ... ignoring crafting	===
			;======================================================================
			if (IsUsingSpecial == FALSE)
				if (PlayerRef.GetSitState() > 0)
					if (psCount >= 2)
						if (IsSitting == FALSE)
							IsSitting = TRUE
							AndunielRef.EvaluatePackage()
							;Debug.Trace("===: MPS -> eval package go sit")
						endif
					endif
					psCount += 1
				else
					if (IsSitting)
						IsSitting = FALSE
						AndunielRef.EvaluatePackage()
						;Debug.Trace("===: MPS-> eval package do not sit")
						psCount = 0
					endif
				endif
			endif
		endif
	endif
	RegisterForSingleUpdate(UpdateInterval)
EndEvent

Borderlands 2 SHIFT Codes

SHIFT Codes for Borderlands 2

Here’s a list of shift codes I found all over the net.
PC Codes only !! (NO xbox or ps3)

Golden Keys
_________________________________________________________________________
30-10-2013

5BCJJ-5SHZ6-SXCK3-3TJ3J-BX39H <- 5 Golden Keys

27-10-2013

CJKB3-HSK6R-WJHJ3-3TTTJ-SHZSZ <- 3 Golden Keys
CBW3T-TTXRR-CTZJB-33TB3-Z39ZS <- 3 Golden Keys

13-10-2013

5TC3J-3Z9HX-SXKCJ-BT3TT-B9WZZ <- 5 Golden Keys

10-10-2013

KT5BJ-THKRF-W3SBT-3TBBJ-HZWFH <- 3 Golden Keys
W353J-WC6ZR-9XK5J-3BTJT-CXF5J <- 3 Golden Keys

25-9-2013

5353T-SRH9F-96W53-3TBTB-FXHF9 <- 5 Golden Keys

18-9-2013

KTC3J-XBZK6-C3HT3-BBTB3-J9KXK <- 3 Golden Keys
CBCB3-FX9H5-KTZJT-B3JJ3-6F335 <- 5 Golden Keys
CTKJB-CBHC6-5JZBT-J3J33-9Z9JH <- 3 Golden Keys
W3KJ3-ZXSH5-53ZJB-TJB3T-CK559 <- 5 Golden Keys

14-9-2013

5TKJJ-5THRC-XZZ3-J33J33-TSZSC <- 5 Golden Keys
WJCBB-SSFFC-XH93J-BJTBT-Z66ZW <- 5 Golden Keys

5-9-2013

KJWB3-6RXRC-CKR5B-H3WB3-WZRF5 <- 5 Golden Keys
CJCJ3-B6XXC-CK6WT-HTWTB-5SSW5 <- 5 Golden Keys
WB53J-KRRXW-5KXCB-STKTT-XC5BR <- 5 Golden Keys
CTC3J-KR9H5-WTZ3T-TJ3TB-6SRRJ <- 5 Golden Keys

18-8-2013

KBC3J-95WXF-WBSBT-TTJJB-KTC6K <- 3 Golden Keys
K3WJT-BFBRW-S5RTT-TBBB3-9XWZ5 <- 5 Golden Keys
KBWJJ-WTXB9-C59J6-WFBTJ-TK6BJ <- 1 Golden Key
W3WJ3-3JXTT-6RW5T-SB53B-XJBX9 <- 3 Golden Keys
WTC3B-Z5ZWC-HW6JT-JJJBJ-9FWXR <- 1 Golden Key
K3K33-3W9JT-6XJJT-TB3JB-HWZZF <- 5 Golden Keys
5BKBB-TXWS5-WX3BB-TBT33-3SHSB <- 1 Golden Key
WTCBB-H5WHC-5F3T3-TBT3T-HR6TJ <- 1 Golden Key
WT5TB-XC5ZC-CX3T3-BBT3B-B35WB <- 5 Golden Keys
KJ5BT-FBKSK-KXJ3T-3BTJT-FJX5C <- 1 Golden Key
5T5B3-CWJSK-KRTJT-TTJJT-9HW63 <- 1 Golden Key
CTWTB-JTBW5-KFTTT-JTB33-JTBWB <- 1 Golden Key
WTCJ3-SHH3K-KFJT3-JBJ3J-H5965 <- 1 Golden Key
KTCJJ-FHZJW-W6JJB-TTBTJ-R9WWJ <- 1 Golden Key
KB53J-RW5XX-539BT-BJT3J-CC55T <- 3 Golden Keys
5TWJ3-KS6CR-C3Z3B-BJBBB-653JZ <- 3 Golden Keys

__________________________________________________________________________

Legendary Items Best to redeem at levels above 50. Will expire September.

5TCJT-FW6XX-W3SJJ-333JT-SKWT9 <- legendary items and shot gun

__________________________________________________________________________

B&B Class mods (will be leveled to the first character you load)
Redeem all and trade with others. Or sell them off.

WJWJ3-FXC33-KT3CR-KR33J-J9B35 <- for Maya (Siren)
5JKBJ-K9WHW-WBZTJ-T3TTB-TW9HR <- for Axton (Commando)
WJKBB-KXC3J-5BBCR-5X33J-XZ6RZ <- for Salvador (Gunzerker)
CBWJ3-S5CJ3-WTTCF-WX333-9STBF <- for Zer0 (Assasin)
WTCJT-J653B-C3TKF-5X333-F6JRH <- for Krieg (Psycho)
W3C3B-5JRZC-WJH33-JBJJB-9S6CJ <- for Gaige (Mechromancer)

__________________________________________________________________________

Only useful for “Tiny Tina’s Assault on Dragon Keep” DLC
However you can just redeem them and sell them off for 600 some credits each.

CBKBB-ZHJC6-SWHJT-JJ3BB-3CXHS <- Head skin for Psycho
KJKJT-WHBKX-HC9BT-TJBJ3-XJFSJ <- Head skin for Commando
CBKBJ-6ZJW6-HKH3T-B3T33-F5ZRS <- Head skin for Mechromancer
CT5BB-XTW5X-9CSBT-3BTTJ-FT5X5 <- Head skin for Assassin
KTC3T-WTW5F-ZCHB3-BT3B3-XJ9WR <- Head skin for Siren

__________________________________________________________________________

Expired as of 17-8-2013

5T5JT-CZZW6-5BHTJ-BJJ33-TZS6S
CJ5BT-KJ3ZW-HHKCT-ZBW3J-3F3ZK
CBCTT-BZF5R-KT93B-3TBJ3-H96HJ
53C33-9R6CX-5B933-BT33T-9X5WH
5T533-9R95X-C39T3-3T3JB-SZZ96
W3WBB-JS9W6-W3HTT-JT33J-5BFXB
WJKJB-C6ZCF-CTZTJ-BBT3J-T9RF6
CJWTB-FF9KX-K3H33-TJJ33-JJHTH
5BCBJ-BRH56-WT9BJ-BJTTB-CSW9B
CT53T-RCSWX-CJHTB-B33B3-K63KC
WT53B-ZCZKR-KJSBT-3TTJJ-JB9CJ
CJWTJ-RFXWF-53ZJT-BTT3J-RSW3W
5JW3B-WX6W6-CT9TB-B3TBT-J9J6C
WTW3J-39F95-ZZKKJ-9TKT3-Z3HBT
5BKJ3-BFXCF-C3SJ3-J3BBB-JCF5B
KTWJJ-XWTW5-BSFTB-BJT3T-SHF5F
K3WTT-WCCFF-C3HTJ-T3JBJ-RR6X3
WJ5B3-JW56X-5393T-JTTJJ-T5Z6T
WJ5J3-3KFWX-WTH33-BJJT3-3FK96
53WBT-ZJ6CR-WJHT3-J3JJB-BX9FZ
W3C33-JBXC6-WBZJJ-333JT-XHSHX
CTWBJ-BXHSC-WBHJB-B3BBT-JJ5R9
5T5T3-9BW6R-WJHBJ-TJJJT-WFXRR
W3WBJ-SC9HC-C3Z3J-3B3TJ-RS3HJ
KJ533-5FCFC-HKR33-JBTJT-SS3FB
KT5JJ-9JBKC-TS63T-J3J3J-96WBW
KJWTJ-WWBR5-9KR3T-3B33J-53WFS
CB5JJ-X3JC5-TSXTT-J33BJ-SRK59
WBKTB-K3J5W-3ZXJ3-3JTTT-B6XTT
WJW3B-W5BK5-JHFBT-T3J33-JK3TT
WBWJT-STBXC-9K6T3-3BJJJ-CHW5W
W35JT-TBT55-JSRJB-JTBJ3-33ZKX
53WTT-99HJW-J9FJ3-3JTJT-XTHZR
K3C3T-XHSTK-3ZXJB-TTJJ3-ZH3XJ
K3WB3-ZRZ3C-TSRTJ-TTB3T-SS36K
WJ5BB-JRZT5-3SFBT-T33JT-R9KTH
5JKJJ-XCZJW-BS6JT-JTB3B-ZSW56
WB5TJ-J5BCC-BHXJB-J3BTJ-RRFHK
5J5BJ-WF9JK-JS6J3-JBJTT-CF3B3
KBCJ3-F6ZBK-B96T3-JBJT3-TCX9T
C3WJ3-6B3FC-Z5XT3-B3J3B-KH669
CB5JJ-CCH35-JSFJB-T33BT-RKCRW
53K33-3W9JC-3ZFJT-J33TJ-BWBBW
KBCJT-JJJ6W-9WXJB-BTBTJ-XJWTF
CT53B-K3BX5-H5FTB-BTT3J-J995C
KBCTT-5JSTW-3SXJ3-BBTT3-RTTK6
5TK3B-Z9SWC-SWRT3-TJ33T-HZW3B
CJC33-F9Z5C-ZCRJJ-JB3TT-J5HSR
W35JB-XT66C-ZWFBT-3TTT3-H9F6F
WT533-J99WW-ZC6JJ-TBJT3-SWKTB
CTKTJ-WHSKC-Z56BJ-BTB3B-9C6FT
WJ5JT-9KK6K-SCRB3-TBT3B-J5R96
53K3B-WK56C-SWF33-BJ3J3-WCBHC
5JC3B-HRS5W-HC6B3-J3TJJ-ZRCKB
KJ5BT-FX9CW-H5XJ3-TTJBB-WH559
WTCBJ-TWCRW-S56T3-TJTBJ-BTT3R
K3CBT-CT56C-ZC6TT-3BTTT-WJTRS
CBWTT-JT5R5-95R33-T3BBJ-HHZ65
K3KJT-6HRT5-BHRTT-3BBTJ-RBWJ9
KBWTT-SZJF5-SCF3J-BBJJ3-HTCHZ
WTWT3-CXSKC-9KFT3-TBBJT-ZX5FF
CBC3B-5ZTF5-9WR3J-TTJJT-3K5K5
53WJJ-THTXW-HWRTJ-3TJBT-53R6S
KTCBJ-C9RTC-BSFTJ-33TT3-FBWHF
KB53J-ZFBR5-HWRTB-T3TTB-RFJFR
K35JT-B3FXC-ZCFJB-BTTBB-CFHRT
KJWJ3-SCBFK-S5F3J-JBBB3-BHCJ3
K3WTJ-TXZWW-SCRJJ-33BTJ-933ZS
WTWT3-596CW-ZKF33-TJ333-9JSRZ
W3CJJ-BZR5C-ZK6T3-TT3TT-JS6T3
W3CTB-HXR5W-S56B3-TTB33-SXTXF
C3CBT-RC3XW-9WF33-BTJ3T-SB99J
CB5BB-XF65C-ZKXTT-TBBBT-TRKJZ
53WTB-S9XKW-SWFT3-TJBJB-FWWZW
C3WBT-C6F5C-HCRTJ-3J3BT-C96ZW
CTWBT-X5ZWC-9WRB3-BJ3B3-RWF96
KBCBB-BFFWC-HKXBT-3TBTJ-9XZ3C
C35TB-ZWFCW-HCF3T-TTBTJ-RHWT6
53KJ3-CK9W5-Z5XB3-T3BJT-969KW
KTKB3-TCZC5-9W6JT-BJBTB-6ZHTS
5B533-HJZKC-SKX3J-BBTBB-HBCBK
C3W3B-6B95C-SWFJJ-B3BJJ-5C6XJ
CTCBJ-CK6KW-SCF33-TJJJT-WB3CB
5TCTJ-XC3S5-C6JJT-3JTTT-HFBW9
W3KTT-ZW39K-56TJ3-J333T-X9FKH
K3KJ3-3RT95-KXB3B-BBTBT-CB6KH
C3C3J-KFTHW-WX3JJ-3BTJ3-ZR6B9
WTKT3-BSJSK-5XBTT-B333T-963SF
WTKB3-Z5RCF-C3ST3-JB33J-9JST9
CB5JB-WBHK9-5CHT6-KXB3B-TBJSX
CBKB3-3BKH9-XB3J3-BJB3B-H53CK
CBK3B-5JCH9-RB3BJ-BBTBB-T6FCR
WTKJJ-566JC-WXJT3-BTJT3-6BTBH

Happy gaming 🙂

PHP mail() with MSMTP

PHP mail() made easy without a whole mail delivery system like sendmail or postfix.
Use msmtp http://msmtp.sourceforge.net/
Lightweight easy to install and configure.

Installation for LFS:

# wget http://sourceforge.net/projects/msmtp/files/msmtp/1.4.30/msmtp-1.4.30.tar.bz2
# tar -xvf msmtp-1.4.30.tar.bz2
# cd msmtp-1.4.30
# autoreconf -i
# ./configure --prefix=/usr
# make
# make install

Configuration for non authorized smtp access to your smtp provider:
ie. No username/password not encrypted.

Edit or create /usr/etc/msmtprc

And put the following in it.

# msmtp configuration file
# Set default values for all following accounts.
defaults
tls off
#tls_trust_file /etc/ssl/certs/ca-certificates.crt
#logfile /var/log/maillog/msmtp.log

# The SMTP server of the provider.
account provider
host smtp.example.com
from youremail@example.com
auth off
#user 123456789
#passwordeval gpg -d ~/.msmtp.password.gpg

# Set a default account
account default : provider

You will have to change smtp.example.com with your smtp provider and change youremail@example.com with your own valid email address.

Next you will have to tell php to use msmtp.
Edit /etc/php.ini
Search for the line that starts with:
sendmail_path
uncomment it and/or change the line to this.

sendmail_path = "/usr/bin/msmtp -t"

Restart your httpd to activate the php changes.
Done !

Happy php mail()ing 🙂

RRDTool PHP plugin.

More on rrdtool

A continuation of Part 1 RRDTOOL with LIBART

Updated 2015 April 2. Using php 5.4.x and php 5.5.x and greater.

Now that the rrdtool version 1.2.30 with libart is working.
I want to use the php-rrdtool plugin that work with the 1.2.30 rrdtool version.
The only php rrd plugin that works is the plugin from the rrdtool website.
http://oss.oetiker.ch/rrdtool/pub/contrib/php_rrdtool.tar.gz
The plugins for rrdtool found at php pecl only work for the newer versions of rrdtool.

Installing it:

# cd /usr/include/php/ext
# wget http://oss.oetiker.ch/rrdtool/pub/contrib/php_rrdtool.tar.gz
# tar -xvf php_rrdtool.tar.gz
# cd rrd-tool
# phpize
# ./configure
# make
# make install

Last line of compile output is:
Installing shared extensions: /usr/lib/no-debug-non-zts-20131226/
(the date stamp varies depending on php version)

Changes to /etc/php.ini
Add or change the extensions-dir
extension_dir = “/usr/lib/no-debug-non-zts-20131226/”
Append below the extensions block
extension=rrdtool.so

Restart the httpd server so that php applies the changes.
Done !

However this only works for PHP versions 5.3.x and lower.
For PHP versions 5.4.x and greater the plugin fails to compile due to changes in php.
Some details about the php changes can be found here
Which has a link to a patch.
Good news and bad new. The patch didn’t quite work for me for reasons unknown. Maybe fedora uses a slight different/modified version. However I was able to fix the patch and it works !

** Update.
PHP version 5.5.x and greater breaks the plugin again.
I have updated the patch that fixes this. Use it when using php 5.4.x and greater.

Download my version of the patch for PHP 5.4.x or greater

Installing it with patch:

# cd /usr/include/php/ext
# wget http://oss.oetiker.ch/rrdtool/pub/contrib/php_rrdtool.tar.gz
# wget http://www.shrike.tk/files/rrdtool-php55.patch
# tar -xvf php_rrdtool.tar.gz
# cd rrd-tool
# patch -Np1 -i ../rrdtool-php55.patch
# phpize
# ./configure
# make
# make install

Happy php graphing 🙂

RRDTOOL with LIBART

Issues with rrdtool 🙂
On Linux from Scratch.

Updated 2015 April 2. Using up to date package versions

rrdtool without cairo/pango
rrdtool with libart

Well rrdtool works great on all distro’s. I use(d) it my self on fedora and centos. No troubles…
But getting it to work on Linux From Scratch took some effort. The thing is that the latest versions of rrdtool are linked against cairo and pango. Which I don’t have installed nor do I want to. Cairo/Pango are X libs depending on even more X libs and X configurations. I’m running an X less server. No trace of X or GTK installed and I want to keep it that way.
So to get it to work I had to fall back to the latest version of rrdtool that didn’t depend on cairo/pango but depends on libart. Which is version 1.2.30 and is still available on the rrdtool website. The only dependencies are pkg-config, zlib, libpng, freetype, libart (optional Bzip2 but recommended).

Versions used:
zlib-1.2.8.tar.bz2 http://www.zlib.net/zlib-1.2.8.tar.xz

bzip2-1.0.6.tar.gz http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz

pkg-config-0.28.tar.gz http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz

libpng-1.6.16.tar.gz http://downloads.sourceforge.net/libpng/libpng-1.6.16.tar.xz

libpng-1.6.16-apng.patch.gz http://downloads.sourceforge.net/libpng-apng/libpng-1.6.16-apng.patch.gz

which-2.20.tar.gz http://ftp.gnu.org/gnu/which/which-2.20.tar.gz

icu4c-54_1-src.tgz http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.tgz

libffi-3.2.1.tar.gz ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz

Python-2.7.9.tar.xz https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz

freetype-2.5.5.tar.bz2 http://downloads.sourceforge.net/freetype/freetype-2.5.5.tar.bz2

harfbuzz-0.9.38.tar.bz2 http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-0.9.38.tar.bz2

libart_lgpl-2.3.21.tar.bz2 http://ftp.gnome.org/pub/gnome/sources/libart_lgpl/2.3/libart_lgpl-2.3.21.tar.bz2

rrdtool-1.2.30.tar.gz http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.2.30.tar.gz

Linux From Scratch users have already zlib, bzip2 and pkg-config installed and should skip those install steps.
Beyond Linux From Scratch users might have already libpng, which, icu, libffi, python, freetype, harfbuzz installed and should skip those install steps.
Or compile/install them again if earlier compiles did not include all dependencies listed above.

Installation documentation used.
rrdtool build instructions
LFS Book 7.7
BLFS Book 7.7

Package Installing:
ZLIB:
As per LFS 7.7 Book directive.

# ./configure --prefix=/usr
# make
# make install
# mv -v /usr/lib/libz.so.* /lib
# ln -sfv ../../lib/$(readlink /usr/lib/libz.so) /usr/lib/libz.so

 
BZIP2
As per LFS 7.7 Book directive.

# sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile
# make -f Makefile-libbz2_so
# make clean
# make
# make PREFIX=/usr install
# cp -v bzip2-shared /bin/bzip2
# cp -av libbz2.so* /lib
# ln -sv /lib/libbz2.so.1.0 /usr/lib/libbz2.so
# rm -v /usr/bin/{bunzip2,bzcat,bzip2}
# ln -sv bzip2 /bin/bunzip2
# ln -sv bzip2 /bin/bzcat

 
PKG-CONFIG
As per LFS 7.7 Book directive.

# ./configure --prefix=/usr --with-internal-glib --disable-host-tool --docdir=/usr/share/doc/pkg-config-0.28
# make
# make install

 
LIBPNG
As per BLFS 7.7 Book directive.

# gzip -cd ../libpng-1.6.16-apng.patch.gz | patch -p1
# ./configure --prefix=/usr --disable-static
# make
# make install
# mkdir -v /usr/share/doc/libpng-1.6.16
# cp -v README libpng-manual.txt /usr/share/doc/libpng-1.6.16

 
WHICH
As per BLFS 7.7 Book directive.

# ./configure --prefix=/usr
# make
# make install

 
ICU
As per BLFS 7.7 Book directive.

# cd source
# ./configure --prefix=/usr
# make
# make install

 
LIBFFI
As per BLFS 7.7 Book directive.

# sed -e '/^includesdir/ s/$(libdir).*$/$(includedir)/' -i include/Makefile.in
# sed -e '/^includedir/ s/=.*$/=@includedir@/' -e 's/^Cflags: -I${includedir}/Cflags:/' -i libffi.pc.in
# ./configure --prefix=/usr --disable-static
# make
# make install

 
PYTHON
As per BLFS 7.7 Book directive.

# ./configure --prefix=/usr --enable-shared --with-system-expat --with-system-ffi --enable-unicode=ucs4
# make
# make install

 
FREETYPE
As per BLFS 7.7 Book directive.

# sed -i -r 's:.*(#.*SUBPIXEL.*) .*:\1:' include/freetype/config/ftoption.h
(the line above is optional see blfs book for details. patent stuff)
# ./configure --prefix=/usr --disable-static
# make
# make install

 
HARFBUZZ
As per BLFS 7.7 Book directive.

# ./configure --prefix=/usr --with-gobject
# make
# make install

 
FREETYPE (again to satisfy cyclic dependency with harfbuzz)
As per BLFS 7.7 Book directive.

# sed -i -r 's:.*(#.*SUBPIXEL.*) .*:\1:' include/freetype/config/ftoption.h
(the line above is optional see blfs book for details. patent stuff)
# ./configure --prefix=/usr --disable-static
# make
# make install

 
LIBART
(libart used to be in BLFS book but is no longer present in versions > 6.3)

# ./configure --prefix=/usr
# make
# make install

 
RRDTOOL
As per rrdtool build directive.
(–disable-tcl –disable-python are optional.)

# ./configure --prefix=/usr --disable-tcl
# make clean
# make
# make install

Done !
You now have rrdtool without cairo/pango.

Goto Part 2 RRDTool PHP plugin

Happy graphing 🙂

Linux ETH Bridging LFS

Turn your Linux server into a humble switch… Not so humble though.
Linux From Scratch specific.

What you need:
Kernel Version 2.4 or higher.
Kernel Configuration ‘802.1d Ethernet Bridging’ build in or module.
A working network configuration with atleast 2 Eth’s (nic’s)
Package ‘bridge-utils’ installed.

What you get:
A network switch with a working IP connection for the server it self to use.

Configuration:

# /etc/sysconfig/ifconfig.eth0
ONBOOT=no
IFACE=eth0
SERVICE=ipv4-static
# /etc/sysconfig/ifconfig.eth1
ONBOOT=no
IFACE=eth1
SERVICE=ipv4-static

etc. etc. for all network cards you want to participate in the bridge.

Then setup a virtual device so that the server as an IP address of it’s own.
Like below.

# /etc/sysconfig/ifconfig.br0
ONBOOT=yes
IFACE=br0
SERVICE="bridge ipv4-static"
IP=192.168.1.1
GATEWAY=192.168.1.254
PREFIX=24
BROADCAST=192.168.1.255
CHECK_LINK=no
STP=no
INTERFACE_COMPONENTS="eth0 eth1"
IP_FORWARD=true

Set the bridging driver to not pass packets to iptables.

# echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables.

Or if you choose to do pass packets to iptables then set iptables forwarding chain to ACCEPT.

note*
The BLFS book has a error in the example #/etc/sysconfig/ifconfig.br0
Instead of the INTERFACES argument use INTERFACE_COMPONENTS.
(edit)
This has been fixed as per SVN 2013 version.

Linux ETH bridging

Turn your Linux server into a humble switch… Not so humble though.
Not recommended for desktop distro’s as you will have to turn off the desktop NetworkManager.

What you need:
Kernel Version 2.4 or higher.
Kernel Configuration ‘802.1d Ethernet Bridging’ build in or module.
A working network configuration with atleast 2 Eth’s (nic’s)
Package ‘bridge-utils’ installed.

What you get:
A network switch with a working IP connection for the server it self to use.

Configuration:

# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
TYPE="Ethernet"
BRIDGE="br0"
HWADDR="00:XX:XX:XX:XX:B0"
ONBOOT="yes"
BOOTPROTO="static"
NM_CONTROLLED="no"
NOZEROCONF="yes"
# /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
TYPE="Ethernet"
BRIDGE="br0"
HWADDR="00:XX:XX:XX:XX:B1"
ONBOOT="yes"
BOOTPROTO="static"
NM_CONTROLLED="no"
NOZEROCONF="yes"
# /etc/sysconfig/network-scripts/ifcfg-ethX
DEVICE="ethX"
TYPE="Ethernet"
BRIDGE="br0"

etc. etc. for all network cards you want to participate in the bridge.

Then setup a virtual device so that the server as an IP address of it’s own.
Like below.

# /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
TYPE="Bridge"
IPADDR="192.168.1.1"
NETMASK="255.255.255.0"
BROADCAST="192.168.1.255"
GATEWAY="192.168.1.254"
ONBOOT="yes"
BOOTPROTO="static"
NM_CONTROLLED="no"
NOZEROCONF="yes"

But I needed 2 nic’s in my server for 2 IP addresses you say ??
No worries… Just alias the br0 device like below.

# /etc/sysconfig/network-scripts/ifcfg-br0:1
DEVICE="br0:1"
TYPE="Bridge"
IPADDR="192.168.2.1"
NETMASK="255.255.255.0"
BROADCAST="192.168.2.255"
GATEWAY="192.168.2.254"
ONBOOT="yes"
BOOTPROTO="static"
NM_CONTROLLED="no"
NOZEROCONF="yes"

Note*
You can’t write iptable rules for eth0 eth1 ethX. You’ll have to write them for br0 instead.
Because all network traffic will pass trough the nic’s transparent at level 2 from the OSI model and iptables packet filtering works at level 3 and 4 from the OSI model.

Note**
The drawback to aliasing is that iptables can’t handle aliased devices.
You’ll have to write iptable rules bound to the ip addresses and not to the devices.

Note***
I read some where that you can not use dhcp client on aliased devices….
I can not confirm or deny that as i don’t use dhcp client on my server.

Note****
Configuring applications and services that (can) bind to hardware devices. The eth0 eth1 ethX are not available to applications and services anymore as they operate now at level 2 data layer (OSI model). You’ll have to modify the configurations to use the bridge devices ‘br0’. Again some applications or services can’t bind to aliases or even virtual devices like the br0. Then you’ll have to bind them to IP address instead.

Note*****
On heavy traffic lan’s cheap ethernet cards won’t cut it.
Low end ethernet devices have a very limited threads capability.
They will start dropping packets… And the whole bridge is as strong as the cheapest card.
because all level 2 traffic from one eth is broadcasted to all other eth devices and that for all eth’s

Note*****
Make sure all eth’s work at the same speed. 1 card at 10Mb half duplex and another at 100Mb full duplex is very very bad. As the slow card now have to buffer traffic from the fast card which it can’t do for long it just don’t have that kind of capabilities. I recon it won’t hold long on even very low traffic lan’s. It’s just bad practice, very bad.