Skip to content

Instantly share code, notes, and snippets.

@ajpen
Created August 26, 2014 03:14
Show Gist options
  • Save ajpen/b73a7ec4cde142ea1f9d to your computer and use it in GitHub Desktop.
Save ajpen/b73a7ec4cde142ea1f9d to your computer and use it in GitHub Desktop.
Automates installation of removed packages from a copy of the apt-get log
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]){
//buffer array
char buffer[120];
//array for the package name
char word[41];
char* newline;
//open the file with packages to install
FILE* in = fopen("copy.txt","r");
//get package after package, truncate unnecessities and make command, then proceed to execute command
while(fgets(buffer,50,in)!=NULL){
//just to ensure its a package so warnings and info can be ignored
if (buffer[0]=='R'){
//truncating the unwanted from list
strcpy(word,(buffer+9));
newline = strchr(word,'\0');
if (newline!=NULL){
newline = newline-5;
*newline = '\0';
}
//making command
sprintf(buffer,"sudo apt-get install %s",word);
//execute command
system(buffer);
}
/*
//debugging
printf("%s\n",buffer);
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment