Set up initial database schema if needed

This commit is contained in:
Simon Kågedal Reimer 2019-06-07 19:50:19 +02:00
parent c6c1cda39c
commit 6486db2796
3 changed files with 31 additions and 9 deletions

View File

@ -46,6 +46,8 @@ class InstallCACommandRunner {
let connection = try trustStore.open()
reporter.info("Opened trust store.")
try connection.setupDatabaseIfNeeded(reporter: reporter)
if try connection.hasCertificate(with: sha1) {
if options.dryRun {
print("Would skip installing '\(certificateName)' into '\(device.name)' it's already there.")

View File

@ -25,7 +25,7 @@ struct TrustStore {
}
func open() throws -> Connection {
return try Connection(openingPath: path.pathString)
return try Connection(openingPath: path)
}
class Connection {
@ -38,8 +38,28 @@ struct TrustStore {
private let tsetColumn = Expression<Blob?>("tset")
private let dataColumn = Expression<Blob?>("data")
fileprivate init(openingPath path: String) throws {
connection = try SQLite.Connection(path)
private let needsCreation: Bool
fileprivate init(openingPath path: AbsolutePath) throws {
needsCreation = !localFileSystem.exists(path)
connection = try SQLite.Connection(path.pathString)
}
func setupDatabaseIfNeeded(reporter: Reporter) throws {
guard needsCreation else { return }
try connection.execute("""
BEGIN TRANSACTION;
CREATE TABLE tsettings (
sha1 BLOB NOT NULL DEFAULT '',
subj BLOB NOT NULL DEFAULT '',
tset BLOB,
data BLOB,
PRIMARY KEY(sha1)
);
CREATE INDEX isubj ON tsettings(subj);
COMMIT TRANSACTION;
"""
)
}
func isValid() -> Bool {

View File

@ -29,22 +29,22 @@ echo "${LOGO} Installing root certificate"
CERT_PATH=`pwd`/test-ca.crt
pushd .. >& /dev/null
echo swift run xcode-simulator-tool --verbosity=loud install-ca ${CERT_PATH} --uuid=${UUID}
echo Please do it yourself
zsh
swift run xcode-simulator-tool --verbosity=loud install-ca ${CERT_PATH} --uuid=${UUID}
popd >& /dev/null
# Booting
echo "${LOGO} Booting simulator; exit subshell when it's done"
echo "${LOGO} Booting simulator; press enter when done"
xcrun simctl boot ${UUID}
open /Applications/Xcode-10.2.1.app/Contents/Developer/Applications/Simulator.app
zsh
read
# Opening the URL
echo "${LOGO} Opening ${URL} in simulator; exit subshell when it's done"
echo "${LOGO} Opening ${URL} in simulator. This should now show the contents of this directory in Safari."
echo "${LOGO} Press enter when done."
xcrun simctl openurl ${UUID} ${URL}
zsh
read
# Killing HTTP server