Skip to content

Commit

Permalink
update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Jul 24, 2024
1 parent 50a13c6 commit f820196
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from the apps. Our only option is to wait for NootedRed to fix this issue.

Install (or update) AMDHelper on your system
```
bash <(curl -sL https://raw.githubusercontent.com/alvindimas05/AMDHelper/main/install.sh)
curl -sL https://raw.githubusercontent.com/alvindimas05/AMDHelper/main/install.sh | bash
```

Run AMDHelper (Please run as sudo)
Expand Down
Binary file modified bun.lockb
Binary file not shown.
30 changes: 24 additions & 6 deletions index.ts
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();
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"@types/bun": "latest",
"@types/node": "^20.14.11",
"@types/yargs": "^17.0.32",
"rimraf": "^6.0.1",
"ts-loader": "^9.5.1",
"webpack": "^5.93.0",
Expand All @@ -23,6 +24,8 @@
"amdfriend": "git+https://github.com/NyaomiDEV/AMDFriend.git",
"chalk": "^5.3.0",
"console-clear": "^1.1.1",
"inquirer": "^10.1.2"
"dotenv": "^16.4.5",
"inquirer": "^10.1.2",
"yargs": "^17.7.2"
}
}
20 changes: 20 additions & 0 deletions src/update.ts
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)}`);
}
}
7 changes: 6 additions & 1 deletion src/utils.ts
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);

0 comments on commit f820196

Please sign in to comment.