-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50a13c6
commit f820196
Showing
6 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
#!/usr/bin/env node | ||
import { promisify } from "util"; | ||
import child_process from "child_process"; | ||
import dotenv from "dotenv"; | ||
import CommandLine from "./src/commandline"; | ||
import {isRoot} from "./src/utils"; | ||
import {isRoot,exec} from "./src/utils"; | ||
import {check_update, update} from "./src/update"; | ||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
|
||
const exec = promisify(child_process.exec); | ||
dotenv.configDotenv(); | ||
|
||
const argv = yargs(hideBin(process.argv)) | ||
.scriptName("amdhelper") | ||
.option("update", { | ||
alias: "u", | ||
describe: "Updating the program.", | ||
demandOption: false, | ||
type: "boolean", | ||
default: false, | ||
}).help() | ||
.argv as { | ||
[x: string]: any | ||
}; | ||
|
||
async function main(){ | ||
if(process.platform != "darwin") return console.error("Sorry, this program is only for AMD Hackintosh."); | ||
|
||
const cpuname = await exec("sysctl -n machdep.cpu.brand_string"); | ||
if(!cpuname.stdout.trim().includes("AMD")) return console.error("Sorry, this program is only for AMD Hackintosh.") | ||
|
||
if(argv.update) return update(); | ||
|
||
await check_update(); | ||
if(!isRoot()) console.log("Please run as sudo to detect apps that's not patched."); | ||
|
||
const cli = new CommandLine(); | ||
cli.start(); | ||
await cli.start(); | ||
} | ||
|
||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {exec} from "./utils"; | ||
|
||
interface UpdateResponse { | ||
tag_name: string | ||
} | ||
|
||
export async function check_update(){ | ||
const res = await fetch(process.env.RELEASE_URL); | ||
const data : UpdateResponse[] = await res.json(); | ||
if(data[0].tag_name === process.env.VERSION) return; | ||
console.log(`New update version ${data[0].tag_name}! Run "amdhelper -u" to update.`); | ||
} | ||
|
||
export async function update(){ | ||
const curl = await exec(`curl -sL ${process.env.INSTALL_URL}`); | ||
for(let cmd of curl.stdout.split("\n")){ | ||
const { stdout } = await exec(cmd); | ||
if(stdout != "") console.log(`${stdout.slice(0, -1)}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
// @ts-ignore | ||
export const isRoot = () => process!.getuid() === 0 ; | ||
import {promisify} from "util"; | ||
import child_process from "child_process"; | ||
|
||
export const isRoot = () => process!.getuid() === 0 ; | ||
|
||
export const exec = promisify(child_process.exec); |