Packaging Appworx for SCCM
19 Oct 2022
(top of file structure)
|- application
| |- jars
| | |_ (lots of files)
| |- jre8
| | |_ (lots of folders and files)
| |- client.properties
| |_ RunClient.jar
|- zz-envs
| |- 01-production
| | |- APPWORXPROD
| | | |- user_keystore
| | | |_ user_keystore_config
| | |_ connections.properties
| |- 02-qa
| | |- APPWORXQA
| | | |- user_keystore
| | | |_ user_keystore_config
| | |_ connections.properties
| |_ 03-developer
| | |- APPWORXDEV
| | | |- user_keystore
| | | |_ user_keystore_config
| | |_ connections.properties
|- AppWorx 01 - Production.lnk
|- AppWorx 02 - QA.lnk
|- AppWorx 03 - Developer.lnk
|- appworx.ico
|- installhelper.ps1
|- package.txt
|_ package(datestamp goes here).txt
<#
installation occurs as a system user, since we deploy software by device. This is needed to install the SSL certificates
for each user of the workstation. Unfortunately, from what I can determine - Microsoft does not provide an easy way to
find the logged in user, so deploying the SSL certificates to all users.
#>
#Requires -RunAsAdministrator
$appworx_environments = @{
'01-production' = 'APPWORXPROD';
'02-qa' = 'APPWORXQA';
'03-developer' = 'APPWORXDEV'
}
$appworx_desktop_shortcut_filenames = @(
'AppWorx 01 - Production.lnk',
'AppWorx 02 - QA.lnk',
'AppWorx 03 - Developer.lnk'
)
$homeFolders = Get-ChildItem 'c:\users\'
$system_folder = 'C:\Appworx\'
$system_application_folder = join-path $system_folder 'application\'
$system_environments_folder = join-path $system_folder 'zz-envs\'
function CreateSymbolicLinksAndAppCopies {
$application_components = Get-ChildItem $system_application_folder
# Loop through each environment
foreach ($appworx_environment_key in $appworx_environments.keys) {
# Loop through application components, creating a symbolic link in the environment's sub-folder of the system-wide Appworx folder for each one
foreach ($application_component in $application_components) {
$source_path = join-path $system_application_folder $application_component
$dest_sub_folder = join-path $system_environments_folder $appworx_environment_key
$dest_path = join-path $dest_sub_folder $application_component
if (!(test-path ($dest_path))) { New-Item -Path $dest_path -ItemType SymbolicLink -Value $source_path | out-null}
}
}
}
function RemovePublicDesktopShortcuts {
# Delete the "Appworx" user-level folder
Remove-Item "C:\Users\Public\Appworx.lnk" -Force -ErrorAction silentlycontinue # Shortcut from older versions
foreach ($appworx_desktop_shortcut_filename in $appworx_desktop_shortcut_filenames) {
Remove-Item "C:\Users\Public\Desktop\$appworx_desktop_shortcut_filename" -Force -ErrorAction silentlycontinue
}
}
function CreatePublicDesktopShortcuts {
foreach ($appworx_desktop_shortcut_filename in $appworx_desktop_shortcut_filenames) {
$source_path = join-path $system_folder $appworx_desktop_shortcut_filename
copy-item -Path $source_path -Destination "C:\Users\Public\Desktop\$appworx_desktop_shortcut_filename"
}
}
function RemoveStartMenuShortcuts {
# Delete the "Appworx" user-level folder
Remove-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Appworx.lnk" -Force -ErrorAction silentlycontinue # Shortcut from older versions
foreach ($appworx_desktop_shortcut_filename in $appworx_desktop_shortcut_filenames) {
Remove-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\$appworx_desktop_shortcut_filename" -Force -ErrorAction silentlycontinue
}
}
function CreateStartMenuShortcuts {
foreach ($appworx_desktop_shortcut_filename in $appworx_desktop_shortcut_filenames) {
$source_path = join-path $system_folder $appworx_desktop_shortcut_filename
copy-item -Path $source_path -Destination "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\$appworx_desktop_shortcut_filename"
}
}
function RemoveAppworxUserFolders {
param (
$user
)
$appworx_folder = "C:\users\" + $user + "\AppWorx"
$dot_appworx_folder = "C:\users\" + $user + "\.AppWorx"
# Delete the "Appworx" user-level folder
Remove-Item $appworx_folder -Recurse -Force -ErrorAction silentlycontinue
# Delete the ".Appworx" user-level folder
Remove-Item $dot_appworx_folder -Recurse -Force -ErrorAction silentlycontinue
}
function CreateEnvironmentUserFolderPaths {
param (
$user
)
# Create the "Appworx" user-level folder
if (!(test-path ("C:\Users\$user\AppWorx"))) { New-Item -Path "C:\Users\$user\" -Name "\AppWorx" -ItemType 'directory' | out-null}
# Create the environment sub-folders of the "Appworx" user-level folder
foreach ($appworx_environment_value in $appworx_environments.values) {
if (!(test-path ("C:\Users\$user\AppWorx\$appworx_environment_value"))) { New-Item -Path "C:\Users\$user\AppWorx\" -Name "\$appworx_environment_value" -ItemType 'directory' | out-null}
}
}
function CopySSLCerts {
param (
$user
)
# Loop through each environment
$appworx_environments.GetEnumerator() | ForEach-Object {
# Copy the keystore into the environment's sub-folder of the "Appworx" user-level folder
copy-item -Path "$system_environments_folder\$($_.Key)\$($_.Value)\user_keystore" -Destination "C:\Users\$user\AppWorx\$($_.Value)"
# Copy the keystore config into the environment's sub-folder of the "Appworx" user-level folder
copy-item -Path "$system_environments_folder\$($_.Key)\$($_.Value)\user_keystore_config" -Destination "C:\Users\$user\AppWorx\$($_.Value)"
}
}
# ############### BEGIN MAIN SCRIPT ###############
# Create the symbolic links
CreateSymbolicLinksAndAppCopies
# Loop through every Windows user on the machine
foreach($user in $homeFolders){
# Skip user if "default" or "public" user
if($user.toString().ToLower().contains('default') -or $user.toString().ToLower().contains('public')){
continue
}
# Remove "Appworx" user folders
RemoveAppworxUserFolders($user)
# Rebuild "Appworx" and sub-environment user folders
CreateEnvironmentUserFolderPaths($user)
# Copy SSL certs
CopySSLCerts($user)
}
# Delete old desktop shortcuts
RemovePublicDesktopShortcuts
# Create new desktop shortcuts
CreatePublicDesktopShortcuts
# Delete old start menu shortcuts
RemoveStartMenuShortcuts
# Create new start menu shortcuts
CreateStartMenuShortcuts
# ############### END MAIN SCRIPT ###############