summaryrefslogblamecommitdiff
path: root/hscript/script.cc
blob: 748b09a69c87d84a5f80499a2bd8b3f26d66471f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                           

                   
                    
                  


                     



                              
                                                          
                                                    
                                        
                                                      


                                                        
                                                          

                                                                




                  



















                                                                       

 
                                                           


                                       
                   


                         
                 


 
/*
 * script.hh - Implementation of the Script class
 * libhscript, the HorizonScript library for
 * Project Horizon
 *
 * Copyright (c) 2019 Adélie Linux and contributors.  All rights reserved.
 * This code is licensed under the AGPL 3.0 license, as noted in the
 * LICENSE-code file in the root directory of this repository.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

#include <fstream>
#include <iostream>
#include "script.hh"
#include "disk.hh"
#include "meta.hh"
#include "network.hh"
#include "user.hh"

namespace Horizon {

struct Script::ScriptPrivate {
    /*! Determines whether or not to enable networking. */
    std::unique_ptr<Horizon::Keys::Network> network;
    /*! The target system's hostname. */
    std::unique_ptr<Horizon::Keys::Hostname> hostname;
    /*! The packages to install to the target system. */
    std::vector<std::string> packages;
    /*! The root shadow line. */
    std::unique_ptr<Horizon::Keys::RootPassphrase> rootpw;
    /*! Target system's mountpoints. */
    std::vector< std::unique_ptr<Horizon::Keys::Mount> > mounts;
};

Script::Script() {
}

const Script *Script::load(std::string path, ScriptOptions opts) {
    std::ifstream file;
    std::string maybe_error;

    file.exceptions(std::ios::badbit);
    try {
        file.open(path);
    } catch(const std::ios::failure &error) {
        maybe_error = error.what();
    } catch(const std::exception &error) {
        maybe_error = error.what();
    }
    if(!file) {
        std::cerr << "Cannot open installfile at \"" << path << "\": ";
        std::cerr << maybe_error;
        std::cerr << std::endl;
        return nullptr;
    }

    return Script::load(file, opts);
}

const Script *Script::load(std::istream &, ScriptOptions) {
    Script *foo = new Script;
    delete foo;
    std::cout << "loaded" << std::endl;
    return nullptr;
}

bool Script::validate() {
    return false;
}

}