Friday, February 19, 2016

Thursday, February 18, 2016

icacls, grant authenticated users write permissions

This is how to create a temp direcotry and grand all authenticated users write permissions:
if exist "c:\temp" rd "c:\temp" /Q /S
if not exist "c:\temp" md "c:\temp"
c:\windows\system32\icacls c:\temp /grant "Authenticated Users":(OI)(CI)M

Wednesday, February 17, 2016

Update Adobe Reader DC to version 15.010.20059

Download installer:
http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/1500720033/AcroRdrDC1500720033_en_US.msi
03602e4c6f342f6cf8253661c72c6638
d509f92d07774197ae044cd248ae9fd888b73bb1

Download patch:
http://ardownload.adobe.com/pub/adobe/reader/win/AcrobatDC/1501020059/AcroRdrDCUpd1501020059.msp
c5479921e2428fc21cc0a7a621d5eb47
f60f100890cad43073a81f05ca4bf3c12a532f70

Run the script:
silent-install-adobe-reader-dc.cmd
@echo off
setlocal EnableDelayedExpansion
set U=Microsoft\Windows\CurrentVersion\Uninstall
set v=DisplayVersion
set AR={AC76BA86-7AD7-1033-7B44-AC0F074E4100}
if "%ProgramFiles(x86)%"=="" (
set SW=HKLM\SOFTWARE
) else (
set SW=HKLM\SOFTWARE\Wow6432Node
)

reg query "%SW%\%U%\%AR%" > nul 2>&1
if !errorlevel!==0 (
reg query "%SW%\%U%\%AR%" /v %v% | findstr "15.007.20033"
if !errorlevel!==0 (
echo installing patch 15.008.20082
%systemroot%\system32\msiexec.exe ^
/p "%~dp0AcroRdrDCUpd1500820082.msp" /qb
)
reg query "%SW%\%U%\%AR%" /v %v% | findstr "15.010.20056"
if !errorlevel!==0 (
echo installing patch 15.010.20059
%systemroot%\system32\msiexec.exe ^
/p "%~dp0AcroRdrDCUpd1501020059.msp" /qb
)
echo now the version is:
reg query "%SW%\%U%\%AR%" /v %v% | findstr "%v%"
goto AdbRdrOK
) else echo Adobe Reader DC not found!

start /wait "" %systemroot%\system32\msiexec.exe ^
/i "%~dp0AcroRdrDC1500720033_en_US.msi" ^
PATCH="%~dp0AcroRdrDCUpd1501020059.msp" ^
EULA_ACCEPT=YES /qn /norestart

:AdbRdrOK
endlocal

Tuesday, February 16, 2016

Get value from agent failed: ZBX_TCP_READ() failed: [4] Interrupted system call

Every command which you request from zabbix server using system.run[] are supposed to run in 1 second or less. If this command takes longer time then you get:
Get value from agent failed: ZBX_TCP_READ() failed: [4] Interrupted system call
By defalt when you run zabbix agent on client computer it open three handlers which will wait for any requests:
ps aux|grep [z]abbix
You can set more my modifying zabbix_agentd
StartAgents=10
To set that each request can execute 10 seconds you can set:
Timeout=10
Full zabbix_agentd.conf configuration:
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=ip.addres.of.server
EnableRemoteCommands=1
Hostname=raspberry
StartAgents=10
Timeout=10
DebugLevel=3
Also make sure that zabbix_server.conf needs Timeout option to be increased:
If Timeout is not configured then it is 3 which is too low for serious monitoring.
Timeout=10
Some debugging tools:

Check if zabbix server can reach zabbix agent:
nc -v -z ip.of.zabbix.agent 10050
This should report one line which ends with succeeded!

Check if zabbix agent can reach zabbix server:
nc -v -z ip.of.zabbix.server 10051
This should report one line which ends with succeeded!

Check if zabbix agent receive incoming connection from zabbix server
tcpdump -i any -n tcp port 10050
This should report a lot of stuff

Zabbix 3.0.0 appliance for Raspberry Pi

Good news everyone. Zabbix 3.0.0 stable version is out.

On the top of 2016-02-09-raspbian-jessie-lite i have
made the main partition a little bit longer but not to the maximum.

Then i update system and install git:
sudo su
apt-get update -y && apt-get upgrade -y
apt-get install git -y
And now the zabbix server installation:
sudo su
cd
git clone https://github.com/catonrug/raspbian-zabbix-3.git && cd raspbian-zabbix-3 && chmod +x agent-install.sh server-install.sh
./server-install.sh
At the installation process you are prompted to enter mysql root password.
In this case if you want to go things further automatically you have to enter password reverse

What really happens under the hood you can see:
https://github.com/catonrug/raspbian-zabbix-3/blob/master/server-install.sh

After 70 minutes on raspberry pi 1 or 40 minutes on raspberry pi 2 all the installation and compile process has been done. You have to manually reboot the system:
reboot
Now boot up your Raspberry Pi and go to address:
http://raspberry.pi.ip.address/zabbix
Use username Admin (case sensitive) with password zabbix (case sensitive)

And here is new design:

Monday, February 15, 2016

Do not let run same script at the same time

I have sheduled my detection collection to run every hour. The collection are getting larger and already have developed some child script which will run 3 hours or something. Today i have learned this brilliant command flock which will make sure if your executed script is not running already. So the script will be not executed if it still are doing his job.

For example this is my line in crontab now:
10 * * * * flock -n ~/check.pid -c ~/detect/check-all.sh
You can still broke the process by manual executing:
~/detect/check-all.sh
But cronjob will not brake your system :)

Sunday, February 14, 2016

Emulate Internet Explorer in python mechanize

Install python mechanize:
sudo apt-get install python-mechanize
Create file html-downloader.py
import sys
from mechanize import Browser
br = Browser()

br.set_handle_robots( False )
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko')]

url = str(sys.argv[1])
filename = str(sys.argv[2])

f = br.retrieve(url,filename)[0]
Test if it is working:
python html-downloader.py http://catalog.update.microsoft.com/v7/site/Search.aspx?q=KB3078601 test.html
grep KB3078601 test.html
Related:
http://www.useragentstring.com/

Friday, February 12, 2016

Detect new Google Chrome version for windows

This is my twenty-seventh project for offline installer detection.
Now i look for Google Chrome offline installers:

Google Chrome gives you latest version folowing these links which inlude direct offline installer for 32-bit and 64-bit systems, exe and msi installers:
https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BBF2074E4-8356-F8B3-CA3E-6A3D31706CF5%7D%26lang%3Den%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers/dl/chrome/install/googlechromestandaloneenterprise.msi
https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BBF2074E4-8356-F8B3-CA3E-6A3D31706CF5%7D%26lang%3Den%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-stable/dl/chrome/install/googlechromestandaloneenterprise64.msi
https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BCCC2CBDB-3B3D-8579-804A-661B13499EAC%7D%26lang%3Dlv%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dtrue/update2/installers/ChromeStandaloneSetup.exe
https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BCCC2CBDB-3B3D-8579-804A-661B13499EAC%7D%26lang%3Dlv%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dtrue%26ap%3Dx64-stable/update2/installers/ChromeStandaloneSetup64.exe
New version is based on "Last-Modified" content which wget spider gives me. Here is basic idea which will detect 32-bit msi installer and do not download it again it has aleady the latest. Everything will work out with copy and paste:
#!/bin/sh

#set database variable
db=$(echo "chrome.db")

#if database file do not exist then create one
if [ ! -f "$db" ]; then
  touch "$db"
fi

#installers destination on server
url=$(echo "https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BBF2074E4-8356-F8B3-CA3E-6A3D31706CF5%7D%26lang%3Den%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers/dl/chrome/install/googlechromestandaloneenterprise.msi")

#set filename
filename=$(echo $url | sed "s/^.*\///g")

#download all information about file information on server but do not download the file by itself
wget -S --spider -o output.log "$url"

#set last modified field in variable
lastmodified=$(grep -A99 "^Resolving" output.log | grep "Last-Modified" | sed "s/^.*: //")

grep "$filename $lastmodified" $db
if [ $? -ne 0 ]; then
echo new file detected

#download the file itself
wget $url -O $filename

#set this file in database
echo "$filename $lastmodified">> $db

else
echo $filename is already in database
fi
During the project i have faced a challange to detect google chrome version from setup file. This was quite hard for me and i invested like 3 hours searching for sulution. My detect file version from linux was useless this time. I even start work in hex level just to look for version number. After all these hours i find completely another command strings which was very helpful in my situation.

To detect Chrome version from exe installer i use:
7z x ChromeStandaloneSetup.exe -y
strings 102~ | grep "url.*codebase" | sed "s/\//\n/g" | grep "^[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+"
To detect Chrome version from msi installer is use:
7z x googlechromestandaloneenterprise.msi -y
7z x Binary.GoogleChromeInstaller -y
strings 102~ | grep "url.*codebase" | sed "s/\//\n/g" | grep "^[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+"
To detect change log i have learned very important command.
For example this is how i output change log for version 48.0.2564:
changes=$(echo "https://en.wikipedia.org/wiki/Google_Chrome_release_history")
wget -qO- "$changes" | grep -A 99 "48.0.2564" | grep -B99 -m1 "</tr>" | grep -m99 -A99 "<ul" | sed -e "s/<[^>]*>//g" | grep -v "^$" | sed "s/\[.*\]//g"
And i got information like this:
Window change in right-clicking an embedded web link
The key icon in "Save your password" turns black
"Clear browsing history" has been improved
A large number of fixes and improvements
Android version:
Bug fixes and speedy performance improvements.
iOS version:
This version uses WKWebView, the latest rendering engine from Apple.
The crash rate was reduced by 70% and JavaScript execution is now faster.
Redesigned icons on the New Tab page: easier access to more of your frequently-visited sites.
Spotlight integration: Drag down or right from the Home screen and search for your Chrome bookmarks.
What if we can seperate somehow all lines exept these two? Lucky for us these lines only contains : at the end! Lets add a - simbol before every line exept the lines which end with :. This is possible with:
sed -e "/:$/! s/^/- /"
And now the content look much eye catchy:
- Window change in right-clicking an embedded web link
- The key icon in "Save your password" turns black
- "Clear browsing history" has been improved
- A large number of fixes and improvements
Android version:
- Bug fixes and speedy performance improvements.
iOS version:
- This version uses WKWebView, the latest rendering engine from Apple.
- The crash rate was reduced by 70% and JavaScript execution is now faster.
- Redesigned icons on the New Tab page: easier access to more of your frequently-visited sites.
- Spotlight integration: Drag down or right from the Home screen and search for your Chrome bookmarks.
The whole project is located here:
https://github.com/catonrug/chrome-detect/blob/master/check.sh

Thursday, February 11, 2016

Detect new Picasa version for Windows

This is twenty-six project of offline installer detection.
Now it is time for Google Picasa.

Do detect latest installer link i use:
home=$(echo "https://picasa.google.com/")
wget -qO- "$home" | sed "s/\d034/\n/g" | grep exe
I look file modify time with
home=$(echo "https://picasa.google.com/")
url=$(wget -qO- "$home" | sed "s/\d034/\n/g" | grep exe)
wget -S --spider -o output.log "$url"
grep -A99 "^Resolving" output.log | grep "Last-Modified" | sed "s/^.*: //"
This is necessary cause i do not want to download file every time to to check it it the latest.

To detect version i use:
wget https://dl.google.com/picasa/picasa39-setup.exe
pestr picasa39-setup.exe | grep -m1 -A1 "ProductVersion" | grep -v "ProductVersion" | sed "s/\.[0-9]\+//3"
For change log detect:
changes=$(echo "https://support.google.com/picasa/answer/53209?hl=en")
wget -qO- "$changes" | grep -A99 -m1 "3.9.141" | grep -B99 -m2 "</strong>" | grep -v "<strong>" | sed -e "s/<[^>]*>//g" | sed "s/^[ \t]*//g" | grep -v "^$" | sed "s/^/- /"
grep -A99 -m1 "3.9.141" - grep 99 lines after first match
grep -B99 -m2 "</strong>" - grep 99 lines before second match
grep -v "<strong>" - strike out all "version headings" from result
sed -e "s/<[^>]*>//g" - remove all html tags
sed "s/^[ \t]*//g" - remove all white spaces from left side
grep -v "^$" - remove empty lines
sed "s/^/- /" - add - to start of each line

Whole project is located here:
https://github.com/catonrug/picasa-detect/blob/master/check.sh

Wednesday, February 10, 2016

WinRAR new version detect

This is my twenty-five offline installer detect project. This time it is WinRAR.

To detect 32-bit and 64-bit latest english installer i use:
download=$(echo "http://rarlab.com/download.htm")
wget -qO- "$download" | sed "s/\d034/\n/g" | grep "exe$" | sed "s/^/http:\/\/rarlab\.com/" | sort | uniq | grep "rar.*[0-9]\+\.exe
To detect change log i use WhatsNew.txt which is inside the installer:
unrar-nonfree x winrar-x64-531.exe -y
grep -A99 "   Version $version" WhatsNew.txt | grep -B99 -m2 "   Version" | grep -v "   Version" | grep "\w"
To detect exact version number:
unrar-nonfree x winrar-x64-531.exe -y
pestr Rar.exe | grep -m1 -A1 "ProductVersion" | grep -v "ProductVersion" | sed "s/\.[0-9]\+//2"
Things i have challenged and learned:
1. It is impossible to extract winrar installer with 7z library. I need unrar for raspbian.
2. I do not know why but to delete empty lines in WhatsNew.txt these command do not work:
grep -v "^$" WhatsNew.txt
sed "/^$/d" WhatsNew.txt
I created a workaround to look for all lines which INCLUDES white space character:
grep "\w" WhatsNew.txt
3. I have found a solution how to insert . character after first simbol:
sed "s/^\(.\{1\}\)/\1\./"
Whole project is located here:
https://github.com/catonrug/winrar-detect/blob/master/check.sh

Tuesday, February 9, 2016

Turn on DHCP at system startup, CentOS 6

If you missed to set up DHCP configuration at CentOS installation.

You can fix this with:
sed -i "s/^ONBOOT=.*$/ONBOOT=yes/" /etc/sysconfig/network-scripts/ifcfg-eth0

7-Zip new version detect for windows

This is my twenty-four project about offline installer detect. This time it is 7-Zip.

To get all links on download page i use:
download=$(echo "http://www.7-zip.org/download.html")
wget -qO- "$download" | sed "s/\d034/\n/g" | grep "exe$\|msi$" | grep -v "ia64\|arm" | sed "s/^/http:\/\/www\.7-zip\.org\//"
It was quite a challange to detect change log but i made it with this method:
#set change log url
changes=$(echo "http://www.7-zip.org/history.txt")

#for example look for version 15.14
#there must be two spaces after version
wget -qO- "$changes" | grep -A99 "^15.14  " | grep -m2 -B99 "\-\-\-\-\-" | head -n -4
The things i learn during this project:
To delete last 4 lines from output is quite easy to done with:
head -n -4
After exe installer extract i work with 7z.exe file to detect version.
After msi installer extract i have to look for _7z.exe file do detect version.

Interesting part about custom subject was this part:
case "$filename" in
*x64.exe)
bit=$(echo "(64-bit)")
;;
*x64.msi)
bit=$(echo "msi (64-bit)")
;;
*msi)
bit=$(echo "msi (32-bit)")
;;
*exe)
bit=$(echo "(32-bit)")
;;
esac
In this "case" scenario the sequence is very inportant cause after a match it quits searching for other cases. This was quit new to me in practice :)

Complete project is located here:
https://github.com/catonrug/7zip-detect/blob/master/check.sh

Monday, February 8, 2016

Detect new VirtualBox version for Windows

Now i am detecting VirtualBox version.

It was quite a challange to detect change log but i finally implemented it with these commands:
#!/bin/sh

#set change log url
changes=$(echo "https://www.virtualbox.org/wiki/Changelog")

#this is where the latest installer in located
#it is necesary to find wich version today is the latest
download=$(echo "https://www.virtualbox.org/wiki/Downloads")

#get the latest installer full link
url=$(wget -qO- "$download" | sed "s/\d034/\n/g" | grep exe | head -1)

#calculate filename
filename=$(echo $url | sed "s/^.*\///g")

#find the version number from filename
version=$(echo "$filename" | sed "s/-/\n/g" | grep "^[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+")

#scrap the changes content based on version number
wget -qO- "$changes" | grep -A99 "$version" | grep -m2 -B99 "strong" | grep -v "<strong>" | sed -e "s/<[^>]*>//g" > change.log

#check if even something has been created
if [ -f change.log ]; then

#calculate how many lines log file contains
lines=$(cat change.log | wc -l)
if [ $lines -gt 0 ]; then
echo change log found:
echo

#output the log
cat change.log

else
echo change.log has been created but no content is inside
fi

else
echo no change.log has beed created
fi
The commands i learn:

remove html tags with sed

sed -e "s/<[^>]*>//g"

combine two if statement using and

if [ -f change.log ] && [ $lines -gt 0 ]; then
echo change.log exists and has content
else file change.log not found
fi
Whole project is located here:
https://github.com/catonrug/virtualbox-detect/blob/master/check.sh

Sunday, February 7, 2016

Wipe free space on external SD card, Raspberry Pi

In this scenario i want to wipe raspberry pi ext4 main partition in my appliance:

These are commands i do in another raspberry pi system:

Install secure-delete package:
sudo apt-get install secure-delete -y
Plug the appliance sd card into usb

Check out partitions Reserved block count:
sudo tune2fs -l /dev/sda2 | grep "Reserved block count"
If the block size are not 0 then set it to 0:
sudo tune2fs -m 0 /dev/sda2
Check again:
sudo tune2fs -l /dev/sda2 | grep "Reserved block count"
Now the block size is 0

Now i mount the filesystem:
sudo mount /dev/sda2 /mnt

Move to the direcotry which include the disk you want to wipe.
cd /mnt
Execute commands:
sudo su
dd if=/dev/zero of=zero.small.file bs=1024 count=102400
dd if=/dev/zero of=zero.file bs=1024
sync ; sleep 60 ; sync
rm zero.small.file
rm zero.file
Leave the disk:
cd ..
Umount disk:
umount /mnt
Set back Reserved block count:
tune2fs -m 5 /dev/sda2
log out root:
exit
Appendix:
Install wipe-free-space.sh command:
sudo su
cat > /usr/bin/wipe-free-space.sh << EOF
dd if=/dev/zero of=zero.small.file bs=1024 count=102400
dd if=/dev/zero of=zero.file bs=1024
sync ; sleep 60 ; sync
rm zero.small.file
rm zero.file
EOF
chmod +x /usr/bin/wipe-free-space.sh

Saturday, February 6, 2016

paint.net latest version detect

Welcome to my twenty-two project for offline installers latest version detect:
All detection projects can be listed by choosing label detect.

Latest paint.net is located under:
http://www.dotpdn.com/downloads/pdn.html

The application which will search for latest version looks like this:
#!/bin/sh

#where the latest installer are located
download=$(echo "http://www.dotpdn.com/downloads/pdn.html")

#get the zip file installer direct link
url=$(wget -qO- "$download" | sed "s/\d034/\n/g" | grep zip | head -1 | sed "s/\.*//" | sed "s/^/http:\/\/www.dotpdn.com/")

#get filename
filename=$(echo $url | sed "s/^.*\///g")

#download file
wget $url -O $filename
Whole project is located here:
https://github.com/catonrug/pdn-detect/blob/master/check.sh

Friday, February 5, 2016

Notepad++ latest version detect

This is my twenty-one project of detection offline installer. This time it is Notepad++

The basic program works just like this:
#!/bin/sh

#where the latest installer are located
download=$(echo "https://notepad-plus-plus.org/download/")

#note down where the default download page redirects
wget -S --spider -o output.log $download

#get the exact link where the latest installer is located
latest=$(grep "\[following\]$" output.log | sed "s/^.*: \| \[following\]//g" )

#get the exe file installer direct link
url=$(wget -qO- "$latest" | sed "s/\d034\|\d039/\n/g" | grep -i "npp.*installer.*exe" | head -1 | sed "s/^/https:\/\/notepad-plus-plus\.org/")

#set filename
filename=$(echo $url | sed "s/^.*\///g")

#download file
wget $url -O $filename
Whole application is located here:
https://github.com/catonrug/npp-detect/blob/master/check.sh

Thursday, February 4, 2016

Google Drive new version detect

This is my twenty project of offline installer new version detection.
This time it is Google Drive.

List all project by opening the tag:
http://www.catonrug.net/search/label/detect

The detection is based on wget spider and modify date:
wget -S --spider -o output.log https://dl.google.com/drive/gsync_enterprise.msi
And now we check the log:
grep "Last-Modified" output.log | sed "s/^.*: //"
This will report:
Wed, 20 Jan 2016 17:09:00 GMT
And now we compare this date with database!

Whole project can be found here:
https://github.com/catonrug/google-drive-detect/blob/master/check.sh

Wednesday, February 3, 2016

Detect VLC Media Player latest version for windows

To detect VLC Media Player version i use this link:
https://get.videolan.org/vlc/last/

When you browse this url it looks like the files are hosted on the same server but it is not!
When i click to one of files it redirects to completely another server like this:
http://ftp.free.org/mirrors/videolan/vlc/last/

This is how the latest VLC media player for windows can be downloaded:
#/bin/sh

#define base url
base=$(echo "https://get.videolan.org/vlc/last")

#we have two arhitectures in array
architectures=$(cat <<EOF
win32
win64
extra line
EOF
)

#the loop starts
printf %s "$architectures" | while IFS= read -r architecture
do {

#get the latest filename
filename=$(wget -qO- $base/$architecture/ | grep -v "$architecture\.exe\." | sed "s/exe/exe\n/g" | sed "s/\d034\|>/\n/g" | grep "$architecture\.exe" | head -1)

#request all information about file we are suposed to download
wget -S --spider -o output.log $base/$architecture/$filename -q

#get the real direct url of installer
url=$(sed "s/http/\nhttp/g" output.log | sed "s/exe/exe\n/g" | grep "^http.*exe$")
echo $url

echo Downloading $filename
wget $url -O $filename

} done
Whole program is located here:
https://github.com/catonrug/vlc-detect/blob/master/check.sh

Tuesday, February 2, 2016

HandBrake new version detect

Now i am detecting latest HandBrake installers for windows.

This is how i get full installer links:
#/bin/sh

#global link
site=$(echo "https://handbrake.fr/downloads.php")

#get 64-bit and 32-bit installer link on web site
linklist=$(wget -qO- "$site" | sed "s/\d034/\n/g" | grep "exe$" | sed "s/^/https:\/\/handbrake\.fr\//" | sed '$alast line')

#create loop
printf %s "$linklist" | while IFS= read -r link
do {

#use spider mode to look what content are exactly are under the link
wget -S --spider -o output.log "$link"

#get full direct link
grep -A99 "^Resolving" output.log | sed "s/http/\nhttp/g" | sed "s/exe/exe\n/g" | grep "^http.*exe$" | head -1

} done
Whole project is located here:
https://github.com/catonrug/handbrake-detect/blob/master/check.sh

Monday, February 1, 2016

CCleaner, Recuva, Speccy, Defraggler new version detect

This is my seventeenth project for offline installer detection.

In this project i look for all four home products from www.piriform.com:
CCleaner, Recuva, Speccy and Defraggler

When i use one of these applicaitions i never install it to my computer. I use 7-zip instead and extract installer. There are executable files inside wich can be executed instantly without installation.

In this automation project i look for latest installer, download it, seperate 32-bit and 64-bit files, archive it with 7-zip and upload to google drive. The result you can pretty much see under http://dl4ou.blogspot.com/

I have faced a lot of challanges during this project:

Lower case the names:
echo CCleaner | tr '[:upper:]' '[:lower:]'
Find exact filename using insensitive patter:
exe32=$(find . -maxdepth 1 -iname *Recuva.exe* | sed "s/^.*\///g")
Search for exact version. Yes! recuva.exe is in lowercase:
pestr CCleaner.exe | grep -A2 "^CCleaner" | grep -A1 "^ProductVersion" | grep -v "ProductVersion"
pestr Speccy.exe | grep -A2 "^Speccy" | grep -A1 "^ProductVersion" | grep -v "ProductVersion"
pestr Defraggler.exe | grep -A2 "^Defraggler" | grep -A1 "^ProductVersion" | grep -v "ProductVersion"
pestr recuva.exe | grep -A2 "^Recuva" | grep -A1 "^ProductVersion" | grep -v "ProductVersion"
An this will report numbers like
5, 14, 00, 5493
1.29.0.714
2.20.0.989
1.52.0.1086 -- 1.52.0.1086
At first i want to create a detection rule which will say that this founding is good
grep "^[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+[\., ]\+[0-9]\+"
Delete all spaces, delete all content after -, substitute all comas with dots:
sed "s/\s//g;s/-.*$//g;s/,/\./g"
This will leave me to:
5.14.00.5493
1.29.0.714
2.20.0.989
1.52.0.1086
To delete the third part from version i use seds second match:
sed "s/\.[0-9]\+//2"
Result will be similar to this:
5.14.00.5493
1.29.0.714
2.20.0.989
1.52.0.1086
Since periform company keep all thing pretty clean i will try to scrap the change log information from web site:

This can be done:
wget -qO- "https://www.piriform.com/ccleaner/version-history" | \
sed "s/<h6>/\n<h6>/g;s/<\/h6>/<\/h6>\n/g;s/<br\/>\|<br \/>//g" | \
grep -A99 "5.14.5493" | grep -m2 -B99 "<h6>" | \
sed '/^\s*$/d' | grep -v "<h6>"
You have to look on https://www.piriform.com/ccleaner/version-history and write the correct latest version number into the grep

Most interesting part is showing next 99 line after match and before second heading.
grep -A99 "5.14.5493" | grep -m2 -B99 "<h6>"
To archive the files i executed man 7z and found the recommended command:
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z CCleaner.exe
Whole project is located here:
https://github.com/catonrug/piriform-detect/blob/master/check.sh

Blog Archive