Skip to content

Instantly share code, notes, and snippets.

@santiihoyos
Last active March 13, 2016 17:55
Show Gist options
  • Save santiihoyos/cc13521323d693852833 to your computer and use it in GitHub Desktop.
Save santiihoyos/cc13521323d693852833 to your computer and use it in GitHub Desktop.
Creador de script con permisos de ejecución autoañadidos para Linux.
File scriptCreator(String MAC, String interfaz) throws InterruptedException, IOException {
File fichero = new File(".tempLixScrip.sh");
BufferedWriter out = null;
if (fichero.exists()) {
return fichero;
} else {
out = new BufferedWriter(new FileWriter(".tempLixScrip.sh", true));
out.write("!/bin/bash\n"
+ "$USER - sudo with zenity password window\n"
+ "zenity --title=\"We need your authorization:\" --text=\"Change MAC requires authorization please enter the Administrator password:\" \\\n"
+ "--entry --entry-text \"\" --hide-text \\\n"
+ "|sudo -S \"$@\" rfkill block all\n"
+ "sleep 1s\n"
+ "sudo -S \"$@\" ifconfig " + interfaz + " hw ether " + MAC + " \n"
+ "sleep 1s\n"
+ "sudo -S \"$@\" rfkill unblock all \n");
Process pro = Runtime.getRuntime().exec("chmod 777 .tempLixScrip.sh");
out.close();
return fichero;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment