pvetools.sh 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734
  1. #!/bin/bash
  2. #############--Proxmox VE Tools--##########################
  3. # Author : 龙天ivan
  4. # Mail: ivanhao1984@qq.com
  5. # Version: v2.2.5
  6. # Github: https://github.com/ivanhao/pvetools
  7. ########################################################
  8. #js whiptail --title "Success" --msgbox "c" 10 60
  9. if [ `export|grep 'LC_ALL'|wc -l` = 0 ];then
  10. if [ `grep "LC_ALL" /etc/profile|wc -l` = 0 ];then
  11. echo "export LC_ALL='en_US.UTF-8'" >> /etc/profile
  12. fi
  13. fi
  14. if [ `grep "alias ll" /etc/profile|wc -l` = 0 ];then
  15. echo "alias ll='ls -alh'" >> /etc/profile
  16. echo "alias sn='snapraid'" >> /etc/profile
  17. fi
  18. source /etc/profile
  19. #-----------------functions--start------------------#
  20. example(){
  21. #msgbox
  22. whiptail --title "Success" --msgbox "
  23. " 10 60
  24. #yesno
  25. if (whiptail --title "Yes/No Box" --yesno "
  26. " 10 60);then
  27. echo ""
  28. fi
  29. #password
  30. PASSWORD=$(whiptail --title "Password Box" --passwordbox "
  31. Enter your password and choose Ok to continue.
  32. " 10 60 3>&1 1>&2 2>&3)
  33. exitstatus=$?
  34. if [ $exitstatus = 0 ]; then
  35. echo "Your password is:" $m
  36. fi
  37. #input form
  38. NAME=$(whiptail --title "
  39. Free-form Input Box
  40. " --inputbox "
  41. What is your pet's name?
  42. " 10 60
  43. Peter
  44. 3>&1 1>&2 2>&3)
  45. exitstatus=$?
  46. if [ $exitstatus = 0 ]; then
  47. echo ""
  48. else
  49. echo ""
  50. fi
  51. #processing
  52. apt -y install mailutils
  53. }
  54. smbp(){
  55. m=$(whiptail --title "Password Box" --passwordbox "
  56. Enter samba user 'admin' password:
  57. 请输入samba用户admin的密码:
  58. " 10 60 3>&1 1>&2 2>&3)
  59. exitstatus=$?
  60. if [ $exitstatus = 0 ]; then
  61. while [ true ]
  62. do
  63. if [[ ! `echo $m|grep "^[0-9a-zA-Z.-@]*$"` ]] || [[ $m = '^M' ]];then
  64. whiptail --title "Warnning" --msgbox "
  65. Wrong format!!! input again:
  66. 密码格式不对!!!请重新输入:
  67. " 10 60
  68. smbp
  69. else
  70. break
  71. fi
  72. done
  73. fi
  74. }
  75. #修改debian的镜像源地址:
  76. chSource(){
  77. clear
  78. if [ $1 ];then
  79. #x=a
  80. whiptail --title "Warnning" --msgbox "Not supported!
  81. 不支持该模式。" 10 60
  82. chSource
  83. fi
  84. sver=`cat /etc/debian_version |awk -F"." '{print $1}'`
  85. case "$sver" in
  86. 10 )
  87. sver="buster"
  88. ;;
  89. 9 )
  90. sver="stretch"
  91. ;;
  92. 8 )
  93. sver="jessie"
  94. ;;
  95. 7 )
  96. sver="wheezy"
  97. ;;
  98. 6 )
  99. sver="squeeze"
  100. ;;
  101. * )
  102. sver=""
  103. esac
  104. if [ ! $sver ];then
  105. whiptail --title "Warnning" --msgbox "Not supported!
  106. 您的版本不支持!无法继续。" 10 60
  107. main
  108. fi
  109. #"a" "Automation mode." \
  110. #"a" "无脑模式" \
  111. if [ $L = "en" ];then
  112. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config apt source:" 25 60 15 \
  113. "b" "Change to cn source." \
  114. "c" "Disable enterprise." \
  115. "d" "Undo Change." \
  116. "q" "Main menu." \
  117. 3>&1 1>&2 2>&3)
  118. else
  119. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置apt镜像源:" 25 60 15 \
  120. "b" "更换为国内源" \
  121. "c" "关闭企业更新源" \
  122. "d" "还原配置" \
  123. "q" "返回主菜单" \
  124. 3>&1 1>&2 2>&3)
  125. fi
  126. exitstatus=$?
  127. if [ $exitstatus = 0 ]; then
  128. case "$OPTION" in
  129. a | A )
  130. if (whiptail --title "Yes/No Box" --yesno "修改为ustc.edu.cn源,禁用企业订阅更新源,添加非订阅更新源(ustc.edu.cn),修改ceph镜像更新源" 10 60) then
  131. if [ `grep "ustc.edu.cn" /etc/apt/sources.list|wc -l` = 0 ];then
  132. #sver=`cat /etc/apt/sources.list|awk 'NR==1{print $3}'`
  133. cp /etc/apt/sources.list /etc/apt/sources.list.bak
  134. cp /etc/apt/sources.list.d/pve-no-sub.list /etc/apt/sources.list.d/pve-no-sub.list.bak
  135. cp /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak
  136. cp /etc/apt/sources.list.d/ceph.list /etc/apt/sources.list.d/ceph.list.bak
  137. echo "deb https://mirrors.ustc.edu.cn/debian/ $sver main contrib non-free
  138. deb-src https://mirrors.ustc.edu.cn/debian/ $sver main contrib non-free
  139. deb https://mirrors.ustc.edu.cn/debian/ $sver-updates main contrib non-free
  140. deb-src https://mirrors.ustc.edu.cn/debian/ $sver-updates main contrib non-free
  141. deb https://mirrors.ustc.edu.cn/debian/ $sver-backports main contrib non-free
  142. deb-src https://mirrors.ustc.edu.cn/debian/ $sver-backports main contrib non-free
  143. deb https://mirrors.ustc.edu.cn/debian-security/ $sver/updates main contrib non-free
  144. deb-src https://mirrors.ustc.edu.cn/debian-security/ $sver/updates main contrib non-free" > /etc/apt/sources.list
  145. #修改pve 5.x更新源地址为非订阅更新源,不使用企业订阅更新源。
  146. echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve/ $sver pve-no-subscription" > /etc/apt/sources.list.d/pve-no-sub.list
  147. #关闭pve 5.x企业订阅更新源
  148. sed -i 's|deb|#deb|' /etc/apt/sources.list.d/pve-enterprise.list
  149. #修改 ceph镜像更新源
  150. echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/ceph-luminous $sver main" > /etc/apt/sources.list.d/ceph.list
  151. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  152. 软件源已更换成功!" 10 60
  153. apt-get update
  154. apt-get -y install net-tools
  155. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  156. 软件源已更换成功!" 10 60
  157. else
  158. whiptail --title "Success" --msgbox " Already changed apt source to ustc.edu.cn!
  159. 已经更换apt源为 ustc.edu.cn" 10 60
  160. fi
  161. if [ ! $1 ];then
  162. chSource
  163. fi
  164. fi
  165. ;;
  166. b | B )
  167. if [ $L = "en" ];then
  168. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config apt source:" 25 60 15 \
  169. "a" "aliyun.com" \
  170. "b" "ustc.edu.cn" \
  171. "q" "Main menu." \
  172. 3>&1 1>&2 2>&3)
  173. else
  174. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置apt镜像源:" 25 60 15 \
  175. "a" "aliyun.com" \
  176. "b" "ustc.edu.cn" \
  177. "q" "返回主菜单" \
  178. 3>&1 1>&2 2>&3)
  179. fi
  180. exitstatus=$?
  181. if [ $exitstatus = 0 ]; then
  182. case "$OPTION" in
  183. a )
  184. ss="aliyun.com"
  185. ;;
  186. b)
  187. ss="ustc.edu.cn"
  188. ;;
  189. q )
  190. chSource
  191. esac
  192. if (whiptail --title "Yes/No Box" --yesno "修改更新源为$ss?" 10 60) then
  193. if [ `grep $ss /etc/apt/sources.list|wc -l` = 0 ];then
  194. cp /etc/apt/sources.list /etc/apt/sources.list.bak
  195. #cp /etc/apt/sources.list.d/ceph.list /etc/apt/sources.list.d/ceph.list.bak
  196. #sver=`cat /etc/apt/sources.list|awk 'NR==1{print $3}'`
  197. echo "deb https://mirrors.$ss/debian/ $sver main contrib non-free
  198. deb-src https://mirrors.$ss/debian/ $sver main contrib non-free
  199. deb https://mirrors.$ss/debian/ $sver-updates main contrib non-free
  200. deb-src https://mirrors.$ss/debian/ $sver-updates main contrib non-free
  201. deb https://mirrors.$ss/debian/ $sver-backports main contrib non-free
  202. deb-src https://mirrors.$ss/debian/ $sver-backports main contrib non-free
  203. deb https://mirrors.$ss/debian-security/ $sver/updates main contrib non-free
  204. deb-src https://mirrors.$ss/debian-security/ $sver/updates main contrib non-free" > /etc/apt/sources.list
  205. #修改 ceph镜像更新源
  206. #echo "deb http://mirrors.$ss/proxmox/debian/ceph-luminous $sver main" > /etc/apt/sources.list.d/ceph.list
  207. #修改pve 更新源地址为非订阅更新源,不使用企业订阅更新源。
  208. echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve/ $sver pve-no-subscription" > /etc/apt/sources.list.d/pve-no-sub.list
  209. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  210. 软件源已更换成功!" 10 60
  211. apt-get update
  212. apt-get -y install net-tools
  213. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  214. 软件源已更换成功!" 10 60
  215. else
  216. whiptail --title "Success" --msgbox " Already changed apt source to $ss!
  217. 已经更换apt源为 $ss" 10 60
  218. fi
  219. else
  220. chSource
  221. fi
  222. chSource
  223. else
  224. chSource
  225. fi
  226. ;;
  227. c | C )
  228. if (whiptail --title "Yes/No Box" --yesno "禁用企业订阅更新源?" 10 60) then
  229. #sver=`cat /etc/apt/sources.list|awk 'NR==1{print $3}'`
  230. if [ -f /etc/apt/sources.list.d/pve-no-sub.list ];then
  231. #修改pve 5.x更新源地址为非订阅更新源,不使用企业订阅更新源
  232. echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve/ $sver pve-no-subscription" > /etc/apt/sources.list.d/pve-no-sub.list
  233. else
  234. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  235. 软件源已更换成功!" 10 60
  236. fi
  237. if [ `grep "^deb" /etc/apt/sources.list.d/pve-enterprise.list|wc -l` != 0 ];then
  238. #关闭pve 5.x企业订阅更新源
  239. sed -i 's|deb|#deb|' /etc/apt/sources.list.d/pve-enterprise.list
  240. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  241. 软件源已更换成功!" 10 60
  242. else
  243. whiptail --title "Success" --msgbox " apt source has been changed successfully!
  244. 软件源已更换成功!" 10 60
  245. fi
  246. chSource
  247. fi
  248. ;;
  249. d | D )
  250. cp /etc/apt/sources.list.bak /etc/apt/sources.list
  251. cp /etc/apt/sources.list.d/pve-no-sub.list.bak /etc/apt/sources.list.d/pve-no-sub.list
  252. cp /etc/apt/sources.list.d/pve-enterprise.list.bak /etc/apt/sources.list.d/pve-enterprise.list
  253. #cp /etc/apt/sources.list.d/ceph.list.bak /etc/apt/sources.list.d/ceph.list
  254. whiptail --title "Success" --msgbox "apt source has been changed successfully!
  255. 软件源已更换成功!" 10 60
  256. chSource
  257. ;;
  258. q )
  259. echo "q"
  260. #main
  261. ;;
  262. esac
  263. fi
  264. }
  265. chMail(){
  266. #set mailutils to send mail
  267. addMail(){
  268. if (whiptail --title "Yes/No Box" --yesno "
  269. Will you want to config mailutils & postfix to send notification?(Y/N):
  270. 是否配置mailutils和postfix来发送邮件通知?
  271. " 10 60);then
  272. qqmail=$(whiptail --title "Config mail" --inputbox "
  273. Input email adress:
  274. 输入邮箱地址:
  275. " 10 60 3>&1 1>&2 2>&3)
  276. exitstatus=$?
  277. if [ $exitstatus = 0 ]; then
  278. while [ true ]
  279. do
  280. if [ `echo $qqmail|grep '^[a-zA-Z0-9\_\-\.]*\@[A-Za-z0-9\_\-\.]*\.[a-zA-Z\_\-\.]*$'` ];then
  281. break
  282. else
  283. whiptail --title "Warnning" --msgbox "
  284. Wrong email format!!! input xxxx@qq.com for example.retry:
  285. 错误的邮箱格式!!!请输入类似xxxx@qq.com并重试:
  286. " 10 60
  287. addMail
  288. fi
  289. done
  290. if [[ ! -f /etc/mailname || `dpkg -l|grep mailutils|wc -l` = 0 ]];then
  291. apt -y install mailutils
  292. fi
  293. {
  294. echo 10
  295. sleep 1
  296. $(echo "pve.local" > /etc/mailname)
  297. echo 40
  298. sleep 1
  299. $(sed -i -e "/root:/d" /etc/aliases)
  300. echo 70
  301. sleep 1
  302. $(echo "root: $qqmail">>/etc/aliases)
  303. echo 100
  304. sleep 1
  305. } | whiptail --gauge "Please wait while installing" 10 60 0
  306. sleep 1
  307. dpkg-reconfigure postfix
  308. service postfix reload
  309. echo "This is a mail test." |mail -s "mail test" root
  310. whiptail --title "Success" --msgbox "
  311. Config complete and send test email to you.
  312. 已经配置好并发送了测试邮件。
  313. " 10 60
  314. main
  315. else
  316. main
  317. fi
  318. else
  319. main
  320. fi
  321. }
  322. if [ -f /etc/mailname ];then
  323. if (whiptail --title "Yes/No Box" --yesno "
  324. It seems you have already configed it before.Reconfig?
  325. 您好像已经配置过这个了。重新配置?
  326. " --defaultno 10 60);then
  327. addMail
  328. else
  329. main
  330. fi
  331. fi
  332. addMail
  333. }
  334. chZfs(){
  335. #set max zfs ram
  336. setMen(){
  337. x=$(whiptail --title "Config ZFS" --inputbox "
  338. set max zfs ram 4(G) or 8(G) etc, just enter number or n?
  339. 设置最大zfs内存(zfs_arc_max),比如4(G)或8(G)等, 只需要输入纯数字即可,比如4G输入4?
  340. " 20 60 3>&1 1>&2 2>&3)
  341. exitstatus=$?
  342. if [ $exitstatus = 0 ]; then
  343. while [ true ]
  344. do
  345. if [[ "$x" =~ ^[1-9]+$ ]]; then
  346. update-initramfs -u
  347. {
  348. $(echo "options zfs zfs_arc_max=$[$x*1024*1024*1024]">/etc/modprobe.d/zfs.conf)
  349. echo 10
  350. echo 70
  351. sleep 1
  352. #set rpool to list snapshots
  353. $(if [ `zpool get listsnapshots|grep rpool|awk '{print $3}'` = "off" ];then
  354. zpool set listsnapshots=on rpool
  355. fi)
  356. echo 100
  357. }|whiptail --gauge "installing" 10 60 0
  358. whiptail --title "Success" --msgbox "
  359. Config complete!you should reboot later.
  360. 配置完成,一会儿最好重启一下系统。
  361. " 10 60
  362. break
  363. else
  364. whiptail --title "Warnning" --msgbox "
  365. Invalidate value.Please comfirm!
  366. 输入的值无效,请重新输入!
  367. " 10 60
  368. setMen
  369. fi
  370. done
  371. #zfs-zed
  372. if (whiptail --title "Yes/No Box" --yesno "
  373. Install zfs-zed to get email notification of zfs scrub?(Y/n):
  374. 安装zfs-zed来发送zfs scrub的结果提醒邮件?(Y/n):
  375. " 10 60);then
  376. if [ `dpkg -l|grep zfs-zed|wc -l` = 0 ];then
  377. apt-get -y install zfs-zed
  378. fi
  379. whiptail --title "Success" --msgbox "
  380. Install complete!
  381. 安装zfs-zed成功!
  382. " 10 60
  383. else
  384. chZfs
  385. fi
  386. else
  387. main
  388. fi
  389. }
  390. if [ ! -f /etc/modprobe.d/zfs.conf ] || [ `grep "zfs_arc_max" /etc/modprobe.d/zfs.conf|wc -l` = 0 ];then
  391. setMen
  392. else
  393. if(whiptail --title "Yes/No box" --yesno "
  394. It seems you have already configed it before.Reconfig?
  395. 您好像已经配置过这个了。是否重新配置?
  396. " --defaultno 10 60 );then
  397. setMen
  398. else
  399. main
  400. fi
  401. fi
  402. }
  403. chSamba(){
  404. #config samba
  405. addSmbRecycle(){
  406. if(whiptail --title "Yes/No" --yesno "enable recycle?
  407. 开启回收站?" 10 60 )then
  408. if [ ! -f '/etc/samba/smb.conf' ];then
  409. whiptail --title "Warnning" --msgbox "You should install samba first!
  410. 请先安装samba!" 10 60
  411. else
  412. if [ `sed -n "/\[$2\]/,/$2 end/p" /etc/samba/smb.conf|egrep '^recycle'|wc -l` != 0 ];then
  413. whiptail --title "Warnning" --msgbox "Already configed! 已经配置过了。" 10 60
  414. smbRecycle
  415. else
  416. cat << EOF > ./recycle
  417. # $2--recycle-start--
  418. vfs object = recycle
  419. recycle:repository = $1/.deleted
  420. recycle:keeptree = Yes
  421. recycle:versions = Yes
  422. recycle:maxsixe = 0
  423. recycle:exclude = *.tmp
  424. # $2--recycle-end--
  425. EOF
  426. #n=`sed '/\['$2'\]/' /etc/samba/smb.conf -n|sed -n '$p'`
  427. cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
  428. sed -i '/\['$2'\]/r ./recycle' /etc/samba/smb.conf
  429. rm ./recycle
  430. # cat << EOF >> /etc/samba/smb.conf
  431. #[$2-recycle]
  432. #comment = All
  433. #browseable = yes
  434. #path = $1/.deleted
  435. #guest ok = no
  436. #read only = no
  437. #create mask = 0750
  438. #directory mask = 0750
  439. #; $2-recycle end
  440. #EOF
  441. systemctl restart smbd
  442. whiptail --title "Success" --msgbox "Done.
  443. 配置完成" 10 60
  444. fi
  445. fi
  446. else
  447. continue
  448. fi
  449. }
  450. delSmbRecycle(){
  451. if [ ! -f '/etc/samba/smb.conf' ];then
  452. whiptail --title "Warnning" --msgbox "You should install samba first!
  453. 请先安装samba!" 10 60
  454. else
  455. if [ `sed -n "/\[$1\]/,/$1 end/p" /etc/samba/smb.conf|egrep '^recycle'|wc -l` = 0 ];then
  456. whiptail --title "Warnning" --msgbox "Already configed! 已经配置过了。" 10 60
  457. smbRecycle
  458. else
  459. cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
  460. sed -i '/.*'$1'.*recycle.*start/,/.*'$1'.*end/d' /etc/samba/smb.conf
  461. sed "/\[${1}\-recycle\]/,/${n}\-recycle end/d" /etc/samba/smb.conf -i
  462. systemctl restart smbd
  463. whiptail --title "Success" --msgbox "Done.
  464. 配置完成" 10 60
  465. fi
  466. fi
  467. }
  468. clear
  469. #$(grep -E "^\[[0-9a-zA-Z.-]*\]$|^path" /etc/samba/smb.conf|awk 'NR>3{print $0}'|sed 's/path/ path/'|grep -v '-recycle')
  470. if [ $L = "en" ];then
  471. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config samba:" 25 60 15 \
  472. "a" "Install samba and config user." \
  473. "b" "Add folder to share." \
  474. "c" "Delete folder to share." \
  475. "d" "Config recycle" \
  476. "q" "Main menu." \
  477. 3>&1 1>&2 2>&3)
  478. else
  479. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置samba:" 25 60 15 \
  480. "a" "安装配置samba并配置好samba用户" \
  481. "b" "添加共享文件夹" \
  482. "c" "取消共享文件夹" \
  483. "d" "配置回收站" \
  484. "q" "返回主菜单" \
  485. 3>&1 1>&2 2>&3)
  486. fi
  487. if [ $1 ];then
  488. OPTION=a
  489. fi
  490. exitstatus=$?
  491. if [ $exitstatus = 0 ]; then
  492. case "$OPTION" in
  493. a | A )
  494. if [ `grep samba /etc/group|wc -l` = 0 ];then
  495. if (whiptail --title "Yes/No Box" --yesno "set samba and admin user for samba?
  496. 安装samba并配置admin为samba用户?
  497. " 10 60);then
  498. apt -y install samba
  499. groupadd samba
  500. useradd -g samba -M -s /sbin/nologin admin
  501. smbp
  502. echo -e "$m\n$m"|smbpasswd -a admin
  503. service smbd restart
  504. echo -e "已成功配置好samba,请记好samba用户admin的密码!"
  505. whiptail --title "Success" --msgbox "
  506. 已成功配置好samba,请记好samba用户admin的密码!
  507. " 10 60
  508. fi
  509. else
  510. whiptail --title "Success" --msgbox "Already configed samba.
  511. 已配置过samba,没什么可做的!
  512. " 10 60
  513. fi
  514. if [ ! $1 ];then
  515. chSamba
  516. fi
  517. ;;
  518. b | B )
  519. # echo -e "Exist share folders:"
  520. # echo -e "已有的共享目录:"
  521. # echo "`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'`"
  522. # echo -e "Input share folder path:"
  523. # echo -e "输入共享文件夹的路径:"
  524. addFolder(){
  525. h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
  526. if [ $h -lt 3 ];then
  527. let h=$h*15
  528. else
  529. let h=$h*5
  530. fi
  531. x=$(whiptail --title "Add Samba Share folder" --inputbox "
  532. Exist share folders:
  533. 已有的共享目录:
  534. ----------------------------------------
  535. $(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
  536. ----------------------------------------
  537. Input share folder path(like /root):
  538. 输入共享文件夹的路径(只需要输入/root类似的路径):
  539. " $h 60 "" 3>&1 1>&2 2>&3)
  540. exitstatus=$?
  541. if [ $exitstatus = 0 ]; then
  542. while [ ! -d $x ]
  543. do
  544. whiptail --title "Success" --msgbox "Path not exist!
  545. 路径不存在!
  546. " 10 60
  547. addFolder
  548. done
  549. while [ `grep "path \= ${x}$" /etc/samba/smb.conf|wc -l` != 0 ]
  550. do
  551. whiptail --title "Success" --msgbox "Path exist!
  552. 路径已存在!
  553. " 10 60
  554. addFolder
  555. done
  556. n=`echo $x|grep -o "[a-zA-Z0-9.-]*$"`
  557. while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ]
  558. do
  559. n=$(whiptail --title "Samba Share folder" --inputbox "
  560. Input share name:
  561. 输入共享名称:
  562. " 10 60 "" 3>&1 1>&2 2>&3)
  563. exitstatus=$?
  564. if [ $exitstatus = 0 ]; then
  565. while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ]
  566. do
  567. whiptail --title "Success" --msgbox "Name exist!
  568. 名称已存在!
  569. " 10 60
  570. addFolder
  571. done
  572. fi
  573. done
  574. oldgrp=`ls -l $x|awk 'NR==2{print $4}'`
  575. if [ `grep "${x}$" /etc/samba/smb.conf|wc -l` = 0 ];then
  576. cat << EOF >> /etc/samba/smb.conf
  577. [$n]
  578. comment = All
  579. browseable = yes
  580. path = $x
  581. guest ok = no
  582. read only = no
  583. create mask = 0750
  584. directory mask = 0750
  585. ; oldgrp $oldgrp
  586. ; $n end
  587. EOF
  588. whiptail --title "Success" --msgbox "
  589. Configed!
  590. 配置成功!
  591. " 10 60
  592. #--2.2.5 add group
  593. chgrp -R samba $x
  594. chmod -R g+w $x
  595. addSmbRecycle $x $n
  596. service smbd restart
  597. else
  598. whiptail --title "Success" --msgbox "Already configed!
  599. 已经配置过了!
  600. " 10 60
  601. fi
  602. addFolder
  603. else
  604. chSamba
  605. fi
  606. }
  607. addFolder
  608. ;;
  609. c )
  610. delFolder(){
  611. h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
  612. if [ $h -lt 3 ];then
  613. let h=$h*15
  614. else
  615. let h=$h*5
  616. fi
  617. n=$(whiptail --title "Remove Samba Share folder" --inputbox "
  618. Exist share folders:
  619. 已有的共享目录:
  620. ----------------------------------------
  621. $(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
  622. ----------------------------------------
  623. Input share folder name(type words in []):
  624. 输入共享文件夹的名称(只需要输入[]中的名字):
  625. " $h 60 "" 3>&1 1>&2 2>&3)
  626. exitstatus=$?
  627. if [ $exitstatus = 0 ]; then
  628. while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
  629. do
  630. whiptail --title "Success" --msgbox "
  631. Name not exist!:
  632. 名称不存在!:
  633. " 10 60
  634. delFolder
  635. done
  636. if [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ];then
  637. oldgrp=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf |grep oldgrp|awk '{print $3}'`
  638. x=`grep -E "^path = [0-9a-zA-Z/-.]*${n}" /etc/samba/smb.conf|awk '{print $3}'`
  639. if [ $oldgrp ];then
  640. chgrp -R $oldgrp $x
  641. fi
  642. sed "/\[${n}\]/,/${n} end/d" /etc/samba/smb.conf -i
  643. sed "/\[${n}-recycle\]/,/${n}-recycle end/d" /etc/samba/smb.conf -i
  644. whiptail --title "Success" --msgbox "
  645. Configed!
  646. 配置成功!
  647. " 10 60
  648. service smbd restart
  649. fi
  650. delFolder
  651. else
  652. chSamba
  653. fi
  654. }
  655. delFolder
  656. ;;
  657. d )
  658. smbRecycle(){
  659. if [ $L = "en" ];then
  660. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config samba recycle:" 12 60 4 \
  661. "a" "Enable samba recycle." \
  662. "b" "Disable samba recycle." \
  663. "c" "Clear recycle." \
  664. 3>&1 1>&2 2>&3)
  665. else
  666. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置samba回收站!" 12 60 4 \
  667. "a" "开启samba回收站。" \
  668. "b" "关闭samba回收站。" \
  669. "c" "清空samba回收站。" \
  670. 3>&1 1>&2 2>&3)
  671. fi
  672. exitstatus=$?
  673. if [ $exitstatus = 0 ]; then
  674. case "$x" in
  675. a )
  676. enSmbRecycle(){
  677. h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
  678. if [ $h -lt 3 ];then
  679. let h=$h*15
  680. else
  681. let h=$h*5
  682. fi
  683. n=$(whiptail --title "Remove Samba recycle" --inputbox "
  684. Exist share folders:
  685. 已有的共享目录:
  686. ----------------------------------------
  687. $(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
  688. ----------------------------------------
  689. Input share folder name(type words in []):
  690. 输入共享文件夹的名称(只需要输入[]中的名字):
  691. " $h 60 "" 3>&1 1>&2 2>&3)
  692. exitstatus=$?
  693. if [ $exitstatus = 0 ]; then
  694. while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
  695. do
  696. whiptail --title "Success" --msgbox "
  697. Name not exist!:
  698. 名称不存在!:
  699. " 10 60
  700. enSmbRecycle
  701. done
  702. if [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ];then
  703. if [ `sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|egrep '^recycle'|wc -l` != 0 ];then
  704. whiptail --title "Warnning" --msgbox "Already configed! 已经配置过了。" 10 60
  705. smbRecycle
  706. else
  707. x=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|grep path|awk '{print $3}'`
  708. addSmbRecycle $x $n
  709. service smbd restart
  710. fi
  711. fi
  712. disSmbRecycle
  713. else
  714. smbRecycle
  715. fi
  716. }
  717. enSmbRecycle
  718. ;;
  719. b )
  720. disSmbRecycle(){
  721. h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
  722. if [ $h -lt 3 ];then
  723. let h=$h*15
  724. else
  725. let h=$h*5
  726. fi
  727. n=$(whiptail --title "Remove Samba recycle" --inputbox "
  728. Exist share folders:
  729. 已有的共享目录:
  730. ----------------------------------------
  731. $(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
  732. ----------------------------------------
  733. Input share folder name(type words in []):
  734. 输入共享文件夹的名称(只需要输入[]中的名字):
  735. " $h 60 "" 3>&1 1>&2 2>&3)
  736. exitstatus=$?
  737. if [ $exitstatus = 0 ]; then
  738. while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
  739. do
  740. whiptail --title "Success" --msgbox "
  741. Name not exist!:
  742. 名称不存在!:
  743. " 10 60
  744. disSmbRecycle
  745. done
  746. x=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|grep path|awk '{print $3}'`
  747. if [ `ls $x/.deleted/|wc -l` != 0 ];then
  748. if(whiptail --title "Warnning" --yesno "recycle not empty, you should clear it first.continue?
  749. 回收站中存在文件,建议先清空,是否确认要继续?" 10 60);then
  750. if [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ];then
  751. delSmbRecycle $n
  752. service smbd restart
  753. fi
  754. disSmbRecycle
  755. else
  756. disSmbRecycle
  757. fi
  758. fi
  759. else
  760. smbRecycle
  761. fi
  762. }
  763. disSmbRecycle
  764. ;;
  765. c )
  766. checkClearSmb(){
  767. c=$(whiptail --title "Clear Samba recycle" --inputbox "
  768. you can disable recycle to clear it.
  769. clear recycle may cause data lose,pvetools will not response for that,do you agree?
  770. type 'YesIdo' to continue:
  771. 你可以先取消回收站再手工清空。
  772. 工具清空samba回收站不可逆,pvetools不会对此操作负责,是否同意?
  773. 如果确认要清空,请输入'YesIdo'继续:" 20 60 "" 3>&1 1>&2 2>&3)
  774. exitstatus=$?
  775. if [ $exitstatus = 0 ]; then
  776. while [ $c != 'YesIdo' ]
  777. do
  778. whiptail --title "Success" --msgbox "
  779. Woring words,try again:
  780. 输入错误,请重试:
  781. " 10 60
  782. checkClearSmb
  783. done
  784. else
  785. continue
  786. fi
  787. }
  788. clearSmbRecycle(){
  789. h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
  790. if [ $h -lt 3 ];then
  791. let h=$h*15
  792. else
  793. let h=$h*5
  794. fi
  795. n=$(whiptail --title "Clear Samba recycle" --inputbox "
  796. Exist share folders:
  797. 已有的共享目录:
  798. ----------------------------------------
  799. $(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
  800. ----------------------------------------
  801. Input share folder name(type words in []):
  802. 输入共享文件夹的名称(只需要输入[]中的名字):
  803. " $h 60 "" 3>&1 1>&2 2>&3)
  804. exitstatus=$?
  805. if [ $exitstatus = 0 ]; then
  806. while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
  807. do
  808. whiptail --title "Success" --msgbox "
  809. Name not exist!:
  810. 名称不存在!:
  811. " 10 60
  812. clearSmbRecycle
  813. done
  814. x=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|grep path|awk '{print $3}'`
  815. if [ `ls -a $x/.deleted/|wc -l` -gt 2 ];then
  816. if(whiptail --title "Warnning" --yesno "recycle not empty,continue?
  817. 回收站中存在文件,是否确认要继续?" 10 60);then
  818. checkClearSmb
  819. rm -rf $x/.deleted/*
  820. rm -rf $x/.deleted/.*
  821. whiptail --title "Success" --msgbox "ok." 10 60
  822. else
  823. clearSmbRecycle
  824. fi
  825. else
  826. whiptail --title "Success" --msgbox "Already empty.回收站是空的,不需要清空。" 10 60
  827. fi
  828. else
  829. smbRecycle
  830. fi
  831. }
  832. clearSmbRecycle
  833. ;;
  834. esac
  835. else
  836. chSamba
  837. fi
  838. }
  839. smbRecycle
  840. ;;
  841. q )
  842. main
  843. ;;
  844. esac
  845. else
  846. chSamba
  847. fi
  848. }
  849. chVim(){
  850. #config vim
  851. if [ $L = "en" ];then
  852. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config VIM:" 12 60 4 \
  853. "a" "Install vim & simply config display." \
  854. "b" "Install vim & config 'vim-for-server'." \
  855. "c" "Uninstall." \
  856. 3>&1 1>&2 2>&3)
  857. else
  858. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "安装配置VIM!" 12 60 4 \
  859. "a" "安装VIM并简单配置,如配色行号等。" \
  860. "b" "安装VIM并配置'vim-for-server'。" \
  861. "c" "还原配置。" \
  862. 3>&1 1>&2 2>&3)
  863. fi
  864. exitstatus=$?
  865. if [ $exitstatus = 0 ]; then
  866. case "$x" in
  867. a )
  868. if(whiptail --title "Yes/No Box" --yesno "
  869. Install vim & simply config display.Continue?
  870. 安装VIM并简单配置,如配色行号等,基本是vim原味儿。是否继续?
  871. " 10 60) then
  872. if [ ! -f /root/.vimrc ] || [ `cat /root/.vimrc|wc -l` = 0 ] || [ `dpkg -l |grep vim|wc -l` = 0 ];then
  873. apt -y install vim
  874. else
  875. cp ~/.vimrc ~/.vimrc.bak
  876. fi
  877. {
  878. echo 10
  879. echo 50
  880. $(
  881. cat << EOF > ~/.vimrc
  882. set number
  883. set showcmd
  884. set incsearch
  885. set expandtab
  886. set showcmd
  887. set history=400
  888. set autoread
  889. set ffs=unix,mac,dos
  890. set hlsearch
  891. set shiftwidth=2
  892. set wrap
  893. set ai
  894. set si
  895. set cindent
  896. set termencoding=unix
  897. set tabstop=2
  898. set nocompatible
  899. set showmatch
  900. set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
  901. set termencoding=utf-8
  902. set encoding=utf-8
  903. set fileformats=unix
  904. set ttyfast
  905. syntax on
  906. set imcmdline
  907. set previewwindow
  908. set showfulltag
  909. set cursorline
  910. set ruler
  911. color ron
  912. autocmd InsertEnter * se cul
  913. set ruler
  914. set showcmd
  915. set laststatus=2
  916. set tabstop=2
  917. set softtabstop=4
  918. inoremap fff <esc>h
  919. autocmd BufWritePost \$MYVIMRC source \$MYVIMRCi
  920. EOF
  921. )
  922. echo 100
  923. }|whiptail --gauge "installing" 10 60
  924. whiptail --title "Success" --msgbox "
  925. Install & config complete!
  926. 安装配置完成!
  927. " 10 60
  928. else
  929. chVim
  930. fi
  931. ;;
  932. b | B )
  933. if(whiptail --title "Yes/No Box" --yesno "
  934. 安装VIM并配置 \'vim-for-server\'(https://github.com/wklken/vim-for-server).
  935. yes or no?
  936. " 12 60) then
  937. echo "Use curl or git? If one not work,change to another."
  938. echo "选择git或curl,如果一个方式不行可以换一个。"
  939. echo "1 ) git"
  940. echo "2 ) curl"
  941. echo "Please choose:"
  942. read x
  943. case $x in
  944. 2 )
  945. apt -y install curl vim
  946. cp ~/.vimrc ~/.vimrc_bak
  947. curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
  948. whiptail --title "Success" --msgbox "
  949. Install & config complete!
  950. 安装配置完成!
  951. " 10 60
  952. ;;
  953. 1 | "" )
  954. apt -y install git vim
  955. rm -rf vim-for-server
  956. git clone https://github.com/wklken/vim-for-server.git
  957. mv ~/.vimrc ~/.vimrc_bak
  958. mv vim-for-server/vimrc ~/.vimrc
  959. rm -rf vim-for-server
  960. whiptail --title "Success" --msgbox "
  961. Install & config complete!
  962. 安装配置完成!
  963. " 10 60
  964. ;;
  965. * )
  966. chVim
  967. esac
  968. else
  969. chVim
  970. fi
  971. ;;
  972. c )
  973. if(whiptail --title "Yes/No Box" --yesno "
  974. Remove Config?
  975. 确认要还原配置?
  976. " --defaultno 10 60) then
  977. cp ~/.vimrc.bak ~/.vimrc
  978. whiptail --title "Success" --msgbox "
  979. Done
  980. 已经完成配置
  981. " 10 60
  982. else
  983. chVim
  984. fi
  985. esac
  986. else
  987. main
  988. fi
  989. }
  990. chSpindown(){
  991. #set hard drivers to spindown
  992. spinTime(){
  993. x=$(whiptail --title "config" --inputbox "
  994. input number of minite to auto spindown:
  995. 输入硬盘自动休眠的检测时间,周期为分钟,输入5为5分钟:
  996. " 10 60 3>&1 1>&2 2>&3)
  997. exitstatus=$?
  998. if [ $exitstatus = 0 ]; then
  999. while [ true ]
  1000. do
  1001. if [ `echo "$x"|grep "^[0-9]*$"|wc -l` = 0 ];then
  1002. whiptail --title "Warnning" --msgbox "
  1003. 输入格式错误,请重新输入:
  1004. " 10 60
  1005. spinTime
  1006. else
  1007. break
  1008. fi
  1009. done
  1010. cat << eof >> /etc/crontab
  1011. */$x * * * * root /root/hdspindown/spindownall
  1012. eof
  1013. service cron reload
  1014. whiptail --title "Success" --msgbox "
  1015. config every $x minite to check disks and auto spindown:
  1016. 已为您配置好硬盘每$x分钟自动检测硬盘和休眠。
  1017. " 10 60
  1018. fi
  1019. }
  1020. doSpindown(){
  1021. if(whiptail --title "Yes/No Box" --yesno "
  1022. Config hard drives to auto spindown?(Y/n):
  1023. 配置硬盘自动休眠?(Y/n):
  1024. " 10 60) then
  1025. if [ `dpkg -l|grep git|wc -l` = 0 ];then
  1026. apt -y install git
  1027. fi
  1028. cd /root
  1029. git clone https://github.com/ivanhao/hdspindown.git
  1030. {
  1031. echo 10
  1032. echo 50
  1033. echo 90
  1034. cd hdspindown
  1035. chmod +x *.sh
  1036. ./spindownall
  1037. echo 100
  1038. } | whiptail --gauge "installing" 10 60 0
  1039. if [ `grep "spindownall" /etc/crontab|wc -l` = 0 ];then
  1040. spinTime
  1041. fi
  1042. else
  1043. chSpindown
  1044. fi
  1045. }
  1046. chApm(){
  1047. clear
  1048. apm=$(
  1049. whiptail --title " PveTools Version : 2.2.5 " --menu "Config hard disks APM & AAM:
  1050. 配置硬盘静音、降温:
  1051. " 25 60 15 \
  1052. "128" "Config hard drivers to auto spindown." \
  1053. "b" "Remove config hdspindown." \
  1054. "c" "Config pvestatd service(in case of spinup drives)." \
  1055. "d" "Config drivers aam\apm to low temp and quiet." \
  1056. 3>&1 1>&2 2>&3)
  1057. }
  1058. if [ $L = "en" ];then
  1059. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config hard disks spindown:" 25 60 15 \
  1060. "a" "Config hard drivers to auto spindown." \
  1061. "b" "Remove config hdspindown." \
  1062. "c" "Config pvestatd service(in case of spinup drives)." \
  1063. "d" "Config drivers aam\apm to low temp and quiet." \
  1064. 3>&1 1>&2 2>&3)
  1065. else
  1066. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置硬盘自动休眠" 25 60 15 \
  1067. "a" "配置硬盘自动休眠" \
  1068. "b" "还原硬盘自动休眠配置" \
  1069. "c" "配置pvestatd服务(防止休眠后马上被唤醒)。" \
  1070. "d" "设置硬盘静音、降温" \
  1071. 3>&1 1>&2 2>&3)
  1072. fi
  1073. if [ $1 ];then
  1074. OPTION=a
  1075. fi
  1076. exitstatus=$?
  1077. if [ $exitstatus = 0 ]; then
  1078. case "$OPTION" in
  1079. a | A )
  1080. if [ ! -f /root/hdspindown/spindownall ];then
  1081. doSpindown
  1082. else
  1083. whiptail --title "Yes/No Box" --msgbox "
  1084. It seems you have already configed it before.
  1085. 您好像已经配置过这个了。
  1086. " 10 60
  1087. chSpindown
  1088. fi
  1089. ;;
  1090. b )
  1091. if(whiptail --title "Yes/No Box" --yesno "
  1092. Remove config spindown?
  1093. 确认要还原配置?
  1094. " 10 60) then
  1095. sed -i '/spindownall/d' /etc/crontab
  1096. rm /usr/bin/hdspindown
  1097. if(whiptail --title "Yes/No Box" --yesno "
  1098. Remove source code?
  1099. 是否要删除休眠程序代码?
  1100. " 10 60) then
  1101. rm -rf /root/hdspindown
  1102. fi
  1103. whiptail --title "Success" --msgbox "
  1104. OK
  1105. 已经完成配置
  1106. " 10 60
  1107. else
  1108. chSpindown
  1109. fi
  1110. ;;
  1111. c )
  1112. if (whiptail --title "Enable/Disable pvestatd" --yes-button "停止(Disable)" --no-button "启动(Enable)" --yesno "
  1113. pvestatd may spinup the drivers,if hdspindown can not effective, you can disable it to make drives to spindown.
  1114. 使用lvm的时候pvestatd 可能会造成硬盘频繁唤醒从而导致hdspindown无法让你的硬盘休眠,如果需要,你可以在这里停止这个服务。
  1115. 停止这个服务,在web界面将会显示一些异常,如果需要在web界面进行操作,可以再启动这个服务。这个操作不是必须的,要自己灵活应用。
  1116. " 20 60) then
  1117. {
  1118. pvestatd stop
  1119. echo 100
  1120. sleep 1
  1121. }|whiptail --gauge "configing..." 10 60 50
  1122. else
  1123. {
  1124. pvestatd start
  1125. echo 100
  1126. sleep 1
  1127. }|whiptail --gauge "configing..." 10 60 50
  1128. fi
  1129. ;;
  1130. esac
  1131. fi
  1132. }
  1133. chCpu(){
  1134. maxCpu(){
  1135. info=`cpufreq-info|grep -E "available|analyzing CPU|current"|sed -n "/analyz/,/analyz/p"|sed '$d'`
  1136. x=$(whiptail --title "Max cpufrequtils最大频率" --inputbox "
  1137. $info
  1138. --------------------------------------------
  1139. Input MAX_SPEED(example: 1.6GHz type 1600000):
  1140. 输入最大频率(示例:1.6GHz 输入1600000):
  1141. " 20 60 3>&1 1>&2 2>&3)
  1142. exitstatus=$?
  1143. if [ $exitstatus = 0 ]; then
  1144. while [ true ]
  1145. do
  1146. if [[ `echo "$x"|grep "^[0-9]*$"|wc -l` = 0 ]] || [[ $x = "" ]];then
  1147. whiptail --title "Warnning" --msgbox "
  1148. example: 1.6GHz type 1600000
  1149. retry
  1150. 示例:1.6GHz 输入1600000
  1151. 输入格式错误,请重新输入:
  1152. " 15 60
  1153. maxCpu
  1154. else
  1155. break
  1156. fi
  1157. done
  1158. mx=$x
  1159. else
  1160. chCpu
  1161. fi
  1162. }
  1163. minCpu(){
  1164. x=$(whiptail --title "Mini cpufrequtils最小频率" --inputbox "
  1165. $info
  1166. --------------------------------------------
  1167. Input MIN_SPEED(example: 1.6GHz type 1600000):
  1168. 输入最小频率(示例:1.6GHz 输入1600000):
  1169. " 20 60 3>&1 1>&2 2>&3)
  1170. exitstatus=$?
  1171. if [ $exitstatus = 0 ]; then
  1172. while [ true ]
  1173. do
  1174. if [[ `echo "$x"|grep "^[0-9]*$"|wc -l` = 0 ]] || [[ $x = "" ]];then
  1175. whiptail --title "Warnning" --msgbox "
  1176. example: 1.6GHz type 1600000
  1177. retry
  1178. 示例:1.6GHz 输入1600000
  1179. 输入格式错误,请重新输入:
  1180. " 15 60
  1181. minCpu
  1182. else
  1183. break
  1184. fi
  1185. done
  1186. mi=$x
  1187. else
  1188. chCpu
  1189. fi
  1190. }
  1191. #setup for cpufreq
  1192. doChCpu(){
  1193. if(whiptail --title "Yes/No Box" --yesno "
  1194. Install cpufrequtils to save power?
  1195. 安装配置CPU省电?
  1196. " --defaultno 10 60) then
  1197. apt -y install cpufrequtils
  1198. if [ `grep "intel_pstate=disable" /etc/default/grub|wc -l` = 0 ];then
  1199. sed -i.bak 's|quiet|quiet intel_pstate=disable|' /etc/default/grub
  1200. update-grub
  1201. fi
  1202. cpufreq-info|grep -E "available|analyzing CPU|current"|sed -n "/analyz/,/analyz/p"|sed '$d'
  1203. maxCpu
  1204. minCpu
  1205. cat << EOF > /etc/default/cpufrequtils
  1206. ENABLE="true"
  1207. GOVERNOR="powersave"
  1208. MAX_SPEED="$mx"
  1209. MIN_SPEED="$mi"
  1210. EOF
  1211. whiptail --title "Success" --msgbox "
  1212. cpufrequtils need to reboot to apply! Please reboot.
  1213. cpufrequtils 安装好后需要重启系统,请稍后重启。
  1214. " 10 60
  1215. else
  1216. main
  1217. fi
  1218. }
  1219. #-------------chCpu--main---------------
  1220. if [ $L = "en" ];then
  1221. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config Cpufrequtils:" 25 60 15 \
  1222. "a" "Config cpufrequtils to save power." \
  1223. "b" "Remove config." \
  1224. 3>&1 1>&2 2>&3)
  1225. else
  1226. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "安装配置CPU省电" 25 60 15 \
  1227. "a" "安装配置CPU省电" \
  1228. "b" "还原配置" \
  1229. 3>&1 1>&2 2>&3)
  1230. fi
  1231. if [ $1 ];then
  1232. OPTION=a
  1233. fi
  1234. exitstatus=$?
  1235. if [ $exitstatus = 0 ]; then
  1236. case "$OPTION" in
  1237. a | A )
  1238. if [ `grep "intel_pstate=disable" /etc/default/grub|wc -l` = 0 ];then
  1239. doChCpu
  1240. else
  1241. if(whiptail --title "Yes/No Box" --yesno "
  1242. It seems you have already configed it before.
  1243. 您好像已经配置过这个了。
  1244. " --defaultno 10 60) then
  1245. doChCpu
  1246. else
  1247. main
  1248. fi
  1249. fi
  1250. ;;
  1251. b )
  1252. if(whiptail --title "Yes/No" --yesno "
  1253. continue?
  1254. 还原配置?
  1255. " --defaultno 10 60 ) then
  1256. #sed -i 's/ intel_pstate=disable//g' /etc/default/grub
  1257. #rm -rf /etc/default/cpufrequtils
  1258. cat << EOF > /etc/default/cpufrequtils
  1259. ENABLE="true"
  1260. GOVERNOR="ondemand"
  1261. EOF
  1262. systemctl restart cpufrequtils
  1263. if (whiptail --title "Yes/No" --yesno "
  1264. Uninstall cpufrequtils?
  1265. 卸载cpufrequtils?
  1266. " 10 60 ) then
  1267. apt -y remove cpufrequtils 2>&1 &
  1268. sed -i 's/ intel_pstate=disable//g' /etc/default/grub
  1269. rm -rf /etc/default/cpufrequtils
  1270. fi
  1271. whiptail --title "Success" --msgbox "
  1272. Done
  1273. 配置完成
  1274. " 10 60
  1275. fi
  1276. chCpu
  1277. esac
  1278. fi
  1279. #-------------chCpu--main--end------------
  1280. }
  1281. chSubs(){
  1282. clear
  1283. if [ $L = "en" ];then
  1284. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config Cpufrequtils:" 25 60 15 \
  1285. "a" "Remove subscribe notice." \
  1286. "b" "Unset config." \
  1287. 3>&1 1>&2 2>&3)
  1288. else
  1289. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "安装配置CPU省电" 25 60 15 \
  1290. "a" "去除订阅提示" \
  1291. "b" "还原配置" \
  1292. 3>&1 1>&2 2>&3)
  1293. fi
  1294. exitstatus=$?
  1295. if [ $exitstatus = 0 ]; then
  1296. case "$OPTION" in
  1297. a )
  1298. if(whiptail --title "Yes/No" --yesno "
  1299. continue?
  1300. 是否去除订阅提示?
  1301. " 10 60 )then
  1302. #whiptail --title " in " --msgbox "$bver $cver $dver" 10 60
  1303. if [ `grep "data.status.toLowerCase() !== 'active'" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js|wc -l` = 1 ];then
  1304. sed -i.bak "s/data.status.toLowerCase() !== 'active'/false/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
  1305. whiptail --title "Success" --msgbox "
  1306. Done!!
  1307. 去除成功!
  1308. " 10 60
  1309. elif [ `grep "data.status !== 'Active'" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js|wc -l` = 1 ];then
  1310. sed -i.bak "s/data.status !== 'Active'/false/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
  1311. whiptail --title "Success" --msgbox "
  1312. Done!!
  1313. 去除成功!
  1314. " 10 60
  1315. else
  1316. whiptail --title "Success" --msgbox "
  1317. You already removed.
  1318. 已经去除过了,不需要再次去除。
  1319. " 10 60
  1320. fi
  1321. fi
  1322. ;;
  1323. b )
  1324. if(whiptail --title "Yes/No" --yesno "
  1325. continue?
  1326. 是否还原订阅提示?
  1327. " 10 60) then
  1328. if [ `grep "data.status !== 'Active'" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js|wc -l` = 0 ];then
  1329. mv /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.bak /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
  1330. whiptail --title "Success" --msgbox "
  1331. Done!!
  1332. 还原成功!
  1333. " 10 60
  1334. else
  1335. whiptail --title "Success" --msgbox "
  1336. You already removed.
  1337. 已经还原过了,不需要再次还原。
  1338. " 10 60
  1339. fi
  1340. fi
  1341. ;;
  1342. esac
  1343. fi
  1344. }
  1345. chSmartd(){
  1346. hds=`lsblk|grep "^[s,h]d[a-z]"|awk '{print $1}'`
  1347. }
  1348. chNestedV(){
  1349. clear
  1350. unsetVmN(){
  1351. list=`qm list|awk 'NR>1{print $1":"$2"......."$3" "}'`
  1352. ls=`for i in $list;do echo $i|awk -F ":" '{print $1" "$2}';done`
  1353. h=`echo $ls|wc -l`
  1354. let h=$h*1
  1355. if [ $h -lt 30 ];then
  1356. h=30
  1357. fi
  1358. list1=`echo $list|awk 'NR>1{print $1}'`
  1359. vmid=$(whiptail --title " PveTools Version : 2.2.5 " --menu "
  1360. Choose vmid to unset nested:
  1361. 选择需要关闭嵌套虚拟化的vm:" 25 60 15 \
  1362. $(echo $ls) \
  1363. 3>&1 1>&2 2>&3)
  1364. exitstatus=$?
  1365. if [ $exitstatus = 0 ]; then
  1366. if(whiptail --title "Yes/No" --yesno "
  1367. you choose: $vmid ,continue?
  1368. 你选的是:$vmid ,是否继续?
  1369. " 10 60)then
  1370. while [ true ]
  1371. do
  1372. if [ `echo "$vmid"|grep "^[0-9]*$"|wc -l` = 0 ];then
  1373. whiptail --title "Warnning" --msgbox "
  1374. 输入格式错误,请重新输入:
  1375. " 10 60
  1376. setVmN
  1377. else
  1378. break
  1379. fi
  1380. done
  1381. if [ `qm showcmd $vmid|grep "+vmx"|wc -l` = 0 ];then
  1382. whiptail --title "Success" --msgbox "
  1383. You already unseted.Nothing to do.
  1384. 您的虚拟机未开启过嵌套虚拟化支持。
  1385. " 10 60
  1386. else
  1387. args=`qm showcmd $vmid|grep "\-cpu [0-9a-zA-Z,+_]*" -o`
  1388. sed -i '/,+vmx/d' /etc/pve/qemu-server/$vmid.conf
  1389. echo "args: "$args >> /etc/pve/qemu-server/$vmid.conf
  1390. whiptail --title "Success" --msgbox "
  1391. Unset OK.Please reboot your vm.
  1392. 您的虚拟机已经关闭嵌套虚拟化支持。重启虚拟机后生效。
  1393. " 10 60
  1394. fi
  1395. else
  1396. chNestedV
  1397. fi
  1398. else
  1399. chNestedV
  1400. fi
  1401. }
  1402. setVmN(){
  1403. list=`qm list|awk 'NR>1{print $1":"$2"......."$3" "}'`
  1404. ls=`for i in $list;do echo $i|awk -F ":" '{print $1" "$2}';done`
  1405. h=`echo $ls|wc -l`
  1406. let h=$h*1
  1407. if [ $h -lt 30 ];then
  1408. h=30
  1409. fi
  1410. list1=`echo $list|awk 'NR>1{print $1}'`
  1411. vmid=$(whiptail --title " PveTools Version : 2.2.5 " --menu "
  1412. Choose vmid to set nested:
  1413. 选择需要配置嵌套虚拟化的vm:" 25 60 15 \
  1414. $(echo $ls) \
  1415. 3>&1 1>&2 2>&3)
  1416. exitstatus=$?
  1417. if [ $exitstatus = 0 ]; then
  1418. if(whiptail --title "Yes/No" --yesno "
  1419. you choose: $vmid ,continue?
  1420. 你选的是:$vmid ,是否继续?
  1421. " 10 60)then
  1422. while [ true ]
  1423. do
  1424. if [ `echo "$vmid"|grep "^[0-9]*$"|wc -l` = 0 ];then
  1425. whiptail --title "Warnning" --msgbox "
  1426. 输入格式错误,请重新输入:
  1427. " 10 60
  1428. setVmN
  1429. else
  1430. break
  1431. fi
  1432. done
  1433. if [ `qm showcmd $vmid|grep "+vmx"|wc -l` = 0 ];then
  1434. args=`qm showcmd $vmid|grep "\-cpu [0-9a-zA-Z,+_]*" -o`
  1435. for i in 'boot:' 'memory:' 'core:';do
  1436. if [ `grep '^'$i /etc/pve/qemu-server/$vmid.conf|wc -l` -gt 0 ];then
  1437. con=$i
  1438. break
  1439. fi
  1440. done
  1441. sed "/"$con"/a\args: $args,+vmx" -i /etc/pve/qemu-server/$vmid.conf
  1442. #echo "args: "$args",+vmx" >> /etc/pve/qemu-server/$vmid.conf
  1443. whiptail --title "Success" --msgbox "
  1444. Nested OK.Please reboot your vm.
  1445. 您的虚拟机已经开启嵌套虚拟化支持。重启虚拟机后生效。
  1446. " 10 60
  1447. else
  1448. whiptail --title "Success" --msgbox "
  1449. You already seted.Nothing to do.
  1450. 您的虚拟机已经开启过嵌套虚拟化支持。
  1451. " 10 60
  1452. fi
  1453. else
  1454. chNestedV
  1455. fi
  1456. else
  1457. chNestedV
  1458. fi
  1459. }
  1460. if [ $L = "en" ];then
  1461. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config Nested:" 25 60 15 \
  1462. "a" "Enable nested" \
  1463. "b" "Set vm to nested" \
  1464. "c" "Unset vm nested" \
  1465. "d" "Disable nested" \
  1466. 3>&1 1>&2 2>&3)
  1467. else
  1468. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置嵌套虚拟化:" 25 60 15 \
  1469. "a" "开启嵌套虚拟化" \
  1470. "b" "开启某个虚拟机的嵌套虚拟化" \
  1471. "c" "关闭某个虚拟机的嵌套虚拟化" \
  1472. "d" "关闭嵌套虚拟化" \
  1473. 3>&1 1>&2 2>&3)
  1474. fi
  1475. exitstatus=$?
  1476. if [ $exitstatus = 0 ]; then
  1477. case "$x" in
  1478. a )
  1479. if(whiptail --title "Yes/No" --yesno "
  1480. Are you sure to enable Nested?
  1481. It will stop all your runnging vms (Y/n):
  1482. 确定要开启嵌套虚拟化吗?
  1483. 这个操作会停止你现在所有运行中的虚拟机!(Y/n):
  1484. " 10 60) then
  1485. if [ `cat /sys/module/kvm_intel/parameters/nested` = 'N' ];then
  1486. for i in `qm list|awk 'NR>1{print $1}'`;do
  1487. qm stop $i
  1488. done
  1489. modprobe -r kvm_intel
  1490. modprobe kvm_intel nested=1
  1491. if [ `cat /sys/module/kvm_intel/parameters/nested` = 'Y' ];then
  1492. echo "options kvm_intel nested=1" >> /etc/modprobe.d/modprobe.conf
  1493. whiptail --title "Success" --msgbox "
  1494. Nested ok.
  1495. 您已经开启嵌套虚拟化。
  1496. " 10 60
  1497. else
  1498. whiptail --title "Warnning" --msgbox "
  1499. Your system can not open nested.
  1500. 您的系统不支持嵌套虚拟化。
  1501. " 10 60
  1502. fi
  1503. else
  1504. whiptail --title "Warnning" --msgbox "
  1505. You already enabled nested virtualization.
  1506. 您已经开启过嵌套虚拟化。
  1507. " 10 60
  1508. fi
  1509. fi
  1510. chNestedV
  1511. ;;
  1512. b )
  1513. if [ `cat /sys/module/kvm_intel/parameters/nested` = 'Y' ];then
  1514. if [ `qm list|wc -l` = 0 ];then
  1515. whiptail --title "Warnning" --msgbox "
  1516. You have no vm.
  1517. 您还没有虚拟机。
  1518. " 10 60
  1519. else
  1520. setVmN
  1521. fi
  1522. chNestedV
  1523. else
  1524. whiptail --title "Warnning" --msgbox "
  1525. Your system can not open nested.
  1526. 您的系统不支持嵌套虚拟化。
  1527. " 10 60
  1528. chNestedV
  1529. fi
  1530. ;;
  1531. c )
  1532. if [ `cat /sys/module/kvm_intel/parameters/nested` = 'Y' ];then
  1533. if [ `qm list|wc -l` = 0 ];then
  1534. whiptail --title "Warnning" --msgbox "
  1535. You have no vm.
  1536. 您还没有虚拟机。
  1537. " 10 60
  1538. else
  1539. unsetVmN
  1540. fi
  1541. chNestedV
  1542. else
  1543. whiptail --title "Warnning" --msgbox "
  1544. Your system can not open nested.
  1545. 您的系统不支持嵌套虚拟化。
  1546. " 10 60
  1547. chNestedV
  1548. fi
  1549. ;;
  1550. q )
  1551. main
  1552. ;;
  1553. esac
  1554. else
  1555. main
  1556. fi
  1557. }
  1558. chSensors(){
  1559. #安装lm-sensors并配置在界面上显示
  1560. #for i in `sed -n '/Chip drivers/,/\#----cut here/p' /tmp/sensors|sed '/Chip /d'|sed '/cut/d'`;do modprobe $i;done
  1561. clear
  1562. if [ $L = "en" ];then
  1563. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config lm-sensors & proxmox ve display:" 25 60 15 \
  1564. "a" "Install." \
  1565. "b" "Uninstall." \
  1566. 3>&1 1>&2 2>&3)
  1567. else
  1568. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置Sensors:" 25 60 15 \
  1569. "a" "安装配置温度显示" \
  1570. "b" "删除配置" \
  1571. 3>&1 1>&2 2>&3)
  1572. fi
  1573. exitstatus=$?
  1574. if [ $exitstatus = 0 ]; then
  1575. case "$x" in
  1576. a )
  1577. if(whiptail --title "Yes/No" --yesno "
  1578. Your OS:$pve, you will install sensors interface, continue?(y/n)
  1579. 您的系统是:$pve, 您将安装sensors界面,是否继续?(y/n)
  1580. " 10 60) then
  1581. js='/usr/share/pve-manager/js/pvemanagerlib.js'
  1582. pm='/usr/share/perl5/PVE/API2/Nodes.pm'
  1583. sh='/usr/bin/s.sh'
  1584. ppv=`/usr/bin/pveversion`
  1585. OS=`echo $ppv|awk -F'-' 'NR==1{print $1}'`
  1586. ver=`echo $ppv|awk -F'/' 'NR==1{print $2}'|awk -F'-' '{print $1}'`
  1587. bver=`echo $ppv|awk -F'/' 'NR==1{print $2}'|awk -F'.' '{print $1}'`
  1588. pve=$OS$ver
  1589. if [[ "$OS" != "pve" ]];then
  1590. whiptail --title "Warnning" --msgbox "
  1591. 您的系统不是Proxmox VE, 无法安装!
  1592. Your OS is not Proxmox VE!
  1593. " 10 60
  1594. if [[ "$bver" != "5" || "$bver" != "6" ]];then
  1595. whiptail --title "Warnning" --msgbox "
  1596. 您的系统版本无法安装!
  1597. Your Proxmox VE version can not install!
  1598. " 10 60
  1599. main
  1600. fi
  1601. main
  1602. fi
  1603. if [[ ! -f "$js" || ! -f "$pm" ]];then
  1604. whiptail --title "Warnning" --msgbox "
  1605. 您的Proxmox VE版本不支持此方式!
  1606. Your Proxmox VE\'s version is not supported,Now quit!
  1607. " 10 60
  1608. main
  1609. fi
  1610. #if [[ -f "$js.backup" && -f "$sh" ]];then
  1611. if [[ `cat $js|grep Sensors|wc -l` -gt 0 ]];then
  1612. whiptail --title "Warnning" --msgbox "
  1613. 您已经安装过本软件,请不要重复安装!
  1614. You already installed,Now quit!
  1615. " 10 60
  1616. chSensors
  1617. fi
  1618. if [ ! -f "/usr/bin/sensors" ];then
  1619. apt-get -y install lm-sensors
  1620. fi
  1621. sensors-detect --auto > /tmp/sensors
  1622. drivers=`sed -n '/Chip drivers/,/\#----cut here/p' /tmp/sensors|sed '/Chip /d'|sed '/cut/d'`
  1623. if [ `echo $drivers|wc -w` = 0 ];then
  1624. whiptail --title "Warnning" --msgbox "
  1625. Sensors driver not found.
  1626. 没有找到任何驱动,似乎你的系统不支持。
  1627. " 10 60
  1628. chSensors
  1629. else
  1630. for i in $drivers
  1631. do
  1632. modprobe $i
  1633. if [ `grep $i /etc/modules|wc -l` = 0 ];then
  1634. echo $i >> /etc/modules
  1635. fi
  1636. done
  1637. sensors
  1638. sleep 3
  1639. whiptail --title "Success" --msgbox "
  1640. Install complete,if everything ok ,it\'s showed sensors.Next, restart you web.
  1641. 安装配置成功,如果没有意外,上面已经显示sensors。下一步会重启web界面,请不要惊慌。
  1642. " 20 60
  1643. fi
  1644. rm /tmp/sensors
  1645. cp $js $js.backup
  1646. cp $pm $pm.backup
  1647. cat << EOF > /usr/bin/s.sh
  1648. r=\`sensors|grep '^[a-zA-Z0-9].[[:print:]]*:.\s*\S*[0-9].\s*[A-Z].' -o|sed 's/:\ */:/g'|sed 's/:/":"/g'|sed 's/^/"/g' |sed 's/$/",/g'|sed 's/\ C\ /C/g'|sed 's/\ V\ /V/g'|sed 's/\ RP/RPM/g'|sed 's/\ //g'|awk 'BEGIN{ORS=""}{print \$0}'|sed 's/,$//g'|sed 's/°C/C/g'\`
  1649. r="{"\$r"}"
  1650. echo \$r
  1651. EOF
  1652. chmod +x /usr/bin/s.sh
  1653. #--create the configs--
  1654. d=`sensors|grep '^[a-zA-Z0-9].[[:print:]]*:.\s*\S*[0-9].\s*[A-Z].' -o|sed 's/:\ */:/g'|sed 's/\ C\ /C/g'|sed 's/\ V\ /V/g'|sed 's/\ RP/RPM/g'|sed 's/\ //g'|awk -F ":" '{print $1}'`
  1655. if [ -f ./p1 ];then rm ./p1;fi
  1656. cat << EOF >> ./p1
  1657. ,{
  1658. xtype: 'box',
  1659. colspan: 2,
  1660. title: gettext('Sensors Data:'),
  1661. padding: '0 0 20 0'
  1662. }
  1663. ,{
  1664. itemId: 'Sensors',
  1665. colspan: 2,
  1666. printBar: false,
  1667. title: gettext('Sensors Data:')
  1668. }
  1669. EOF
  1670. for i in $d
  1671. do
  1672. cat << EOF >> ./p1
  1673. ,{
  1674. itemId: '$i',
  1675. colspan: 1,
  1676. printBar: false,
  1677. title: gettext('$i'),
  1678. textField: 'tdata',
  1679. renderer:function(value){
  1680. var d = JSON.parse(value);
  1681. var s = "";
  1682. s = d['$i'];
  1683. return s;
  1684. }
  1685. }
  1686. EOF
  1687. done
  1688. cat << EOF >> ./p2
  1689. \$res->{tdata} = \`/usr/bin/s.sh\`;
  1690. EOF
  1691. #--configs end--
  1692. #h=`sensors|awk 'END{print NR}'`
  1693. itemC=`s.sh|sed 's/\,/\r\n/g'|wc -l`
  1694. if [ $h = 0 ];then
  1695. h=400
  1696. else
  1697. #let h=$h*9+320
  1698. let h=$itemC*24/2+360
  1699. fi
  1700. n=`sed '/widget.pveNodeStatus/,/height/=' $js -n|sed -n '$p'`
  1701. sed -i ''$n'c \ \ \ \ height:\ '$h',' $js
  1702. n=`sed '/pveversion/,/\}/=' $js -n|sed -n '$p'`
  1703. sed -i ''$n' r ./p1' $js
  1704. n=`sed '/pveversion/,/version_text/=' $pm -n|sed -n '$p'`
  1705. sed -i ''$n' r ./p2' $pm
  1706. if [ -f ./p1 ];then rm ./p1;fi
  1707. if [ -f ./p2 ];then rm ./p2;fi
  1708. systemctl restart pveproxy
  1709. whiptail --title "Success" --msgbox "
  1710. 如果没有意外,已经安装完成!浏览器打开界面刷新看一下概要界面!
  1711. Installation Complete! Go to websites and refresh to enjoy!
  1712. " 10 60
  1713. else
  1714. chSensors
  1715. fi
  1716. ;;
  1717. b )
  1718. if(whiptail --title "Yes/No" --yesno "
  1719. Uninstall?
  1720. 确认要还原配置?
  1721. " 10 60)then
  1722. js='/usr/share/pve-manager/js/pvemanagerlib.js'
  1723. pm='/usr/share/perl5/PVE/API2/Nodes.pm'
  1724. if [[ ! -f $js.backup && ! -f /usr/bin/sensors ]];then
  1725. whiptail --title "Warnning" --msgbox "
  1726. No sensors found.
  1727. 没有检测到安装,不需要卸载。
  1728. " 10 60
  1729. else
  1730. sensors-detect --auto > /tmp/sensors
  1731. drivers=`sed -n '/Chip drivers/,/\#----cut here/p' /tmp/sensors|sed '/Chip /d'|sed '/cut/d'`
  1732. if [ `echo $drivers|wc -w` != 0 ];then
  1733. for i in $drivers
  1734. do
  1735. if [ `grep $i /etc/modules|wc -l` != 0 ];then
  1736. sed -i '/'$i'/d' /etc/modules
  1737. fi
  1738. done
  1739. fi
  1740. apt-get -y remove lm-sensors
  1741. {
  1742. mv $js.backup $js
  1743. mv $pm.backup $pm
  1744. echo 50
  1745. echo 100
  1746. sleep 1
  1747. }|whiptail --gauge "Uninstalling" 10 60 0
  1748. whiptail --title "Success" --msgbox "
  1749. Uninstall complete.
  1750. 卸载成功。
  1751. " 10 60
  1752. fi
  1753. fi
  1754. chSensors
  1755. ;;
  1756. esac
  1757. fi
  1758. }
  1759. chPassth(){
  1760. #--------------funcs-start----------------
  1761. enablePass(){
  1762. if(whiptail --title "Yes/No Box" --yesno "
  1763. Enable PCI Passthrough(need reboot host)?
  1764. 是否开启硬件直通支持(需要重启物理机)?
  1765. " --defaultno 10 60) then
  1766. if [ `dmesg | grep -e DMAR -e IOMMU|wc -l` = 0 ];then
  1767. whiptail --title "Warnning" --msgbox "
  1768. Your hardware do not support PCI Passthrough(No IOMMU)
  1769. 您的硬件不支持直通!
  1770. " 10 60
  1771. chPassth
  1772. fi
  1773. if [ `cat /proc/cpuinfo|grep Intel|wc -l` = 0 ];then
  1774. iommu="amd_iommu=on"
  1775. else
  1776. iommu="intel_iommu=on"
  1777. fi
  1778. if [ `grep $iommu /etc/default/grub|wc -l` = 0 ];then
  1779. sed -i.bak 's|quiet|quiet '$iommu'|' /etc/default/grub
  1780. update-grub
  1781. if [ `grep "vfio" /etc/modules|wc -l` = 0 ];then
  1782. cat <<EOF >> /etc/modules
  1783. vfio
  1784. vfio_iommu_type1
  1785. vfio_pci
  1786. vfio_virqfd
  1787. EOF
  1788. fi
  1789. whiptail --title "Success" --msgbox "
  1790. need to reboot to apply! Please reboot.
  1791. 安装好后需要重启系统,请稍后重启。
  1792. " 10 60
  1793. else
  1794. whiptail --title "Warnning" --msgbox "
  1795. You already configed!
  1796. 您已经配置过这个了!
  1797. " 10 60
  1798. chPassth
  1799. fi
  1800. else
  1801. main
  1802. fi
  1803. }
  1804. disablePass(){
  1805. if(whiptail --title "Yes/No Box" --yesno "
  1806. disable PCI Passthrough(need reboot host)?
  1807. 是否关闭硬件直通支持(需要重启物理机)?
  1808. " --defaultno 10 60) then
  1809. if [ `dmesg | grep -e DMAR -e IOMMU|wc -l` = 0 ];then
  1810. whiptail --title "Warnning" --yesno "
  1811. Your hardware do not support PCI Passthrough(No IOMMU)
  1812. 您的硬件不支持直通!
  1813. " 10 60
  1814. chPassth
  1815. fi
  1816. if [ `cat /proc/cpuinfo|grep Intel|wc -l` = 0 ];then
  1817. iommu='amd_iommu=on'
  1818. else
  1819. iommu='intel_iommu=on'
  1820. fi
  1821. if [ `grep $iommu /etc/default/grub|wc -l` = 0 ];then
  1822. whiptail --title "Warnning" --msgbox "not config yet.
  1823. 您还没有配置过该项" 10 60
  1824. chPassth
  1825. else
  1826. update-grub
  1827. {
  1828. sed -i 's/ '$iommu'//g' /etc/default/grub
  1829. echo 30
  1830. echo 80
  1831. sed -i '/vfio/d' /etc/modules
  1832. echo 100
  1833. sleep 1
  1834. }|whiptail --gauge "installing..." 10 60 10
  1835. whiptail --title "Success" --msgbox "
  1836. need to reboot to apply! Please reboot.
  1837. 安装好后需要重启系统,请稍后重启。
  1838. " 10 60
  1839. fi
  1840. else
  1841. main
  1842. fi
  1843. }
  1844. enVideo(){
  1845. clear
  1846. if [ `dmesg | grep -e DMAR -e IOMMU|wc -l` = 0 ];then
  1847. whiptail --title "Warnning" --msgbox "
  1848. Your hardware do not support PCI Passthrough(No IOMMU)
  1849. 您的硬件不支持直通!
  1850. " 10 60
  1851. configVideo
  1852. fi
  1853. if [ `grep 'iommu=on' /etc/default/grub|wc -l` = 0 ];then
  1854. if(whiptail --title "Warnning" --yesno "
  1855. your host not enable IOMMU,jump to enable?
  1856. 您的主机系统尚未配置直通支持,跳转去设置?
  1857. " 10 60)then
  1858. enablePass
  1859. fi
  1860. fi
  1861. if [ `grep 'vfio' /etc/modules|wc -l` = 0 ];then
  1862. if(whiptail --title "Warnning" --yesno "
  1863. your host not enable IOMMU,jump to enable?
  1864. 您的主机系统尚未配置直通支持,跳转去设置?
  1865. " 10 60)then
  1866. enablePass
  1867. fi
  1868. fi
  1869. getVideo
  1870. }
  1871. getVideo(){
  1872. if [ -f "cards" ];then
  1873. rm cards
  1874. fi
  1875. if [ -f "cards-out" ];then
  1876. rm cards-out
  1877. fi
  1878. lspci |grep -E 'VGA|Audio' > cards
  1879. cat cards|while read line
  1880. do
  1881. c=`echo $line |awk -F '.' '{print $1" " }'``echo $line|awk -F ': ' '{for (i=2;i<=NF;i++)printf("%s_", $i);print ""}'|sed 's/ /_/g'``echo ' OFF'`
  1882. echo $c >> cards-out
  1883. done
  1884. cat cards-out > cards
  1885. id=`cat /etc/modprobe.d/vfio.conf|grep -o "ids=[0-9a-zA-Z,:]*"|awk -F "=" '{print $2}'|sed 's/,/ /g'|sort -u`
  1886. n=`for i in $id;do lspci -n -d $i|awk -F "." '{print $1}';done|sort -u`
  1887. for i in $n
  1888. do
  1889. cards=`sed -n '/'$i'/ s/OFF/ON/p' cards`
  1890. done
  1891. DISTROS=$(whiptail --title "Video cards:" --checklist \
  1892. "Choose cards to config(* mark means configed):
  1893. 选择显卡(标*号为已经配置过的):
  1894. " 15 90 4 \
  1895. $(echo $cards) \
  1896. 3>&1 1>&2 2>&3)
  1897. exitstatus=$?
  1898. if [ $exitstatus = 0 ];then
  1899. #--config-id---
  1900. if [ $DISTROS ];then
  1901. rm cards*
  1902. if(whiptail --title "Warnning" --yesno "
  1903. Continue?
  1904. 请确认是否继续?
  1905. " 10 60)then
  1906. clear
  1907. else
  1908. getVideo
  1909. fi
  1910. ids=""
  1911. for i in $DISTROS
  1912. do
  1913. i=`echo $i|sed 's/\"//g'`
  1914. ids=$ids`lspci -n -s ${i}|awk '{print ","$3}'`
  1915. done
  1916. ids=`echo $ids|sed 's/^,//g'|sed 's/ ,/,/g'`
  1917. if [ `grep $ids'$' /etc/modprobe.d/vfio.conf|wc -l` = 0 ];then
  1918. echo "options vfio-pci ids=$ids" > /etc/modprobe.d/vfio.conf
  1919. else
  1920. if(whiptail --defaultno --title "Warnning" --yesno "
  1921. It seems you have already configed it before.Reconfig?
  1922. 您好像已经配置过这个了。重新配置?
  1923. " 10 60)then
  1924. clear
  1925. else
  1926. getVideo
  1927. fi
  1928. fi
  1929. #--config-blacklist--
  1930. for i in nvidiafb nouveau nvidia radeon amdgpu
  1931. do
  1932. if [ `grep '^blacklist '$i'$' /etc/modprobe.d/pve-blacklist.conf|wc -l` = 0 ];then
  1933. echo "blacklist "$i >> /etc/modprobe.d/pve-blacklist.conf
  1934. fi
  1935. done
  1936. #--iommu-groups--
  1937. if [ `find /sys/kernel/iommu_groups/ -type l|wc -l` = 0 ];then
  1938. if [ `grep 'pcie_acs_override=downstream' /etc/default/grub|wc -l` = 0 ];then
  1939. sed -i.bak 's|iommu=on|iommu=on 'iommu=pt pcie_acs_override=downstream'|' /etc/default/grub
  1940. update-grub
  1941. fi
  1942. fi
  1943. #--video=efifb:off--
  1944. if [ `grep 'video=efifb:off' /etc/default/grub|wc -l` = 0 ];then
  1945. sed -i.bak 's|quiet|quiet video=efifb:off|' /etc/default/grub
  1946. update-grub
  1947. fi
  1948. #--kvm-parameters--
  1949. if [ `cat /sys/module/kvm/parameters/ignore_msrs` = 'N' ];then
  1950. echo 1 > /sys/module/kvm/parameters/ignore_msrs
  1951. echo "options kvm ignore_msrs=Y">>/etc/modprobe.d/kvm.conf
  1952. fi
  1953. update-initramfs -u -k all
  1954. whiptail --title "Success" --msgbox "
  1955. need to reboot to apply! Please reboot.
  1956. 安装好后需要重启系统,请稍后重启。
  1957. " 10 60
  1958. else
  1959. if(whiptail --title "Warnning" --yesno "
  1960. Continue?
  1961. 请确认是否继续?
  1962. " 10 60)then
  1963. clear
  1964. else
  1965. getVideo
  1966. fi
  1967. {
  1968. echo "" > /etc/modprobe.d/vfio.conf
  1969. echo 0 > /sys/module/kvm/parameters/ignore_msrs
  1970. sed -i '/ignore_msrs=Y/d' /etc/modprobe.d/kvm.conf
  1971. for i in nvidiafb nouveau nvidia radeon amdgpu
  1972. do
  1973. sed -i '/'$i'/d' /etc/modprobe.d/pve-blacklist.conf
  1974. done
  1975. echo 100
  1976. sleep 1
  1977. }|whiptail --gauge "configing..." 10 60 10
  1978. whiptail --title "Success" --msgbox "Done.
  1979. 配置完成" 10 60
  1980. fi
  1981. else
  1982. configVideo
  1983. fi
  1984. }
  1985. disVideo(){
  1986. clear
  1987. getVideo dis
  1988. }
  1989. addVideo(){
  1990. if [ -f "cards" ];then
  1991. rm cards
  1992. fi
  1993. if [ -f "cards-out" ];then
  1994. rm cards-out
  1995. fi
  1996. lspci |grep -e VGA > cards
  1997. cat cards|while read line
  1998. do
  1999. c=`echo $line |awk -F '.' '{print $1" " }'``echo $line|awk -F ': ' '{for (i=2;i<=NF;i++)printf("%s_", $i);print ""}'|sed 's/ /_/g'``echo ' OFF'`
  2000. echo $c >> cards-out
  2001. done
  2002. cards=`cat cards-out`
  2003. rm cards*
  2004. DISTROS=$(whiptail --title "Video cards:" --checklist \
  2005. "Choose cards to config?" 15 90 4 \
  2006. $(echo $cards) \
  2007. 3>&1 1>&2 2>&3)
  2008. exitstatus=$?
  2009. if [ $exitstatus = 0 ];then
  2010. #--config-id---
  2011. if [ $DISTROS ];then
  2012. confPath='/etc/pve/qemu-server/'
  2013. ids=""
  2014. for i in $DISTROS
  2015. do
  2016. i=`echo $i|sed 's/\"//g'`
  2017. for j in `ls $confPath`
  2018. do
  2019. if [ `grep $i $confPath$j|wc -l` != 0 ];then
  2020. confId=`echo $j|awk -F '.' '{print $1}'`
  2021. fi
  2022. done
  2023. done
  2024. list=`qm list|awk 'NR>1{print $1":"$2".................."$3" "}'`
  2025. echo -n "">lsvm
  2026. ls=`for i in $list;do echo $i|awk -F ":" '{print $1" "$2" OFF"}'>>lsvm;done`
  2027. ls=`sed -i '/'$confId'/ s/OFF/ON/g' lsvm`
  2028. ls=`cat lsvm`
  2029. rm lsvm
  2030. h=`echo $ls|wc -l`
  2031. let h=$h*1
  2032. if [ $h -lt 30 ];then
  2033. h=30
  2034. fi
  2035. list1=`echo $list|awk 'NR>1{print $1}'`
  2036. vmid=$(whiptail --title " PveTools Version : 2.2.5 " --radiolist "
  2037. Choose vmid to set video card Passthrough:
  2038. 选择需要配置显卡直通的vm:" 20 60 10 \
  2039. $(echo $ls) \
  2040. 3>&1 1>&2 2>&3)
  2041. exitstatus=$?
  2042. if [ $exitstatus = 0 ]; then
  2043. if(whiptail --title "Yes/No" --yesno "
  2044. you choose: $vmid ,continue?
  2045. 你选的是:$vmid ,是否继续?
  2046. " 10 60)then
  2047. echo $vmid>vmid
  2048. while [ true ]
  2049. do
  2050. if [ `echo "$vmid"|grep "^[0-9]*$"|wc -l` = 0 ];then
  2051. whiptail --title "Warnning" --msgbox "
  2052. 输入格式错误,请重新输入:
  2053. " 10 60
  2054. addVideo
  2055. else
  2056. break
  2057. fi
  2058. done
  2059. if [ $vmid -eq $confId ];then
  2060. whiptail --title "Warnning" --msgbox "
  2061. You already configed!
  2062. 您已经配置过这个了!
  2063. " 10 60
  2064. addVideo
  2065. fi
  2066. opt=$(whiptail --title " PveTools Version : 2.2.5 " --checklist "
  2067. Choose options:
  2068. 选择选项:" 20 60 10 \
  2069. "q35" "q35支持,gpu直通建议选择,独显留空" OFF \
  2070. "ovmf" "gpu直通选择" OFF \
  2071. "x-vga" "主gpu,默认已选择" ON \
  2072. 3>&1 1>&2 2>&3)
  2073. exitstatus=$?
  2074. if [ $exitstatus = 0 ]; then
  2075. for i in 'boot:' 'memory:' 'core:';do
  2076. if [ `grep '^'$i $confPath$vmid.conf|wc -l` != 0 ];then
  2077. con=$i
  2078. break
  2079. fi
  2080. done
  2081. for op in $opt
  2082. do
  2083. op=`echo $op|sed 's/\"//g'`
  2084. if [ $op = 'q35' ];then
  2085. sed "/"$con"/a\machine\: q35" -i $confPath$vmid.conf
  2086. fi
  2087. if [ $op = 'ovmf' ];then
  2088. sed "/"$con"/a\bios\: ovmf" -i $confPath$vmid.conf
  2089. fi
  2090. done
  2091. #--config-vmid.conf---
  2092. for i in $DISTROS
  2093. do
  2094. if [ `cat $confPath$vmid.conf |sed -n '/^hostpci/p'|grep $i|wc -l` = 0 ];then
  2095. pcid=`cat $confPath$vmid.conf |sed -n '/^hostpci/p'|awk -F ':' '{print $1}'|sort -u|grep '[0-9]*$' -o`
  2096. if [ $pcid ];then
  2097. pcid=$((pcid+1))
  2098. else
  2099. pcid=0
  2100. fi
  2101. i=`echo $i|sed 's/\"//g'`
  2102. sed -i "/"$con"/a\hostpci"$pcid": "$i",x-vga=1" $confPath$vmid.conf
  2103. else
  2104. whiptail --title "Warnning" --msgbox "
  2105. You already configed!
  2106. 您已经配置过这个了!
  2107. " 10 60
  2108. fi
  2109. if [ $confId ];then
  2110. rmVideo $confId $confPath $i
  2111. fi
  2112. whiptail --title "Success" --msgbox "
  2113. Configed!Please reboot vm.
  2114. 配置成功!重启虚拟机后生效。
  2115. " 10 60
  2116. if(whiptail --title "Yes/No" --yesno "
  2117. Let tool auto switch vm?
  2118. 是否自动帮你重启切换虚拟机?" 10 60)then
  2119. #vmid=`echo $vmid|sed 's/\"//g'`
  2120. vmid=`cat vmid`
  2121. rm vmid
  2122. if [ $confId ];then
  2123. usb=`cat /etc/pve/qemu-server/115.conf |grep '^usb'|wc -l`
  2124. if [ $usb ];then
  2125. if(whiptail --title "Yes/No" --yesno "
  2126. Let tool auto switch usb?
  2127. 是否自动切换usb设备?
  2128. " 10 60)then
  2129. cat $confPath$confId.conf |grep '^usb'|sed 's/ //g'>usb
  2130. sed -i '/^usb/d' $confPath$confId.conf
  2131. for i in `cat usb`;do sed -i '/memory/a\'$i $confPath$vmid.conf;done
  2132. sed -i 's/:host/: host/g' $confPath$vmid.conf
  2133. rm usb
  2134. fi
  2135. fi
  2136. qm stop $confId
  2137. fi
  2138. qm stop $vmid
  2139. if [ $confId ];then
  2140. qm start $confId
  2141. fi
  2142. qm start $vmid
  2143. whiptail --title "Success" --msgbox "
  2144. Configed!
  2145. 配置成功!
  2146. " 10 60
  2147. else
  2148. configVideo
  2149. fi
  2150. done
  2151. else
  2152. addVideo
  2153. fi
  2154. configVideo
  2155. else
  2156. addVideo
  2157. fi
  2158. else
  2159. configVideo
  2160. fi
  2161. else
  2162. whiptail --title "Warnning" --msgbox "
  2163. Please choose a card.
  2164. 请选择一个显卡。" 10 60
  2165. addVideo
  2166. fi
  2167. else
  2168. configVideo
  2169. fi
  2170. }
  2171. rmVideo(){
  2172. clear
  2173. vmid=$1
  2174. confPath=$2
  2175. DISTROS=$3
  2176. for i in $vmid
  2177. do
  2178. sed -i '/q35/d' $confPath$vmid.conf
  2179. for i in $DISTROS
  2180. do
  2181. if [ `cat $confPath$vmid.conf |sed -n '/^hostpci/p'|grep $i|wc -l` != 0 ];then
  2182. sed -i '/'$i'/d' $confPath$vmid.conf
  2183. fi
  2184. done
  2185. done
  2186. }
  2187. switchVideo(){
  2188. if [ -f "cards" ];then
  2189. rm cards
  2190. fi
  2191. if [ -f "cards-out" ];then
  2192. rm cards-out
  2193. fi
  2194. lspci |grep -e VGA > cards
  2195. cat cards|while read line
  2196. do
  2197. c=`echo $line |awk -F '.' '{print $1" " }'``echo $line|awk -F ': ' '{for (i=2;i<=NF;i++)printf("%s_", $i);print ""}'|sed 's/ /_/g'``echo ' OFF'`
  2198. echo $c >> cards-out
  2199. done
  2200. cards=`cat cards-out`
  2201. rm cards*
  2202. DISTROS=$(whiptail --title "Video cards:" --checklist \
  2203. "Choose cards to config?" 15 90 4 \
  2204. $(echo $cards) \
  2205. 3>&1 1>&2 2>&3)
  2206. exitstatus=$?
  2207. if [ $exitstatus = 0 ];then
  2208. #--config-id---
  2209. if [ $DISTROS ];then
  2210. confPath='/etc/pve/qemu-server/'
  2211. ids=""
  2212. for i in $DISTROS
  2213. do
  2214. i=`echo $i|sed 's/\"//g'`
  2215. for j in `ls $confPath`
  2216. do
  2217. if [ `grep $i $confPath$j|wc -l` != 0 ];then
  2218. confId=`echo $j|awk -F '.' '{print $1}'`
  2219. fi
  2220. done
  2221. done
  2222. list=`qm list|awk 'NR>1{print $1":"$2".................."$3" "}'`
  2223. echo -n "">lsvm
  2224. ls=`for i in $list;do echo $i|awk -F ":" '{print $1" "$2" OFF"}'>>lsvm;done`
  2225. ls=`sed -i '/'$confId'/ s/OFF/ON/g' lsvm`
  2226. ls=`cat lsvm`
  2227. rm lsvm
  2228. h=`echo $ls|wc -l`
  2229. let h=$h*1
  2230. if [ $h -lt 30 ];then
  2231. h=30
  2232. fi
  2233. list1=`echo $list|awk 'NR>1{print $1}'`
  2234. vmid=$(whiptail --title " PveTools Version : 2.2.5 " --radiolist "
  2235. Choose vmid to set video card Passthrough:
  2236. 选择需要配置显卡直通的vm:" 20 60 10 \
  2237. $(echo $ls) \
  2238. 3>&1 1>&2 2>&3)
  2239. exitstatus=$?
  2240. if [ $exitstatus = 0 ]; then
  2241. if(whiptail --title "Yes/No" --yesno "
  2242. you choose: $vmid ,continue?
  2243. 你选的是:$vmid ,是否继续?
  2244. " 10 60)then
  2245. echo $vmid>vmid
  2246. while [ true ]
  2247. do
  2248. if [ `echo "$vmid"|grep "^[0-9]*$"|wc -l` = 0 ];then
  2249. whiptail --title "Warnning" --msgbox "
  2250. 输入格式错误,请重新输入:
  2251. " 10 60
  2252. addVideo
  2253. else
  2254. break
  2255. fi
  2256. done
  2257. if [ $vmid -eq $confId ];then
  2258. whiptail --title "Warnning" --msgbox "
  2259. You already configed!
  2260. 您已经配置过这个了!
  2261. " 10 60
  2262. addVideo
  2263. fi
  2264. opt=$(whiptail --title " PveTools Version : 2.2.5 " --checklist "
  2265. Choose options:
  2266. 选择选项:" 20 60 10 \
  2267. "q35" "q35支持,gpu直通建议选择,独显留空" OFF \
  2268. "ovmf" "gpu直通选择" OFF \
  2269. "x-vga" "主gpu,默认已选择" ON \
  2270. 3>&1 1>&2 2>&3)
  2271. exitstatus=$?
  2272. if [ $exitstatus = 0 ]; then
  2273. for i in 'boot:' 'memory:' 'core:';do
  2274. if [ `grep '^'$i $confPath$vmid.conf|wc -l` != 0 ];then
  2275. con=$i
  2276. break
  2277. fi
  2278. done
  2279. for op in $opt
  2280. do
  2281. op=`echo $op|sed 's/\"//g'`
  2282. if [ $op = 'q35' ];then
  2283. sed "/"$con"/a\machine\: q35" -i $confPath$vmid.conf
  2284. fi
  2285. if [ $op = 'ovmf' ];then
  2286. sed "/"$con"/a\bios\: ovmf" -i $confPath$vmid.conf
  2287. fi
  2288. done
  2289. #--config-vmid.conf---
  2290. for i in $DISTROS
  2291. do
  2292. if [ `cat $confPath$vmid.conf |sed -n '/^hostpci/p'|grep $i|wc -l` = 0 ];then
  2293. pcid=`cat $confPath$vmid.conf |sed -n '/^hostpci/p'|awk -F ':' '{print $1}'|sort -u|grep '[0-9]*$' -o`
  2294. if [ $pcid ];then
  2295. pcid=$((pcid+1))
  2296. else
  2297. pcid=0
  2298. fi
  2299. i=`echo $i|sed 's/\"//g'`
  2300. sed -i "/"$con"/a\hostpci"$pcid": "$i",x-vga=1" $confPath$vmid.conf
  2301. else
  2302. whiptail --title "Warnning" --msgbox "
  2303. You already configed!
  2304. 您已经配置过这个了!
  2305. " 10 60
  2306. fi
  2307. if [ $confId ];then
  2308. rmVideo $confId $confPath $i
  2309. fi
  2310. whiptail --title "Success" --msgbox "
  2311. Configed!Please reboot vm.
  2312. 配置成功!重启虚拟机后生效。
  2313. " 10 60
  2314. if(whiptail --title "Yes/No" --yesno "
  2315. Let tool auto switch vm?
  2316. 是否让工具自动帮你重启切换虚拟机?" 10 60)then
  2317. #vmid=`echo $vmid|sed 's/\"//g'`
  2318. vmid=`cat vmid`
  2319. rm vmid
  2320. qm stop $confId
  2321. qm stop $vmid
  2322. qm start $confId
  2323. qm start $vmid
  2324. whiptail --title "Success" --msgbox "
  2325. Configed!
  2326. 配置成功!
  2327. " 10 60
  2328. else
  2329. configVideo
  2330. fi
  2331. done
  2332. else
  2333. addVideo
  2334. fi
  2335. configVideo
  2336. else
  2337. addVideo
  2338. fi
  2339. else
  2340. configVideo
  2341. fi
  2342. else
  2343. whiptail --title "Warnning" --msgbox "
  2344. Please choose a card.
  2345. 请选择一个显卡。" 10 60
  2346. addVideo
  2347. fi
  2348. else
  2349. configVideo
  2350. fi
  2351. }
  2352. configVideo(){
  2353. if [ $L = "en" ];then
  2354. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config PCI Video card Passthrough:" 25 60 15 \
  2355. "a" "Config Video Card Passthrough" \
  2356. "b" "Config Video Card Passthrough to vm" \
  2357. 3>&1 1>&2 2>&3)
  2358. else
  2359. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置PCI显卡直通:" 25 60 15 \
  2360. "a" "配置物理机显卡直通支持。" \
  2361. "b" "配置显卡直通给虚拟机。" \
  2362. 3>&1 1>&2 2>&3)
  2363. fi
  2364. exitstatus=$?
  2365. if [ $exitstatus = 0 ]; then
  2366. case "$x" in
  2367. a )
  2368. enVideo
  2369. ;;
  2370. b )
  2371. addVideo
  2372. ;;
  2373. esac
  2374. else
  2375. main
  2376. fi
  2377. }
  2378. #--------------funcs-end----------------
  2379. if [ $L = "en" ];then
  2380. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config PCI Passthrough:" 25 60 15 \
  2381. "a" "Config IOMMU on." \
  2382. "b" "Config IOMMU off." \
  2383. "c" "Config Video Card Passthrough" \
  2384. "d" "Config qm set disks." \
  2385. 3>&1 1>&2 2>&3)
  2386. else
  2387. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置硬件直通:" 25 60 15 \
  2388. "a" "配置开启物理机硬件直通支持。" \
  2389. "b" "配置关闭物理机硬件直通支持。" \
  2390. "c" "配置显卡直通。" \
  2391. "d" "配置qm set 硬盘给虚拟机。" \
  2392. 3>&1 1>&2 2>&3)
  2393. fi
  2394. exitstatus=$?
  2395. if [ $exitstatus = 0 ]; then
  2396. case "$x" in
  2397. a )
  2398. enablePass
  2399. ;;
  2400. b )
  2401. disablePass
  2402. ;;
  2403. c )
  2404. configVideo
  2405. ;;
  2406. d )
  2407. chQmdisk
  2408. esac
  2409. else
  2410. main
  2411. fi
  2412. }
  2413. checkPath(){
  2414. x=$(whiptail --title "Choose a path" --inputbox "
  2415. Input path:
  2416. 请输入路径:" 10 60 \
  2417. $1 \
  2418. 3>&1 1>&2 2>&3)
  2419. exitstatus=$?
  2420. if [ $exitstatus = 0 ]; then
  2421. while [ true ]
  2422. do
  2423. if [ ! -d $x ];then
  2424. whiptail --title "Warnning" --msgbox "Path not found.
  2425. 没有检测到路径,请重新输入" 10 60
  2426. checkPath
  2427. else
  2428. break
  2429. fi
  2430. done
  2431. echo $x
  2432. return $?
  2433. fi
  2434. }
  2435. chRoot(){
  2436. #--base-funcs-start--
  2437. setChroot(){
  2438. clear
  2439. if(whiptail --title "Yes/No" --yesno "
  2440. Continue?
  2441. 是否继续?" --defaultno 10 60 )then
  2442. if [ ! -f "/usr/bin/schroot" ];then
  2443. whiptail --title "Warnning" --msgbox "you not installed schroot.
  2444. 您还没有安装schroot。" 10 60
  2445. if [ `ps aux|grep apt-get|wc -l` -gt 1 ];then
  2446. if(whiptail --title "Yes/No" --yesno "apt-get is running,killit and install schroot?
  2447. 后台有apt-get正在运行,是否杀掉进行安装?
  2448. " 10 60);then
  2449. killall apt-get && apt-get -y install schroot
  2450. else
  2451. setChroot
  2452. fi
  2453. else
  2454. apt-get -y install schroot
  2455. fi
  2456. fi
  2457. sed '/^$/d' /etc/schroot/default/fstab
  2458. if [ `grep '\/run\/udev' /etc/schroot/default/fstab|wc -l` = 0 ];then
  2459. cat << EOF >> /etc/schroot/default/fstab
  2460. /run/udev /run/udev none rw,bind 0 0
  2461. EOF
  2462. fi
  2463. if [ `grep '\/sys\/fs\/cgroup' /etc/schroot/default/fstab|wc -l` = 0 ];then
  2464. sed '/cgroup/d' /etc/schroot/default/fstab
  2465. cat << EOF >> /etc/schroot/default/fstab
  2466. /sys/fs/cgroup /sys/fs/cgroup none rw,rbind 0 0
  2467. EOF
  2468. fi
  2469. sed -i '/\/home/d' /etc/schroot/default/fstab
  2470. checkPath /
  2471. chrootp=${x%/}"/alpine"
  2472. echo $chrootp > /etc/schroot/chrootp
  2473. if [ ! -d $chrootp ];then
  2474. mkdir $chrootp
  2475. else
  2476. clear
  2477. fi
  2478. cd $chrootp
  2479. if [ `ls $chrootp/bin|wc -l` -gt 0 ];then
  2480. if(whiptail --title "Warnning" --yesno "files exist, remove and reinstall?
  2481. 已经存在文件,是否清空重装?" --defaultno 10 60)then
  2482. for i in `schroot --list --all-sessions|awk -F ":" '{print $2}'`;do schroot -e -c $i;done
  2483. killall dockerd
  2484. killall portainer
  2485. rm -rf $chrootp/*
  2486. else
  2487. configChroot
  2488. fi
  2489. fi
  2490. if [ $L = "en" ];then
  2491. alpineUrl='http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/x86_64'
  2492. else
  2493. alpineUrl='https://mirrors.aliyun.com/alpine/v3.10/releases/x86_64'
  2494. fi
  2495. version=`wget $alpineUrl/ -q -O -|grep minirootfs|grep -o '[0-9]*\.[0-9]*\.[0-9]*'|sort -u -r|awk 'NR==1{print $1}'`
  2496. echo $alpineUrl
  2497. echo $version
  2498. sleep 3
  2499. wget -c --timeout 15 --waitretry 5 --tries 5 $alpineUrl/alpine-minirootfs-$version-x86_64.tar.gz
  2500. tar -xvzf alpine-minirootfs-$version-x86_64.tar.gz
  2501. rm -rf alpine-minirootfs-$version-x86_64.tar.gz
  2502. if [ ! -f "/etc/schroot/chroot.d/alpine.conf" ] || [ `cat /etc/schroot/chroot.d/alpine.conf|wc -l` -lt 8 ];then
  2503. cat << EOF > /etc/schroot/chroot.d/alpine.conf
  2504. [alpine]
  2505. description=alpine $version
  2506. directory=$chrootp
  2507. users=root
  2508. groups=root
  2509. root-users=root
  2510. root-groups=root
  2511. type=directory
  2512. shell=/bin/sh
  2513. EOF
  2514. fi
  2515. echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > $chrootp/etc/apk/repositories \
  2516. && echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> $chrootp/etc/apk/repositories
  2517. cat << EOF >> $chrootp/etc/profile
  2518. echo "Welcome to alpine $version chroot."
  2519. echo "Create by PveTools."
  2520. echo "Author: 龙天ivan"
  2521. echo "Github: https://github.com/ivanhao/pvetoools"
  2522. EOF
  2523. schroot -c alpine apk update
  2524. whiptail --title "Success" --msgbox "Done.
  2525. 安装配置完成!" 10 60
  2526. docker
  2527. dockerWeb
  2528. configChroot
  2529. else
  2530. configChroot
  2531. fi
  2532. }
  2533. installOs(){
  2534. clear
  2535. }
  2536. enterChroot(){
  2537. clear
  2538. checkSchroot
  2539. c=`schroot -l|awk -F ":" '{print $2" "$1}'`
  2540. if [ $L = "en" ];then
  2541. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Enter chroot:" 25 60 15 \
  2542. $(echo $c) \
  2543. 3>&1 1>&2 2>&3)
  2544. else
  2545. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "进入chroot环境:" 25 60 15 \
  2546. $(echo $c) \
  2547. 3>&1 1>&2 2>&3)
  2548. fi
  2549. exitstatus=$?
  2550. if [ $exitstatus = 0 ]; then
  2551. if [ $x ];then
  2552. schroot -c $x -d /root
  2553. else
  2554. chRoot
  2555. fi
  2556. else
  2557. chRoot
  2558. fi
  2559. }
  2560. docker(){
  2561. clear
  2562. checkSchroot
  2563. if [ `schroot -c alpine -d /root ls /usr/bin|grep docker|wc -l` = 0 ];then
  2564. if(whiptail --title "Warnning" --yesno "No docker found.Install?
  2565. 您还没有安装docker,是否安装?" 10 60)then
  2566. schroot -c alpine -d /root apk update
  2567. schroot -c alpine -d /root apk add docker
  2568. cat << EOF >> $chrootp/etc/profile
  2569. export DOCKER_RAMDISK=true
  2570. echo "Docker installed."
  2571. for i in {1..10}
  2572. do
  2573. if [ \`ps aux|grep dockerd|wc -l\` -gt 1 ];then
  2574. break
  2575. else
  2576. nohup /usr/bin/dockerd > /dev/null 2>&1 &
  2577. fi
  2578. done
  2579. EOF
  2580. if [ ! -d "$chrootp/etc/docker" ];then
  2581. mkdir $chrootp/etc/docker
  2582. fi
  2583. if [ $L = "en" ];then
  2584. cat << EOF > $chrootp/etc/docker/daemon.json
  2585. {
  2586. "registry-mirrors": [
  2587. "https://dockerhub.azk8s.cn",
  2588. "https://reg-mirror.qiniu.com",
  2589. "https://registry.docker-cn.com"
  2590. ]
  2591. }
  2592. EOF
  2593. fi
  2594. else
  2595. configChroot
  2596. fi
  2597. fi
  2598. if [ -f "/usr/bin/screen" ];then
  2599. apt-get install screen -y
  2600. fi
  2601. if [ `screen -ls|grep docker|wc -l` != 0 ];then
  2602. screen -S docker -X quit
  2603. fi
  2604. if(whiptail --title "Yes/No" --yesno "Install portainer web interface?
  2605. 是否安装web界面(portainer)?" 10 60);then
  2606. dockerWeb
  2607. else
  2608. clear
  2609. fi
  2610. screen -dmS docker schroot -c alpine -d /root
  2611. configChroot
  2612. }
  2613. dockerWeb(){
  2614. checkSchroot
  2615. checkDocker
  2616. checkDockerWeb
  2617. if [ `cat $chrootp/etc/profile|grep portainer|wc -l` = 0 ];then
  2618. cat << EOF >> $chrootp/etc/profile
  2619. if [ ! -d "/root/portainer_data" ];then
  2620. mkdir /root/portainer_data
  2621. fi
  2622. if [ \`docker ps -a|grep portainer|wc -l\` = 0 ];then
  2623. docker run -d -p 9000:9000 -p 8000:8000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /root/portainer_data:/data portainer/portainer
  2624. else
  2625. docker start portainer > /dev/null
  2626. fi
  2627. echo "Portainer installed."
  2628. EOF
  2629. fi
  2630. if [ ! -f "/usr/bin/screen" ];then
  2631. apt-get install screen -y
  2632. fi
  2633. chrootReDaemon
  2634. sleep 5
  2635. if [ `schroot -c alpine -d /root docker images|grep portainer|wc -l` = 0 ];then
  2636. schroot -c alpine -d /root docker pull portainer/portainer
  2637. fi
  2638. if [ `schroot -c alpine -d /root docker ps -a|grep portainer|wc -l` = 0 ];then
  2639. schroot -c alpine -d /root docker run -d -p 9000:9000 -p 8000:8000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /root/portainer_data:/data portainer/portainer
  2640. fi
  2641. checkDockerWeb
  2642. }
  2643. checkSchroot(){
  2644. if [ `ls /usr/bin|grep schroot|wc -l` = 0 ] || [ `schroot -l|wc -l` = 0 ];then
  2645. whiptail --title "Warnning" --msgbox "No schroot found.Install schroot first.
  2646. 您还没有安装schroot环境,请先安装。" 10 60
  2647. chRoot
  2648. else
  2649. if [ -f "/etc/schroot/chrootp" ];then
  2650. chrootp=`cat /etc/schroot/chrootp`
  2651. else
  2652. if [ -d "/alpine" ];then
  2653. chrootp="/alpine"
  2654. echo $chrootp > /etc/schroot/chrootp
  2655. else
  2656. whiptail --title "Warnning" --msgbox "Chroot path not found!
  2657. 没有检测到chroot安装目录!" 10 60
  2658. fi
  2659. fi
  2660. fi
  2661. }
  2662. checkDocker(){
  2663. if [ `ls $chrootp/usr/bin|grep docker|wc -l` = 0 ];then
  2664. whiptail --title "Warnning" --msgbox "No docker found.Install docker first.
  2665. 您还没有安装docker环境,请先安装。" 10 60
  2666. chRoot
  2667. fi
  2668. }
  2669. checkDockerWeb(){
  2670. if [ `schroot -c alpine -d /root docker images|grep portainer|wc -l` != 0 ];then
  2671. whiptail --title "Warnning" --msgbox "DockerWeb found.Quit.
  2672. 您已经安装dockerWeb环境。
  2673. 请进入http://ip:9000使用。
  2674. " 10 60
  2675. chRoot
  2676. fi
  2677. }
  2678. chrootReDaemon(){
  2679. if [ `screen -ls|grep docker|wc -l` != 0 ];then
  2680. for i in `screen -ls|grep docker|awk -F " " '{print $1}'|awk -F "." '{print $1}'`
  2681. do
  2682. screen -S $i -X quit
  2683. done
  2684. fi
  2685. screen -dmS docker schroot -c alpine -d /root
  2686. if [ `cat /etc/crontab|grep schroot|wc -l` = 0 ];then
  2687. cat << EOF >> /etc/crontab
  2688. @reboot root screen -dmS docker schroot -c alpine -d /root
  2689. EOF
  2690. fi
  2691. whiptail --title "Success" --msgbox "Chroot daemon done." 10 60
  2692. }
  2693. checkChrootDaemon(){
  2694. if [ `screen -ls|grep docker|wc -l` = 0 ];then
  2695. screen -dmS docker schroot -c alpine -d /root
  2696. if [ `screen -ls|grep docker|wc -l` != 0 ];then
  2697. whiptail --title "Warnning" --msgbox "Chroot daemon started.
  2698. 已经为您开启chroot后台运行环境。
  2699. " 10 60
  2700. chRoot
  2701. else
  2702. checkChrootDaemon
  2703. fi
  2704. else
  2705. if(whiptail --title "Warnning" --yesno "Chroot daemon already runngin.Restart?
  2706. chroot后台运行环境已经运行,需要重启吗?
  2707. " --defaultno 10 60)then
  2708. chrootReDaemon
  2709. checkChrootDaemon
  2710. else
  2711. chRoot
  2712. fi
  2713. fi
  2714. chRoot
  2715. }
  2716. configChroot(){
  2717. if [ $L = "en" ];then
  2718. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config chroot & docker etc:" 25 60 15 \
  2719. "a" "Config base schroot." \
  2720. "b" "Docker in alpine" \
  2721. "c" "Portainer in alpine" \
  2722. "d" "Change chroot path" \
  2723. 3>&1 1>&2 2>&3)
  2724. else
  2725. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置chroot环境和docker等:" 25 60 15 \
  2726. "a" "配置基本的chroot环境(schroot 默认为alpine)。" \
  2727. "b" "Docker(alpine)。" \
  2728. "c" "Docker配置界面(portainer in alpine)。" \
  2729. "d" "迁移chroot目录到其他路径。" \
  2730. 3>&1 1>&2 2>&3)
  2731. fi
  2732. exitstatus=$?
  2733. if [ $exitstatus = 0 ]; then
  2734. case "$x" in
  2735. a )
  2736. setChroot
  2737. ;;
  2738. b )
  2739. docker
  2740. #whiptail --title "Warnning" --msgbox "Not supported." 10 60
  2741. chroot
  2742. ;;
  2743. c )
  2744. dockerWeb
  2745. chRoot
  2746. ;;
  2747. d )
  2748. mvChrootp
  2749. esac
  2750. else
  2751. chRoot
  2752. fi
  2753. }
  2754. mvChrootp(){
  2755. if (whiptail --title "Yes/No" --yesno "Continue?
  2756. 是否继续?" --defaultno 10 60)then
  2757. checkSchroot
  2758. chrootpNew=$(whiptail --title "Choose a path" --inputbox "
  2759. Current Path:
  2760. 当前路径:
  2761. $(echo $chrootp)
  2762. ---------------------------------
  2763. Input new chroot path:
  2764. 请输入迁移的新路径:" 20 60 \
  2765. "" \
  2766. 3>&1 1>&2 2>&3)
  2767. exitstatus=$?
  2768. if [ $exitstatus = 0 ]; then
  2769. while [ true ]
  2770. do
  2771. if [ ! -d $chrootpNew ];then
  2772. whiptail --title "Warnning" --msgbox "Path not found.
  2773. 没有检测到路径,请重新输入" 10 60
  2774. mvChrootp
  2775. else
  2776. break
  2777. fi
  2778. done
  2779. chrootpNew=${chrootpNew%/}"/alpine"
  2780. echo $chrootpNew > /etc/schroot/chrootp
  2781. for i in `schroot --list --all-sessions|awk -F ":" '{print $2}'`;do schroot -e -c $i;done
  2782. if [ -d "$chrootp/sys/fs/cgroup" ];then
  2783. mount --make-rslave $chrootp/sys/fs/cgroup
  2784. umount -R $chrootp/sys/fs/cgroup
  2785. fi
  2786. killall portainer
  2787. killall dockerd
  2788. rsync -a -r -v $chrootp"/" $chrootpNew
  2789. sync
  2790. sync
  2791. sleep 3
  2792. rm -rf $chrootp
  2793. sed -i 's#'$chrootp'#'$chrootpNew'#g' /etc/schroot/chroot.d/alpine.conf
  2794. whiptail --title "Success" --msgbox "Done.
  2795. 迁移成功" 10 60
  2796. checkChrootDaemon
  2797. else
  2798. configChroot
  2799. fi
  2800. else
  2801. chRoot
  2802. fi
  2803. }
  2804. delChroot(){
  2805. if (whiptail --title "Yes/No" --yesno "Continue?
  2806. 是否继续?" --defaultno 10 60)then
  2807. checkSchroot
  2808. for i in `schroot --list --all-sessions|awk -F ":" '{print $2}'`;do schroot -e -c $i;done
  2809. apt-get -y autoremove schroot debootstrap
  2810. if [ -d "$chrootp/sys/fs/cgroup" ];then
  2811. mount --make-rslave $chrootp/sys/fs/cgroup
  2812. umount -R $chrootp/sys/fs/cgroup
  2813. fi
  2814. killall portainer
  2815. killall dockerd
  2816. rm -rf $chrootp
  2817. whiptail --title "Success" --msgbox "Done.
  2818. 删除成功" 10 60
  2819. else
  2820. chRoot
  2821. fi
  2822. }
  2823. #--base-funcs-end--
  2824. if [ $L = "en" ];then
  2825. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config chroot & docker etc:" 25 60 15 \
  2826. "a" "Install & config base schroot." \
  2827. "b" "Enter chroot." \
  2828. "c" "Chroot daemon manager" \
  2829. "d" "Remove all chroot." \
  2830. 3>&1 1>&2 2>&3)
  2831. else
  2832. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置chroot环境和docker等:" 25 60 15 \
  2833. "a" "安装配置基本的chroot环境(schroot 默认为alpine)。" \
  2834. "b" "进入chroot。" \
  2835. "c" "Chroot后台管理。" \
  2836. "d" "彻底删除chroot。" \
  2837. 3>&1 1>&2 2>&3)
  2838. fi
  2839. exitstatus=$?
  2840. if [ $exitstatus = 0 ]; then
  2841. case "$x" in
  2842. a )
  2843. configChroot
  2844. ;;
  2845. b )
  2846. enterChroot
  2847. ;;
  2848. c )
  2849. checkChrootDaemon
  2850. ;;
  2851. d )
  2852. delChroot
  2853. esac
  2854. else
  2855. main
  2856. fi
  2857. }
  2858. #--qm set <ide,scsi,sata> disk
  2859. chQmdisk(){
  2860. clear
  2861. confDisk(){
  2862. list=`qm list|awk 'NR>1{print $1":"$2".................."$3" "}'`
  2863. echo -n "">lsvm
  2864. ls=`for i in $list;do echo $i|awk -F ":" '{print $1" "$2}'>>lsvm;done`
  2865. ls=`cat lsvm`
  2866. rm lsvm
  2867. h=`echo $ls|wc -l`
  2868. let h=$h*1
  2869. if [ $h -lt 30 ];then
  2870. h=30
  2871. fi
  2872. list1=`echo $list|awk 'NR>1{print $1}'`
  2873. vmid=$(whiptail --title " PveTools Version : 2.2.5 " --menu "
  2874. Choose vmid to set disk:
  2875. 选择需要配置硬盘的vm:" 20 60 10 \
  2876. $(echo $ls) \
  2877. 3>&1 1>&2 2>&3)
  2878. exitstatus=$?
  2879. if [ $exitstatus = 0 ]; then
  2880. if(whiptail --title "Yes/No" --yesno "
  2881. you choose: $vmid ,continue?
  2882. 你选的是:$vmid ,是否继续?
  2883. " 10 60)then
  2884. while [ true ]
  2885. do
  2886. if [ `echo "$vmid"|grep "^[0-9]*$"|wc -l` = 0 ];then
  2887. whiptail --title "Warnning" --msgbox "
  2888. 输入格式错误,请重新输入:
  2889. " 10 60
  2890. chQmdisk
  2891. else
  2892. break
  2893. fi
  2894. done
  2895. if [ $1 = 'add' ];then
  2896. #disks=`ls -alh /dev/disk/by-id|awk '{print $11" "$9" OFF"}'|awk -F "/" '{print $3}'|sed '/^$/d'|sed '/wwn/d'|sed '/^dm/d'|sed '/lvm/d'`
  2897. #added=`cat /etc/pve/qemu-server/$vmid.conf|grep -E '^ide[0-9]|^scsi[0-9]|^sata[0-9]'|awk -F ":" '{print $1" "$2$3"\r\n"}'`
  2898. disks=`ls -alh /dev/disk/by-id|sed '/\.$/d'|sed '/^$/d'|awk 'NR>1{print $9" "$11" OFF"}'|sed 's/\.\.\///g'|sed '/wwn/d'|sed '/^dm/d'|sed '/lvm/d'|sed '/nvme-nvme/d'`
  2899. d=$(whiptail --title " PveTools Version : 2.2.5 " --checklist "
  2900. disk list:
  2901. 已添加的硬盘:
  2902. $(cat /etc/pve/qemu-server/$vmid.conf|grep -E '^ide[0-9]|^scsi[0-9]|^sata[0-9]'|awk -F ":" '{print $1" "$2" "$3}')
  2903. -----------------------
  2904. Choose disk:
  2905. 选择硬盘:" 30 90 10 \
  2906. $(echo $disks) \
  2907. 3>&1 1>&2 2>&3)
  2908. exitstatus=$?
  2909. t=$(whiptail --title " PveTools Version : 2.2.5 " --menu "
  2910. Choose disk type:
  2911. 选择硬盘接口类型:" 20 60 10 \
  2912. "sata" "vm sata type" \
  2913. "scsi" "vm scsi type" \
  2914. "ide" "vm ide type" \
  2915. 3>&1 1>&2 2>&3)
  2916. exits=$?
  2917. if [ $exitstatus = 0 ] && [ $exits = 0 ]; then
  2918. did=`qm config $vmid|sed -n '/^'$t'/p'|awk -F ':' '{print $1}'|sort -u -r|grep '[0-9]*$' -o|awk 'NR==1{print $0}'`
  2919. if [ $did ];then
  2920. did=$((did+1))
  2921. else
  2922. did=0
  2923. fi
  2924. #d=`ls -alh /dev/disk/by-id|grep $d|awk 'NR==1{print $9}'`
  2925. d=`echo $d|sed 's/\"//g'`
  2926. for i in $d
  2927. do
  2928. if [ `cat /etc/pve/qemu-server/$vmid.conf|grep $i|wc -l` = 0 ];then
  2929. #if [ $t = "ide" ] && [ `echo $i|grep "nvme"|wc -l` -gt 0 ];then
  2930. if [ $t = "ide" ] && [ $did -gt 3 ];then
  2931. whiptail --title "Warnning" --msgbox "ide is greate then 3.
  2932. ide的类型已经超过3个,请重选其他类型!" 10 60
  2933. else
  2934. qm set $vmid --$t$did /dev/disk/by-id/$i
  2935. fi
  2936. sleep 1
  2937. did=$((did+1))
  2938. fi
  2939. done
  2940. whiptail --title "Success" --msgbox "Done.
  2941. 配置完成" 10 60
  2942. chQmdisk
  2943. else
  2944. chQmdisk
  2945. fi
  2946. fi
  2947. if [ $1 = 'rm' ];then
  2948. disks=`qm config $vmid|grep -E '^ide[0-9]|^scsi[0-9]|^sata[0-9]'|awk -F ":" '{print $1" "$2$3" OFF"}'`
  2949. d=$(whiptail --title " PveTools Version : 2.2.5 " --checklist "
  2950. Choose disk:
  2951. 选择硬盘:" 20 90 10 \
  2952. $(echo $disks) \
  2953. 3>&1 1>&2 2>&3)
  2954. exitstatus=$?
  2955. if [ $exitstatus = 0 ]; then
  2956. for i in $d
  2957. do
  2958. i=`echo $i|sed 's/\"//g'`
  2959. qm set $vmid --delete $i
  2960. done
  2961. whiptail --title "Success" --msgbox "Done.
  2962. 配置完成" 10 60
  2963. chQmdisk
  2964. else
  2965. chQmdisk
  2966. fi
  2967. fi
  2968. else
  2969. chQmdisk
  2970. fi
  2971. fi
  2972. }
  2973. if [ $L = "en" ];then
  2974. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Config qm set disks:" 25 60 15 \
  2975. "a" "set disk to vm." \
  2976. "b" "unset disk to vm." \
  2977. 3>&1 1>&2 2>&3)
  2978. else
  2979. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "配置qm set 物理硬盘给虚拟机:" 25 60 15 \
  2980. "a" "添加硬盘给虚拟机。" \
  2981. "b" "删除虚拟机里的硬盘。" \
  2982. 3>&1 1>&2 2>&3)
  2983. fi
  2984. exitstatus=$?
  2985. if [ $exitstatus = 0 ]; then
  2986. case "$x" in
  2987. a )
  2988. clear
  2989. confDisk add
  2990. ;;
  2991. b )
  2992. clear
  2993. confDisk rm
  2994. esac
  2995. fi
  2996. }
  2997. manyTools(){
  2998. clear
  2999. nMap(){
  3000. clear
  3001. if [ ! -f "/usr/bin/nmap" ];then
  3002. apt-get install nmap -y
  3003. fi
  3004. map=$(whiptail --title "nmap tools." --inputbox "
  3005. Input the Ip address.(192.168.1.0/24)
  3006. 输入局域网ip地址段。(例子:192.168.1.0/24)
  3007. " 10 60 \
  3008. "" \
  3009. 3>&1 1>&2 2>&3)
  3010. exitstatus=$?
  3011. if [ $exitstatus = 0 ]; then
  3012. while [ true ]
  3013. do
  3014. if [ ! `echo $map|grep "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\/[0-9]*$"` ];then
  3015. whiptail --title "Warnning" --msgbox "
  3016. Wrong format!!! input again:
  3017. 格式不对!!!请重新输入:
  3018. " 10 60
  3019. nMap
  3020. else
  3021. break
  3022. fi
  3023. done
  3024. maps=`nmap -sP $map`
  3025. whiptail --title "nmap tools." --msgbox "
  3026. $maps
  3027. " --scrolltext 30 60
  3028. else
  3029. manyTools
  3030. fi
  3031. }
  3032. setDns(){
  3033. clear
  3034. dname=`cat /etc/resolv.conf|grep 'nameserver'`
  3035. if [ `cat /etc/resolv.conf|grep 'nameserver'|wc -l` != 0 ];then
  3036. if [ $L = "en" ];then
  3037. d=$(whiptail --title " PveTools Version : 2.2.5 " --menu "DNS - Many Tools:
  3038. Detect exist nameserver,Please choose:
  3039. " 25 60 15 \
  3040. "a" "Add nameserver." \
  3041. "b" "Replace nameserver." \
  3042. 3>&1 1>&2 2>&3)
  3043. else
  3044. d=$(whiptail --title " PveTools Version : 2.2.5 " --menu "DNS - 常用的工具:
  3045. 检测到已经配置有dns服务器: \
  3046. $(for i in $dname;do echo $i ;done) \
  3047. ------------------------------ \
  3048. 请选择以下操作:
  3049. " 25 60 15 \
  3050. "a" "添加dns." \
  3051. "b" "替换dns." \
  3052. 3>&1 1>&2 2>&3)
  3053. fi
  3054. exitstatus=$?
  3055. if [ $exitstatus != 0 ]; then
  3056. manyTools
  3057. fi
  3058. fi
  3059. if [ $L = "en" ];then
  3060. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "DNS - Many Tools:" 25 60 15 \
  3061. "a" "8.8.8.8(google)." \
  3062. "b" "223.5.5.5(alidns)." \
  3063. 3>&1 1>&2 2>&3)
  3064. else
  3065. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "DNS - 常用的工具:" 25 60 15 \
  3066. "a" "8.8.8.8(谷歌)." \
  3067. "b" "223.5.5.5(阿里)." \
  3068. 3>&1 1>&2 2>&3)
  3069. fi
  3070. exitstatus=$?
  3071. if [ $exitstatus = 0 ]; then
  3072. case "$x" in
  3073. a )
  3074. dn="8.8.8.8"
  3075. case "$d" in
  3076. b )
  3077. echo "nameserver 8.8.8.8" > /etc/resolv.conf
  3078. esac
  3079. echo "nameserver 8.8.8.8" >> /etc/resolv.conf
  3080. ;;
  3081. b )
  3082. dn="223.5.5.5"
  3083. case "$d" in
  3084. b )
  3085. echo "nameserver 223.5.5.5" > /etc/resolv.conf
  3086. esac
  3087. echo "nameserver 223.5.5.5" >> /etc/resolv.conf
  3088. ;;
  3089. esac
  3090. if [ `cat /etc/resolv.conf | grep ${dn}|wc -l` != 0 ];then
  3091. whiptail --title "Success" --msgbox "Done.
  3092. 配置完成。" 10 60
  3093. manyTools
  3094. else
  3095. whiptail --title "Warnning" --msgbox "Unsuccess.Please retry.
  3096. 配置未成功。请重试。" 10 60
  3097. setDns
  3098. fi
  3099. else
  3100. manyTools
  3101. fi
  3102. }
  3103. freeMemory(){
  3104. clear
  3105. if(whiptail --title "Free memory" --yesno "Free memory?
  3106. 释放内存?" 10 60 );then
  3107. sync
  3108. sync
  3109. sync
  3110. echo 3 > /proc/sys/vm/drop_caches
  3111. echo 0 > /proc/sys/vm/drop_caches
  3112. whiptail --title "Success" --msgbox "Done." 10 60
  3113. else
  3114. manyTools
  3115. fi
  3116. }
  3117. speedTest(){
  3118. op=`pwd`
  3119. cd ~
  3120. git clone https://github.com/sivel/speedtest-cli.git
  3121. chmod +x ~/speedtest-cli/speedtest.py
  3122. python ~/speedtest-cli/speedtest.py
  3123. echo "Enter to continue."
  3124. cd $op
  3125. read x
  3126. }
  3127. bbr(){
  3128. op=`pwd`
  3129. if [ ! -d "/opt/bbr" ];then
  3130. mkdir /opt/bbr
  3131. fi
  3132. cp ./plugins/tcp.sh /opt/bbr
  3133. cd /opt/bbr
  3134. ./tcp.sh
  3135. cd $op
  3136. }
  3137. v2ray(){
  3138. op=`pwd`
  3139. cd ~
  3140. git clone https://github.com/ivanhao/ivan-v2ray
  3141. chmod +x ~/ivan-v2ray/install.sh
  3142. ~/ivan-v2ray/install.sh
  3143. echo "Enter to continue."
  3144. cd $op
  3145. read x
  3146. }
  3147. vbios(){
  3148. echo "..."
  3149. if(whiptail --title "vbios tools" --yesno "get vbios?
  3150. 提取显卡?" 10 60 );then
  3151. cd ..
  3152. git clone https://github.com/ivanhao/envytools
  3153. cd envytools
  3154. apt-get install cmake flex libpciaccess-dev bison libx11-dev libxext-dev libxml2-dev libvdpau-dev python3-dev cython3 pkg-config
  3155. cmake .
  3156. make
  3157. make install
  3158. nvagetbios -s prom > vbios.bin
  3159. cd ..
  3160. git clone https://github.com/awilliam/rom-parser
  3161. cd rom-parser
  3162. make
  3163. ./rom-parser ../envytools/vbios.bin
  3164. sleep 5
  3165. if [ `rom-parser ../envytools/vbios.bin|grep Error|wc -l` = 0 ];then
  3166. cp ../envytools/vbios.bin /usr/share/kvm/
  3167. whiptail --title "Success" --msgbox "Done.see vbios in '/usr/share/kvm/vbios.bin'
  3168. 提取显卡vbios成功,文件在'/usr/share/kvm/vbios.bin',可以直接在配置文件中添加romfile=vbios.bin" 10 60
  3169. else
  3170. whiptail --title "Warnning" --msgbox "Room parse error.
  3171. 提取显卡vbios失败。" 10 60
  3172. fi
  3173. fi
  3174. manyTools
  3175. }
  3176. folder2ram(){
  3177. if [ $L = "en" ];then
  3178. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "folder2ram:" 25 60 15 \
  3179. "a" "install" \
  3180. "b" "Uninstall" \
  3181. 3>&1 1>&2 2>&3)
  3182. else
  3183. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "USB设备做为系统盘的优化:" 25 60 15 \
  3184. "a" "安装。" \
  3185. "b" "卸载。" \
  3186. 3>&1 1>&2 2>&3)
  3187. fi
  3188. exitstatus=$?
  3189. if [ $exitstatus = 0 ]; then
  3190. case "$x" in
  3191. a )
  3192. if(whiptail --title "vbios tools" --yesno "install folder2ram to optimaz USB OS storage?
  3193. 安装USB设备做为系统盘的优化?" 10 60 );then
  3194. wget https://raw.githubusercontent.com/ivanhao/pve-folder2ram/master/install.sh -O -| bash
  3195. whiptail --title "Success" --msgbox "Done. \
  3196. 配置完成" 10 60
  3197. fi
  3198. ;;
  3199. b )
  3200. if(whiptail --title "vbios tools" --yesno "uninstall folder2ram optimaz?
  3201. 卸载USB设备做系统盘的优化?" 10 60 );then
  3202. wget https://raw.githubusercontent.com/ivanhao/pve-folder2ram/master/uninstall.sh -O -| bash
  3203. whiptail --title "Success" --msgbox "Done. \
  3204. 配置完成" 10 60
  3205. fi
  3206. ;;
  3207. esac
  3208. fi
  3209. manyTools
  3210. }
  3211. if [ $L = "en" ];then
  3212. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Many Tools:" 25 60 15 \
  3213. "a" "Local network scans(nmap)." \
  3214. "b" "Set DNS." \
  3215. "c" "Free Memory." \
  3216. "d" "net speedtest" \
  3217. "e" "bbr\\bbr+" \
  3218. "f" "config v2ray" \
  3219. "g" "Nvida Video Card vbios" \
  3220. "h" "folder2ram" \
  3221. 3>&1 1>&2 2>&3)
  3222. else
  3223. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "常用的工具:" 25 60 15 \
  3224. "a" "局域网扫描。" \
  3225. "b" "配置DNS。" \
  3226. "c" "释放内存。" \
  3227. "d" "speedtest测速" \
  3228. "e" "安装bbr\\bbr+" \
  3229. "f" "配置v2ray" \
  3230. "g" "显(N)卡vbios提取" \
  3231. "h" "USB设备做为系统盘的优化" \
  3232. 3>&1 1>&2 2>&3)
  3233. fi
  3234. exitstatus=$?
  3235. if [ $exitstatus = 0 ]; then
  3236. case "$x" in
  3237. a )
  3238. nMap
  3239. ;;
  3240. b )
  3241. setDns
  3242. ;;
  3243. c )
  3244. freeMemory
  3245. ;;
  3246. d )
  3247. speedTest
  3248. ;;
  3249. e )
  3250. bbr
  3251. ;;
  3252. f )
  3253. v2ray
  3254. ;;
  3255. g )
  3256. vbios
  3257. ;;
  3258. h|H )
  3259. folder2ram
  3260. ;;
  3261. esac
  3262. fi
  3263. }
  3264. chNFS(){
  3265. if [ $L = "en" ];then
  3266. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "NFS:" 25 60 15 \
  3267. "a" "Install nfs server." \
  3268. 3>&1 1>&2 2>&3)
  3269. else
  3270. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "NFS:" 25 60 15 \
  3271. "a" "安装NFS服务器。" \
  3272. 3>&1 1>&2 2>&3)
  3273. fi
  3274. exitstatus=$?
  3275. if [ $exitstatus = 0 ]; then
  3276. case "$x" in
  3277. a )
  3278. if(whiptail --title "Yes/No" --yesno "Comfirm?
  3279. 是否安装?" 10 60)then
  3280. apt-get install nfs-kernel-server
  3281. whiptail --title "OK" --msgbox "Complete.If you use zfs use 'zfs set sharenfs=on <zpool> to enable NFS.'
  3282. 安装配置完成。如果你使用zfs,执行'zfs set sharenfs=on <zpool>来开启NFS。" 10 60
  3283. else
  3284. chNFS
  3285. fi
  3286. ;;
  3287. esac
  3288. fi
  3289. }
  3290. sambaOrNfs(){
  3291. if [ $L = "en" ];then
  3292. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Samba or NFS:" 25 60 15 \
  3293. "a" "samba." \
  3294. "b" "NFS" \
  3295. 3>&1 1>&2 2>&3)
  3296. else
  3297. x=$(whiptail --title " PveTools Version : 2.2.5 " --menu "Samba or NFS:" 25 60 15 \
  3298. "a" "samba." \
  3299. "b" "NFS" \
  3300. 3>&1 1>&2 2>&3)
  3301. fi
  3302. exitstatus=$?
  3303. if [ $exitstatus = 0 ]; then
  3304. case "$x" in
  3305. a )
  3306. chSamba
  3307. ;;
  3308. b )
  3309. chNFS
  3310. esac
  3311. fi
  3312. }
  3313. omvInPve(){
  3314. if(whiptail --title "Yes/No" --yesno "Install omv in proxmox ve directlly?
  3315. 将要在proxmox ve中直接安装omv,请确认是否继续:" 10 60);then
  3316. if [ -f "/usr/sbin/omv-engined" ];then
  3317. if(whiptail --title "Yes/No" --yesno "Already installed omv in proxmox ve.Reinstall?
  3318. 已经检测到安装了omv,请确认是否重装?" 10 60);then
  3319. echo "reinstalling..."
  3320. else
  3321. main
  3322. fi
  3323. fi
  3324. apt-get -y install git
  3325. cd ~
  3326. git clone https://github.com/ivanhao/omvinpve
  3327. cd omvinpve
  3328. ./OmvInPve.sh
  3329. main
  3330. else
  3331. main
  3332. fi
  3333. }
  3334. ConfBackInstall(){
  3335. path(){
  3336. x=$(whiptail --title "config path" --inputbox "Input backup path:
  3337. 输入备份路径:" 10 60 3>&1 1>&2 2>&3)
  3338. exitstatus=$?
  3339. if [ $exitstatus = 0 ];then
  3340. if [ ! -d $x ];then
  3341. whiptail --title "Warnning" --msgbox "Path not found." 10 60
  3342. path
  3343. fi
  3344. else
  3345. main
  3346. fi
  3347. }
  3348. count(){
  3349. y=$(whiptail --title "config backup number" --inputbox "Input backup last number:
  3350. 输入保留备份数量:" 10 60 3>&1 1>&2 2>&3)
  3351. exitstatus=$?
  3352. if [ $exitstatus = 0 ];then
  3353. if [ ! `echo $y|grep '^[0-9]$'` ];then
  3354. whiptail --title "warnning" --msgbox "Invalid content,retry!" 10 60
  3355. count
  3356. fi
  3357. else
  3358. main
  3359. fi
  3360. }
  3361. path
  3362. count
  3363. x=$x'/pveConfBackup'
  3364. if [ ! -d $x ];then
  3365. mkdir $x
  3366. fi
  3367. if [ ! -d $x/`date '+%Y%m%d'` ];then
  3368. mkdir $x/`date '+%Y%m%d'`
  3369. fi
  3370. cp -rf /etc/pve/qemu-server/* $x/`date '+%Y%m%d'`/
  3371. d=`ls -l $x|awk 'NR>1{print $9}'|wc -l`
  3372. while [ $d -gt $y ]
  3373. do
  3374. rm -rf $x'/'`ls -l $x|awk 'NR>1{print $9}'|head -n 1`
  3375. d=`ls -l $x|awk 'NR>1{print $9}'|wc -l`
  3376. done
  3377. cat << EOF > /usr/bin/pveConfBackup
  3378. #!/bin/bash
  3379. x='$x'
  3380. y=$y
  3381. if [ ! -d $x/`date '+%Y%m%d'` ];then
  3382. mkdir $x/`date '+%Y%m%d'`
  3383. fi
  3384. cp -r /etc/pve/qemu-server/* $x/\`date '+%Y%m%d'\`/
  3385. d=\`ls -l $x|awk 'NR>1{print \$9}'|wc -l\`
  3386. while [ \$d -gt \$y ]
  3387. do
  3388. rm -rf $x/\`ls -l $x|awk 'NR>1{print \$9}'|head -n 1\`
  3389. d=\`ls -l $x|awk 'NR>1{print \$9}'|wc -l\`
  3390. done
  3391. EOF
  3392. chmod +x /usr/bin/pveConfBackup
  3393. sed -i '/pveConfBackup/d' /etc/crontab
  3394. echo "0 0 * * * root /usr/bin/pveConfBackup" >> /etc/crontab
  3395. systemctl restart cron
  3396. whiptail --title "success" --msgbox "Install complete." 10 60
  3397. main
  3398. }
  3399. ConfBackUninstall(){
  3400. if [ `cat /etc/crontab|grep pveConfBackup|wc -l` -gt 0 ];then
  3401. sed -i '/pveConfBackup/d' /etc/crontab
  3402. rm -rf /usr/bin/pveConfBackup
  3403. whiptail --title "success" --msgbox "Uninstall complete." 10 60
  3404. else
  3405. whiptail --title "warnning" --msgbox "No installration found." 10 60
  3406. fi
  3407. main
  3408. }
  3409. ConfBack(){
  3410. OPTION=$(whiptail --title " pve vm config backup " --menu "
  3411. auto backup /etc/pve/qemu-server path's conf files.
  3412. 自动备份/etc/pve/qemu-server路径下的conf文件
  3413. Select: " 25 60 15 \
  3414. "a" "Install. 安装" \
  3415. "b" "Uninstall. 卸载" \
  3416. 3>&1 1>&2 2>&3)
  3417. exitstatus=$?
  3418. if [ $exitstatus = 0 ]; then
  3419. case "$OPTION" in
  3420. a | A )
  3421. ConfBackInstall
  3422. ;;
  3423. b | B)
  3424. ConfBackUninstall
  3425. ;;
  3426. * )
  3427. ConfBack
  3428. esac
  3429. fi
  3430. }
  3431. #----------------------functions--end------------------#
  3432. #--------------------------function-main-------------------------#
  3433. # "a" "无脑模式" \
  3434. # a )
  3435. # if (whiptail --title "Test Yes/No Box" --yesno "Choose between Yes and No." 10 60) then
  3436. # whiptail --title "OK" --msgbox "OK" 10 60
  3437. # else
  3438. # whiptail --title "OK" --msgbox "OK" 10 60
  3439. # fi
  3440. # sleep 3
  3441. # main
  3442. # ;;
  3443. # b )
  3444. # echo "b"
  3445. # ;;
  3446. # c )
  3447. # echo "c"
  3448. # ;;
  3449. main(){
  3450. clear
  3451. if [ $L = "en" ];then
  3452. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "
  3453. Github: https://github.com/ivanhao/pvetools
  3454. Please choose:" 25 60 15 \
  3455. "b" "Config apt source(change to ustc.edu.cn and so on)." \
  3456. "c" "Install & config samba or NFS." \
  3457. "d" "Install mailutils and config root email." \
  3458. "e" "Config zfs_arc_max & Install zfs-zed." \
  3459. "f" "Install & config VIM." \
  3460. "g" "Install cpufrequtils to save power." \
  3461. "h" "Config hard disks to spindown." \
  3462. "i" "Config PCI hardware pass-thrugh." \
  3463. "j" "Config web interface to display sensors data." \
  3464. "k" "Config enable Nested virtualization." \
  3465. "l" "Remove subscribe notice." \
  3466. "m" "Config chroot & docker etc." \
  3467. "n" "Many tools." \
  3468. "p" "Auto backup vm conf file." \
  3469. "u" "Upgrade this script to new version." \
  3470. "L" "Change Language." \
  3471. 3>&1 1>&2 2>&3)
  3472. else
  3473. OPTION=$(whiptail --title " PveTools Version : 2.2.5 " --menu "
  3474. Github: https://github.com/ivanhao/pvetools
  3475. 请选择相应的配置:" 25 60 15 \
  3476. "b" "配置apt国内源(更换为ustc.edu.cn,去除企业源等)" \
  3477. "c" "安装配置samba或NFS" \
  3478. "d" "安装配置root邮件通知" \
  3479. "e" "安装配置zfs最大内存及zed通知" \
  3480. "f" "安装配置VIM" \
  3481. "g" "安装配置CPU省电" \
  3482. "h" "安装配置硬盘休眠" \
  3483. "i" "配置PCI硬件直通" \
  3484. "j" "配置pve的web界面显示传感器温度" \
  3485. "k" "配置开启嵌套虚拟化" \
  3486. "l" "去除订阅提示" \
  3487. "m" "配置chroot环境和docker等" \
  3488. "n" "常用的工具" \
  3489. "p" "自动备份虚拟机conf文件" \
  3490. "u" "升级该pvetools脚本到最新版本" \
  3491. "L" "Change Language" \
  3492. 3>&1 1>&2 2>&3)
  3493. fi
  3494. exitstatus=$?
  3495. if [ $exitstatus = 0 ]; then
  3496. case "$OPTION" in
  3497. a )
  3498. echo "Not support!Please choose other options."
  3499. echo "本版本已不支持无脑更新,请选择具体项目进行操作!"
  3500. sleep 3
  3501. main
  3502. chSource wn
  3503. chSamba wn
  3504. chMail wn
  3505. # chZfs wn
  3506. chVim wn
  3507. # chCpu wn
  3508. chSpindown wn
  3509. chNestedV wn
  3510. chSubs wn
  3511. chSensors wn
  3512. echo "Config complete!Back to main menu 5s later."
  3513. echo "已经完成配置!5秒后返回主界面。"
  3514. echo "5"
  3515. sleep 1
  3516. echo "4"
  3517. sleep 1
  3518. echo "3"
  3519. sleep 1
  3520. echo "2"
  3521. sleep 1
  3522. echo "1"
  3523. sleep 1
  3524. main
  3525. ;;
  3526. b )
  3527. chSource
  3528. main
  3529. ;;
  3530. c )
  3531. sambaOrNfs
  3532. main
  3533. ;;
  3534. d )
  3535. chMail
  3536. main
  3537. ;;
  3538. e )
  3539. chZfs
  3540. main
  3541. ;;
  3542. f )
  3543. chVim
  3544. main
  3545. ;;
  3546. g )
  3547. chCpu
  3548. main
  3549. ;;
  3550. h )
  3551. chSpindown
  3552. main
  3553. ;;
  3554. i )
  3555. #echo "not support yet."
  3556. chPassth
  3557. main
  3558. ;;
  3559. j )
  3560. chSensors
  3561. sleep 2
  3562. main
  3563. ;;
  3564. k )
  3565. clear
  3566. chNestedV
  3567. main
  3568. ;;
  3569. l )
  3570. chSubs
  3571. main
  3572. ;;
  3573. m )
  3574. chRoot
  3575. main
  3576. ;;
  3577. n )
  3578. manyTools
  3579. main
  3580. ;;
  3581. o )
  3582. omvInPve
  3583. ;;
  3584. p )
  3585. ConfBack
  3586. ;;
  3587. u )
  3588. git pull
  3589. echo "Now go to main interface:"
  3590. echo "即将回主界面。。。"
  3591. echo "3"
  3592. sleep 1
  3593. echo "2"
  3594. sleep 1
  3595. echo "1"
  3596. sleep 1
  3597. ./pvetools.sh
  3598. ;;
  3599. L )
  3600. if (whiptail --title "Yes/No Box" --yesno "Change Language?
  3601. 修改语言?" 10 60);then
  3602. if [ $L = "zh" ];then
  3603. L="en"
  3604. else
  3605. L="zh"
  3606. fi
  3607. main
  3608. #main $L
  3609. fi
  3610. ;;
  3611. exit | quit | q )
  3612. exit
  3613. ;;
  3614. esac
  3615. else
  3616. exit
  3617. fi
  3618. }
  3619. #----------------------functions--end------------------#
  3620. #if [ `export|grep "zh_CN"|wc -l` = 0 ];then
  3621. # L="en"
  3622. #else
  3623. # L="zh"
  3624. #fi
  3625. #--------santa-start--------------
  3626. DrawTriangle() {
  3627. a=$1
  3628. color=$[RANDOM%7+31]
  3629. if [ "$a" -lt "8" ] ;then
  3630. b=`printf "%-${a}s\n" "0" |sed 's/\s/0/g'`
  3631. c=`echo "(31-$a)/2"|bc`
  3632. d=`printf "%-${c}s\n"`
  3633. echo "${d}`echo -e "\033[1;5;${color}m$b\033[0m"`"
  3634. elif [ "$a" -ge "8" -a "$a" -le "21" ] ;then
  3635. e=$[a-8]
  3636. b=`printf "%-${e}s\n" "0" |sed 's/\s/0/g'`
  3637. c=`echo "(31-$e)/2"|bc`
  3638. d=`printf "%-${c}s\n"`
  3639. echo "${d}`echo -e "\033[1;5;${color}m$b\033[0m"`"
  3640. fi
  3641. }
  3642. DrawTree() {
  3643. e=$1
  3644. b=`printf "%-3s\n" "|" | sed 's/\s/|/g'`
  3645. c=`echo "($e-3)/2"|bc`
  3646. d=`printf "%-${c}s\n" " "`
  3647. echo -e "${d}${b}\n${d}${b}\n${d}${b}\n${d}${b}\n${d}${b}\n${d}${b}"
  3648. echo " Merry Cristamas!"
  3649. }
  3650. Display(){
  3651. for i in `seq 1 2 31`; do
  3652. [ "$i"="21" ] && DrawTriangle $i
  3653. if [ "$i" -eq "31" ];then
  3654. DrawTree $i
  3655. fi
  3656. done
  3657. }
  3658. if [[ `date +%m%d` = 1224 || `date +%m%d` = 1225 ]] && [ ! -f '/tmp/santa' ];then
  3659. for i in {1..6}
  3660. do
  3661. Display
  3662. sleep 1
  3663. clear
  3664. done
  3665. touch /tmp/santa
  3666. fi
  3667. #--------santa-end--------------
  3668. if (whiptail --title "Language" --yes-button "中文" --no-button "English" --yesno "Choose Language:
  3669. 选择语言:" 10 60) then
  3670. L="zh"
  3671. else
  3672. L="en"
  3673. fi
  3674. main