Skip to content

Commit

Permalink
Improvements to project layout within Xcode
Browse files Browse the repository at this point in the history
Cosmetic changes to build script
Simplify the processing flow within the driver
  • Loading branch information
rodyager committed Jan 18, 2023
1 parent 9c46c36 commit 6c3dc74
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
30 changes: 29 additions & 1 deletion PDFWriter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
5506A7B0285F18C100C5BDF5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5506A7B3285F18C100C5BDF5 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
5506A7B5285F18C100C5BDF5 /* PDFWriter_Utility.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PDFWriter_Utility.entitlements; sourceTree = "<group>"; };
5557B91A2978AD6F00199134 /* buildscript.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = buildscript.sh; sourceTree = "<group>"; };
5557B91B2978AD6F00199134 /* postinstall */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = postinstall; sourceTree = "<group>"; };
5557B91C2978AD6F00199134 /* RWTS PDFwriter.ppd */ = {isa = PBXFileReference; lastKnownFileType = text; path = "RWTS PDFwriter.ppd"; sourceTree = "<group>"; };
5557B91D2978AD6F00199134 /* README.rtfd */ = {isa = PBXFileReference; lastKnownFileType = wrapper.rtfd; path = README.rtfd; sourceTree = "<group>"; };
5557B91E2978AD6F00199134 /* component */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = component; sourceTree = "<group>"; };
5557B91F2978AD6F00199134 /* requirements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = requirements; sourceTree = "<group>"; };
5557B9202978AD6F00199134 /* uninstall */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = uninstall; sourceTree = "<group>"; };
5557B9212978AD6F00199134 /* preinstall */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = preinstall; sourceTree = "<group>"; };
5557B9222978AD6F00199134 /* PDFwriter.iconset */ = {isa = PBXFileReference; lastKnownFileType = folder.iconset; path = PDFwriter.iconset; sourceTree = "<group>"; };
5557B9232978AD6F00199134 /* PDFfolder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = PDFfolder.png; sourceTree = "<group>"; };
55BA6F6F297812A30090F158 /* pdfwriter */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = pdfwriter; sourceTree = BUILT_PRODUCTS_DIR; };
55BA6F71297812A40090F158 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -58,8 +68,9 @@
5506A7A0285F18BF00C5BDF5 = {
isa = PBXGroup;
children = (
5506A7AB285F18BF00C5BDF5 /* PDFWriter Utility */,
55BA6F70297812A40090F158 /* pdfwriter */,
5506A7AB285F18BF00C5BDF5 /* PDFWriter Utility */,
5557B9192978AD6F00199134 /* build */,
5506A7AA285F18BF00C5BDF5 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -93,6 +104,23 @@
path = "Preview Content";
sourceTree = "<group>";
};
5557B9192978AD6F00199134 /* build */ = {
isa = PBXGroup;
children = (
5557B91A2978AD6F00199134 /* buildscript.sh */,
5557B91B2978AD6F00199134 /* postinstall */,
5557B91C2978AD6F00199134 /* RWTS PDFwriter.ppd */,
5557B91D2978AD6F00199134 /* README.rtfd */,
5557B91E2978AD6F00199134 /* component */,
5557B91F2978AD6F00199134 /* requirements */,
5557B9202978AD6F00199134 /* uninstall */,
5557B9212978AD6F00199134 /* preinstall */,
5557B9222978AD6F00199134 /* PDFwriter.iconset */,
5557B9232978AD6F00199134 /* PDFfolder.png */,
);
path = build;
sourceTree = "<group>";
};
55BA6F70297812A40090F158 /* pdfwriter */ = {
isa = PBXGroup;
children = (
Expand Down
13 changes: 7 additions & 6 deletions build/buildscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ PDFWRITERDIR="pkgroot/Library/Printers/RWTS/PDFwriter"
UTILITIESDIR="pkgroot/Library/Printers/RWTS/Utilities"
PPDDIR="pkgroot/Library/Printers/PPDs/Contents/Resources"
UTILITYAPP="PDFWriter Utility.app"
UTILITYZIP="PDFWriter Utility.zip"
PDFWRITER="pdfwriter"
PPDFILE="RWTS PDFwriter"
BUILDTEMP="/tmp/PDFWriter.dst"

while getopts "s:n:" opt; do
case ${opt} in
Expand All @@ -40,8 +41,8 @@ xcodebuild -alltargets archive
cd build

echo "### move binaries from tempory build folder"
mv "/tmp/PDFWriter.dst/$UTILITYAPP" "$UTILITYAPP"
mv "/tmp/PDFWriter.dst/pdfwriter" pdfwriter
mv "$BUILDTEMP/$UTILITYAPP" "$UTILITYAPP"
mv "$BUILDTEMP/$PDFWRITER" $PDFWRITER

echo "### clean up build artefacts"

Expand All @@ -55,12 +56,12 @@ mkdir -m 775 $UTILITIESDIR

echo "#### populating directory structure"
iconutil -c icns -o $PDFWRITERDIR/PDFwriter.icns PDFwriter.iconset
cp pdfwriter $PDFWRITERDIR/
cp $PDFWRITER $PDFWRITERDIR/
cp -r "$UTILITYAPP" $UTILITIESDIR/
cp uninstall PDFfolder.png $PDFWRITERDIR/
gzip -c "$PPDFILE".ppd > $PPDDIR/"$PPDFILE".gz

chmod 700 $PDFWRITERDIR/pdfwriter
chmod 700 $PDFWRITERDIR/$PDFWRITER
chmod 755 $PDFWRITERDIR/uninstall postinstall preinstall # uninstall will be root:admin 750 after postinstall, but this will be ok if permissions are "repaired"

chmod 644 $PPDDIR/"$PPDFILE".gz
Expand Down Expand Up @@ -101,6 +102,6 @@ if [ ! -z "$SIGNSTRING" ]; then echo "#### signing product";
else mv RWTS-PDFwriter.pkg ../RWTS-PDFwriter.pkg; fi

echo "#### cleaning up"
rm -r pkgroot resources scripts expanded *.pkg distribution.dist "$UTILITYAPP" pdfwriter
rm -r pkgroot resources scripts expanded *.pkg distribution.dist "$UTILITYAPP" $PDFWRITER

exit 0
6 changes: 2 additions & 4 deletions build/uninstall
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/bin/sh

# uninstall.sh
# uninstall
# unistall RWTS PDFwriter
#
# Created by Simone Karin Lehmann on 30.08.10.
# Copyright 2010 Simone Karin Lehmann. All rights reserved.
# Modified 2016 -2022 Rodney I. Yager
# Copyright 2023 Rodney I. Yager

echo "
Expand Down
34 changes: 16 additions & 18 deletions pdfwriter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@ import AppKit
import Darwin

var outDir = "/var/spool/pdfwriter/"
var nobodyName = "anonaymous users"
var folderIconPath = "/Library/Printers/RWTS/PDFwriter/PDFfolder.png"

if ( setuid(0) != 0 ) {
fputs("pdfwriter cannot be called without root privileges!\n", stderr)
exit(0)
}

let group = getgrnam("_lp").pointee

setgid(group.gr_gid)

var isDir: ObjCBool = true

if ( CommandLine.argc == 1) {
fputs("file pdfwriter:/ \"Virtual PDF Printer\" \"PDFwriter\" \"MFG:RWTS;MDL:PDFwriter;DES:RWTS PDFwriter - Prints documents as PDF files;CLS:PRINTER;CMD:POSTSCRIPT;\"\n", stderr)
switch CommandLine.argc {
case 1: fputs("file pdfwriter:/ \"Virtual PDF Printer\" \"PDFwriter\" \"MFG:RWTS;MDL:PDFwriter;DES:RWTS PDFwriter - Prints documents as PDF files;CLS:PRINTER;CMD:POSTSCRIPT;\"\n", stderr)
exit(0)
}

if (CommandLine.argc != 6 ) {
fputs("Usage: pdfwriter job-id user title copies options [file]\n", stderr)
case 6: break
default: fputs("Usage: pdfwriter job-id user title copies options [file]\n", stderr)
exit(0)
}

// check that it is actually a PDF file
let stdIn: FileHandle = .standardInput
let stdIn: FileHandle = .standardInput
let prefix:Data
do {
prefix = try stdIn.read(upToCount: 4)!
Expand All @@ -53,11 +47,15 @@ if let p = getpwnam(user)?.pointee {
passwd = p
} else {
passwd = getpwnam("nobody")!.pointee
user = "anonymous users"
user = nobodyName
}

outDir += user

let group = getgrnam("_lp").pointee
setgid(group.gr_gid)
var isDir: ObjCBool = true

if !FileManager.default.fileExists(atPath: outDir, isDirectory: &isDir) {
// create output Directory, setting icon, ownership and permissions.
umask(0o022)
Expand All @@ -68,8 +66,8 @@ if !FileManager.default.fileExists(atPath: outDir, isDirectory: &isDir) {
fputs("Unable to create output directory at \(outDir)\n", stderr)
exit(0)
}
NSWorkspace.shared.setIcon(NSImage(byReferencingFile: "/Library/Printers/RWTS/PDFwriter/PDFfolder.png"), forFile: outDir, options: .excludeQuickDrawElementsIconCreationOption)
let mode = user == "anonymous users" ? mode_t(0o777) : mode_t(0o700)
NSWorkspace.shared.setIcon(NSImage(byReferencingFile: folderIconPath), forFile: outDir, options: .excludeQuickDrawElementsIconCreationOption)
let mode = user == nobodyName ? mode_t(0o777) : mode_t(0o700)
chmod(outDir, mode)
chown(outDir, passwd.pw_uid, passwd.pw_gid)
}
Expand All @@ -91,10 +89,10 @@ while ( FileManager.default.fileExists( atPath: outFile )) {
}

umask(0o077)
// create output file and set appropriate
// create output file and set appropriate ownership and permissions
FileManager.default.createFile(atPath: outFile, contents: nil )
chown(outFile, passwd.pw_uid, passwd.pw_gid)
let mode = user == "anonymous users" ? mode_t(0o666) : mode_t(0o600)
let mode = user == nobodyName ? mode_t(0o666) : mode_t(0o600)

chmod(outFile, mode)

Expand Down

0 comments on commit 6c3dc74

Please sign in to comment.