Commit 90ae6bd6 authored by Nong Hoang Tu's avatar Nong Hoang Tu

Add source code

Pipeline #704 canceled with stages
import strutils
import httpclient
import os
Mirror = object
url: string
edition: string
repoConfig = "/etc/apt/sources.list.d/parrot.list"
localRepoIndex = "/var/lib/apt/lists/"
iterator readTextLines(data: string): TaintedString =
var txt: string
for chr in data:
if chr != '\n':
txt &= chr
yield txt
txt = ""
proc urlToFileName(url, edition: string): string =
let info = url.split("/")
return info[2] & "_" & info[3] & "_dists_" & edition & "_InRelease"
proc urlToRepoURL(url, edition: string): string =
return url & "/dists/" & edition & "/InRelease"
proc updateServerChange(url: string): string =
var client = newHttpClient()
let resp = client.get(url)
return resp.body
proc parseDateFromFile(filePath: string): string =
for line in lines(filePath):
if line.startsWith("Date: "):
return line
proc parseDateFromText(data: string): string =
for line in readTextLines(data):
if line.startsWith("Date: "):
return line
proc main() =
for line in lines(repoConfig):
if line.startsWith("deb "):
info = line.split(" ")
mirror = Mirror(
url: info[1],
edition: info[2]
echo "[i] Checking " & mirror.url
let fileFromURL = localRepoIndex & urlToFileName(mirror.url, mirror.edition)
if not fileExists(fileFromURL):
echo "[x] You system hasn't updated from current mirror"
localDate = parseDateFromFile(fileFromURL)
serverDate = parseDateFromText(updateServerChange(urlToRepoURL(mirror.url, mirror.edition)))
if localDate == serverDate:
echo "[*] Your system is up to date"
echo "[!] New update is available"
echo "[+] Your last update: " & localDate
echo "[+] Repo last update: " & serverDate
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment