unixwz0r

bbinst.c (bsdbox install)

Jan 31st, 2016
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.86 KB | None | 0 0
  1. /*
  2.  *
  3.  * bbinst.c BSDBOX installer Program
  4.  * cc bbinst.c -o bbinst  
  5.  * ./bbinst
  6.  * The BSDBox Project By: Gary Perreault, and Vincent (anybody is welcome to contrib).
  7.  * 2016
  8.  *
  9.  *
  10.  * Copyright (c) 2016, The BSDBOX Project Team.
  11.  * All rights reserved.
  12.  *
  13.  * Redistribution and use in source and binary forms, with or without
  14.  * modification, are permitted provided that the following conditions are met:
  15.  *
  16.  * 1. Redistributions of source code must retain the above copyright notice, this
  17.  * list of conditions and the following disclaimer.
  18.  * 2. Redistributions in binary form must reproduce the above copyright notice,
  19.  * this list of conditions and the following disclaimer in the documentation
  20.  * and/or other materials provided with the distribution.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25.  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  26.  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.  *
  33.  * The views and conclusions contained in the software and documentation are those
  34.  * of the authors and should not be interpreted as representing official policies,
  35.  * either expressed or implied, of the FreeBSD Project.
  36.  */
  37. #include <ncurses.h>
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <sys/utsname.h>
  41. #include <unistd.h>
  42. #include <string.h>
  43. #include <errno.h>
  44. #include <sys/wait.h>
  45. #include <sys/sysctl.h>
  46. #define RED     "\x1b[31m" // Colours for the logo to make it pretty!
  47. #define GREEN   "\x1b[32m"
  48. #define BLUE    "\x1b[34m"
  49. #define RESET   "\x1b[0m"
  50.  
  51. /* BSDBOX logo created by me, I use block characters */
  52. void print_logo(){
  53.  
  54. printf(RED"╔═══════════════════════════════════════════════════════════════════╗\n");
  55. printf(RED"║ ▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄    ▄▄▄▄ "RED"║\n");
  56. printf(RED"║ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄   ▄▄    ▄▄  "RED" ║\n");
  57. printf(RED"║  ▄▄   ▄▄▄ ▄▄        ▄▄▄    ▄▄▄▄  ▄▄   ▄▄▄ ▄▄▄    ▄▄▄     ▄  ▄    "RED" ║\n");
  58. printf(RED"║  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄ ▄▄▄    ▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄    ▄▄▄      ▄▄     "RED" ║\n");
  59. printf(RED"║  ▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄ ▄▄▄    ▄▄▄▄  ▄▄▄▄▄▄▄  ▄▄▄    ▄▄▄      ▄▄     "RED" ║\n");
  60. printf(RED"║  ▄▄   ▄▄▄        ▄▄ ▄▄▄    ▄▄▄▄  ▄▄   ▄▄▄ ▄▄▄    ▄▄▄     ▄  ▄    "RED" ║\n");
  61. printf(RED"║ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄   ▄▄    ▄▄  "RED" ║\n");
  62. printf(RED"║ ▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄    ▄▄▄▄"RED" ║\n");
  63. printf(RED"║"GREEN"                                                      Install v2.1"RED" ║\n");
  64. printf(RED"╚═══════════════════════════════════════════════════════════════════╝"RESET"\n");
  65. }
  66.  
  67. /* This function does pkg install and all the packages you need for the Skel */
  68. void pkg_inst(){
  69. printf("\n\n");
  70. printf(BLUE"This is the Default Base Packages for BSDBox X11, and extra useful packages .. ");
  71. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  72. getchar();
  73. printf("\n\n");
  74.                 char *argv[] = {
  75.                                   "pkg",  "install",
  76.                                   "xorg",
  77.                                   "dmenu",
  78.                                   "compton",
  79.                                   "geany",
  80.                                   "vim",
  81.                                   "irssi",
  82.                                   "firefox",
  83.                                   "smplayer",
  84.                                   "openshot",
  85.                                   "thunar",
  86.                                   "lxappearance",
  87.                                   "gimp",
  88.                                   "sudo",
  89.                                   "gksu",
  90.                                   "nitrogen",
  91.                                   "lxmusic",
  92.                                   "ppsspp",
  93.                                   "rxvt-unicode",
  94.                                   "bash",
  95.                                   "mc",
  96.                                   "tmux",
  97.                                   "scrot",
  98.                                   "gtk-murrine-engine",
  99.                                   "webcamd",
  100.                                   "pwcview",
  101.                                   "engrampa",
  102.                                   "eggdrop",
  103.                                   "tdom",
  104.                                   "nano",
  105.                                   "git",
  106.                                   "subversion",
  107.                                   "weechat",
  108.                                   "rtorrent",
  109.                                   "feh",
  110.                                   "fusefs-ntfs",
  111.                                   0,
  112.                               };
  113.  
  114. pid_t pid = fork();
  115. if(pid == 0) {
  116.                               execv("/usr/sbin/pkg", argv);
  117.                              
  118. }
  119.  else {
  120.     waitpid(pid, NULL, 0);
  121.  }                            
  122. }
  123. /* This function will extract the Skel Gunzip Config to the $home <DIR> */
  124. void skel_extract(){
  125. printf("\n\n");
  126. printf(BLUE"Now lets unextract the SKEL configs for BSDBox ..");
  127. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  128. getchar();
  129. printf("\n\n");
  130.     char buf[256];
  131.     sprintf(buf, "/usr/home/%s", getlogin());
  132.     char *argv[] = {
  133.                      "tar", "-xvzf",
  134.                      "bsdboxskel.tar.gz",
  135.                      "-C",
  136.                      buf,                    
  137.                      0,
  138.                    };
  139. pid_t pid = fork();
  140. if(pid == 0) {
  141.                    execv("/usr/bin/tar", argv);
  142. }                  
  143.  else {
  144.      waitpid(pid, NULL, 0);
  145.  }                 
  146. }
  147. /* This Function will run 4 runlevel of cp -v of 4 files being copied to /usr/local/bin for bsdboxdwm status*/
  148. void status_bsdboxdwm1(){
  149. printf("\n\n");
  150. printf(BLUE"This part will copy 4 shell scripts for BSDBOXdwm Status");
  151. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  152. getchar();
  153. printf("\n\n");
  154.     char buf[256];
  155.     char *argv[] = {
  156.                      "cp", "-v", "timedwm", "/usr/local/bin",
  157.                      0,
  158.                    };
  159. pid_t pid = fork();
  160. if(pid == 0) {
  161.                    execv("/bin/cp", argv);
  162. }                  
  163.  else {
  164.      waitpid(pid, NULL, 0);
  165.  }                 
  166. }
  167.  
  168. void status_bsdboxdwm2(){
  169.     char buf[256];
  170.     char *argv[] = {
  171.                      "cp", "-v", "uptimedwm", "/usr/local/bin",
  172.                      0,
  173.                    };
  174. pid_t pid = fork();
  175. if(pid == 0) {
  176.                    execv("/bin/cp", argv);
  177. }                  
  178.  else {
  179.      waitpid(pid, NULL, 0);
  180.  }                 
  181. }
  182.  
  183. void status_bsdboxdwm3(){
  184.     char buf[256];
  185.     char *argv[] = {
  186.                      "cp", "-v", "xmms2np", "/usr/local/bin",
  187.                      0,
  188.                    };
  189. pid_t pid = fork();
  190. if(pid == 0) {
  191.                    execv("/bin/cp", argv);
  192. }                  
  193.  else {
  194.      waitpid(pid, NULL, 0);
  195.  }                 
  196. }
  197.  
  198. void status_bsdboxdwm4(){
  199.     char buf[256];
  200.     char *argv[] = {
  201.                      "cp", "-v", "memuse", "/usr/local/bin",
  202.                      0,
  203.                    };
  204. pid_t pid = fork();
  205. if(pid == 0) {
  206.                    execv("/bin/cp", argv);
  207. }                  
  208.  else {
  209.      waitpid(pid, NULL, 0);
  210.  }                 
  211. }
  212.  
  213. /* This function will run portsnap fetch and extract ports tree */
  214. void portsnap_fetch(){
  215. printf("\n\n");
  216. printf(BLUE"BSDBox Installer will now portsnap fetch .. ");
  217. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  218. getchar();
  219. printf("\n\n");
  220.                 char *argv[] = {
  221.                                   "portsnap",
  222.                                   "fetch",
  223.                                    0,
  224.                               };
  225.  
  226. pid_t pid = fork();
  227. if(pid == 0) {
  228.                               execv("/usr/sbin/portsnap", argv);
  229.                              
  230. }
  231.  else {
  232.     waitpid(pid, NULL, 0);
  233.  }                            
  234. }
  235. /* This function will run portsnap fetch and extract ports tree */
  236. void portsnap_extract(){
  237. printf("\n\n");
  238. printf(BLUE"BSDBox Installer will now portsnap extract .. ");
  239. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  240. getchar();
  241. printf("\n\n");
  242.                 char *argv[] = {
  243.                                   "portsnap",
  244.                                   "extract",
  245.                                    0,
  246.                               };
  247.  
  248. pid_t pid = fork();
  249. if(pid == 0) {
  250.                               execv("/usr/sbin/portsnap", argv);
  251.                              
  252. }
  253.  else {
  254.     waitpid(pid, NULL, 0);
  255.  }                            
  256. }                
  257.  
  258. /* This function will run dwm_conf and install bsdbox UI */
  259. /* Will also be using chdir in this function */
  260.  
  261. void DWM_CONF1(){
  262. printf("\n\n");
  263. printf(BLUE"DWM_CONF1 will make deinstall BSDBox DWM .. ");
  264. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  265. getchar();
  266. printf("\n\n");
  267. char *dconf = "/usr/ports/x11-wm/dwm";
  268. int ret;
  269. ret = chdir ( dconf );
  270.               char *argv[] = {
  271.                                   "make",
  272.                                   "deinstall",
  273.                                    0,
  274.                               };
  275.  
  276. pid_t pid = fork();
  277. if(pid == 0) {
  278.                               execv("/usr/bin/make", argv);
  279.                              
  280. }
  281.  else {
  282.     waitpid(pid, NULL, 0);
  283.  }  
  284.  
  285. }
  286.  
  287. void DWM_CONF2(){
  288. printf("\n\n");
  289. printf(BLUE"DWM_CONF2 will make BSDBox DWM config.h .. ");
  290. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  291. getchar();
  292. printf("\n\n");
  293. char buf[256];
  294.     sprintf(buf, "DWM_CONF=/usr/home/%s/dwm-6_1/config.h", getlogin());
  295. char *dconf = "/usr/ports/x11-wm/dwm";
  296. int ret;
  297. ret = chdir ( dconf );
  298.               char *argv[] = {
  299.                                   "make",
  300.                                    buf,
  301.                                    0,
  302.                               };
  303.  
  304. pid_t pid = fork();
  305. if(pid == 0) {
  306.                               execv("/usr/bin/make", argv);
  307.                              
  308. }
  309.  else {
  310.     waitpid(pid, NULL, 0);
  311.  }  
  312.  
  313. }
  314.  
  315. void DWM_CONF3(){
  316. printf("\n\n");
  317. printf(BLUE"DWM_CONF3 will make install clean BSDBox DWM .. ");
  318. printf(RED" PLEASE HIT "GREEN"ENTER"RED" TO PROCEED."GREEN"\n");
  319. getchar();
  320. printf("\n\n");
  321. char *dconf = "/usr/ports/x11-wm/dwm";
  322. int ret;
  323. ret = chdir ( dconf );
  324.               char *argv[] = {
  325.                                   "make",
  326.                                   "install",
  327.                                   "clean",
  328.                                    0,
  329.                               };
  330.  
  331. pid_t pid = fork();
  332. if(pid == 0) {
  333.                               execv("/usr/bin/make", argv);
  334.                              
  335. }
  336.  else {
  337.     waitpid(pid, NULL, 0);
  338.  }  
  339.  
  340. }
  341. /* This function just thank you for trying out the project ;) */
  342. void thank_you(){
  343.     printf("\n\n");
  344.     printf(RED"Thank You for trying out "BLUE"BSDBox"RED"!"RESET"\n");
  345.     printf("\n\n");
  346.    
  347.  
  348. }
  349.  
  350.                      
  351.  
  352. int main( int argc, char **argv ){
  353.    
  354. print_logo();
  355. pkg_inst();
  356. skel_extract();
  357. status_bsdboxdwm1();
  358. status_bsdboxdwm2();
  359. status_bsdboxdwm3();
  360. status_bsdboxdwm4();
  361. portsnap_fetch();
  362. portsnap_extract();
  363. DWM_CONF1();
  364. DWM_CONF2();
  365. DWM_CONF3();
  366. thank_you();
  367. return 0;
  368. }
Advertisement
Add Comment
Please, Sign In to add comment