-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppGrabber.ps1
More file actions
136 lines (109 loc) · 4.57 KB
/
AppGrabber.ps1
File metadata and controls
136 lines (109 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
################################# SLACK INTEGRATION #############################################
$enableSlack = $false # $true/$false
if($enableSlack){
Function SlackWrite {
Param ([string]$slackstring)
$payload = @{
"channel" = "#SLACK-CHANNEL"
"text" = "$slackstring"
}
Invoke-WebRequest `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri "https://CHANGEMEPLEASE.CHANGE" | Out-Null
}
}
################################# AppGrabber Settings ###########################################
# Download location
$dlLocation = "$PSSCRIPTROOT\AppGrabber_Downloads"
if(!(Test-Path $dlLocation)){
New-Item $dlLocation -Type Directory | Out-Null
}
# Recepies location
$recepieLocation = "$PSSCRIPTROOT\AppGrabber_Recepies"
$recepies = Get-ChildItem "$recepieLocation\*.ps1"
$totalRecepies = Get-Childitem $recepieLocation | Where-Object {$_.extension -in ".ps1"} | Group-Object Extension -NoElement | Sort-Object count -desc | Select-Object -ExpandProperty count
# File versions location
$fvLocation = "$PSSCRIPTROOT\AppGrabber_Downloads\file_versions"
if(!(Test-Path $fvLocation)){
New-Item $fvLocation -Type Directory | Out-Null
}
# Log vars
$logPath = "$PSScriptRoot\AppGrabber_Log" # Log file folder in same location as the script
$logFileName = "AppGrabber.log" # Log filename
$logFile = "$logPath\$logFileName" # Combine LPath and LFile to make one full path
# Create log file and folder if missing
if(!(Test-Path $logPath)){
New-Item $logPath -Type Directory | Out-Null
}
if(!(Test-Path $logFile)){
New-Item $logFile -Type file | Out-Null
}
Function LogWrite {
Param ([string]$logstring)
$logTime = Get-Date -format "yyyy-MM-dd HH:mm:ss"
$logText = $logTime + " - " + $logstring
Add-content $logFile -value $logText
}
# Function for gathering version numbers
function Get-ChocoPackageVersion {
# Gets the version of the Chocolatey package.
[cmdletbinding()]
param(
[Parameter(Position=0)]
# Example: https://chocolatey.org/packages/GoogleChrome
[String]$ChocoPackageURL
)
$script:ChocoPackageVersion = ((Invoke-RestMethod -Uri "$ChocoPackageURL").Split("`r`n") | Select-String "<title>").ToString() -split " " -replace "</title>","" | Select-Object -Last 1
}
################################# Build Settings ###########################################
# Builds location
$buildLocation = "$PSSCRIPTROOT\AppGrabber_Builds"
if(!(Test-Path $buildLocation)){
New-Item $buildLocation -Type Directory | Out-Null
}
$templateLocation = "$PSSCRIPTROOT\AppGrabber_Templates"
if(!(Test-Path $templateLocation)){
New-Item $templateLocation -Type Directory | Out-Null
}
################################# Define softwares ###########################################
# Set start time
$startTime = Get-Date -Format HH:mm:ss
# Set counting apps to download to zero
$appsToDL = 0
# Count recepies, starts from 1
$countRecepie = 1
Write-Host("`n`n`n`n`n`n`n")
Write-Host "============================================================" -ForegroundColor 'green'
Write-Host "AppGrabber - Script started" -ForegroundColor 'green'
LogWrite "AppGrabber - Script started"
Write-Host "============================================================" -ForegroundColor 'green'
# Cycle through all recepies found in $recepieLocation
forEach($recepie in $recepies){
# Set app name to the recepie name without .extension
$recepieName = $recepie.BaseName
Write-Host "Processing $recepieName | Recepie [$countRecepie/$totalRecepies]" -ForegroundColor 'green'
LogWrite "Processing $recepieName"
. $recepieLocation\$recepieName.ps1
Write-Host "------------------------------------------------------------" -ForegroundColor 'green'
$countRecepie++
}
$endTime = Get-Date -Format HH:mm:ss
$totalTime = New-TimeSpan $startTime $endTime
# Updates available (Slack)
if($enableSlack -and $appsToDL -gt 0){
if($appsToDL -eq 1){
SlackWrite "*1* new app grabbed!"
} else {
SlackWrite "*$appsToDL* new apps grabbed!"
}
SlackWrite "*Script has completed in $totalTime*"
SlackWrite "============================================================"
} else {
#SlackWrite "*Sorry! No apps to grab..*"
}
Write-Host "============================================================" -ForegroundColor 'green'
Write-Host "Script has completed in $totalTime " -ForegroundColor 'green'
Write-Host "============================================================" -ForegroundColor 'green'
LogWrite "Script has completed in $totalTime"
LogWrite "============================================================"