PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/slackconf.sh

http://slackconf.googlecode.com/
Shell | 645 lines | 518 code | 64 blank | 63 comment | 75 complexity | d7e77bc1044d0931015fc6db188b2e55 MD5 | raw file
Possible License(s): AGPL-1.0
  1. #!/bin/bash
  2. # Configure Global`s Variables
  3. VERSION="0.0.25"
  4. NAME="SlackConf GUI for Slackware Configuration"
  5. DIA="/bin/dialog"
  6. BKP_OPT="Y"
  7. # Function check_depends
  8. function check_depends()
  9. {
  10. #Check if user run is 'root'
  11. USER_RUN=`whoami`
  12. if [ $USER_RUN != "root" ]; then
  13. echo -e ''
  14. echo -e '*** Please only run as root user ***'
  15. echo -e ''
  16. echo -e ''
  17. exit_
  18. fi
  19. #Create temporary directories, and set global variable
  20. mkdir -p /tmp/.slackconf
  21. DIR_TMP="/tmp/.slackconf"
  22. }
  23. # Function for exit program
  24. function exit_()
  25. {
  26. rm -rf /tmp/.slackconf
  27. #Exit program
  28. echo -e "$NAME"
  29. echo -e "========================================="
  30. echo -e ""
  31. echo -e "bye ... ;-)"
  32. echo -e ""
  33. echo -e ""
  34. exit 0;
  35. }
  36. # Function for display information about program
  37. function about()
  38. {
  39. $DIA \
  40. --title "$NAME - $VERSION" \
  41. --msgbox "\n $NAME, version $VERSION.
  42. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- \n\n\n
  43. slackconf is a tool for setting up a Slackware Linux System. \n\n
  44. You can help by reporting an error, correcting some function, or by \n
  45. sending ideas in the solution can be useful. \n\n
  46. Or if you want to submit your comment, please write to: \n\n
  47. contato@brunorusso.eti.br \n\n\n
  48. http://brunorusso.eti.br/slackconf \n\n\n
  49. Slackware (R) is a registered trademark of Patrick Volkerding, for more \n
  50. information visit: http://slackware.com/trademark/trademark.php \n
  51. Join the project group: slackconf@googlegroups.com " \
  52. 30 90
  53. main_menu
  54. }
  55. #Function Conf_Network
  56. Conf_Network()
  57. {
  58. #run netconfig
  59. netconfig
  60. main
  61. }
  62. #Function Conf_Mouse
  63. Conf_Mouse()
  64. {
  65. #run mouseconfig
  66. mouseconfig
  67. main
  68. }
  69. #Function Conf_Packages
  70. Conf_Packages()
  71. {
  72. #run pkgtool
  73. pkgtool
  74. main
  75. }
  76. #Function Conf_Log
  77. Conf_Log()
  78. {
  79. LOG_OPT=$($DIA --stdout \
  80. --title "$NAME - $VERSION" \
  81. --menu 'Do you need?' \
  82. 0 0 0 \
  83. Messages 'logs from system' \
  84. Security 'messages from system' \
  85. Mail 'log from system' \
  86. Syslog 'from ssytem' )
  87. if [ $? = 1 ]; then
  88. main_menu
  89. fi
  90. #View messages
  91. if [ $LOG_OPT = "Messages" ]; then
  92. tail -f /var/log/messages > $DIR_TEMP/out &
  93. $DIA \
  94. --title "$NAME - $VERSION" \
  95. --tailbox $DIR_TEMP/out \
  96. 0 0
  97. Conf_Log
  98. fi
  99. #View security messages
  100. if [ $LOG_OPT = "Security" ]; then
  101. tail -f /var/log/secure > $DIR_TEMP/out &
  102. $DIA \
  103. --title "$NAME - $VERSION" \
  104. --tailbox $DIR_TEMP/out \
  105. 0 0
  106. Conf_Log
  107. fi
  108. #View maillog messages
  109. if [ $LOG_OPT = "Mail" ]; then
  110. tail -f /var/log/maillog > $DIR_TEMP/out &
  111. $DIA \
  112. --title "$NAME - $VERSION" \
  113. --tailbox $DIR_TEMP/out \
  114. 0 0
  115. Conf_Log
  116. fi
  117. #View syslog messages
  118. if [ $LOG_OPT = "Syslog" ]; then
  119. tail -f /var/log/syslog > $DIR_TEMP/out &
  120. $DIA \
  121. --title "$NAME - $VERSION" \
  122. --tailbox $DIR_TEMP/out \
  123. 0 0
  124. Conf_Log
  125. fi
  126. main_menu
  127. }
  128. #Function Conf_Sound
  129. Conf_Sound()
  130. {
  131. SOUND_OPT=$($DIA --stdout \
  132. --title "$NAME - $VERSION" \
  133. --menu 'Do you need?' \
  134. 0 0 0 \
  135. Modify 'sound volum' \
  136. Configure 'sound card' )
  137. if [ $? = 1 ]; then
  138. main_menu
  139. fi
  140. #Modify sound volum
  141. if [ $SOUND_OPT = "Modify" ]; then
  142. #run alsamixer
  143. alsamixer
  144. fi
  145. #Configure sound card
  146. if [ $SOUND_OPT = "Configure" ]; then
  147. #run alsaconf
  148. alsaconf
  149. fi
  150. main_menu
  151. }
  152. #Function Conf_System
  153. Conf_System()
  154. {
  155. SYSTEM_OPT=$($DIA --stdout \
  156. --title "$NAME - $VERSION" \
  157. --menu 'Do you need more informatin...' \
  158. 0 0 0 \
  159. CPU 'configuration' \
  160. Memory 'information' )
  161. if [ $? = 1 ]; then
  162. main_menu
  163. fi
  164. if [ $SYSTEM_OPT = "CPU" ]; then
  165. cat /proc/cpuinfo > $DIR_TEMP/cpuinfo
  166. $DIA \
  167. --title "$NAME - $VERSION" \
  168. --textbox $DIR_TEMP/cpuinfo \
  169. 0 0
  170. Conf_System
  171. fi
  172. if [ $SYSTEM_OPT = "Memory" ]; then
  173. echo "Simple information" > $DIR_TEMP/memory
  174. echo "==================" >> $DIR_TEMP/memory
  175. echo "" >> $DIR_TEMP/memory
  176. free >> $DIR_TEMP/memory
  177. echo "" >> $DIR_TEMP/memory
  178. echo "" >> $DIR_TEMP/memory
  179. echo "Full information" >> $DIR_TEMP/memory
  180. echo "==================" >> $DIR_TEMP/memory
  181. echo "" >> $DIR_TEMP/memory
  182. cat /proc/meminfo >> $DIR_TEMP/memory
  183. $DIA \
  184. --title "$NAME - $VERSION" \
  185. --textbox $DIR_TEMP/memory \
  186. 0 0
  187. Conf_System
  188. fi
  189. main_menu
  190. }
  191. #Function Check_IP
  192. Check_IP()
  193. {
  194. #need check is OK!
  195. VERIFY_IP=`echo $1 | egrep '^([0-9]{1,3}\.){3}[0-9]{1-3}$' -c`
  196. VERIFY_IP="1"
  197. if [ $VERIFY_IP -eq "0" ]; then
  198. $DIA \
  199. --title "$NAME - $VERSION" \
  200. --msgbox "Sorry, but \"$1\" dont see a valid IP adrress" \
  201. 0 0
  202. return 0
  203. fi
  204. return 1
  205. }
  206. #Function Conf_Dns
  207. Conf_Dns()
  208. {
  209. clear
  210. DNS_CUR=`cat /etc/resolv.conf | grep -v ^# | cut -f2 -d" " `
  211. DNS_OPTION=$( $DIA \
  212. --stdout \
  213. --title "$NAME - $VERSION" \
  214. --inputbox "The DNS Servers currently configured are: \n
  215. $DNS_CUR \n\n
  216. Input your host or domain to check! " \
  217. 0 0 )
  218. #If cancel return is 1
  219. if [ $? = 1 ]; then
  220. main
  221. fi
  222. #Check doman
  223. if [ $DNS_OPTION != " " ]; then
  224. echo " $DNS_OPTION" | tr [:lower:] [:upper:] > $DIR_TMP/dns.log
  225. echo "" >> $DIR_TMP/dns.log
  226. echo "" >> $DIR_TMP/dns.log
  227. nslookup $DNS_OPTION >> $DIR_TMP/dns.log
  228. $DIA \
  229. --title "$NAME - $VERSION" \
  230. --textbox $DIR_TMP/dns.log \
  231. 0 0
  232. Conf_Dns
  233. else
  234. #return to main
  235. main
  236. fi
  237. }
  238. #Function Conf_User
  239. Conf_User()
  240. {
  241. echo "hello"
  242. }
  243. #Function Conf_Routes
  244. Conf_Routes()
  245. {
  246. clear
  247. ROUTES_NOW=`route -n`
  248. ROUTES_OPTION=$( $DIA \
  249. --stdout \
  250. --title "$NAME - $VERSION" \
  251. --yesno "The routing table is configured as follows: \n\n $ROUTES_NOW \n\n\n \
  252. Want to change? \n\n" \
  253. 0 0 )
  254. if [ $? = 0 ]; then
  255. Create_Route
  256. else
  257. #return to main
  258. main
  259. fi
  260. }
  261. #Functio Create_Route
  262. Create_Route()
  263. {
  264. ROUTE_CREATE_OPT=$($DIA --stdout \
  265. --title "$NAME - $VERSION" \
  266. --menu 'Do you need?' \
  267. 0 0 0 \
  268. 1 'Create a new Route' \
  269. 2 'Modify a existing Route' \
  270. 3 'Delete a existing Route')
  271. if [ $? = 1 ]; then
  272. main_menu
  273. fi
  274. if [ $ROUTE_CREATE_OPT == "1" ]; then
  275. ROUTE_TYPE=$($DIA --stdout \
  276. --title "$NAME - $VERSION" \
  277. --menu 'You will create a route to a network or a host?' \
  278. 0 0 0 \
  279. 1 'Network' \
  280. 2 'Host')
  281. if [ $? = 1 ]; then
  282. main_menu
  283. fi
  284. ROUTE_HOST=$( $DIA \
  285. --stdout \
  286. --title "$NAME - $VERSION" \
  287. --inputbox "Insert HOST or NETWORK destination. \n\n \
  288. \nHost --> 192.168.0.1
  289. \n
  290. \nNETWORK --> 10.0.0.0 netmask 255.255.0.0 \n
  291. \n" 0 0 )
  292. #If cancel return is 1
  293. if [ $? = 1 ]; then
  294. main
  295. fi
  296. ROUTE_GW=$( $DIA \
  297. --stdout \
  298. --title "$NAME - $VERSION" \
  299. --inputbox "Insert ROUTER ADDRESS. \n\n \
  300. \nRouter --> 192.168.0.1
  301. \n" 0 0 )
  302. #If cancel return is 1
  303. if [ $? = 1 ]; then
  304. main
  305. fi
  306. if [ $ROUTE_TYPE == "1" ]; then
  307. echo "route add -net $ROUTE_HOST gw $ROUTE_GW"
  308. route add -net $ROUTE_HOST gw $ROUTE_GW
  309. fi
  310. if [ $ROUTE_TYPE == "2" ]; then
  311. echo "route add -host $ROUTE_HOST gw $ROUTE_GW"
  312. route add -host $ROUTE_HOST gw $ROUTE_GW
  313. fi
  314. fi
  315. if [ $ROUTE_CREATE_OPT == "2" ]; then
  316. echo "Modify route"
  317. fi
  318. if [ $ROUTE_CREATE_OPT == "3" ]; then
  319. echo "Delete route"
  320. fi
  321. }
  322. #Function BKP_FILE
  323. function BKP_FILE()
  324. {
  325. cp $1 $1.bkp
  326. }
  327. #Function Conf_Update
  328. function Conf_Update()
  329. {
  330. UPDATE_OPT=$($DIA --stdout \
  331. --title "$NAME - $VERSION" \
  332. --menu 'Do you need?' \
  333. 0 0 0 \
  334. Check 'for available updates' \
  335. Install 'new package' \
  336. Upgrade 'a package' \
  337. Reinstall 'a package' \
  338. Remove 'a package' \
  339. Search 'a package' \
  340. Search-File 'into Pakage' \
  341. Info 'about a package' \
  342. )
  343. if [ $? = 1 ]; then
  344. main_menu
  345. fi
  346. if [ $UPDATE_OPT = "Check" ]; then
  347. #run slackpkg update
  348. slackpkg update
  349. echo "Done. Return to slackconf!"
  350. sleep 3
  351. Conf_Update
  352. fi
  353. if [ $UPDATE_OPT = "Install" ]; then
  354. UPDATE_NAME=$($DIA --stdout \
  355. --title "$NAME - $VERSION" \
  356. --inputbox "Enter the name of the package to be installed" \
  357. 0 0 )
  358. #run slackpkg install
  359. slackpkg install $UPDATE_NAME
  360. echo "Done. Return to slackconf!"
  361. sleep 3
  362. Conf_Update
  363. fi
  364. if [ $UPDATE_OPT = "Upgrade" ]; then
  365. UPDATE_NAME=$($DIA --stdout \
  366. --title "$NAME - $VERSION" \
  367. --inputbox "Enter the name of the package to be upgraded" \
  368. 0 0 )
  369. #run slackpkg upgrade
  370. slackpkg upgrade $UPDATE_NAME
  371. echo "Done. Return to slackconf!"
  372. sleep 3
  373. Conf_Update
  374. fi
  375. if [ $UPDATE_OPT = "Reinstall" ]; then
  376. UPDATE_NAME=$($DIA --stdout \
  377. --title "$NAME - $VERSION" \
  378. --inputbox "Enter the name of the package to be re-installed" \
  379. 0 0 )
  380. #run slackpkg reinstall
  381. slackpkg reinstall $UPDATE_NAME
  382. echo "Done. Return to slackconf!"
  383. sleep 3
  384. Conf_Update
  385. fi
  386. if [ $UPDATE_OPT = "Remove" ]; then
  387. UPDATE_NAME=$($DIA --stdout \
  388. --title "$NAME - $VERSION" \
  389. --inputbox "Enter the name of the package to be removed" \
  390. 0 0 )
  391. #run slackpkg remove
  392. slackpkg remove $UPDATE_NAME
  393. echo "Done. Return to slackconf!"
  394. sleep 3
  395. Conf_Update
  396. fi
  397. if [ $UPDATE_OPT = "Search" ]; then
  398. UPDATE_NAME=$($DIA --stdout \
  399. --title "$NAME - $VERSION" \
  400. --inputbox "Enter the name of the package you want to search" \
  401. 0 0 )
  402. #run slackpkg search
  403. slackpkg search $UPDATE_NAME
  404. echo "Done. Return to slackconf!"
  405. sleep 0
  406. Conf_Update
  407. fi
  408. if [ $UPDATE_OPT = "Search-File" ]; then
  409. UPDATE_NAME=$($DIA --stdout \
  410. --title "$NAME - $VERSION" \
  411. --inputbox "Enter the name of the file you want to find" \
  412. 0 0 )
  413. #run slackpkg file-search
  414. slackpkg file-search $UPDATE_NAME
  415. echo "Done. Return to slackconf!"
  416. sleep 3
  417. Conf_Update
  418. fi
  419. if [ $UPDATE_OPT = "Info" ]; then
  420. UPDATE_NAME=$($DIA --stdout \
  421. --title "$NAME - $VERSION" \
  422. --inputbox "Enter the name of the package you want information" \
  423. 0 0 )
  424. #run slackpkg info
  425. slackpkg info $UPDATE_NAME
  426. echo "Done. Return to slackconf!"
  427. sleep 3
  428. Conf_Update
  429. fi
  430. }
  431. #Function Conf_Runlevel
  432. function Conf_Runlevel()
  433. {
  434. FILE_INITTAB="/etc/inittab"
  435. #Detect runlevel configurated
  436. RUNLEVEL=`cat /etc/inittab | grep id: | cut -d":" -f2`
  437. RUNLEVEL_OPTION=$( $DIA \
  438. --stdout \
  439. --title "$NAME - $VERSION" \
  440. --inputbox "Your level configured is $RUNLEVEL, but you can change. \n\n \
  441. \n0 halt
  442. \n1 single user mode
  443. \n2 unused (but configured the same as runlevel 3)
  444. \n3 multiuser mode (default Slackware runlevel)
  445. \n4 X11 with KDM/GDM/XDM (session managers)
  446. \n5 unused (but configured the same as runlevel 3)
  447. \n6 reboot \n" 0 0 )
  448. #If cancel return is 1
  449. if [ $? = 1 ]; then
  450. main
  451. fi
  452. #if opntion is equal runlevel, nothing
  453. if [ $RUNLEVEL_OPTION == $RUNLEVEL ]; then
  454. main;
  455. fi
  456. #Case value not 0-6 reload this function
  457. if [[ $RUNLEVEL_OPTION != [0-6] ]]; then
  458. Conf_Runlevel
  459. fi
  460. if [[ $RUNLEVEL_OPTION = [0-6] ]]; then
  461. RUNLEVEL_OPTION_YN=$($DIA \
  462. --stdout \
  463. --title "$NAME - $VERSION" \
  464. --yesno "Runlevel is changed to $RUNLEVEL_OPTION, ok?" \
  465. 0 0 \
  466. )
  467. if [ $? = 0 ]; then
  468. #change file
  469. if [ $BKP_OPT == "Y" ]; then
  470. BKP_FILE "$FILE_INITTAB"
  471. fi
  472. sed "s/id:$RUNLEVEL:initdefault:/id:$RUNLEVEL_OPTION:initdefault:/g" $FILE_INITTAB > /tmp/INITTAB.tmp && cp /tmp/INITTAB.tmp $FILE_INITTAB && rm /tmp/INITTAB.tmp
  473. main
  474. else
  475. #return to conf_Runlevel
  476. Conf_Runlevel
  477. fi
  478. fi
  479. }
  480. #Function Conf_Services
  481. function Conf_Services()
  482. {
  483. SERVICE_OPT=$($DIA --stdout \
  484. --title "$NAME - $VERSION" \
  485. --menu 'Do you need?' \
  486. 0 0 0 \
  487. Enables 'a Service' \
  488. Disables 'a Service')
  489. if [ $? = 1 ]; then
  490. main_menu
  491. fi
  492. if [ $SERVICE_OPT == "Disables" ]; then
  493. #Identifies the executable scripts
  494. find /etc/rc.d/ -perm -400 | grep -v "rc.[0-6]" | grep -v "rc.[K,M,S]" | grep -v "init.d" | grep -v "rc[0-9]" | cut -d"/" -f4 | sort > /tmp/.services.slackconf00
  495. cp /tmp/.services.slackconf00 /tmp/.services.slackconf01
  496. paste /tmp/.services.slackconf00 /tmp/.services.slackconf01 -d" " > /tmp/.services.slackconf
  497. #cat /tmp/.services.slackconf02 | sed 's/$/ ON/' > /tmp/.services.slackconf
  498. escolha=$($DIA --stdout \
  499. --title "$NAME - $VERSION" \
  500. --menu "What service you want to disable?" \
  501. 0 0 0 \
  502. $(cat /tmp/.services.slackconf))
  503. chmod -x /etc/rc.d/$escolha
  504. Conf_Services
  505. fi
  506. #Identifies non executable scripts
  507. find /etc/rc.d/ -perm -400 | grep -v "rc.[0-6]" | grep -v "rc.[K,M,S]" | grep -v "init.d" | grep -v "rc[0-9]" | cut -d"/" -f4 | sort > /tmp/.services.slackconf00
  508. cp /tmp/.services.slackconf00 /tmp/.services.slackconf01
  509. paste /tmp/.services.slackconf00 /tmp/.services.slackconf01 -d" " > /tmp/.services.slackconf
  510. #cat /tmp/.services.slackconf02 | sed 's/$/ ON/' > /tmp/.services.slackconf
  511. escolha=$($DIA --stdout \
  512. --title "$NAME - $VERSION" \
  513. --menu "What service you want to enable?" \
  514. 0 0 0 \
  515. $(cat /tmp/.services.slackconf))
  516. chmod +x /etc/rc.d/$escolha
  517. Conf_Services
  518. }
  519. main_menu()
  520. {
  521. OPTION=$($DIA --stdout \
  522. --title "$NAME - $VERSION" \
  523. --menu 'Which option would you like?' \
  524. 0 0 0 \
  525. RunLevel 'Configure runlevel startup' \
  526. Packages 'Manage Packages using pkgtool' \
  527. Update 'using slackpkg' \
  528. Services 'Enable or disable startup script' \
  529. Mouse 'Configure mouse using mouseconfig' \
  530. Network 'Configure network using netconfig' \
  531. DNS 'Query information about host/domain' \
  532. Routes 'Display and configure the routing table in the kernel' \
  533. Sound 'Configure sound devices' \
  534. Log 'View logs from system' \
  535. User 'Management users account' \
  536. System 'Information' \
  537. About "About $NAME" \
  538. Exit "Return to prompt")
  539. if [ $? = 1 ]; then
  540. exit_
  541. fi
  542. if [ $OPTION == 'RunLevel' ]; then
  543. Conf_Runlevel
  544. elif [ $OPTION == "Services" ]; then
  545. main_menu
  546. #Conf_Services
  547. elif [ $OPTION == "Packages" ]; then
  548. Conf_Packages
  549. elif [ $OPTION == "Network" ]; then
  550. Conf_Network
  551. elif [ $OPTION == "Mouse" ]; then
  552. Conf_Mouse
  553. elif [ $OPTION == "About" ]; then
  554. about
  555. elif [ $OPTION == "DNS" ]; then
  556. #main_menu
  557. Conf_Dns
  558. elif [ $OPTION == "Routes" ]; then
  559. main_menu
  560. #Conf_Routes
  561. elif [ $OPTION == "Sound" ]; then
  562. Conf_Sound
  563. elif [ $OPTION == "Log" ]; then
  564. Conf_Log
  565. elif [ $OPTION == "System" ]; then
  566. Conf_Sound
  567. elif [ $OPTION == "Update" ]; then
  568. Conf_Update
  569. elif [ $OPTION == "User" ]; then
  570. main_menu
  571. #Conf_User
  572. elif [ $OPTION == "Exit" ]; then
  573. exit_
  574. fi
  575. }
  576. main()
  577. {
  578. check_depends
  579. main_menu
  580. }
  581. main