def main(args): """ This is the main function of the repo runner It will be executed with the arguments suplied if the end user called this. """ dependency.installCommon() dependency.installFullRepo() if not checks.inCorrectDirectory("repo"): logger.log( "Could not detect build files in the current directory, Setting up environment" ) download.downloadRepo("repo") logger.log("Build files should be here: {}".format(os.getcwd())) if args.all: BuildFullRepo(args.upload) return if args.packages: buildBase(args.upload) if args.fonts: buildFonts(args.upload) if args.kernel: buildKernel(args.upload) if args.sync: syncRepo(args.upload) if args.list: listAllPackages() elif args.list_fonts: listFonts() elif args.list_packages: listPackages()
def checkRoot(message): """ Check if the user is root otherwise error out """ if os.geteuid() != 0: logger.log(message, logger.LOG_ERROR) raise Exception("You need root privileges to do this operation.")
def main(args): """ This is the main function of the image runner It will be executed with the arguments suplied if the end user called this. """ checks.checkRoot( "Trying to build tos images without root privileges\nIf you are using environment variables don't forget to set them in your root session" ) dependency.installCommon() dependency.installImage() if not checks.inCorrectDirectory(): logger.log( "Could not detect build files in the current directory. Setting up environment", logger.LOG_WARM) download.downloadRepo() logger.log("Build files should be here: {}".format(os.getcwd())) local = "-a" if args.azerty else "" if args.awesome: BuildAwesome(local) elif args.server: BuildServer(local) elif args.suite: BuildAwesome(local) BuildServer(local) elif args.all: BuildAwesome("") BuildServer("") BuildAwesome("-a") BuildServer("-a")
def downloadRepo(subpath="toslive"): """ Try to download the tos image repository and make that the current directory """ result = fd.CMD(["git", "clone", "https://github.com/ODEX-TOS/tos-live.git"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when trying to download build files, checking for existing build files", logger.LOG_ERROR) os.chdir("tos-live/"+subpath)
def isInstalled(self): for package in self.packages: if not package in self.installed: logger.log( "Package is not in the installed list: {}".format(package), logger.LOG_WARM) return False return True
def Install(self): result = filedescriptor.CMD( ['yay', "-Syu", "--noconfirm", self.package]).execute(True) if not result.exitcode == 0: logger.log( "Something failed during the package installation procedure", logger.LOG_ERROR) return False return self.isInstalled()
def buildFonts(bUpload=True): """ Build all fonts """ result = fd.CMD(["./build.sh", "-f"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when building fonts") raise Exception(result.stderr) upload(bUpload)
def buildBase(bUpload=True): """ Build all base packages """ result = fd.CMD(["./build.sh", "-a"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when building packages") raise Exception(result.stderr) upload(bUpload)
def uploadRepo(): """ Upload an existing repository. Only execute this if a full repository exists. Otherwise the repository will be incomplete """ result = fd.CMD(["./upload.sh", "-y"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when uploading data to the server",logger.LOG_ERROR) raise Exception(result.stderr)
def syncRepo(bUpload=True): """ Sync the repository packages with the package database """ result = fd.CMD( ["bash", "-c", "cd arch && repo-add tos.db.tar.gz *.pkg.tar.*"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when syncing packages to the repo") raise Exception(result.stderr) upload(bUpload)
def BuildServer(local=""): """ local is the command to be supplied to the build script only call this command if you are have the build files in the current directory """ result = fd.CMD(["bash", "-c", "./start.sh -s {}".format(local)]).execute(True) if not result.exitcode == 0: logger.log("Failed to build the package, please review the logs", logger.LOG_ERROR) raise Exception(result.stderr)
def buildKernel(cores): """ This should only be executed if you are in the correct repo cores should be an integer telling us howmany cores to use to compile the kernel """ result = fd.CMD(["bash", "-c", "./build.sh -k {}".format(cores)]).execute(True) if not result.exitcode == 0: logger.log("Failed to build the kernel, please review the logs", logger.LOG_ERROR) raise Exception(result.stderr)
def checkYay(): """ Check if yay is installed If it doesn't exist then try to build it """ state = installer.Package("yay") if not state.isInstalled(): logger.log( "Yay is not installed. We will try to compile it in order to install our aur based packages", logger.LOG_WARM) checks.checkRoot("Installing packages requires root permission") result = fd.CMD([ "bash", "-c", """git clone https://aur.archlinux.org/yay.git cd yay || exit 1 makepkg -si cd ../ || exit 1 rm -rf yay""" ]).execute(True) if not result.exitcode == 0: logger.log("Unexpected error happend when installing yay", logger.LOG_ERROR) raise Exception(result.stderr) else: logger.log("yay has been succesfully installed") else: logger.log("yay has been detected, AUR support is enabled")
def uploadImage(): """ Upload already build images. It only works if images are build in the toslive setting. Otherwise the repository will be incomplete """ result = fd.CMD(["./build.sh", "-u"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when moving existing images",logger.LOG_ERROR) raise Exception(result.stderr) result = fd.CMD(["./upload.sh", "-y"]).execute(True) if not result.exitcode == 0: logger.log("Something went wrong when uploading data to the server",logger.LOG_ERROR) raise Exception(result.stderr)
def execute(self, bPrintOutput=False): result = subprocess.Popen(self.command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=10) self.stdout = "" self.stderr = "" with result.stdout: for line in iter(result.stdout.readline, b''): # b'\n'-separated lines line = line.decode(self.decoder) if bPrintOutput: logger.log(line.replace("\n", "")) self.stdout += line self.exitcode = result.wait() return self
def main(args): """ This is the main function of the upload runner It will be executed with the arguments suplied if the end user called this. """ dependency.installCommon() dependency.installUpload() if not checks.inCorrectDirectory("repo"): logger.log("Could not detect build files in the current directory, Setting up environment") download.downloadRepo("repo") logger.log("Build files should be here: {}".format(os.getcwd())) if args.repo: uploadRepo() elif args.image: uploadImage() elif args.all: uploadRepo() uploadImage()
def main(args): """ This is the main function of the dependency runner It will be executed with the arguments suplied if the end user called this. You can install multiple things by supplying multiple options """ logger.log( "Trying to install dependencies with the following settings: {}". format(args)) installCommon() if args.all: installAll() elif args.repo_full: installFullRepo() else: if args.image: installImage() if args.kernel: installKernel() if args.upload: installUpload() if args.repo: installRepo()
def main(args): """ This is the main function of the kernel runner It will be executed with the arguments suplied if the end user called this. """ dependency.installCommon() dependency.installKernel() if not checks.inCorrectDirectory("repo"): logger.log( "Could not detect build files in the current directory, Setting up environment" ) download.downloadRepo("repo") logger.log("Build files should be here: {}".format(os.getcwd())) cores = args.cores if args.auto: logger.log( "Automatically detecting the amount of cores your system has...") import multiprocessing cores = multiprocessing.cpu_count() logger.log("Detected {} cores".format(cores)) if args.build: logger.log("Building the kernel using {} cores".format(cores)) # add one to the cores as recommended by make the underlying build system buildKernel(cores + 1)
def checkInstall(payload): """ Check if packages are already installed otherwise install them This will trow an error if we are unable to install packages. Payload is a list of packages to install """ logger.log("Trying to install: {}".format(payload)) state = installer.Packages(payload) logger.log("State of package install: {}".format(state.isInstalled())) if state.isInstalled(): return if not state.Install(): logger.log( "Something went wrong when trying to install packages to your system", logger.LOG_ERROR) raise Exception( "Cannot install packages to your system. The culprit is in one of the following packages: \n {}" .format(payload)) logger.log("All packages are installed correctly")
def inCorrectDirectory(subpath="toslive"): """ try to check if the current directory is the directory containing the build files """ # check if the current repo is correct result = fd.CMD(["git", "remote", "-v"]).execute() if not result.exitcode == 0: logger.log( "Something went wrong when scanning the current directory for build files" ) raise Exception(result.stderr) if not "ODEX-TOS/tos-live" in result.stdout: logger.log( "Current directory does not contain build files, downloading files" ) return False result = fd.CMD(["git", "rev-parse", "--show-toplevel"]).execute() if not result.exitcode == 0: logger.log("Could not move to the correct location in the repo") raise Exception(result.stderr) os.chdir(result.stdout + "/" + subpath) return True
def upload(bUpload=True): if bUpload: logger.log("Detected upload option after build.") upload.main({"all": True}) # upload everything