Skip to content

Commit

Permalink
Add a script to copy the disc images and image files. Also add in jsb…
Browse files Browse the repository at this point in the history
…eeb.
  • Loading branch information
pau1ie committed Sep 8, 2019
1 parent de408ad commit c871638
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
web/includes/config.php
web/gameimg/discs
web/gameimg/screenshots
web/jsbeeb
*.log
.vagrant
27 changes: 25 additions & 2 deletions scripts/bootstrap.sh
Expand Up @@ -8,7 +8,7 @@ echo "+++ Installing packages "

export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y apache2 php mariadb-server php-mysql
apt-get install -y apache2 php mariadb-server php-mysql unzip

echo "Password is $PASSWORD"
echo "+++ Setting up the databse"
Expand All @@ -24,7 +24,7 @@ mysql -vu "$DBUSER" -D "$DBNAME" -p"$PASSWORD" < /vagrant/db/db.sql > /vagrant/
echo "+++ Creating and loading user table."
mysql -vu "$DBUSER" -D "$DBNAME" -p"$PASSWORD" < /vagrant/db/users.sql > /vagrant/db/users.log

echo "+++Setting up config"
echo "+++ Setting up config"

sed -e "s/DB_NAME','bbc'/DB_NAME','$DBNAME'/" \
-e "s/DB_USER','bbc'/DB_USER','$DBUSER'/" \
Expand All @@ -44,4 +44,27 @@ sed 's/;extension=pdo_mysql/extension=pdo_mysql/' /etc/php/"$PHPV"/apache2/php.i

sudo systemctl restart apache2.service

if [[ -f BBCMicroFiles.zip ]] && [[ -f BBCMicroScShots.zip ]]
then
echo "++ Files already downloaded."
else
echo "+++ Getting files"
wget http://bbcmicro.co.uk/tmp/BBCMicroFiles.zip
wget http://bbcmicro.co.uk/tmp/BBCMicroScShots.zip
fi
echo "+++ Unzipping files"

[[ -d files ]] || mkdir files
[[ -d screens ]] || mkdir screens
cd files
unzip -f ../BBCMicroFiles.zip
cd ../screens
unzip -f ../BBCMicroScShots.zip

echo "+++ Copy disc images and screenshots into place"
php scripts/copyfiles.php
echo "+++ Copy jsbeeb"
cd /vagrant/web
git clone https://github.com/mattgodbolt/jsbeeb.git
cp -pr jsb/* jsbeeb
echo "+++Done!"
83 changes: 83 additions & 0 deletions scripts/copyfiles.php
@@ -0,0 +1,83 @@
<?php
require dirname(__FILE__) . '/../web/includes/config.php';
require dirname(__FILE__) . '/../web/includes/db_connect.php';
require dirname(__FILE__) . '/../web/includes/playlink.php';

define('WEBBASE','/vagrant/web');
define('UNZIPBASE','/home/vagrant');

$sql = "select * from screenshots";
$sth = $db->prepare($sql,array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->bindParam(1, $id, PDO::PARAM_INT);
if ($sth->execute()) {
$shots = $sth->fetchAll();
} else {
echo "Error:";
echo "\n";
$sth->debugDumpParams ();
$shots=array();
}

foreach ($shots as $shot) {
//$imagefile = WEBBASE . '/' . get_scrshot($shot['filename'],$shot['subdir']);
$subdir = $shot['subdir'];
$file = $shot['filename'];
if ($subdir === NULL or $subdir === '') {
$imagefile = WEBBASE . '/gameimg/screenshots/' . $file;
} else {
$imagefile = WEBBASE . '/gameimg/screenshots/' . $subdir . '/' . $file;
}
$dir = dirname($imagefile);
if ( ! is_dir($dir)) {
mkdir($dir , 0777,True);
}
$files=glob(UNZIPBASE . '/screens/?/*-' . $shot['gameid'] . '.???');
if (sizeof($files) > 1) {
print("Too many images match");
print_r($shot);
}
if (sizeof($files)!=0) {
copy($files[0], $imagefile);
} else {
print("Screnshot missing for:");
print_r($shot);
}
}

$sql = "select * from images";
$sth = $db->prepare($sql,array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->bindParam(1, $id, PDO::PARAM_INT);
if ($sth->execute()) {
$shots = $sth->fetchAll();
} else {
echo "Error:";
echo "\n";
$sth->debugDumpParams ();
$shots=array();
}

foreach ($shots as $shot) {
$subdir=$shot['subdir'];
$file=$shot['filename'];
if ($subdir === NULL or $subdir === '') {
$imagefile = WEBBASE . '/gameimg/discs/' . $file;
} else {
$imagefile = WEBBASE . '/gameimg/discs/' . $subdir . '/' . $file;
}
$dir = dirname($imagefile);
if ( ! is_dir($dir)) {
mkdir($dir , 0777,True);
}
$files=glob(UNZIPBASE . '/files/?/*-' . $shot['gameid'] . '.???');
if (sizeof($files) > 1) {
print("Too many images match");
print_r($shot);
}
if (sizeof($files)!=0) {
copy($files[0], $imagefile);
} else {
print("Screnshot missing for:");
print_r($shot);
}
}
?>

0 comments on commit c871638

Please sign in to comment.