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

Add source code

parents
Pipeline #704 canceled with stages
import strutils
import httpclient
import os
type
Mirror = object
url: string
edition: string
const
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
else:
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 "):
let
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"
else:
let
localDate = parseDateFromFile(fileFromURL)
serverDate = parseDateFromText(updateServerChange(urlToRepoURL(mirror.url, mirror.edition)))
if localDate == serverDate:
echo "[*] Your system is up to date"
else:
echo "[!] New update is available"
echo "[+] Your last update: " & localDate
echo "[+] Repo last update: " & serverDate
main()
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