Skip to content

Commit

Permalink
Update current OS after a macOS update
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Jan 9, 2024
1 parent de53153 commit d402b56
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion migrations/2017_12_17_0000001_supported_os.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function up()
$table->index('last_touch');
});
}

public function down()
{
$capsule = new Capsule();
Expand Down
2 changes: 1 addition & 1 deletion migrations/2020_05_10_000001_supported_os_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
$table->index('shipping_os');
});
}

public function down()
{
$capsule = new Capsule();
Expand Down
30 changes: 15 additions & 15 deletions scripts/supported_os
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
#!/bin/sh
# Check the supported_os once a week
# Check the supported_os once a week or if the cached OS version changes

# Seconds between checks
CHECK=604800

# Get the cache directory
DIR=$(dirname $0)
DIR=$(/usr/bin/dirname $0)

# Check if supported_os.plist exists
if [ -e "$DIR/cache/supported_os.plist" ]; then

# Get current time
TIME=$(date +%s)
TIME=$(/bin/date +%s)

# Get file modified time
FILEMTIME=$(stat -f "%Sm" -t "%s" "$DIR/cache/supported_os.plist")
FILEMTIME=$(/usr/bin/stat -f "%Sm" -t "%s" "$DIR/cache/supported_os.plist")

# Calculate the difference in seconds
DIFF=$(( $TIME - $FILEMTIME ))

if [ $DIFF -gt $CHECK ]; then
# Get the cached OS version
CACHED_OS=$(/usr/bin/defaults read "$DIR/cache/supported_os.plist" current_os)

# If cache file was last touched over a week ago or contains an outdated OS version, update it
if [ $DIFF -gt $CHECK ] || [ $(/usr/bin/sw_vers -productVersion) != "${CACHED_OS}" ]; then
# Store date in file
defaults write "$DIR/cache/supported_os.plist" last_touch $(date +%s)
defaults write "$DIR/cache/supported_os.plist" current_os $(sw_vers -productVersion)
defaults write "$DIR/cache/supported_os.plist" machine_id $(/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | awk '{print $NF}')
/usr/bin/defaults write "$DIR/cache/supported_os.plist" last_touch $(/bin/date +%s)
/usr/bin/defaults write "$DIR/cache/supported_os.plist" current_os $(/usr/bin/sw_vers -productVersion)
/usr/bin/defaults write "$DIR/cache/supported_os.plist" machine_id $(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep "Model Identifier" | /usr/bin/awk '{print $NF}')
fi


else

# Store date in file
defaults write "$DIR/cache/supported_os.plist" last_touch $(date +%s)
defaults write "$DIR/cache/supported_os.plist" current_os $(sw_vers -productVersion)
defaults write "$DIR/cache/supported_os.plist" machine_id $(/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | awk '{print $NF}')

/usr/bin/defaults write "$DIR/cache/supported_os.plist" last_touch $(/bin/date +%s)
/usr/bin/defaults write "$DIR/cache/supported_os.plist" current_os $(/usr/bin/sw_vers -productVersion)
/usr/bin/defaults write "$DIR/cache/supported_os.plist" machine_id $(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep "Model Identifier" | /usr/bin/awk '{print $NF}')
fi
18 changes: 9 additions & 9 deletions supported_os_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function os()
$out = array();
$machine = new Supported_os_model();
$sql = "SELECT count(1) as count, highest_supported
FROM supported_os
LEFT JOIN reportdata USING (serial_number)
WHERE ".get_machine_group_filter('')."
AND highest_supported > 0
GROUP BY highest_supported
ORDER BY highest_supported DESC";
FROM supported_os
LEFT JOIN reportdata USING (serial_number)
WHERE ".get_machine_group_filter('')."
AND highest_supported > 0
GROUP BY highest_supported
ORDER BY highest_supported DESC";

foreach ($machine->query($sql) as $obj) {
$obj->highest_supported = $obj->highest_supported ? $obj->highest_supported : '0';
Expand All @@ -51,7 +51,7 @@ public function os()

jsonView($out);
}

/**
* Force data pull from supported_os GitHub
*
Expand Down Expand Up @@ -188,15 +188,15 @@ public function pull_all_supported_os_data($incoming_serial = '')
jsonView($machine->process($data));
}
}

/**
* Reprocess serial number
*
* @return void
* @author tuxudo
**/
public function recheck_highest_os($serial)
{
{
// Remove non-serial number characters
$serial = preg_replace("/[^A-Za-z0-9_\-]]/", '', $serial);

Expand Down
4 changes: 2 additions & 2 deletions supported_os_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use munkireport\lib\Request;

class Supported_os_model extends \Model
{
{
public function __construct($serial = '')
{
parent::__construct('id', 'supported_os'); // Primary key, tablename
Expand Down Expand Up @@ -245,7 +245,7 @@ public function process($data)

// Save OS gibblets
$this->save();

// Return something if reprocessing
if(is_array($data)){
return true;
Expand Down
12 changes: 6 additions & 6 deletions views/supported_os_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<script>
var supported_os_pull_all_running = 0;

$(document).on('appReady', function(e, lang) {

// Get JSON of admin data
Expand All @@ -41,7 +41,7 @@

$('#SupportedOS-Status').html(sosrows+'</tbody></table>') // Close table framework and assign to HTML ID
});

// Generate pull all button and header
$('#supported_os_pull_all').html('<h3 class="col-lg-6" >&nbsp;&nbsp;'+i18n.t('supported_os.title_admin')+'&nbsp;&nbsp;<button id="GetAllSupportedOS" class="btn btn-default btn-xs">'+i18n.t("supported_os.pull_in_all")+'</button>&nbsp;&nbsp;<button id="UpdateSupportedOS" class="btn btn-default btn-xs">'+i18n.t("supported_os.update_cache_file")+'</button>&nbsp;<i id="GetAllSupportedOSProgess" class="hide fa fa-cog fa-spin" aria-hidden="true"></i></h3>');

Expand All @@ -51,7 +51,7 @@
$('#GetAllSupportedOS').addClass('disabled');
$('#GetAllSupportedOSProgess').removeClass('hide');
$('#UpdateSupportedOS').addClass('disabled');

$.getJSON(appUrl + '/module/supported_os/update_cached_data', function (processdata) {
if(processdata['status'] == 1){
var date = new Date(processdata['timestamp'] * 1000);
Expand All @@ -61,9 +61,9 @@
$('#GetAllSupportedOS').removeClass('disabled');
$('#UpdateSupportedOS').removeClass('disabled');
$('#GetAllSupportedOSProgess').addClass('hide');

} else if(processdata['status'] == 2){

var date = new Date(processdata['timestamp'] * 1000);
$('#sos_time').html('<span title="'+moment(date).fromNow()+'">'+moment(date).format('llll')+'</span>')
$('#sos_source').html(i18n.t('supported_os.update_from_local'))
Expand Down Expand Up @@ -170,7 +170,7 @@ function process_serial(serial,progessvalue,progressmax,processdata,serial_index
return;
}
};

</script>

<?php $this->view('partials/foot'); ?>
72 changes: 36 additions & 36 deletions views/supported_os_tab.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<h2>Supported OS <a data-i18n="supported_os.recheck" class="btn btn-default btn-xs" href="<?php echo url('module/supported_os/recheck_highest_os/' . $serial_number);?>"></a></h2>

<div id="supported_os-msg" data-i18n="listing.loading" class="col-lg-12 text-center"></div>
<div id="supported_os-view" class="row hide">
<div class="col-md-3">
<table class="table table-striped">
<tr>
<th data-i18n="supported_os.current_os"></th>
<td id="supported_os-current_os"></td>
</tr>
<tr>
<th data-i18n="supported_os.highest_supported"></th>
<td id="supported_os-highest_supported"></td>
</tr>
<tr>
<th data-i18n="supported_os.shipping_os"></th>
<td id="supported_os-shipping_os"></td>
</tr>
<tr>
<th data-i18n="supported_os.machine_id"></th>
<td id="supported_os-machine_id"></td>
</tr>
<tr>
<th data-i18n="supported_os.last_touch"></th>
<td id="supported_os-last_touch"></td>
</tr>
</table>
</div>
</div>
<div id="supported_os-view" class="row hide">
<div class="col-md-3">
<table class="table table-striped">
<tr>
<th data-i18n="supported_os.current_os"></th>
<td id="supported_os-current_os"></td>
</tr>
<tr>
<th data-i18n="supported_os.highest_supported"></th>
<td id="supported_os-highest_supported"></td>
</tr>
<tr>
<th data-i18n="supported_os.shipping_os"></th>
<td id="supported_os-shipping_os"></td>
</tr>
<tr>
<th data-i18n="supported_os.machine_id"></th>
<td id="supported_os-machine_id"></td>
</tr>
<tr>
<th data-i18n="supported_os.last_touch"></th>
<td id="supported_os-last_touch"></td>
</tr>
</table>
</div>
</div>

<script>
$(document).on('appReady', function(e, lang) {

// Get supported_os data
$.getJSON( appUrl + '/module/supported_os/get_data/' + serialNumber, function( data ) {
// Get supported_os data
$.getJSON( appUrl + '/module/supported_os/get_data/' + serialNumber, function( data ) {
// Check if we have valid data
if( ! data.current_os){
$('#supported_os-msg').text(i18n.t('no_data'));
if( ! data.current_os){
$('#supported_os-msg').text(i18n.t('no_data'));
$('#supported_os-cnt').text("");
} else {
} else {

// Hide
$('#supported_os-msg').text('');
$('#supported_os-view').removeClass('hide');
// Hide
$('#supported_os-msg').text('');
$('#supported_os-view').removeClass('hide');

// Add data
$('#supported_os-cnt').text(mr.integerToVersion(data.highest_supported));
Expand All @@ -58,8 +58,8 @@
} else {
$('#supported_os-last_touch').text(i18n.t('supported_os.never'));
}
}
});
}
});
});

</script>

0 comments on commit d402b56

Please sign in to comment.