sany_ok

apm

Nov 11th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.87 KB | None | 0 0
  1. #=====begin of copyright notice=====                                                                                                                        
  2. copyright()                                                                                                                                                
  3. {                                                                                                                                                          
  4.         echo -e "                                                                                                                                          
  5.                                                                                                                                                            
  6.        THE AULIX_UTILS FOR DEBIAN AND CENTOS \n                                                                                                            
  7.        The AUTHOR of this file is Alexander Borisovich Prokopyev, Kurgan, Russia \n                                                                        
  8.        More info can be found at the AUTHOR's website: http://www.aulix.com/resume \n                                                                      
  9.        Contact: alexander.prokopyev at aulix dot com \n                                                                                                    
  10.                                                                                                                                                            
  11.        Copyright (c) Alexander Prokopyev, 2006-2014 \n                                                                                                    
  12.                                                                                                                                                            
  13.        All materials contained in this file are protected by copyright law. \n                                                                            
  14.        Nobody except the AUTHOR may alter or remove this copyright notice from copies of the content. \n                                                  
  15.                                                                                                                                                            
  16.        The AUTHOR allows to use this content under AGPL v3 license:                                                                                        
  17.        http://opensource.org/licenses/agpl-v3.html                                                                                                        
  18.                                                                                                                                                            
  19.        ";                                                                                                                                                  
  20. }                                                                                                                                                          
  21.                                                                                                                                                            
  22. copyright;
  23. #=====end of copyright notice=====
  24.  
  25.  
  26. Action=$1;
  27.  
  28. echo "Start the proxy on the workstation!";
  29. echo;echo;echo;
  30.  
  31. source /utils/custom/use_proxy.sh;
  32. #set -x;
  33.  
  34. Distro=`lsb_release -i | awk '{print $3}'`;
  35. case $Distro in
  36.         ( Debian | Ubuntu )
  37.                 PkgType="deb";
  38.         ;;
  39.         ( CentOS )
  40.                 PkgType="rpm";
  41.         ;;
  42.         ( * )
  43.                 echo "Error: unknown distro: $Distro !";
  44.                 exit 1;
  45.         ;;
  46. esac;
  47.  
  48. info_deb()
  49. {
  50.         wajig describe $1; # -vv # wajig what-is
  51.         wajig detail $1; #apt-cache showpkg $1;
  52.         echo "--- DPKG Status -------------------------"
  53.         dpkg --status $1;
  54.         echo "--- Contains files ----------------------"
  55.         wajig list-files $1;
  56.         scripts_deb $1;
  57.         echo "--- Other dependands --------------------"
  58.         wajig dependents $1;
  59. }
  60.  
  61. info_rpm()
  62. {
  63.         rpm -qi $1;
  64.         rpm -ql $1; # list files
  65. }
  66.  
  67. sections_deb()
  68. {
  69.         wajig list-sections;
  70. }
  71.                                                                                                
  72.  
  73. purge_deb()
  74. {
  75.         apt-get --yes autoremove;
  76.         dpkg --get-selections | awk '/deinstall/ {print $1}' | xargs dpkg --purge;
  77.         sync;
  78. }
  79.  
  80. purge2_deb()
  81. {
  82.         wajig remove-orphans;
  83. }
  84.  
  85.  
  86.  
  87. remove_deb()
  88. {
  89.         apt-get remove $@;
  90. }
  91.  
  92. remove_rpm()
  93. {
  94.         yum remove $@;
  95. }
  96.  
  97. file_deb()
  98. {
  99.         wajig whichpkg $1;
  100.         wajig find-file $1;
  101.         dpkg --search $1;
  102. }
  103.  
  104. file_rpm()
  105. {
  106.         rpm -qf | grep $1;
  107. }
  108.  
  109. search_deb()
  110. {
  111.         dpkg -al | grep -i $1;
  112.         wajig status-search $1;
  113. }
  114.  
  115. large_deb()
  116. {
  117.         wajig size | tail -n 100;
  118. }
  119.  
  120. best_deb()
  121. {
  122.         wajig search-apt squeeze;
  123. }
  124.  
  125. verify_deb()
  126. {
  127.         apt-get --reinstall -d install `debsums -l`;
  128.         wajig integrity  2>&1;
  129. }
  130.  
  131. restore_deb()
  132. {
  133.         FromFile=$1;
  134.         wajig fileinstall $FromFile;
  135. }
  136.  
  137. fix_bash_deb()
  138. {
  139. #       rm /bin/sh;
  140. #       ln -s /bin/bash /bin/sh;
  141. # use alter instead!
  142.         echo ""; # not blank body
  143. }
  144.  
  145. upgrade_deb()
  146. {
  147. #       set -x;
  148.  
  149. #       DirName="/boot/kernel.bak/"$(date +\%Y_\%m_\%d__\%H_\%M_\%S);
  150. #       mkdir $DirName;
  151. #       cp /boot/*-2.6.* $DirName/;
  152.         apt-get update;
  153.         apt-get dist-upgrade;
  154.         fix_bash_deb;
  155. }
  156.  
  157. extract_deb()
  158. {
  159.         ar x $1;
  160.         /utils/pkg/untar/gz.sh data.tar.gz;
  161.         rm -f control.tar.gz data.tar.gz debian-binary;
  162. #       chown -R alex:alex /download/lib64;
  163. }
  164.  
  165. tar() # outputs in tar format to console; can redirect to file.tar
  166. {
  167.         dpkg --fsys-tarfile $1;
  168. }
  169.  
  170. extract_rpm()
  171. {
  172.         rpm2cpio $1 | cpio -idmv;
  173. }
  174.  
  175. create_repo_rpm()
  176. {
  177.         createrepo /var/cache/yum/core/packages;
  178.         createrepo /var/cache/yum/updates/packages;
  179.         createrepo /var/cache/yum/extras/packages;
  180.         createrepo /var/cache/yum/livna/packages;
  181.         createrepo /var/cache/yum/openoffice/packages;
  182. }
  183.  
  184. scripts_deb()
  185. {
  186.         echo "Listing SCRIPTS in: /var/lib/dpkg/info/";
  187.         ls -al /var/lib/dpkg/info/ | grep $1;
  188. }
  189.  
  190. config_deb()
  191. {
  192.         apt-config dump;
  193. }
  194.  
  195. list_installed_rpm()
  196. {
  197.         rpm -qa | grep -i "$1";
  198.         # show architecture # rpm -qa --qf "%{name}-%{version}-%{release}.%{arch}\n"
  199. }
  200.  
  201. #list_installed_deb()
  202. #{
  203. #       ToFile=$1;
  204. #       wajig listinstalled > $ToFile;
  205. #}
  206.  
  207.  
  208. list_installed_deb()
  209. {
  210. #       dpkg --get-selections | cut -f1 | sort;
  211. #       dpkg --get-selections;
  212.         apt-mark showmanual;
  213. }
  214.  
  215. install_listed_deb()
  216. {
  217.         set -x;
  218.         ListFile=$@;
  219.         #dpkg --set-selections < $ListFile;
  220.         apt-get install $(cat $ListFile);
  221. }
  222.  
  223. install_deb()
  224. {
  225.         apt-get install $@;
  226. }
  227.  
  228. install_rpm()
  229. {
  230.         yum install $@;
  231. }
  232.  
  233. install_sid_deb()
  234. {
  235.         echo "Uncomment following line in the /etc/apt/source.list: deb http://ftp.debian.org/debian experimental main";
  236.         apt-get update;
  237.         apt-get -t sid install $@; #experimental
  238. }
  239.  
  240. reinstall_deb()
  241. {
  242. #       wajig reinstall $@;
  243.         apt-get -o Dpkg::Options::="--force-confask" --reinstall install $@;
  244.         #--yes
  245. }
  246.  
  247. add_key_deb()
  248. {
  249.         set -x;
  250.         apt-key adv --recv-keys --keyserver $1 key-fingerprint;
  251. }
  252.  
  253. waste_deb()  
  254. {
  255.         deborphan --guess-all | sort;
  256. #       debfoster;
  257. }
  258.  
  259. purge_waste_deb()
  260. {
  261.         for i in {1..5}
  262.         do
  263.                 apt-get remove $(waste_deb);
  264.  
  265.         done;
  266.         purge_deb;
  267.         purge2_deb;
  268. }
  269.  
  270. #gen_deb()
  271. #{
  272. #
  273. #}
  274.  
  275. reconfigure_deb()
  276. {
  277.         dpkg-reconfigure --all -u;
  278. }
  279.  
  280. upgrade_remote_deb()
  281. {
  282.         set -x;
  283.         Host=$1;
  284.         DebDir="/var/cache/apt/archives";
  285.         /utils/rsync.sh data $DebDir/ $Host:$DebDir/;
  286. }
  287.  
  288. hold_deb()
  289. {
  290.         echo $Package" hold" | dpkg --set-selections;
  291. #        echo "$1 install" | dpkg --set-selections;
  292. }
  293.  
  294. get_home_debs()
  295. {
  296.         /utils/rsync.sh data home:/var/cache/apt/archives/*.deb /var/cache/apt/archives/;
  297. }
  298.  
  299. convert_from_rpm_deb()
  300. {
  301.         for f in *.rpm; do
  302.                 fakeroot alien --to-deb --scripts --keep $f;
  303.         done;
  304. }
  305.  
  306. remote_install_deb()
  307. {
  308.         HostName=$1;
  309.         RPMName=$2;
  310.         cat $RPMName | ssh $HostName "rpm -Uvh -";
  311. }
  312.  
  313. edit_deb()
  314. {
  315.  
  316. # edit the control data of a deb file,
  317. # usually to get round a dependency problem
  318. # adapted from http://ubuntuforums.org/showthread.php?t=636724
  319. # needs libnotify-bin for notifications if used without a terminal
  320.  
  321. # choose your editor:
  322.         EDITOR=joe
  323.  
  324.  
  325.         [[ "$1" ]] ||  { echo "Syntax: $0 debfile" >&2; exit 1; }
  326.  
  327.         DEBFILE="$1"
  328.         TMPDIR=$(mktemp -d /tmp/deb.XXXXXXXXXX) || exit 1
  329.         OUTPUT="${DEBFILE%.deb}".modfied-$( date +%FT%T ).deb
  330.  
  331.         if [[ -e "$OUTPUT" ]]; then
  332.                 echo "$0: $OUTPUT exists." >&2
  333.                 rm -r "$TMPDIR"
  334.                 exit 1
  335.         fi
  336.      
  337.         dpkg-deb -x "$DEBFILE" "$TMPDIR"
  338.         dpkg-deb --control "$DEBFILE" "$TMPDIR"/DEBIAN
  339.         CONTROL="$TMPDIR"/DEBIAN/control
  340.         [[ -e "$CONTROL" ]] || {
  341.                 echo "$0: DEBIAN/control not found in $1." >&2
  342.                 [ -t 1 ] || notify-send "$1: DEBIAN/control not found."
  343.                 rm -r "$TMPDIR"
  344.                 exit 1
  345.         }
  346.              
  347.         MOD=$(md5sum "$CONTROL")
  348.         $EDITOR "$CONTROL"
  349.              
  350.         if [[ $MOD = $(md5sum "$CONTROL") ]]; then
  351.                 [ -t 1 ] && echo "Not modfied."
  352.         else
  353.                 [ -t 1 ] && echo "Building new deb..." || notify-send "Building new deb..." "Please wait a moment."
  354.                 dpkg -b "$TMPDIR" "$OUTPUT"
  355.                 [ -t 1 ] && echo "Built new debfile: $OUTPUT" || notify-send "Built new debfile:" "$OUTPUT"
  356.         fi
  357.                      
  358.         rm -r "$TMPDIR"
  359.         exit
  360. }
  361.  
  362.  
  363. case $Action in
  364. ( info | search | large | install | install_listed | install_sid | remove | purge | purge2 | sections | file | best | installed | reinstall | verify | save | restore | search | deps | upgrade | extract | 2tar | scripts | config | hold | list_installed | add_key | waste | purge_waste | reconfigure | upgrade_remote | get_debs | edit | remote_install )
  365.         $Action"_"$PkgType ${@:2};
  366. ;;
  367.  
  368. #( install )
  369. #       $Action ${@:2};
  370. #;;
  371. #
  372. #( install_sid )
  373. #       $Action"_"$PkgType ${@:2};
  374. #;;
  375.  
  376. ( * )
  377.         echo "Unknown action: $Action !";
  378. ;;
  379. esac;
  380.  
  381.  
  382.  
  383.  
  384. #file: /etc/apt/sources.list
  385. #deb http://http.us.debian.org/debian/ squeeze main contrib non-free
  386. #deb http://http.us.debian.org/debian/ sid main contrib non-free
  387.  
  388. #file /etc/apt/preferences:
  389. #Package: *
  390. #Pin: release n=squeeze
  391. #Pin-Priority: 1000
  392. #Package: *
  393. #Pin: release n=sid
  394. #Pin-Priority: 100
Advertisement
Add Comment
Please, Sign In to add comment