Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. #!/bin/bash
  3. #!/bin/bash -e
  4.  
  5. #-Försöker få whiptail att fungera med bash - Mest som ett test-#
  6. version="0.6.1"
  7. www="http://alturl.com/w9wbu"
  8. email="hynten@speed-mailer.com"
  9. depends="whiptail fakeroot grep sed dpkg-repack dpkg-dev apt-move sudo \
  10. taskset gzip nano awk perl cowsay toilet rmdupe apt-cdrom genisoimage dd"
  11.  
  12.  
  13. #===========================#)
  14. # datum="-`date +%Y-%m-%d`" #)
  15. #===========================#)
  16.  
  17. #===========================================================#)
  18. # Then when I need to colourize some output #)
  19. #=============================0=============================#)
  20. black() { echo "$(tput setaf 0)$*$(tput setaf 9)"; } #)
  21. red() { echo "$(tput setaf 1)$*$(tput setaf 9)"; } #)
  22. green() { echo "$(tput setaf 2)$*$(tput setaf 9)"; } #)
  23. yellow() { echo "$(tput setaf 3)$*$(tput setaf 9)"; } #)
  24. blue() { echo "$(tput setaf 4)$*$(tput setaf 9)"; } #)
  25. magenta() { echo "$(tput setaf 5)$*$(tput setaf 9)"; } #)
  26. cyan() { echo "$(tput setaf 6)$*$(tput setaf 9)"; } #)
  27. white() { echo "$(tput setaf 7)$*$(tput setaf 9)"; } #)
  28. #===========================================================#)
  29. # echo -en "\033[s\033[7B\033[1;34m 7 violet \033[u\033[0m" #)
  30. # echo -en "\033[s\033[7A\033[1;32m 7 green \033[u\033[0m" #)
  31. #===========================================================#)
  32.  
  33. #---PASSWORD-CHECK-START----------------------------------------------------------------------------------------------------#
  34. get_password() {
  35. exec 3>&1
  36. REPLY=`whiptail --ok-button 'Unlock' --nocancel --passwordbox 'Enter password:' 7 21 2>&1 1>&3`
  37. exec 3>&-
  38. return 0
  39. }
  40.  
  41. while
  42. get_password
  43. [[ $REPLY != '0' ]]
  44. do
  45. whiptail --ok-button 'Try again' --msgbox 'Access denied!' 7 19
  46. done
  47.  
  48. whiptail --ok-button 'Continue' --msgbox 'Access granted!' 7 19
  49. #---------------------------------------------------------------------------------------------------------#
  50.  
  51. #-----------------------------------------------------------------------------------------------#
  52. function EDIT-SOURCES-LIST () {
  53. nano /etc/apt/sources.list
  54. }
  55. #------------------------------------------------------------------------------------------------#
  56.  
  57. #===========================#)
  58. #======================================================hynten@speed-mailer.com=======================================#)
  59. CREATE-CHROOT-IN-MNT() { #)
  60. reset #)
  61. echo "chroot" #)
  62. echo "[-> run command or interactive shell <-]" #)
  63. echo "[-> with special root directory <-]" #)
  64. echo "[->----------------------------------<-]" #)
  65. sudo rsync -ahPHAXx --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found} / /mnt #)
  66. for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done #)
  67. sudo cd / ; sudo chroot /mnt ; sudo grub-install --recheck /dev/sda ; sudo update-grub #)
  68. return 0 #)
  69. } #)
  70.  
  71. TEST-CHROOT-IN-MNT() {
  72. #====================================================================================================================#)
  73. # Script: test-chroot <- no .sh this is a command like whoami
  74. # Author: hynt@speed-mailer.com
  75. # url: http://alturl.com/u9qoh
  76. #
  77. # Date: 2015-04-19 - 01 (ee = times edited)
  78. #
  79. # Purpose: Detecting a chroot jail from within
  80. # without root privileges?
  81. #
  82. # Notes: sudo chmod u=rwx,g=rx,o=r test-chroot
  83. # sudo cp test-chroot /bin
  84. # Now you write test-chroot,
  85. # And the program starts---
  86. #
  87.  
  88. clear
  89. echo "☢TEST-CHROOT☢"
  90. echo "-------------------------------"
  91. echo "If you are not in a chroot"
  92. echo "the inode for / will always be 2"
  93. echo "now check that is: ☻"
  94. echo "-------------------------------"
  95. printf 'Inode: %s\n' $( stat -c %i / )
  96. printf ' User: %s\n' $( whoami )
  97. printf ' Path: %s\n' $( pwd )
  98. echo "-------------------------------"
  99. return 0 #)
  100. }
  101.  
  102. START-CHROOT-IN-MNT() {
  103. reset
  104. echo "now enter chroot"
  105. for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
  106. cd / ; sudo chroot mnt
  107.  
  108. clear
  109. echo "☢TEST-CHROOT☢"
  110. echo "-------------------------------"
  111. echo "If you are not in a chroot"
  112. echo "the inode for / will always be 2"
  113. echo "now check that is: ☻"
  114. echo "-------------------------------"
  115. printf 'Inode: %s\n' $( stat -c %i / )
  116. printf ' User: %s\n' $( whoami )
  117. printf ' Path: %s\n' $( pwd )
  118. echo "-------------------------------"
  119. }
  120.  
  121. #=======hynten@speed-mailer.com============#)
  122. SUDO-2-USER() { #)
  123. reset #)
  124. echo "-> ADD USER 2 SUDO LIST <-" #)
  125. echo "-> Enter User:" #)
  126. read usr ; sudo usermod -a -G sudo $usr #)
  127. return 0 #)
  128. } #)
  129. #==========================================#)
  130.  
  131. function REMOVE-ALL-INSTALLED-TODAY () {
  132. whiptail --title "REMOVE ALL PACKAGES INSTALLED TODAY" --msgbox "This can come in handy one day.." 8 78
  133.  
  134. read -p 'Are you sure you want to continue? (y/n) ' -n 1 confirmation
  135. echo ''
  136. if [[ $confirmation != 'y' && $confirmation != 'Y' ]]; then
  137. exit 3
  138. fi
  139.  
  140. dpkg -l | awk '{print $2}' > `date +%Y-%m-%d`-all-installed-before-today-removes.packages
  141. grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq | xargs apt-get -y remove
  142. }
  143.  
  144. #----------------------------------------------------------------------------#
  145. function REMOVE-REPEATED-PPA () {
  146. whiptail --title "REMOVE REPEATED PPPA" --msgbox "Remove All Repeated PPA in Sources.list" 8 78
  147. cat /etc/apt/sources.list | perl -ne '$H{$_}++ or print' > /tmp/sources.list && sudo mv /tmp/sources.list /etc/apt/sources.list
  148. sleep 4
  149. whiptail --msgbox "Now your /etc/apt/sources.list is free from repeated PPA...." --title "Ok! all done.." --backtitle "hynten@speed-mailer-com" 12 60
  150. }
  151. #----------------------------------------------------------------------------#
  152.  
  153. #----------------------------------------------------------------------------#
  154. function QUIT () {
  155. reset
  156. red "Bye!... Nice to meet yaa! cya later!"
  157. red "look 4 new version: http://alturl.com/w9wbu"
  158. sleep 3
  159. exit
  160. }
  161. #------------------------------------------------------------------------------#
  162.  
  163. #----------------------------------------------------------------------------#
  164. function DPKG-REPACK () {
  165. whiptail --title "DPKG-REPACK" --msgbox "All Installed Packages create repack 2 *.deb files script" 8 78
  166. repackSavePath=$(whiptail --inputbox "Where To Save Created Script:?" 8 78 "/home/hynt/" --title "Enter like ex. /home/hynt/backup/" 3>&1 1>&2 2>&3)
  167. dpkg -l | awk '{print $2}' | sed "s/^/\ fakeroot -u dpkg-repack /; s/$/\ /;" > /$repackSavePath/repack-all-packages-`date +%Y-%m-%d`.sh
  168. sed '1,6d' < /$repackSavePath/repack-all-packages-`date +%Y-%m-%d`.sh > /$repackSavePath/repack-all-package-`date +%Y-%m-%d`.sh
  169. rm /$repackSavePath/repack-all-packages-`date +%Y-%m-%d`.sh
  170. chmod u=rwx,g=rx,o=r /$repackSavePath/repack-all-package-`date +%Y-%m-%d`.sh
  171. }
  172. #----------------------------------------------------------------------------#
  173.  
  174. #----------------------------------------------------------------------------#
  175. function ADD-PACKAGE-TO-INSTALL () {
  176. CommandToInstallToScript="sudo apt-get --ignore-missing install "
  177. AddedPackagePath=$(whiptail --inputbox "Where To Append Package:?" 8 78 "/home/hynt/" --title "Enter like ex. /home/hynt/ no need to enter filename" 3>&1 1>&2 2>&3)
  178. AddedPackage=$(whiptail --inputbox "Enter Package To Add:?" 8 78 "?" --title "Add-Package-2-Install-Script" 3>&1 1>&2 2>&3)
  179. #$COMMAND + $INPUT >> $PATCH $FILE
  180. sudo sh -c "echo \"$CommandToInstallToScript $AddedPackage\" >> /$AddedPackagePath/install.sh" ; red "......" ; sleep 1
  181. chmod u=rwx,g=rx,o=r /$AddedPackagePath/install.sh
  182. red "RESTART-SCRIPT" ; RESTART-SCRIPT ; sleep 2
  183. }
  184.  
  185. #----------------------------------------------------------------------------#
  186. function ALL-INSTALLED-PACKAGES () {
  187. AllInstalledPackagesSavePath=$(whiptail --inputbox "Where To Save Created Script:?" 8 78 "/home/hynt/" --title "Enter like ex. /home/hynt/backup/" 3>&1 1>&2 2>&3)
  188. cat /etc/apt/sources.list >> /$AllInstalledPackagesSavePath/sources.list
  189. sudo dpkg --get-selections | awk '$2 ~ /^install$/ {print $1}' > /$AllInstalledPackagesSavePath/installed
  190. sort $AllInstalledPackagesSavePath/installed | uniq -u >> /$AllInstalledPackagesSavePath/installed
  191. awk '{print "sudo apt-get -y --force-yes --allow-unauthenticated --ignore-missing install --reinstall " $0}' < /$AllInstalledPackagesSavePath/installed > $AllInstalledPackagesSavePath/installed-package-installer-`date +%Y-%m-%d`.sh
  192. perl -pi -e 'print "sudo cp sources.list /etc/apt/ && sudo apt-get update\n" if $.==1' /$AllInstalledPackagesSavePath/installed-package-installer-`date +%Y-%m-%d`.sh
  193. perl -pi -e 'print "#! /bin/bash\n" if $.==1' $AllInstalledPackagesSavePath/installed-package-installer-`date +%Y-%m-%d`.sh
  194. echo "sudo apt-get dist-upgrade" >> /$AllInstalledPackagesSavePath/installed-package-installer-`date +%Y-%m-%d`.sh
  195. chmod u=rwx,g=rx,o=r /$AllInstalledPackagesSavePath/installed-package-installer-`date +%Y-%m-%d`.sh
  196. sleep 2
  197. rm $AllInstalledPackagesSavePath/installed
  198. sudo echo echo "hynten@speed-mailer.com" >> $AllInstalledPackagesSavePath/installed-package-installer-`date +%Y-%m-%d`.sh
  199. red "RESTART-SCRIPT" ; RESTART-SCRIPT ; sleep 4
  200. }
  201. #----------------------------------------------------------------------------#
  202.  
  203. #--------------------------------------------------------------------------#
  204. function REBOOT-THE-SYSTEM () {
  205. whiptail --title "reboot the system" --msgbox "Reboot in 5 second" 8 78
  206. read -p 'Are you sure you want to continue? (y/n) ' -n 1 confirmation
  207. echo ''
  208. if [[ $confirmation != 'y' && $confirmation != 'Y' ]]; then
  209. exit 3
  210. fi
  211. reset
  212. seconds=5
  213. (
  214. for i in $(seq $seconds -1 1); do
  215. reset
  216. red "$i seconds to shutdown...";
  217. sleep 1;
  218. done;
  219. red "Shutdown now!")
  220. sudo reboot # REBOOT THE COMPUTER
  221. }
  222. #---------------------------------------------------------------------------#
  223.  
  224. #---------------------------------------------------------------------------#
  225. function MIRROR-HARD-DRIVE-2-USB () {
  226. reset
  227. red "mount" ; sudo mount
  228. red "fdisk -l" ; sudo fdisk -l
  229. red "-------hynten@speed-mailer.com-----------------------------"
  230. red "- ____ _ _ -"
  231. red "- | __ ) __ _ ___| | ___ _ _ __ | | -"
  232. red "- | _ \ / _ |/ __| |/ / | | | _ \| | -"
  233. red "- | |_) | (_| | (__| <| |_| | |_) |_| -"
  234. red "- |____/ \__,_|\___|_|\_\\_ _ | __/(_) -"
  235. red "- |_| -"
  236. red "- mount -"
  237. red "- fdisk -l <-- if my settings if the are ok! 4 u -"
  238. red "- -"
  239. red "- dd if=/dev/sda1 of=/dev/sdc1 bs=16M -"
  240. red "- -"
  241. red "- Careful one char wrong and you can fucked up the system -"
  242. red "- The /dev/sdc1 are not mounting while dd works! -"
  243. red "- -"
  244. red "---------------Look Above E-mail 4 your settings!----------"
  245. echo " "
  246. yellow "dd if=/dev/sda? of=/dev/sdc? bs=16M"
  247. }
  248. #---------------------------------------------------------------------------#
  249. #---------------------------------------------------------------------------#
  250. function RESTART-SCRIPT () {
  251. ./meny
  252. }
  253. #---------------------------------------------------------------------------#
  254.  
  255. function LOCAL-REPO () {
  256. reset
  257. echo "---------------------------------------------------------"
  258. echo "- _ _ ____ -"
  259. echo "- | | ___ ___ __ _| | | _ \ ___ _ __ ___ -"
  260. echo "- | | / _ \ / __/ _ | |_____| |_) / _ \ '_ \ / _ \ -"
  261. echo "- | |__| (_) | (_| (_| | |_____| _ < __/ |_) | (_) | -"
  262. echo "- |_____\___/ \___\__,_|_| |_| \_\___| .__/ \___/ -"
  263. echo "- |_| -"
  264. echo "- APT-MOVE , DPKG-SCANPACKAGES -"
  265. echo "- -"
  266. echo "- deb file:/mirrors/debian/ / -"
  267. echo "- <----------------------------> -"
  268. echo "- \ ^__^ -"
  269. echo "- \ (--)\_______ -"
  270. echo "- (__)\ )\/\ -"
  271. echo "- ||----w | -"
  272. echo "- || || -"
  273. echo "---------------http://alturl.com/w9wbu-------------------"
  274. sleep 5
  275.  
  276. apt-move -a move
  277. echo "apt-move packages" ; taskset -c 0 apt-move -a packages
  278. echo "dpkg-scanpackages"
  279. cd /mirrors/debian/ ; dpkg-scanpackages -m . /dev/null | gzip -9c > Packages.gz
  280. #cd /mirrors//ftp/debian/ ; dpkg-scanpackages . /dev/null 2> error.txt | gzip -9c > Packages.gz
  281. cd /mirrors/debian/ ; dpkg-scansources -m . /dev/null | gzip -9c > Sources.gz
  282. #cd /mirrors//ftp/debian/ ; grep "!" < error.txt > rm.txt
  283. echo "apt-move sync" && apt-move sync
  284. echo "apt-get clean" && apt-get clean
  285. #next line is not get tested
  286. #cd /var/www/debian/ && sed 's/"dpkg-scanpackages: varning: använde den och ignorerade data från jessie/"/"rm /var/www/debian/jessie/"' rm.txt
  287. reset
  288. toilet --gay "Bye!"
  289. /usr/games/cowsay -t "Email:hynten@speed-mailer.com"
  290. }
  291. #---------------------------------------------------------------------------#
  292. function REMOVE-REPEATED-FILES () {
  293. whiptail --title "REMOVE REPEATED FILES" --msgbox "This Function use the program rmdupe" 8 78
  294. rmdupepath=$(whiptail --inputbox "What dir should we begin with?" 8 78 "/srv/ftp/" --title "Enter like ex. /srv/ftp/" 3>&1 1>&2 2>&3)
  295. rmdupe -r $rmdupepath
  296. }
  297.  
  298. function PURGE-CONF-OF-REMOVED () {
  299. whiptail --title "REMOVE CONFIG FILES" --msgbox "From already removed packages files" 8 78
  300. sudo aptitude purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`
  301. toilet --gay "have a nice day!"
  302. }
  303.  
  304.  
  305. function SCAN-PACKAGES-2-DVD () {
  306. ScanPackages2DvdPath=$(whiptail --inputbox "Scanpackages To Make Your Own Deb dvd/cd?" 8 78 "/home/snort/deb/" --title "Enter like ex. /home/snort/deb/" 3>&1 1>&2 2>&3)
  307. ScanPackages2DvdName=$(whiptail --inputbox "Give me a name to give to the iso file?" 8 78 "MyDebFiles-`date +%Y-%m-%d`" --title "Enter like ex. MyDebFiles-`date +%Y-%m-%d`" 3>&1 1>&2 2>&3)
  308. cd /$ScanPackages2DvdPath/ ; dpkg-scanpackages -m . /dev/null | gzip -9c > Packages.gz
  309. #cd /$ScanPackages2DvdPath/ ; mv *.sh ../ #flytta inte installerar med den
  310.  
  311. genisoimage -r -o /$ScanPackages2DvdPath/$ScanPackages2DvdName.iso /$ScanPackages2DvdPath/
  312. whiptail --title "All done!" --msgbox "Burn it with your favorite burn program and run apt-cdrom add" 8 78
  313. }
  314.  
  315. ##################################################################################################################
  316. OPTION=$(whiptail --title "Test Menu Dialog" --menu "Choose your option" --backtitle "Version $version" 15 80 4 \
  317. "ALL-INSTALLED-PACKAGES" "Convert To a Install Script.." \
  318. "ADD-PACKAGE-TO-INSTALL" "Add Package 2 Install Script.." \
  319. "REBOOT-THE-SYSTEM" "Time for a break?" \
  320. "DPKG-REPACK" "ALl installed packages to *.deb" \
  321. "EDIT-SOURCES-LIST" "Use Nano To Edit sources.list" \
  322. "REMOVE-REPEATED-PPA" "In /etc/apt/sources.list" \
  323. "REMOVE-ALL-INSTALLED-TODAY" "Today's installed removes" \
  324. "LOCAL-REPO" "Reindex / Add / Sync Local PPA" \
  325. "REMOVE-REPEATED-FILES" "Remove Repeated files with rmdupe" \
  326. "SCAN-PACKAGES-2-DVD" "Scanpackages To Make Your Own Deb dvd/dvd" \
  327. "MIRROR-HARD-DRIVE-2-USB" "Uses DD Careful copy and paste in terminal" \
  328. "SUDO-2-USER" "Add Normal User To Sudo List!" \
  329. "CREATE-CHROOT-IN-MNT" "Dont runt this if you??" \
  330. "TEST-CHROOT-IN-MNT" "Detecting a chroot jail from within" \
  331. "START-CHROOT-IN-MNT" "Start chroot created with CREATE-CHROOT-IN-MNT" \
  332. "PURGE-CONF-OF-REMOVED" "Purge Config Of Removed Packages Files" \
  333. "QUIT" "Close This Program Say Bye!..." 3>&1 1>&2 2>&3)
  334. exitstatus=$?
  335.  
  336. if [ $exitstatus = 0 ]; then
  337. red "Your chosen option:" $OPTION
  338. $OPTION
  339. else
  340. red "You chose Cancel."
  341. fi
  342. ##################################################################################################################
  343. # If You Got Problem or somthing like that email: hynten@speed-mailer.com #
  344. ##################################################################################################################