From 50c949d1dc452ceed91c36778709bb08fe9a2f2d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 17 Mar 2022 00:24:18 +0100 Subject: [PATCH 001/183] readme: update README.md Signed-off-by: Dominik Willner th33xitus@gmail.com --- README.md | 10 ++++++++-- resources/screenshots/kiauh.png | Bin 32425 -> 18243 bytes 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c48d147..01dadc4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ -![main_menu](resources/screenshots/kiauh.png) +![kiauh-logo](resources/screenshots/kiauh.png) # Klipper Installation And Update Helper -![GitHub](https://img.shields.io/github/license/th33xitus/kiauh) ![GitHub Repo stars](https://img.shields.io/github/stars/th33xitus/kiauh) ![GitHub forks](https://img.shields.io/github/forks/th33xitus/kiauh) ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/th33xitus/kiauh) ![GitHub last commit](https://img.shields.io/github/last-commit/th33xitus/kiauh) ![GitHub contributors](https://img.shields.io/github/contributors/th33xitus/kiauh) +![GitHub](https://img.shields.io/github/license/th33xitus/kiauh) +![GitHub Repo stars](https://img.shields.io/github/stars/th33xitus/kiauh) +![GitHub forks](https://img.shields.io/github/forks/th33xitus/kiauh) +![GitHub top language](https://img.shields.io/github/languages/top/th33xitus/kiauh?logo=gnubash&logoColor=white) +![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/th33xitus/kiauh) +![GitHub last commit](https://img.shields.io/github/last-commit/th33xitus/kiauh) +![GitHub contributors](https://img.shields.io/github/contributors/th33xitus/kiauh) ### **📋 Please see the [Changelog](docs/changelog.md) for possible important information !** diff --git a/resources/screenshots/kiauh.png b/resources/screenshots/kiauh.png index 7c1b9789906ed540177e410a19dbf8476a727f1c..dadb5e2c9e8b06fd6b3f214617b6f21be070d3b2 100644 GIT binary patch delta 17139 zcma&OWmH^U&?VexaJS%Y!QCymg)|<5ySoItH~|ve-3gH35(us#xVyW%+jpP$TeD_< z&6*!g!|m=Pb*pymI=ze1XPEA27^(<0RXKDNViX7jg03Jh4TV5pz+WNtNQmIiDp)GK zI4VL|gvL0bZ;bqGoUEoC92}JVf@~%n76K;bf-IC=99*32oLuZ20<4^ZLY$mJTwK-1 z6EG;;tepHB92`QN{0RfFH2>$HH?ZooeB8#SCVb``tj5N?W~|2iJf^J10{mR8=KQ97 z#(XB`;56K|_Hf293Aph1aIVH439RtsGXF21qNa3plksp9^0YE{5TyoJ$HmI=ztKM;&7Lp-Zvgy&8)%0>B)Jr%B{jS< zkFz{~lWS((iSG^#Ee;+(7h}Q3(O%KR8q0XAN8-J!V3bL5pT=L-|C7)1M_h;HNb#dK zHlbQ9y(SWo6h00PW#R74#meIiANTHUf6FQBfQk!lJU>7G<(KRX2FDCRSBsHb-^F`! zPRkKe$fr-Ae*6M{nHw1em{fo5-=xBcU>V~%zB1zY%}9zd%Arz=aRx`g#>S?Oj{f(c zSu9qWp1&AcYH7dd&l4yAlMxSvC`?jcpDZ{y*v;J?CfCtFL@F;}_E5Cy*RSJ@PNOrf z_SFx0YLq#nG(|tJ5So7fJ|db9mCB>Ti6H%~t?lW-m+^cH$kV!L%gOb7Ufw?mX8^k8 zrKK>Gq!=_sw0J0fCL@`GG4QZ~-O7`+IiseFd{SQ{4I`qW2BT?0IvVUzLSdzlr1HkP znwy*7u?&7PWFbhwkCKTWpyiN->@};px?b`xEG+n&q!(w8?#f|k$sz}`(kUup!RAf* z*p?#vgSEo~V4cjrMGdkQhsG%MlbuSzk3*!QF;>*!nyS!TD&f3_oKZIiGse2>h6fhLLy;;N)~_MVfT6QQ0$Ibr7@cvb zp3h@O77?LE4xziZ*Bq}1k38m${_HWKfmfbrnzDzry}doD+n8iK5@IlF&HT~c+8Y#d z%xozj@NHI>1_RDsa;O>#3{is$M@A8ITF;dGL?`7$Lt{lRs+vOR4C8t0s)S>l5mHEQ zAu`exeZ)$>F=nu+8BI%t%GyRvIioGCL8Uf)aOaE;i${*fnB<#baK7i$nqkAf2_BwF zGc8Mo7vJober}W36hD~aVydKkp*YIZ^H=}_eoUp-Y%E5U`$wHrIriNL4hg~^iLkg; zN`Q>o7c9xZ75eH&Jmw-Sa&08ggP23GQi~&2PYq)Sw@>1mD{^*kAFKImH(8mizxJMO zUv9OmL|`J~@uI8GS`!m>=rJ1Y;}V?_lz#)+*g2+RnyCh%QSt<}s+q`tIUO*FFzI_gryfI}7|blQ=8tz#?lsU%72b zTO2E1*gqn7jm{EDT7QWH?P8<5$3U~E#H*HA+u4a|K0LoX_Y1v1?3m7XFQXd)oB?sz zs?ZK?Mgi==VHJoTRe|cB6Es>B0gw;;8E^C_TLScv2&^EfJPAsyIm7hgw`q*sA8I|6 zZ?&WZR3(ZUNH<|aI-|c_<2wk9^_ufj74`58e>HoD(nPm?)9r1_XbYqF7@FR}|9f~d z0vaD%4gqb&R%jMPMQ@++dEiido|eLTktQxE!WWU*xL_{&*|6A*Y0h~O7{+jOp7;BK zjP5&J^Y`Jo5EkZ}iSwU?Dhu7zbXjUr*$fFIq{@z?k8{pgFUNNjWdA&6b0JyN+mcX4Vu z#(9x8LD!KWs{D!kg#u{>bZAenYx3%o@{QL9-*wdrcIhaZNb9bJQVihFmQV$=LjlxhEaSi|wJk&5 zI4YR735ijrpNUfPyTXi1^Q+(us?~?d4Uu@q4wD@JbCe&7D)BB2UO0sL9%2`m^`@pM zjtzl}Qt_Z;1o#~JAD-2`XXCS8)bk`hLNd4SU~H%A19mnxpxADH`MtuRu^!=@y(`UI zKY#vw^Qk9O(Dfm(S#%i-1eQqdTugNI<9*rxR!!xWGul|PxVEuT6Yk{s;N(0X?u-E5 zC$S-nUdZy-z^K8MKqv}TkB8?~dLo38;zwmA5YuHg;ja&lD===AXvGt$yD(@66v&Uy0VIBVeLgF^xn)uu+(~9Tc!F2hTr}O^Oii(wkTLybrd8UY76X5FR z#-$sbzslqI6Ls8QHrwBzIegwT$%v5e9@UQS)C{uGBq`e8@(XXlPq~v-&JJ$Ih>w(M zmSai%j+P`$Vd`6Ia*dEJNO(BGkb|*XEN*MduD6|?n48-}fq*XuK_gF29Ka;OM+TTW zUqZl*8h?gatBIlMBWzjj&j<7zI3X#11f~01lg>5oo$a=#^2g~yh|^=618Yiv#6f%r z+aqndL+sviz*x|b@OAgpkPwk0M^AD4b5i}Ns6=i9jLL29)D~agyq+^chZ$Da{KF7e zb>tU`T%YHn=fTemdn;jBL04mt>EkypBbdP8kZH68)0q3%w@R1SS)lD7YI{pu`pk^z z^3-zlA>15+6eVw#6!VChB|}8Ef!$oI^W+n|+1rA2`!f~m%-Nvax|d6)El!WORbh|F8q>yldSUt@ zQ)&$gE#+|PfwLv*Luv9bd`Mx5fkah} z@+IESZ%FXmZYSppOkS97>O9QKUAO4ZFDGI_?&wETCnZvpp|mSa$aL_v(Yn%uoeUeO znzbjPa$jzN$`4o-(HrP840y^u#8kXPQptI3FcuWv)C@1(v)0)Fhtlcq@9i(QjbC~A zDC@Gkc$A9MgX}XbCO-O_9;Ou7?V8^oHXzGFh%rRsJzp-?>PB5bHxPh_&JxX4!5IDs z8}xr^C-r_w+e+YQ!M2Nv^Fy5ocA5(*!ik?tW6}N^4$^Z)Sc`=D-d^YNuqj&kgu@u?jml z=L;KfXPZ1Zj(s7~!^N4xO~E%AQ@n`$4u#F`7}`(9OmeDUehDA*-a`i9 z%NFIYuGEH#;&82SP|iZ0&?@vhopvGF9e0bC+j(W~h}pUAv?3*y6h;e3kW%Y8i@5a> z)v)H~w+AQmEAtWd>GJlEIG>3T;Yj$QlVahcqGvd)s5=wa#oT`x(jg&;NMC;ellwix z>j>s4y^iVFb2800M&x2& z6z|nAQ?W1P6z#{zD1r%7MidvKC$E&eWZWtAGt&xUNwVC&ItViPe^BiPtM?fKYgp|_ zFa-9c>~NvalYG3&*Mm5|8BSYBn<-o)v2Q^ zm&6p!Cl)AaJiT__N|O0_*%Be^6{-&_x{>@tU%6;PTmkA~SLEqNEj4lQ4FDYkz)uJ$#pwg-n&ybukviMb5ig>Xy0Ej>hYT#)$P9Qa}NnsmIF_(3ZP z@dciLl}+lIbnfiJCRz0CUC=b3$JR22j(I=Dk(Ni^hlrw~Ac(9rOU3IU|4b-_LlNnE z)n8#g^YL-~&%d_UM3n1JT{=FK;HQ#ik0U-O*v(T5j-?kxd<=YN%2IOxa)Q8y2#yg#c_|#Kl zL22yDyXWGf@Bx}baUV(qj}3uN2LERtF{j>D*CR`|-Oa|=Fz$9&;k0%5P-UB*dv1bK z>q1jMq`b>>LovDTC5s0@OSpD|fKiU-$0|kGpZF!u%->BMf8n2Xtk393ku`vRS60q?~wWLyS*JvRN@M{afOcFt)^oov6zLF)~x zj=Il6v7K*_v2pr}TX~O7xb(zo(f%qxjIoq+(~YsSbm&;TpIe{+VBV-4%t;|V#X%~U zZ(Y4t$>}vt(R`gkwDSo+VU})wjq#6@rmj^P?qVi5^P**aLm}6K%H?c%M(<5Y7@i!; zU{cFVReokO*7}4n!8z7q8f`1omToo3qU`E@s?~Ul3ZeSjYdSTQ+Krv!pKQjC_A@Nd z)7S{z_e?2g{caQhGS)kZOltL*LOOYclGCsbwyrfHfoogCjjyg^GKQyHi2D`{#i=SdWxs&!js$jNE4Us$35&7nMOIX5 z6>bjHgh{hR=v_fQ8YbG=MrFHPZrJ&!VK@3prKqI2R75F{p|qr=_Q%gQx4ZQsl`&orHF{!YTsho-X!3i9<` zFsHw!<4@H$nmYD|5lWe)#YUqGVD6-DexkqYzV-?>X5kiZ8mzNtF*=FZHTLRci8g4r zmn_82|3!yeAW~qXYNAv_G4f{}V*x`){$~MP69A_w36pw{*4a$(O+xfuLqQlP_mQ+@ z(`nWl?R4u+M2&rZ92W3rx5Uo3K3IO!iiLh3He4NvvwEM}o$Q@sLd5lV z+?o+V31V_uz48Ax%8?dmfT-0T)GvNQV~0z;OZFXEC$xs1TCHI_RhTY(Z)F5Dh!ZIw zbguKQF{cG}HI-ThDkX$CPS6>|Ev`VXN0g>gSd4pmoL}LNSn|3!`nQMl+WE+=Kry)7 zBAEt4e%Cj9KfF7dpGuzV(5GxSxKKvU#)GaWS>t(ZK_S3h%YVe6HW{MH;_%9e6C_11 zS=SKuRxVr7!>cX}1!=ldFGhUeLR=J((j=i+eRkk0gMg4v@Z_!*495Lm z!t*^G?i{oHPWr+g*qZas36cUo>JZZvd-r9f+k9%5onx9NzY%oHO);a7NgEVk>PhIRpkD&Go)@FU&D~Muu^bniTo$#$MnwE+;cp*qK-g5PRU2iPcw~DSGGH%!8T}w^ zLADtJ?f;i5g%~m>@G4HRzEt^~c?%qrKP?jiJ@evsqA5!c3J$?{S4Wdj*QONKW&-Y{~Xz4@xI zH;=8&g;%bd1)D{9f52TXjc(~hU3 zNngu*qN6>~xo_SiE)qD{xmN%~mQV??q>h?7CQThCq&qY%5nqz`WM6#OITb?!d|@rf z{e*zLGNfK*6Y2aC#0TqCPxu^Q&wb=+##61KFxK2xKtqBLBd%EJM*JMEj;to2_{$r$ z##a^_iv}F)GCCbH${dfn(1?67sA~>g}TS`?dRks^--IKDA zTsv4Q3eekP+dMb#s7+g%B{<<8*_&e}7y$`GmJ#D!AbP%k#Qe9Z(sX+nx|Y}t>FwuR zCMijZ^{|=avL`*BH=#S%@gEre(y8wu(iF(SAf3q_yuBO=L8AKG7j7-I=ajxPN<+fl z`+)C7gSD7w(XAANjpSV&DPyy^xc})E=z$bQp0RMVh-H8bNR;Jithe>LofpUbLFTg@`!?+1SVSmwkaat+S8rq_4g%HoqO!SRDsyxobyP3Kb3r| zdMn9U;B}K+nFo`%AbX@hptJN-axX0Avq`LP{u@C)!VZsxEoAA;Zx8l1F_HPm+|hSf zfo0H{oJ+nJMmyhoYZEfEyL{g0W`{){9{!8INnmY&#Iex9W8hV7hS<$=9ykOM%(ajI zlrrw0AoG)!Y@j*8Sy&K!8S#AAlBUtlr0@#ADHc=?LSpE@WWB0mnTs5T`H6rurbv-N z0|kAI2Qy8w>iGO6iSv0$d06zCu zu(Z+G59p4Z@0k!@tn3F&9jSVH8oQWx&WVV*V+7&K_ddrkh6;uT)GLuQi-wF`7#86{ zFV)n^wo5bG6c_XQxlZdg_YHZ4lu-7!-B=&rMUdlmSE|dyneY_OJ9VtfXI|Ol?K2uJ$A=5v za9gg&2$j7^o2t#{ej%0Ajb2c&AM|14m5Y+Uu9o>b(;y2_ERLzL&CAtz^4h*W5Ne5e zGps*6e2h6V_*;hq0Tk!qyTybIe8K|jk)_Y6f{ zQGR9@+^4AAeQ`7#=;*uF;GLmC&%yn$5=g=t0@^3xLvO#R8%jU+US);kIfxvMVg6;x+A30xA!0lAvDQ9}#DN zAP8M|{LBEXN2q|al-}F5BwZ!sE=T<1X zr?Z}HYr^>mkP7srm!u-==TbS!|E}vaQD{l#$EEUSm{Ap&JR%oS@ zdFO9$LaKzOA6eL_I90=9Ul1Zg_rPzrWCJCc^pSoJ3p z+kUW6U&%kN!bRqnHzAQ_AOY}JypOOSX4;hM@(8$7K;NrY!ChpIo;z%P7G=55p>SOv z7N;YjnB+r;wyOQf8R-@O60+)l!V@MmYqS^bRD&l?d=LwzE~J6$Pif?FHg&5S3@E+g3oR_5MfkKsx1Wrw8VO8dmmnq#dd z$mNDWc6uyfHzDQ3lnyg-+08*G=A;Uw<16sq_BdWn@F*X(kFHl4k&1MYy8(OWWmy3{ zk`P?+e?Zm}yRzkLd*X@6W@G8tO}NXiw+c&;uJ~8(+efBs0yppFt0b2IySzzK`mOd0 z4Lt0h)LwWC(l0w-g+z)U2o;$wB+4AI3^nl#3(31F`ba9eaFJ+uBPz=R5qABybXmwI|!{0p@u=_IxchiRQo^a)W)o5~c+ew}DkM9>#L2FYK5W6PdtD z{X$b8Cvm-f@CkbUmlo9x{Gz1fKn_gp(uUI#(3{;_zh?WcbUJdpsG+so4;Rj`vo==5t`Y*THFCuQQJhx zQU^j!Jy@mdw1P%EnO}xP_szJf&u3%z0-K`P*3`v;NE3R6!Y}lJ2lOp@HfTA7!<#>P zR&r~l1$a5miQkmIZ$W+1^v4jK#pX$e>GypQDWuo&UAzvlV>AmJzk(*~H;vjMP1olu zs5L~SIw4HoV1K(wFi*}WE!qIyMKhoFlOK9`<|{Tv>lqF0BVHCTNLahxTe7eF z0tZ+jL`t)pKy$r&WiY9lD9G(uvA>t@L^7*U%+ThU*CMrX-Phq zznp))!`wW7qkt*I?D@8KZSMD}@NuyGdP_s(h;!2Z+=#^rvOAOQMyH{yjp|VA(uW3w z@8niud(R^sLtBi6;e9~SVDjZQjS8z3IoV>(mP=U=boYWzdI=xgc1UI-<@kmwDRp+QWs}IApONG zc=*eMDIBlga2v$#R2b?^)6ZrMv+1DX89TuiYsf(H=wQ7z-z$EWLT1j#MCHk zgb*D-y72oS6ZXzq^u|y0ME*b0?!{I<#++Q$t7sM%K_rmSV8{luX;L1DCy0i>l1K*f zZw(y*4<#{YeF?YfdaLq-UAMKX=awA1cdpg~xyV#mlBs|a*M&qr=^}?AGeNaS$(3~ zoCx5N;c@SD8U)0N{Moy+4i#>Ck@;mgU5jw%MhI;zDL%WPC8NGq#RScvrnrv!xUYYY zQhg1lQ9o;sz4B3_@GZgXk%xibg+H-PzD_UCsR-aF{w}*M=itGS>v9j%rQ;2|*$DFP z$M$wv&P`f8d?ie|doQhV-R|tSE-RC0U-_oTyw>JfM0V{Sv@QRlF@58dVK{<*`^0?} zH13FSS)&?1%RYG z6Q$LhD#G>qKpVQ5sh?MOT*MpK0UjcLmL%LT83zXvWnb@ZLfYw7$(Bnp8%y%xxgnEU z2ru{U#x;pfZ`apNPazIg1c;(Bd;yy0?HKTQbIC(?W!xXZhq!z=*HWJSgf7{E`^{vL zU_}j|QHD*hrzRZezX%7w(0?ReCFr}BEcndXuqo4T+LFsQ@ zjyxP01JX=e{Pa)?1RIX6{uCB(qNXrErQ2bPs_}&ocd$vc2+LCON{D4q=0t+0HbA@* zZB|i5gulyxB$y(~b#hY&)rX1(&@tmj%>?$oDG3}O&I-H3Czw8=7NxbW2OvljXDIZ0 zBWuX)>z*?Q+xnC)SH@|){s@aZ3J%@%4NCEM7cG4;=(=W2sC0o(M2)_KGx&rlI=)}x z!p|fJxvKmmE2d4W#_hlMU57ip0SHAk8bYS0O2LEPLjU#=eSXDo{UGF>$-(KWHvJ+d zUK!ko|Mja*Yz0UUfOfEUTg8_?y_U zkYJGoXZ4CN>QrYysl6#;=6#I$Nj`{_A+A=LjTG4d1=wccO6i@czUMAKfT1(N+OIWz zA!oT;ghap8x32fxTG~?AF%r~*RaPCTs_ZgDkwNm7_`=Ua_G>nUCG46O9Y!3W1IcI=j6Qq4A;uf>! zB=n7y@R2L6&)Wg%AvDQNparR4|NQ;Q^GFF2UakDH@cyUp^kQxzC8xCrOU}!`UuYj? z7pc(YQY(OS$&$*DrH$W;fyF+3GCG-WIuy{<7l-lL{PY#^II4Es6Q3hK${8_PGf$|g zXdbd`EFWgN(-qu6Ot9mEcuUL6$eBd70zaQgblozed(ZiSV z@u5v3f#bJFTJ3$5!NiH8J<5#a^*1=3+AH=&@i~K@I(!I3R>IP0S(w)Q@{Y#ff@#-J zvI(jhbJ-_7AYiIi)Vr3xPP4FpsQB?OtE@VEVP80r#i9 zjIQ&G$7xmzaCt>>cjdS$eam(5nRy%G+pV1v$R)DKPOBc$#9g|Q3_X+sp@=o?D58$P z7#jTPuBWNKNw^&zYuS{qI2N&pbaDhLgXN0{r^@AOo`cq<{BL!n-MkN1UGuB0p(ER) zI_t1KDzRGRi!ZD?ZLt#ndSb@Y!D5kXD7WaS0iZ2#D(`6 zFFPP5@VZ?7su+0&fiql=Mgl5zoY}4T%&))mYRv*kbg^lpYo6t9v8Ed@z@$kr+mghF z4HE*iV56^c?CcsdVJz-wG!XI`i>e}ZA6E2LcO%V_{KHP-?z*P&YIVc7-Y!@ih4T|F zw>WV?15VCk*!0+t(;*zYA*f^D#&v%jWgZ&b!4$LZptK-28#s1 z6v1=s2-h6?Kq9vWdROk48~eZz*82=C*EObaLB4vYNXwncs{Q)iGjAnLUXP8t?KBB) z-;hH+GL<$Bo(bliGx+BzdED;9ZsslQZx$1Yfx3S;(7mk1pL$reUYSsZ z41vD;;;9u^p)z}dQd@iD>s1ibFoBovm;P6xD5W2p^7mEwwq6*>I}~PL0vP%55#>CCjK59%@_ODqb@LbR5;-aL(V{0O3Fmjkqn3>w77@8e5gpJxIe55 zkIyhK+A#H{H8aBJyk-9t&ljt2sxf)(Wl$8vzQb~`TG)xVD}8H6e(dVu_zy7JsU7Jm zR#-AA-N#drSrs1iS}kRWzHG;FFL3irOBk$W&O(>peda@FtLBaX^W{JRba_fy@ZsLqAyhhT3vHgi6xePq-zQOzEy&Eo(>tXdJ-Q7v6B$RX!_ zn@{_OY(>Xooy60Q1NF9gx8ufJoc{$5XW#x%6vER|p#`xKGethtSDQcnh5!ShU3jXPL z!r680F2AhKyaT|z90)aQw+xkgt`2kNw81;}4CwwXS*v_~c4RCfwKpMbSZq+vXZ>~M zu+;Nx_>7nG`VylGlY}-k6n27727X_=k5{A6wN4+BD6J-P7tB6!d!m>5Qu!KF94vz7 z=%QTi^67l9Ohzq3Wh4Kp4J-N|#n12&eyz*3S@F@blpLVAts2JKt5Mfcf=T8_Uf{LT z%Mje_6FccsoYI)zFUEHRhrs8dT7CfCk#Xzl)T}FBaXo4({^)oM(@-#cQ~Y&Qr&!W% zS(pVln{})74J}LFvHx1w8e`24(Xjq-Dj!8tABsiuu9vx{P@O608r_W*$o8r5!_W^7 zLI?|ycLfsEtxUJ5wD-is8#K4ZPxVLs^#kvp{ZYsK#Q0eBm3M2}vFsgISdSZ6Gahzi zwZvS-Z~gWMGd-UHBlxuvWWcz-hs8lLQAH=_f)Cj!r2D7}(fB14f@=BW!J*iXHCX!}C zlinZ2k7qnUCcfo(`;sVO57(=l?&V1MQk5g20_Wj;aZQ?36TwqIaoy*-w=0j)IL4r;8PVVZV{fb3Wb8r{1cUSawtEMq|MtI zkxPK1{NyRj?gZNGjhFyo35(qiVHmu=D8buHqs;L zd?2u^g`jjbTi#wjl3T1|Lwtyerv8rn9y$CauDsoeZ*NUjX~SHvhmcy6bt#*!x2Ic; zSH!5^WPV17U#!hB8RAt0l*twNf zQc@CEYaC`r4or-%s9^hv9LWXhFqK8S);Yi_QuPc~1gqZDOPHE&R@i2N!bS&6l3zOeJ^$102A2%B6c!qy0xiyx*XH-D+gnFoGjS%E*wI~UYwPtP z?$N^9+5}L--eSPskkNm~NQnbxdq+ow?d>_* z246z$_zu(IK;b{yV9k&6a?_im`K#+|<3&Cf63sYIM%=N(YaEo&-|Jx{UdQ#bUu6p_ znAX6hs42!N)89{|wDq*V9JWuauC_0)9>qe`ih}UAMNDJ*H~&YG*(IOmt&(x|d#Q9f zAj}xZJ#2mlsxphQglQlR?dJcfVe5K9(Iwj>M+M}6D_Fn%_on}mZf?lB{P$diS#T%> z3QIwCCrW5g#(Wdz210eiYk= z-s%Iv8wy{JY8|@|0RLc7*Kb%O3K^!*io-1zL9VnR4^+9|${%k2>a&-pC7U;4{J0Ik zGU;(xP4j0-@vgOB{B=_o19gVUwI<$o^Ojzoa$m-W6_#vL&VWYB(@JS-PJ0}-A6Ixl zz|kUmHxjR@7>mYu(A!r}?XFwvEme`!P~I74XEM8qDpH{X5f;i~F@Uz(N0{70p=uqp zNuH*si@`K;;N>sNR*k7V(>Txf?FLbO@P&!sZnU)t*PT+q3rs%j zMTvz_Ca?_x^zx3wYlm^IQYDlD*wQ>6u^i0(IJ@fB^Ajmtvqvt7^g>rIGj8^;R0x(- ztYT3WV4soU&>W$}-kO+~m&f$jafF^|+m_|>kIDC@HiwQNO0!Nj_f7nfFfi>_&-hwr_b2BmCV&i4@Yq!-K%ZUz(=vWW6&lk^daM_F*Vnnn{L(XseIJ(ag&$)#tP| zB{?~Hd{jk-K6$&4f^>9XRUpobEyDg&w1OJ4oeU*u?sbpFiO{|n;tDCP+Ue@C9y6e= z3`snE!}j@itOoNoefAM-2o`8tLqm$o-O>KjTXhx!@M}_hL7-Y^E12SmGEeR6_F#%B zQD5TCE*csd781O`{Z>NL?TSw|i|y81o?7}qX7R@y{*1gSjsX>>5QBjMh1j{o!uwqM zolM@S=vg7;wbf(GUq6r`V~dMQ8~_pg65f=4pt&vxEDw*51KTdr)Nzs7z;v0WRl2N- z3OeXxinb83oEUl9E>J=Z(^s!~X=P?2h`9PT-_QSDlM}hdHXg+Mov#WEUgV2;@ZKJh z#~)ZVT^JA-njTO72;MHa>i%}3(%08#Ec(p7CaR{Vr^J=E1%`>l>@^T6qnQZh;o&(u z>&A4QRN+6r1zvCOo?k?9B2v-Pi?Na5?~Xx0%<^1ml4?gtvL-AvK6e z`<00)acebKys_^n(w`nagKdKZjkvEifd%OdxOg%$GT(>EoSk=u_b89YjX5O2D+>QU z2AB^fI}frpo?Q$A?2|JyTI0~;ZR+aP*O%KbTXAw$Ha7Wcj2cHz!a>GFAn+!$=|}c& z<`oxPWL7~@g05lWNfMS^7oMlse#*!P)-Z3u^U$URlD;nwN1A#ZZ}}uMqW_U0*Ic)* zp`pfkQ}#bs0;8mXEWv%A+5A^&dppG>57-a$%S-%IG9W{V)v>>J3%gW%plhTj;ppuOUiDGN0q2YhsO-YJP^c_C5 z#NSWGRX+W5-@Q%#ZrYgQna^TL8TLs^qX&tdMp2AYrgsQq?tLlPv;?9Sn43Oi`hUtx zOve!hcvSdVD@2Iid3K>>+oJinA^dgou>zrvuh?R!ueY~|8qA5k<`jMZS4gbEtnIgf zU1(6L)^T%%S)mCtJ{t2F`xDhlm*G0`Tvx(Y($!eK0V^@g|7`d%74_7xgoTGQ;i0H|2v*rIf=;NZi63Tc$Lj-?4@_!gEQ}m6 z`k6?{I1PUlB8smfS@8oh#`7J7CL3GZ`#%1*PM9~O0oLj2)Jg7+?~wwHiQGIrT@QaX zUd-q@YWhmXCdT`UjdpZETz5x`+S&l}NuH8IaA8@})SY^ctug|n^f(cA)s*rF@kbKL zCNqULs(7V?|5*NEQ}QZ!a46Nhllj54m-z?Q7MA%FCM9_cZiMt*FS~zdzD(5K{(fi8 z&sJH#OvOaPk6FGK1Ej#y`Dc%L^PhT+(I7lVqDxHjyd@>w`uDDKtE{}Ds{uG>(#Hg+ zC-+)|sc3)kp0F-Cvuvsi39(~|V%S)}5?0N--;@2BsVfL$Bp<@+b>63~?{!TY{9k?#wX@jKy&}-XlpGPbLYQVC|=Jgs#(gZZM>T3*O*E& zyFA-2$xNz=&b@s9t&Cm((ym|%ofseQ{MEQ3R6(DssfITpBjz@!K9(iUouJKzM#KCl3vWo!z1nEBOE9JndEt= zg*(<@k0E-c)`2Ze9%HFk_PU1j(@jX_{d>4@G7qAT-{}EbE7VxP^`x&dO?N4LS{nchtq!T(&bTVPRp#KXKKVLRU{2NHJ>N_MrjJxUnab^4G=lSIUGG zzsu04ZM1(fz7YU;Ay4)GE?U{&N8L8Yzei>^=F>~?5N}ufIWZZ}m&tVQdy9sF(Tvdn z=HMWZ$Y}l4`Oi|3tEY0a*O6D&piwt^qnb{d4}U)#l*1I)VS+K{e-=z}_Gk6^zgzA+ z{Ue0xOtw|zmR%_}J@@*KU??-9hWXOhhWvZa10KM>a>krN;E838{Gsx@)Tt` zX-#eCUVLpQu#xTik;-n3X<`8+gU^10u>B4Jgft$0e(k!p{9^0>aP!dcH60{oHnb=l z_+YLE-T2}95NvYkJH3rLeMjQ^k$pao6nJ@3hbIY^*Vp(d6f;J9@0Bf8Bk@~sO8|hp z<6vPnz^%&53tV3}_J7)>D6meqg>8`odmgcnG&=KrucKO&IS|32#e|3S(k261DVrQ>#_E~@>HMxrP+#GGSm?y`bZBDyTW*VQKPOz~ISUgR zi}nr=AmC{8^8-N$sJ}s#Pf5o?+EN+0*UXU32P)G+5(>#mB5hG%%-*tC9xET+2T(=6>6z9 z+4;oIatf*RAS{A8_vwl?M^trJ+X}MHoYrTRRc&#J+$K1Fe zp;%_Mx?n@8_+2OF-Ce&ppvsrAY#J5c5T1zBzBwE|8~YRYwlNs&!d98g`IifcfME3C`r?RO7kUX*rYEVh2%}iu;sL{pFT}j|ji|YiD3E}K zg-_sSq`opeRvoE;sX{2LxU38%rk}e;wjDZ@$_Y2g6Vbn^?(c31rph$siJ2Khj*3ba zN=kTiD3{gZRvtjjeWnv;pCQX+J;TFXuhzD~3uE|Y8(-`)ZFKGSKRQ%_<%OAOSzlaC zzv8ut4wiUeWrZ)?K6|(w!H~Tc`L4pKGYA1JPgLfEC>!j-Yyk2@k%zqkd8U43MNE!d zyeL$JHY~Ia{Gfa&{&z&_qQb!%olh({WoqJD8fL)k^tAJ;->viAdbsQTc1psq#d1ES zu!3Md4jSSY@M6>Tj9!E^HO+Y7@^@%tbF&aw{f%g9>-SD;8-5?%&8SgbuJLf0)%QH# zD~OpG8{;@}Mb<#>^qXgqDH53CU}V<($Y5l^^b$K!u38H8W?i44MmcSxTq#MMz($dnmr5YmBu~4uZ zZ@{7!EMV!Ck4Q*|8kP4o68j|k~4-W%)D52P^BO3q1qzj9S5skVO`eD&>6(;9!tG_WbYoWS@ zMEcmX40dsRi}O1w-mt6Y|JcxUTgX(D2wq}p=lpAy-FQ*r!z{-8iyNk&3kS%`=k8nS z(jazHFJ;Z(PFieWNK0qaONq=)q{c$RLJ2+dZuMyvWb=XiSCs+sOx5-oAbS8ketCIW zT`c;v<`8V45{twN3JXJYXn*z~VExpy=-3WsuHbU!Q`7&7wZ6k^&g30|Wvs$4d3_N-t*u@4Wf+$kw9_*0rb!Qp;{~9MnN;M*H zZf*unnm&$&Vu>o279abmBY}(_jP$mf`buM>FyT9}calg7X=4AX@Lw%5mABhs!>l|L z=JE<)baU?u=98GIymF0wCh)LhfF=awBj5>wL8WIo$te<5mAy~B0V7^E*ttz;SDq{F z?#^4;a)AQY>2yt>N67BLI-Rte19TV=YLQjkRVM#h)W$?P2`rIENb@<^svS0~ijXsq z$DE#c`~k6AioOg$ibjl;r(L-A6$9Ftaz>(LSc(>KM6A=?#sFZP%bvhh*%yYXzY<-B;lT5v0GA3?>(lrD-?V{V^EaElm!(2fMm@pO(*syv1BYHr ze1V%=cdbi~469@g?Eh=xYaM$1>*SKy{B60rWmg=$>3b8nZ#65C!BF$5+GUg7zL#r` vZCZ1@`{<)6O;w<_S!!*Gz`nYd=0E$&ZFjkiS`xBAhgo>K`njxgN@xNARAexq literal 32425 zcmbTd1yo$^wjfxzI|N8@2=49@+%>`7-Q6w02_D=61PJc#5ZnR;x8UwxHHZJ+cUQle zp6TgkEvTZ{XMg+KZbYgmNuwdZMFxRDXtFXAY9J6a@D|Dj5gvH4gKX&nFGx-@+O8lF zdjIP;R0;$7I}ix=z*w#oiiYjE{jxOe8T+G}|rfi(-WITM#Y}~AT z?3|2b?5u1&EUY{%Y#dCiZ2YX;{2Y8_|Nf!?PIED{;8&B7`uADDZ$cDSZf;KeEG(X$ zp3I&c%#JRWENpyyd@QW&EbQz|00fh(w}YFp7n6f4<$qz2Fn2X|v37E^c610RU?i75{U_|CAPc`~Mu_>L%#{T;tyi`JY0& zYIr-Dv#6Q7I=Z`@8%*c$`awYE35G-q*gu%saS4-@&t9qk-lfP(?*IR2qRQITKP z!PU*!!PHz+veot-t= zKRUo~Z2GF(LKLR2LNzy|`1i-w|HmBo7g|p%a{%f8hq(U*=IUtS=4tF=E@laE>wlq4 zECA^&uQvFvTd@4!FZj>j{s(*gFL1yKyuSU9_W^$SkN+}v0GyT!;GMRv^H4z`Zwpxo zF%7S*lU2{GEKUD?$RwX~dZ&NUT$yg-N4rtQ(~frv2(w$=a37FcsL1QTiefhp$A|sh zg_p^PMGT`7{o!HNh{S!mTHDGvd}#hOq2#+uw|6(h(Uw|nq1m=HH*xo3QuF?7EX#WG zA;-0I&sRfT9cR)qrl-+ftrQmlgXHgTb>#tfeJLp^D|`DQEygWxlF-mls|sre2ZL(2 zgPHRApW3dCd)~y|dU@ryNw5X@f)SV>5XlXq;OV%AV|E=Rv~=1{w?sc%ZaP~d zLk#f#`zs;$_WIh6Ic=0>X}Bw^6$Z3^SE@np=IP0j#bG%C$r128b!@I&e)E}pz$Ae- z>iZQwKzwn;e8!S!oA+9~H;;CzySk_69VscF%imEUAt6Y$>)yo6uvzV?Xtx{{Hp_!( z+&17tK2Rs+mzS5jZ}x_hYIXSBXu7nlpmm;=l+DqLVS-`=E?=3_e;;$(Acnc|Bs};{ zLtcKg2)LW0r~X0>qwRKgx2U<7*Ec<8o=1UgL+EpV(xB7R)7c5$?U*y03eAU3W!&M! zP5=wrY7CoK&X@UC+r?V*+_-{$VpZG@>$A0v%uq6~#h!=g2@q}3xnMjiYRi5>v_X@@ zYU`P1`J7~70>CUpatn0RF{@g`y~OwOYgsZ>jc1E>mbwi(1I}6a9pfm_pd#E9x$xUt z59W^R84O0l&gb%+J@Z~xL99tJMDj3999&5(Rb2Dk@yxs3xVX6Ijg5`a2S2c6D2O47 zB7}_Ki7suFz_j_WtQ_n#5QP`0$@nHk;QdKSV@c3C7RQ&mUn&_7@BJ-r9Kw1Uj0t6Y4DtG};%?ZWTl`^SiFLy02devT!9N zbn%t-AxsT!z(Ofu=EacvBm`}Q-82*u2WTA~<86c}1-sY=#>G7nN653iUX+I1G)AZ1 zYT7;3{N=hk7)CmAm?}~Ndcj?Fb#;}th&Dy8zNyKws^fOaFx=SdR$~5{vO;z6>$#v> zj&zw?53+bY8?7m;=nt-7dvzu1QmQ1cN|d0SL-Wswh{06*7U2$aT6}QmMsoo)AioGH zieB#Ho}Qu)+}@g^eo|Lg7sNBt&ho!qBpusv zX^J^Lsan|oA#&hdkA^YJEvQhe(R<^6%qk&`#UE8&fJlQVb1!@#7w*;)L;M*wPTWX) zzjVoX1Ln;>b8OvMuYs9y1HFb$p`J=(RAA!UlurOzbEVUKvCsb+X0NdI$VlsGXqoB`#1a*+eJauw>ZQ%uGi~y zQ+%advs zTh4Ug_iZefp$#(ozP^20idx1Wb@UrnqJX3iT+*j%&ux~mY2LGRN0&U|SZeLZ=?sx# zLax5WQli7-YKSD9cbgdZqarsBjO=e0a!aHO&vf$r9_&uAl4kQCi*P(3SMiKLkc87N|6MnPWnyd zZEa5(az!ENeV9Yem2Z{j12r-m9VhmtRozyyA=7uZU&xsncETdpsv^4&XMUi^UeFX- z8+G3sjZbU2YUl}wz6v~&Xm#(X#dVK4LnII!p0hXSk5DKZIBausFLlT=&s#B^DrXig zSrExc7nV1RY}*;9jzwKp7zaYTg^pFCr~?5)Q=$ia$ivm1A+P7@3Y^cy)Thkw zY0^U6PncinQmF0!LY|*AMT<2)C>p)#mdMi;v&6GN=C{HL8L@VY&RE$1u!MaxX`l~s zeZyklmu^sJG437yVbeSw)o&uUf%;?V#-s2wE-VOh51&dXKI|->1r)J`>c3jNt?*L1 zpI6xI5acjNFy4=i^6Dw9^O6fxXq}d?m>4# zWqGYblG))?;8H{_pk9qoqki5i$FmIn&4Mpwp@!Zx3u1Bo6{$Xa^`LItAJ$Kcj`T^_ z3a}${wC{?`yz*aNbNCzUJZr%wl|iHM&E!cx2Gi;xLJ$GWh$?MnX?6xro}Ef+;`@IT zq0j=&Y|yvd=L#-vA?$G;$Gtv}KREt9aI8XQ%4hq zAFrS6thvM{r|M2rK$ioD*f8k2da)`Kd_hL9c=1b*p`d{L@+;v#gcUg>fIi`>%2FXR z+Kxbj>`^*TLfu78rAQ=;Q&Yoofj_L3uIxhrG!%2XsiF zWHy4luSz&N^Uca|oN`#`1Pa439Bug%x7Mt1;+&ZIoY#C2u$XGUU*)OgBMuPJ5d9|1|R|~Nl)0GG>5f)woWiTMcta|F-;nt=q(v1pwBr7H{(8I#|utw68iw8XI#d(boF{GR?b7R1-PkyJy1<{&L4YK}T z8I$3T<_b=Dj9#-|NB@pcRv* z97)-P!8D@2xT+!L1ARF0XPizB{iEkE85smt)?)8mSL%>QK37j}I7W8I%fl*L^;e3v zAa9Gg%ZqYaQM-S74V>T5hq&VAR3(g-iE=o;-1dlNNJ~{mC|{ND{S2Cp6aJmi)5r~< znVHYs=Cq=*a)9uKQo+bcsX=wT|I1w%QQKG^^iSRcmbWqIO$cEy3L|zQuj;lM=S!h0 zjg>He-Pp90M9);+O3SPrhFUtng06I7Zom87xQHWTG+o!0AJ8L~tgiSX| zsa;_bPF^-&^R6hOez1;FaG@wmK~1h`YZW%>o5DR2vJ)A7@Zwu6;;1R&x2r!@OTByo zfvg_dPh2bN?%|6+IW>mV@GnEarysLhm)aGUz)I;PP43W|vGa-r;Ym7UVoFM+N?K`$ z>EQhF@H=)q@ldzF4(q1HP!<009+h798Tk*0p84!uP$@x-=Fz=9-5o<1rpaykwVsDL z>L>ep!-|wkVx|#KH|NgjpAZ~5ED=+fVjYGZ0qz5%!2s!l`@8SkKz7HbtGH;v&9!*+ zkYvr-y!{IM>enP-Y8z4sUcICh z=giYe>=ZtdcAyXffl37<3Y*QMSNhE9k)Q~ozMOHC48W~N4_#kf@)#@HyX(^C3? z?wV=-s%a7Mg~=2@QcK@lxmEI}RdV4^cV4??>{WFu@@!J6O9W4Dtl1w2+z%Z$?>$Kv z2PKWkV6sNbyh;E~f=+VdBP+a8;Eki}8dIR$Y`fCW>GS~gC)MhWpR?Nj+wZ*hk4mn7 z@jx*0&+<9@&55=|*HP1abq#_^#|dqM$*&p|aU#uP1~&^r@+C zhsKb4b>6*qnX&luF*K$+12U3-{I9AI1!82jlV_KN`GJzU+Xe{Aa=08xK~NgeZ(lek zBHoih&qS+3vU53_`VNyrfK2L?$PdqQ2_sG-J3W+MMOew^rpX0aXN7_*(kc}So*dy; z3Jqj}Jf2vo%Q1$PXBGxXOKCY`Pg`7Neqr4{ReUCU??6F0lVFBMiW>kQg{GoJFh`a2~7o;-06^+)) z^>}C*PV)n;fHz;7gb5I^ll-_lcrO46;Ak#O{hi|nPo(VCT=!;b`3&1y>H58Okjt;Q z=g$Y38hp_V6N+D%5I2OlK6(fmpg>atq+|NLFQD~t;DBOC=vOkc!M{x>boxe1g$!LV zH6#Hgx7@&_U5nvMA0B|$CHMh1oOjsmnFLnYp_p(v+gx|uCfmb$15>Oe!ls-96hW5$ zIrV`-Wu(_gMF!+ln*|@S}Bi^$3mPiE-D_f}@%CJs+1eVS(nGO`I!Wc9O`8s3jM1rU(6iWPG8jlI*PLndBaa5Uh z*t)k+983mMcxC}yoth>?`s>C=C+lSABU+KafBLL8G$M|`jr4WYkDdLL+#70EJ?Uy< z5eRkj#h*(MW8~qRQ^ZqOfCjM%OS?Bm+A&ymT)<>OCPWHNo#SlilnB_T+;ZXD}2ju~Wk?UF5yd*5i}I}XhX zUdM{;r9TCVQY@=I#m~xOJ(@qurAsu1hnEUGGedz9YQJ^5(WRcwi=ZY3lkW3c@t(FJ#>~&J-CNID3H| zrar&i(Da(XQ?%A{TSL})6OcmccaHdlXI-FF9s`gDdT^swz(A(fRn)o>cu9WP%?kIz z<0oxUJ z=rRTIz~Q%V2XZt!qGUQgSuP06VH29!3+k?Pc>W$GV%~EkdP{G zr9>i@*_tPDQ{5abOd#6Xo}Nbi>hme%<;5`QtFbDA^X>J3E3X4{Q|YL$ZLC! z4r#l;=*sfgh9D;+*woQ9EX=SB^~l#QZf)K91t|>qk=&<=6#Qw6*BB)_%xuFm1srHH z;GNtZA+Y!zPo`8eDkNp@K@AJ~PytBnC)KC+q$YPSA_Y1`gNi(grrR_LGXyvZBF!jW zuuJfVh#&=!lG=2;)B8iQ^4si&;`SDk!?9BhO*Xn@H4S<1_GdE7&I^o|TS~*cqPFZU z(e^=+X))1#ao0N+7kzoe4*omJ*ww}lwch9qRo)DdoElOF;Jesh8z?}fB+Javjps78 z3gbi7-a48E9cK;by=+#woMx`aomk1is4y+S-$-|*(t`z9ND*KxJ5R?~&W9jM>USJKmAQjhDdF$se#U&+XjksH>H&S-A9&AXTRjr-IdVVoV zsUZbVhjFtRi@KF2ecpjhjY_?Vh3Y{u(7jfHix6it$A=n2QLXpOoiXC(^R+40D?0cXs%kRG9Ei|CsCJ z9umtB34Di;qfSLw4+`;CbLNLofg$(h?Kj~XQlELBm`E)i%<1I*Y-1x{O{*)O0v-2W*#phMR;o{zx!cnS}cY8nKq-K>7x7k8MTV7I>_`;Nfz7M?EREB;B1AYgZ;twzn{YC@^B5Dzwt3FI8S7*E2~6GUvGDj zc8fZLbXr~YAku~w6J;p0dr#>J*(fqc@e{wE;3(M~GvxM(UcqA~nxtIzRpBQ4)N zfPtZ^BfK+P88f`+`vi2@$9S_VqKSYj1S|co(VoBCe~oUWb<6dRlr!&6sdx2+8ot0P zQ3!2f%vzC%c3MUh^D%jao32wMlcn1Zj@SQA1@!~Q5kx3MCt1V_#9Np7@iX&9bI0%A zYwXx9Z<6OVE7@qo%6Vm|~qKGDSw-pS`fEg63oo zpV>C3wy=gw*TI7R0=Z3^LzZ9$&@aL^7EGCnq&iKOr}E)lvq$N1L{oeh6Z!M*?RSUyR8ft zUBM4-g9`t+dbpDHYv$93lKAS2uC9neE;(iWPc7Lp9Mzs2Pr3K+iRIS~?oMJNr8~>3 zAY2}6SN`Y@%>w8YG?9jM)Bd|DVF5`ZCUTFEsA!MVy3bI7)Xtug&~ra|Bj^Xa6x>f`&>sKtja<%F zspWp|FaL}?X{XwP|Cfu2&vOgw-S4{|2$LIuAn?PwlMKNi!ETSD61{)L@$a@1+i zHUPzbF%10om?ARNL;UL5ytxHdl^CgFj{Prx+Skmwjb`*+)g_9{@@qTaWY!-=2}I=` zL7%2-jovTSvT-;c$o^IY)QcL~FS)V#o(B>#>(HKcsnV|8q7!qsjF8eS&Wtud**$CE zjJEJHy&%Iq8H;lpceQmEi^_g>JqpCT++M{2{G;K+=Mz|7>px!06@vG3BJf39HYPX( zHT1-WW22$cgAJ%K|G8+;S>6M*_uoJ?hKr?o2xsM6F)ZVvoBPrk(*niP*-TSjmB#$e~z8nT*)5vjq z9Cp=2X?>Zb5otw-2WSd{zG<0lv}^tpFA&*RjtsKkTWME^z*!oEYW^^f>I$QcxMQno z-lAvrnKU$MlkJVnnXAB^n?YP`iEjDZB&_J_soUNZkU0Om>bCMA0ycyUuI4`JLsvy) zT4$WY8Comu`)Yjl$yM*)F<%y2Iry%#yY)Sj+FJQ$R49-9r_Y$klN^6qm9g9uLlC3s^ihd`@({A_qQ*f``0!|>B zcU#5;LrA8HR;go`DXIO4!l3W%q^6?o@5Vrqb)UpW;?EeTX5aTP-4_Pfr#L;?l!_0+ zV5eVeK-O7;Q1dndgU&02L8+hsLM7jws+#Mq1vRF*ny+^hp15A-AG&&5n*w9r<7XKz z_!xDlRRp17yd2>--{pdXY@882u}2o^E6$_DVFR)$`EW$c*q1|+WN;LnX$avz{xpkv zztr0|lENIb|ML_4M_N7$HmZ!+aSd4SX*vsv-GWuMz0y_{a4&)}k@e|6utjQ9> z8>#|H)8pV^=PsBz-?b+|O?aK0IZuqA#g*6{wR?4q=@&4`H1$k@p#q*SJY6S6Ai~tB zP8>o zco6sC6`qen0xMxGT2`9vrmLwB6*P14%jdrP7AIAuxIP?u9^$wSH$W90`abm0e_x*E zbY~i5QQqw|axRbsvG)CmMuEG58mbkBAH1r>MO^1qDmA z64IonFX?~=G2x(GHM5l+lp0U}iWF_>V|#>LbRkeH{nT|^Thu#`6A`y%Fu>*y#<#)= zZ$6+_Q#^4W_p(AuF~O>0b^E~ZmfFQ0^>ppmZmvJf$?q1hV!IyJL-ldu!t{zieZbDW zbhjK`uTA(={9)iI-k)KGmGkWf{!(5t`fFmpTfHDt#L#<=CI4MK+GUCi6;%{A96+JB zX_M6iT_N_k2z{-cUooY3mV$RQ+jAruV}Il@nirijz^RRA>)lr>Pjm7pnqwz|6PY$N z{Z1j5knN$sTX>&Fkq^ZkDE4hhbsuY_=oIrUMdr4gR`JhiVFgmiXW2+ql9qA`32}^R z)EN07pPk2*w3w4o@XB`R9ekeU$Bi*rkg{(+d%6zVLU;_E%?@3O<4j`67aCxB^w&M4 z?ZwQSb8YBEigZD_EX*>0Yj-RS_kPV=It|q%P2AEIZem6vO`} z9;rjk&t(-ixh&R}0(Bb?{%CSHZVS7=biVTbx`!?U4zUa`qgBaxqI7S*<4w-khsj2? z=VM5Fb}nR~s_yPWTGq_Au$JGDzle->i1_H??A{dUfspLMC|oT0i~%DbbMR$ztsb%c zyoVsnPAqD^vJnU~aB>Fqbg_5BHy~{O#xp?G9@cMUpo${FmPRnH!V43jR&^f-F2H~I zX9E#PASFGlN<*(gRhKzc9r9OCCAhd!322nXC)wE){_zDlntipQBZc68xsZY{{rfZ& z094Btr%0v5tfn&Ld4#__l5ig}YL39Uwa>MqDxdscH1@?CXN?aetIXC-Jqt1n0>X}B zQKxH;6(+n#Nlo}R6wmoBKs-43i;FHp*(-P9@l%j7bt;#NKT0MeQi~T#LG&rlqJBc9 zrhLDDD{;zmc?Lxp<_>q^(zPcT1FqO4qg4R$&`aN*heTWW_5?B-X9xzJh@QpW=-o*h zZYIk!=L<@_;QQh^uG^iCIL(pz#gY17&m|*Z02dM=fB&`4^-V#=V@A0>?d@ra;P2>+ zkhf1PPk&NF$xRmgMK(*rT_w#cVu^MAKuKsTA zoGgGE4Viynh$slE*5NBlZuDM5F$-Rn}i+B5zgnzEcGg_Ap%V+QwaE+&1HNV-Q^GTag?YJgtuMncqXPq-UvYXk_Lvn#6vxDrHqjZIE|Sf1nAcqe~<-!&y|L}uq-|& zv6!Y?eW*(RCWs9hQ&D0co$5R}_P<7-?>uF4U!PzQ8@l{Brt44MM*4Um4-5KiV;u33 zr}N9K!2@@hq`|Yob(;E-Op>CL)hv*v_kQ`~eug1qp)13^U^AoatcqX3)INh4-U+ks zJO;8t!7g3-bM?(GShK+T6nnR#lZ@nrw4Cy1g#?inL|(41gUYocZ_5X+Lm+3PauNc? z<9{h4+f-Z{Q#hZ5l+O-b()DQZn7i0-y8g(Snkf-$sc1~}VV!c7J6>V0y_KKce1O>6 z*==--QvpS{QQq9_>xm}>f0Q{8rm_4;x0cO$89&P%Zu}~ZquG+fVKqCQ0@?prEr%9W zD`4lH_T6o~@#1fNhTbYs2PJ_8|LajAuR|z$!1BrE9k5TDwHiZrfFIF~`t>J9i|9*n z7$!3ffy!oT-!t$G$ODA8eNZ&A)YX~#&&(U^Qi?0*?{^}%PO=MOo@pZt>uv{5^q!`> z3a327^zXpl6zVB*t^Ud2>P@}=6E?Bv)NGni&$te}PkIk2|$6+UvkL7YV%6MLk{w=r2 znNVf5(2*l}XX>QRhc4)ikHE7sdO6Bm*#XKe+k=py zGT>c#r8myvEm4Z|{MtFgSDTUA%Z#Hz{K+|F=C|Fj&PCJP+NnJKJr+WSMKfgIbvMU& zp1GwPg@X(yhDK>jbY!qMP%ZeFflnmXE5~_RxW5Ks4fY!jo^mjguL`pm==$Z@ly*ni zI^-YK7ikP~RG?0JfVKZTU*$Rt8Fqwj!YmKhdk)!_(Oi>dc>Ugwy^d!HU6k0^)!DWQ zN(!J=$;zK=c%)dd^B2q9>Fz#dx<1h(RSqTn$f9YTX;zss4tbHxxj)r(p1E*{zxWHI zf%4T}*|nz)oOQhN-fLi!?!c}uPp-8k)Qnqu;p!88fd63JpX}m()@4Pt;k(*x&GmP> z6lK!5A1Gi@CR&kA$7&YpQhHhNWw||FrX8QTcwTbP>Q3#?DCQCi1$#^}pXKzh+Y?EL zl%d*9+BtW8)rD2>^cqG|?4y+ny}|6zj@TGOnA_A)-KZ8VvOq_{{0s;~5hayJSdXlh z4~t{^-ogPpKk6(~fc9vy{jl{<{}V^-2j^;561mXK&MZBaHC3b7qI{r15vI{-_E_-U)m?YZ;RFpwv_^F?dosw4sJ6GeEf z{cFe8_=vbE$)-}|58)1;(M2mq%lT?j9r!?kwIgr1VcD`=L^Sx&(VR~O~dXM zrE&es-0$e%$E1ws#hOjv3Ce|6f_~-dVuADqh}-Y>|GN_K!fwPes|zfT~v4 zK9;bVv1A0I#{2-oftHWd>MSIMg2?MK?HjAtg@Tu<69-@W3?^VSeMC#`nP#*1OXdZ< zh`d(~j>hBV0ZEtV-G2@J(3%h4)T{5E%Hgr3DM02~L$hU64@G`e`UbLAZj3O9Ef+BJ zr{;(?T)Qmhe9qG;1_D5;ffrXW{@HKd;1ab-g2AAq`fYu>!kdQ^jWWKCHZViP&N1XC#Ky4y_&eWs(VBCszsqDCY85w&1dqY#($?yml|si zUM_8x^V!)W4Br}pHmK`(Bl*kce$$m@m+}Xm?0nb3afbsbA^S8|?473~Z2#>_v*Vq4 zxY8~+`SYWy50wniW6MS6H78Ppoc8iljy7^7TwBB1kW-E-D%7%u30ddEImaURo-Cwn z1xp&^qije|&rKJ_tgz>^Co5e2j>_&`pBR<)vtHKc9wDS0o&@|m-p0}NFc%7 zAnK^dE>{}eVuaWRPf{Cx}YJx^H^!y>bv}0?9X5%rsYSMWOJ-!sULBu^Zvwa@L3XXM`aak$P=q|^36Bt z`8Bf?RixirRP>DYbxNQ0*B;UKS)eX?IM4FU2cDfRIxRQJ?oxln`1(ciXkw?`^O=s8 zcoLJ?62VR(%mW*cuqom0(08)8LMoQA>IAO2eX&G zw1v0`eU~*n#dYmoNHH7b zqm*91Z5`4h@wtUzvd~(I;U+77t2qBGef;`lDQIW@VK9T24%56DA|E)GBb^%+uS+5g zA%t_jyaz>@Po05@oGfurQc$*x`o7RF@K9h+Z8VG20!N3!Nl+fH-s5s$&(Z>fBzshI zJ60iYAEQABqJ%xFh^5h?gM6p(Z8T=|!6$t4Q6OjOQylunSkqsn9|Kkr-y-P zEfUZ|E!kha;1yaXp_&sc0dos>$@aUW)StvKWFeQO=%76xkVexMsirEP&BiB*_zWJ6E8T#zR2;$&jBmOSr<#| zo4-=OoL|CFx!5bn(seki^do&r>D_4F!m<}*UwE?~$~NSWh2D<6SXnft?fgk!mw}0g zx!cXDufwW>#tFBQV)6GxPs!<4Cre;fxyZS;U0N&u&!zFw7}28;3+9*XuHBMA@Tcc3 zGKXSs6K^bdmACeMH#AVt36V!L%8+{z3jtYVA>aK)Fu{p@+fnPdmHV*5P)Kvzx4u#&HvH0&Z(Hd4=?=qNTEQ06%M7k zKg30op~lO6zr8|kMw6#=>3x|QIGOV$AVia>Sm$j%`-*^vR$?SY{mIu~jYf-cZeR{z z5K99Wnl#2*?Th2z#$D^R+S;0QpB%-I8e1t#Iw{(u6Y_DPGb8UAW93SjG;hk2tP*V5 zQYam#fPu4#h9Q`#>UUgp-JByv&10=T2{apBKV^v@h48iiW;~y^!+-P;QiN2NY#l(H zoBHyS!!xZ-j!q0sPs^@&k8YYU;kHN5Xfa;Z+G2GX6454n2W~dAGs#*;ky{vPkiTcPC7ahQ*IAvWQ8YQ1+O_eEIGGl&Mx z5!E__66D4NKoqAv-<}XbM1;Y>k*psRNvT^q7uLaN>1X&2sZsd883}pBKYi+zR%skm zw3tc_J)z!S<(^D;F&b=Nk5z&WN(!sB1Cn|m@b6{0Ot)HFi|-HNhc#6BzEjj6_4+FU zPV|po4Mr*hCP~FKY$^kk(OVn&kK&j(3(U%9x?3V7dyzq^1V$~gK%E?u9V0zI^nIgS z{Z3_HAm}AzOXP+fXqKgH3gLi z(|{3h?k~y-BqdZMBB2X(EJ;}ue~&N`zkteaV^Vr0u$EEQE%&=;SFQs)-%Zlasn4`D zX6~HtKCxk$>9!sELYpiBR-33I7pg|IbPX!X_Zq3lQMekm7Z)5L3a|d#dzIey=qu>I zaOeHp21x@GD;Fg9dL(Hnu`B)HXRGM_7BSOpte~|3+x@2nN{L;7ZgEdl<^3vu+UYEF zUzO=~)k!n$WC9Zg)+YwuVSc3^j$&>b_6Cu-R1|m>prxY#{zbBsHu27I+jdkU5>@X3 z4Ed5IQ+F|B*jEx5SeG*zTC<*B&nSJE0Z6boE>k#eh@|==?Z;OUXh)={nE0(8Yo-Fr@wHwEDKq|ceFl@t{U_t`EjxR+YFAa?#!c=&FK^7wlvr2 zDhO7$jFTb{D5R%d(v` znPcX7e$Zgo5%Ej}exri|^)KJRqpQE=Rj90Msaz)5;()7fJY3eXL0xJDikGc46ubML zy>!>ZmaLo4x`^dN0ep-IpV3cCET0Og*kxA~uBh5SUyLcgCuIr#*?c(im?|0(Sn`t0 zQIn*tfSb<<@C+VEAS4)ydx%nJFpisZ`7~?0!gW z@iGf!R7H&ZIi3aVf?b`SslF9dJL2793UHv8rbro3qN>S)^`MuhSeBx|$u-<4uGNa< zY|QLev^>yrW_H!g3E$De!9cbZ3)<9Mh&Q`6~J(ekCFe52-%;s*l|IfXzh{=D3=u`8>Q)P ziOGIkZ(3w*Tc63wb*nG+vZS5MQGVAs6ynDEDN)vFA#{QA30Np-wP!||Y_VV@JpP8E zKiY5bbhu8v`g^#0ZCpz!#H=#h%ob>5@O{r%k}=b9;!xx*Rq%^zs~AGZc>7Wk*Ho!q z@w>_3sn%v7XC(CErEB9v^{e%y(;CxRzf0oE%L4=$y*ML$-`XxOFM9sNU1!>XtBUBs zE?#U(ZWm}bs6adfWzHqMVo5Ym1O!AG9%Vb}VJqzw=j&}b-HXd%s$FH;qN&ur?i?mB zxOlV5&cu0D#1_72nZHZ47$l`_$+h1MF1fSK7?+K$AReF51;^XD%1eYm1nL5WOxN37 zrwY0mdVAr3U4Cd!_?izRz}LPb_S(OYZWQW0?;-xiDr$?ukS?W*t`lGQyri1kh*m!v8?rrl1E~1Ob3=*C?$KJ$RDOU@lgP*#klH4UW3bjktjh-S??Z|! zc-h80M2}kIBIZ&h8@`pWv-5U}>tS0Tn`Iobab)AZ4hbk5P7LH_xtg|jb+kPe$A1F- zL?g1x(l(fPia$_crsz-m`g96z&G2Zlup2zu7P&KavwOQwV=tJIE0Fv#SVS-vu1mLF z3Bxz2$!FK#zHP6?vS}yJhZ(?iac8RHs~>$GszJMaD7YX&`=Rl?nf`Y&s*$m52l`>n z-;EJixI`pRXs|jlm~c3grZPA+Vqh}`)-Dr)IW{Byf%l^`^jU@0ru9`oh$7qMkudh&Y372v)u^DP zO;VjbC|6BxXpclATAa3GyQG54xIymyI!~oKArrz(g{x|+Q0X2!5r(8aJlT(VNNSmv zfRzdzmNd+^zlLkfwW0%T9wQ2{ZnpWNTv!o(WUGWr`ey!jNBx^_B{O)5 zEGxi|nkC0AJOlfzV($&f7n8Hf_*hw?& zt(9l#VGymUitiM9cMxa+1JlMc+hr>hzUH6&5|ic6(;&5r{W=|jw{7b_ zQBc}S(4(@Qc0;BLVVVTH$)gUtOBjI(sSk7^a(>Wy1fs0h$FA16OP@Dk+6aWJ3md_Z z+*|2>Go@~{D z0w@!DC^)=Jo(lHzdK3u$ZMU^g`2s4)!0vUP{lx*NXVYf!7M4Q;=WtuYSlvhDlsJLZ z;s@e-=FUXCG(*`2*rI&n&v%X`obhkNT5NETWI<-}_V z(SNS@1H(BCV7rsV@;i^`SDWn7b}szdji2S(PPZR9J@>Yh+PFC|!xff}3nOhf&_5D% z%xj_l<Iv@87PF?^m@0mX45613@y#kv`o-#JgfP$(TF-JCmnIoU zeof9(5<7usIbC0H7c$VefFd3emt6O!y@1E z$-x0~4Jq(kF8r<|03`{;xA*JP>$lS0hhHF~M+IDCB3H<%dR{nJN^Rftq;dH15Mb0l zezkJb?AaHU)}G>QN=ZF+XY8;dh9@{Eb+XzHwQIh~MJ%85;?9pd*z`5WW1Q=7k#7Nt<>G4sO(~P1#@A0mjy|s2=v15d&)JQsC`7AiR|SC>HD3!+qIs^ zbC@s~;eG~oAl;5uT0M4SQ+t`vZZN%ebgZ{8*tW-^jOv%x|I$DWa)921=Lq5YpigmD zRaEK@LDVy#Fx;i#lu8NsXX7QxYhC8iJB00ZdXzo>iP%wxrV8ywUO-|i&aEI4=l=@ug zvg2u=+wyld!Uk2I_ZoJx+BP!^lT!OZRVz8Q#4_`PcpJf=4kQ}q`FzjsuXBFyd*1h~ zb=Gn%*P0n-p69vmd+%#sd+%%eD9YS^@99YsSQE$UR9y;zy1c%TLVS!9ujKhjTE}bf z>^wtnh2oExvK{`GpWNr<%x)neRbV?-TJI-39b&4tU(Q;R#zhY=3L-1{HWL=gS!3a56W9Iw|or<5D%KF#7}2Kt9~>_ z(De0;nZDUg|GsMZ;FY%Uv{qp!-qhZisf&B+rW++U+Ao*fhP*c5ik%OpW9jAQzeEszkleWxE#*P}g=WoxU z)bz}=6NcVQuboEa0FI&BNq8SDm;>xFcUaaSf0g&W%Uo&0Ezej^NEO}hd00Ys)_z=E zuhd5qgE#kbhF`NzD#)hX8f#A0?wQR5p=v$Ko1#Dld#J#@ve*+*@+DI!d_|8n-|Oc1 zgUy4U*ay%lUSBe+c`TER{F_(Rzjj@J`5d4WX2utVPWFHGM!af&0Vqx#?l>)O0&V*J zCuONrIoOm^N3+xKd1LoZXQ&+w>g}V&m%4nWdr#*Dm+}a)rtdwEieNjO58Q6x)9xvi zKIQ%u+rd|?Tv3|Ot-TZr zt}9&|f2Q_wt%VdQMzie~JNxjb+4S8eGl+l&>PF=4dUKTme*~Cb^U2)yylFbFT<*SN zxMr1VIs34AkGTe6=>L7Um$%<5S6#QXvXj=`bxPf84pDmG?lNUoM`QZ8-|r$bE8==J zFc8sjunBBqM40Ac?@F#ZV4$kFa73o$n5NX2;Bo@9Dm5h^blq7&EC^V$7ee(3127Pl z%ncHxX1yPJ^6G3ZZt~?GD-rRuYWCJ=$21Q=*0Eox$MiQd%bz{3{riqHeeb3>yrtS+ zJi<%fB=+g8?uV+FH7OH01_p;nN%W=Utx@E^*#vzr=k2)P=(Y8w@(ng*>q9r04FY#) zTy#$Fe*J6}cP{OQ6X?rq0?ovII{E|>B@?bKWOY+IDV(xu0#c&B!h@>*KU?VJ;G;X>>5D8r zP7;podj~f4y9t8Sg->W+z@HJ|=_1vXM2Z(r=-ue{JUMK6mJB{3&?K_;ZxO`f;C5>so;mx?UEzORy;>Q@8Zr?wnO{n046&t6|F?eM2~ zLpJ92XqX){_WFDW-jvJMT)2O0x^od@DB2pycW5er405APwpuT8iwA|W0ndqK1YHcZzC*Uk`^S9 zAKUgTGHBx8TJmGFrhuNX4opxZ4`_N-_?lQUPDv%^H#*!6=9TML(mz62QIWt7Jzkul zKy4e|nIH8F8u&vKl;iP+2&I3Zq+X9Tf5w%D+F#~(v%C*DItAEcY0lT*OhgLFH}mNQ z_U?(IW@RF>A|_X=k#2?0TB>$$Q7l0hREg@Rduc&!6LQk_v{Hq4)P$NXg`Or`t@?p7 zLe10JSuN_CoEVoxgFBU@%*6cMmUt_cFI(gY_vcl7*}nQwJ%ekF%DW!&&A4Wp2s`zC zs{fERx@v7$Ri}76u7U0%*hd~kHl4;ft@s7G+-(TB4v<9TpjO8FM#$f;FC1y$1D;EK zair&Qr2@A9*x|THd+)i73ms@Ni%I$s`-ZrPt8`}P`*b1qtsiSjbOUB)l-!uKn*Q?Z zF|XHvExGcl==aLY;+I)WY#Tvcixn)oyb+EObU+cD!{|sS#mBHidNsljiWua#~Wd3_aLnTal zj2C$b?cxv`GkrdFy{RC$)#`>Yx5QpyE_O^aM?C@_NWkWj-Lw3aAyMqf88G?XnYJV$ z>*SUHwAjLXG58|bPIi_rnE?ql43lUB38d#b=K>%QWE8O>*?~1N*OY^Q7n^qgCY?Z@ zSp4-n(fDyG$$d}nbpgV&YC%J?#p9@EcEX2bTG@KQi{}}g-}!5Q{@L+%KeAp>;6&vz zKH_dS$({4Jbr&vKbIrwrT8tyTyAFpM40d<9kD4!5-jH|)oO$DY7f1zVSUj)ij*cs9 zua89HcOCjTr-RyiF>FnzdpS|pS-;LVWh~%y%N-1VdPjtM59Sfrz#?`9s{}$sriLjF zP&gVbJD$1`Z(hBOdwSKd<{wYzjS2=B1(bOA&$B$;#}8$}=aCnt$aUF0#^-PQ zaQz0S1ppiWTMEEk`W+gSV**EnRl>npjl4%w&1#3Vfeu3 z3Fw*oZ4~HbOtF?s!D~#raLpK^$DEKgM~;~0x9tb_gt%ysk>4({slHmEVY~lRhK%^G zYk6dSr7tV+j6b#*f}+2y7mR~?FxmwlUQPe=W1|}!hGIi{Q>my)#tm_Jc0<)c9% z?*VSFxQ5JrP(OxTe|-=`i}>oFt_}%%oPmv6GWPdUpcwjl!aJMFGS0DqaKvAu-GYA* zZF=l@k`{xc9m*PZG2^B2GAC;O2=N&SLnJ-XKKyw-pAe=}Veoq;`P8hQ5upV83{}|o zECtwI(7N;!Uxi&@ZxMtV>l^IdwGumCa`Btr0XR;rE5t{+z)wtw)6PBPw)CX#&j+I!sQ?`81V{~ zaI@QxSmDe%@4gSG!C(TdWtHnint^FU%jaU~WC05S8_}5-^&h~glj^=#Fyl+5w6TB1 zv7U!ZhK;q!w7Dw%{su=owR>UqhQ9J@=#_zc_nSl2*qq0Rqe{Kj@Q6^thJcK=oL$#H z90i_#SxdP}ZzbvPf+WsKsSY(HSk7*wBUc^E)9D9a{dJ~Tac&H{ZolrVF5OK4($?f)WLwY$#+FL2HriW0|?_H5toKstKxJi?Io zT@Oo;CN7!qLAA~~+e#BddCIp6o_`C4&4P0V#;dQ@>PD))six1=&mH{I*E${v>>U@$ zAW>FqLre*dt2-@iirYuEjTejU3^HSH*Gq7JbfcR!(aA#B?et;DdxeS*i}#lRNW9Xi zxLmPufg-%dTsJGI4mn-<;s?abK)1?EBUg$*sw1VhY$tmb8v`bwFB7lSs_T==22$V2 zG5TvsPLc0WdhNBxB=@L(hP`v$w6l~Wf4p5-ZVpZ(l0oL#6Pah<3XdYBY5b?Q$cwx&ymvE1kA_GxYo4q*|(+?g`#(p9jmTC*-2PGwsO}7@38=G zCo<$ajh%rH|4#wl#wc4(X(1N;)#!uk$MVPqjlo-#o#0!HN$lkFz<~!oBW>`(dwZGV|5fnqJw@2Xh2L)pGa7qR~xz+CReZYOZJzniW zlFI)I-HvF3T(<)08H}_ zJ}g$|sL7MNE$un;r*a@qESZA5EP#^V>83AeJn?%daKWS^4Iq}76gU2VLrWP zM2-RBIo<)0t2gj!(h{GmprSaHetA2&b`>q|?|(f$Pr8;&Dq!bcECo$~3j5RYF&a>A zXWlYXZ7NK*jM`VCxB6lu1Cx;VGMw&>ci3M!EHXumw+CkKqJ9g`;o(Yslrj|gL>JY? z5wb1iZD~*71k12DOEOKe|Thst_|l)=QbkqU%pZbnr|9 z!`|^D&Y(jf#Rpf?y=~ulf1T;yy92tLoKPsI{Bb1JXw#*!EzURIiF`F0GH>e=;opm{ zQJ@X{{+#FX`3uWeRkYqv&O`R{X#cqGEPBhmH%qh(^4Cm5K8S-pI*0s*t{FIrjtpBT z7nArtp8)NWzl`ScjXdaeeYJL=2l=`%F~gBNQEl{laiY8OcJ=0O;Gr<6ek!WaN)R;x zPw7G5C+;kTq6{_ywo`_(^4;dS=#4p9e#C)>vrcg+jPBYkgthHv_RA}AeYZ}|DpJ>C z3ez(GZ@p$`GMB2bo3VyD)EpgKq03ZLGtX9P))()7GEm__Tw2-AksDYs110*{+yq;* zO2gFLdwm`z)2se8C*1GTIyet{?v5zv|baN6NmyV%$K)TK4Rst2SmL*@Wb#I~Qc=OxcSPhn?zRO`uO}E))6cM_X z`CFl&^on(2*!G3(o)GBN#HJe>TN|Ej3$xU@7Kq)=eps26jw{o6hd(O{ zt*;lna9c@1`691!y+`#%D5ne571?EfEk!fe5J~496o)2#fSpVls2}~&+2_E7(cz#Y zp=Ttr(wvnw%0JnXCUN_R4lP3hc{)pK)2KfC+!N`={s7YpHsCoE20nNnBMHn1qSfxnBVlgKdeWWh zdDldP+3HVFT|O)cF=T(~Z?9yI24+#Q<6w&znz$)N@MDWi0V2=`q|S@Bca+2q_84q- zdLNoAAxeU$NWM^axUP=|eQ6lhk-4zRy{<&5`u={AeW-U(@|^5-3p?n(IKQ1@sM^lY ztGc+R85l7L&wA7AMv9ff1mtK=_Kn8SL0v}$A#;|vh7ryi0;lHags_&z^~$AAKyDR* z0>^?5*5#Hs^8@K4kTvqRWrbyd(lP16%CvM^Qb?3R_cRYQL~jeUh;DS~c+bLc`q)=L zt1^nip`6r0Z81q%PUb5a#f|Gz4OK3SA3S&@k{oPAO16l&L=@}!dRCUo9ol!{wDU)d zPU1?&g;UmSg+hZ4oPG>f?C00({f%okD292j$Rn5Q<(z3-w;c@noAY+_-JIoT7@)ej zy1{}P7_raXkpXc_8p{>MqQ{;GHY1!%KwUt%3-ayV)sG_$Y*q@rb56p}v%Kr{5t&O; zBz-$sA@`)CvFj(%cR3mSB%lyQiyO2oG1P1)2&y1;j&MFB&|gY4B9HWkBwj(fXl9)gm)2izkl#Re;8oBS1x$iS#Q=y#z_LK0IrG=#wFFBJ3GRo#2d&0Gh9!+2O~>8lcF?TW zEZ;~NHcy2=B1igr{kk!xM~yC{3*4N<&$DN5=DZnrUlkf|0jgN?`c%fEe{tFDlyj;3 z$D5_+{gc*mytyP%UCRFKZy4@6_TuF`QR9CnY1v0oWCdP5LATg+so=3r2|dxdMW_)Z^0C52%@%x5yc zk(MCt@+p%?ATsV2ntkhilsu{LR0G>{_EHO?wy4U%;(&L}NVI7jd}K}cUQkRQ7;iaN z1_`&2=sUnTC0nUi)e1EZa^MsAZzre^md)t$t0UQ@dYY zsh`sJn_)SG4%Gr%Qy8CEtTZ7335wp3Q*XqH@xRrNxUJB=jegj~A1K+|#gBT~wHEmq zA%)G4c#N0_16ZYisu^IpCt%ptK^5=#u^m}oY#CvnJ8glwNeq`ss$aSfJUy6t6d1w` zN#DTks-gEH?fjJ}h=EjxCDuusHCw`Ag~b!qCu#zYIr>DlBKy;)$JjleU6+4P5Nr47 zuja2kyWbt@J<>OBSzm=4~j5y!Ot0pm*MC)k{OV&TO+_Pkn z)_Eqofjl`_Qdk}>?toR-NqL3RtMnJf=3wQUKKl00BcZ<6UGZ%A_I_L3pe9*&D0^FG zB|0!dPE7)R(Smu==LM`a+z5uxRjC;aKZ|Y&wd>V>r{qfE5x<+k=c0M_WPPJ4se&bp zSVswHYV{~9*{MRu!$mdRDC2x90!K#i?HsJfnrT-HhF>?i*g~T@s97`TuN}5s9&q7;(Y#RDb#*=ffeS|Cs zc04i_m>vn<0k0|KJlBM9J%|B3`q(`+U&yEW=j^>#r@Qkl-UnZDEVzJh-msS}@%ZFq zmw`==B2xk*LAP?t0U0S|4mLvP{j2l5?fiQ+SuFS*F5(FP-5r};Ulz1(Ue-vi5k|)x z=KR?lUdVqgsecP84eo1j_!4gjLrcXBt*G}O#Y1tm&6=i@9`yBK{?E7P|3V`1|M-uE z_zKB?+NbzSYc?6>?r#AZS@bX2YN@aTr9*Xfbt8`nMK1j+$k;JopPKg+(B%x4S|kM8 zjd3c4a>7}g-a+TyP1i?5^KC$J1a-YV4|Aj`(Y0^RVg*XF0+@^nm;!xTCA#`8Ufi=r z?t~?}?`y}Tvp6eTNrM@2iyA`YqS#plAwUAsf*{o@VQBN~%Tl1Ty)OD?%FY3vY6W>j z9Xt%do#^P|>!A#T+W#E`hluh2Stincj`^9g8>wLD?}Zj1KWa-z0W`UBLxZ6uLa7(b z4`1^e$MREJykI6}PEy8Gc}L8uD}NVq=}&J#pqj>0SXvrm#1m;{;I;~io}ll6DmvJW zU^5i8x96p%rbeJ7pKA-j1Z8O%hH8K|^U?lzaI~6ytB4AF@=Ly<{>WNsh?WY8B1w05 zHxTg77HM52G;-;@EA;f~ha2xlMZgqb$#$IW!7p#m+s6XV7nQ)4N_ZjEqj+Z9M+x>1 zq{)Z~o_m^B#13o(f&7n6fya*@TcU-vb1rODWVMJ6?@2GzR~Zr3Uaprg9uek0T(fle zTPO7<@1P8os;I4yueI{aeQYy~;hGWbL!i7%j3wJ`Y}q?(4i~Q2bsKz=R^_#4*mhQ5 ziP&=vqAB<6_6Ytw7;8V1skP3s>ed@fca zfx`F~XbIl;+@Gr)8lzS_r!hN{pD`QepX3syU&F?54N1rYu7nAz&MR(`kv|&Mog^Rg z4dot}wf{&~d6LTgsxMOdCd?~W>_&)<$V`Bf&kn~G)a2`sAR z={LRa?>C3irk0m^ALH{s{tz3BKI}A0huFFPN6J@MSHJ{KEtatZF?EoOq&NsdAu|MR zh$8PZq*^s83jp=KxOd%9h_UlK$iRG@U;7X0Wc(`+F!`I#tu^bf{)@M~rP$ zLw~Rr`7v*HzhaOZy?4Nc$&ufYC>2nv6fUtoCH`z!F5tayG%ADgSLPxWT(E_%)L0FP z9uEtayezG~J*LLONVRfZ{~%KHy7LY&b%n=y3M%YigQ&1OHSe%Ax3qxIc`nXS%Igz~ zZKlK+_-y*CNLh6~-?@G?iit~5xFle_D{g?e(&58a6K!crsuhQP)#U)EIv7aKbEN$6 z5K)RsqlkDEtq`iCA!g-pW-ojkkOw@<%QAgg%7_{vk-I>3>wBiUnJ-g2SI(9Msh?dZiTe0<6PNqCDZ#fcOr+a-eJ2LjSml_tx@rbg zt-CG%iAhSE$>byGFY2;EdNj^tg5zmw%3!!_fbuVnafAb5*0*op{t3)UDLhog=#}ri zIHx%+*ZxFKexCyG2gZ*~W8NNcNkBW*?|k2Cxh;S&LF+a zH0OPeafeqyqPBD>+jwlt_c`y^hUGwswgVB%5DHf}EtQGs>7KCr(gQ%gzyG`OuBD~H zgOBTn$9br1)7zso4==AojpBZ5nT_p>K(3*J+S(*c9HPTK)Mehr@gjBzyxG_PTMn@8x!Oce6IoL^9!pOFx}=6*$c% zsH<5Eg9n>#RPmT0Jtx%P)8}C7s;c)Sy#B7p+^)+2J$=jCc{``YX~DjDl|o8-`mNf$ z8!jNw2F@Nh4RXX-Q;V%hnKRVoPvc~6MNN?lvp#FltOJ$;>n-<{EabX%Oc%mU@%3+J zbnFbXyGNR8-wHot$Ne53;u!X~(eoiq8!Thso{g1aM+7cJrH~YT$f>BQ*Z!$|O97mV zg0@hq$CDn9f0b!viCt!my%B}H0nz2J8YU+v1s2sM%wqY$unMs0FE?0a2B~baJOBJF z9o%$-;<dN0-el);%*5y!o;VyY?nZZ zy%3iJLtY|c@PO{o#NW{$qYTuH5Wc>6jbio`75~d2(=9|l!}c0zrRfa4YblU{2x1RU z$NKD7hrGJ-`BPHdh}>_XqNV-P)a2Wo<<&)H0UklP*#H0xK&SVnvFKZ``-j}SV8%p- zS_BLRi+1LGicouI?S$V>>9VpErcmp^dmS@jXl6q@=?+Dh4o?f!EtsJ~G)P7AgL6Q)L)R>0GL!PS;pl-;R>LvhLIP>UlTDj~3^3qRS)U#AAr+5|xO7A|Qld=__2`m>f!Sb*IO zafDyA$t;eL5f0aIaSg2;Hh;P(eH= zb;UmvSlZHm-un5?S6ko|LZdyzr8*@r$>i#_dX?ul9&EU{6R}x47Jp6d;=Lk|OFmTc z&#nveIw`y68oh#iGAt*Jc;xIm^y=cn@&zFnCIiq2xQ*Qk^XCJbZmlN&}-4<$gkf*`!PLZPYN&_1x$&-gRs~NLD)7XY3Jj~(`>)gq%OYJLUwKz=j|TkKvUpN%aGnhw48VSk zCzGm8o2jqH4F&o5ATK6U(#1do1U!&Y!0FGw^R$esU0!0q| zwUgAK^DA$^KDg#eT?VO#9 zD=VFwvzUAC#j;?f4p~*S-@e^%Lps5n7R7hd?!@wg9pcouioJA{+Mreb5`-B56Bu-# z2Y@ZLJ5#>y=rD$-IZ5o$`sv^Eih`IX}Zj9Kjb z{wPzsb9jI^U5BGvaf?Bc{mWSlv?B%~qK>9iib|ot;t0vw6ZS&zBA9c6o~$FJz?6M} z1Tc`N<*$IzY@sfPx_6Q_MIpHvC6ptjaV7MgevKvGPy6}`c;%vJ#mCdB#-nz_9|GBj&ypKeYMhcI6(waRFNw%n|r@zP{lr z2qW$tfC0f_5!jS@_uOfmM3~U(TTH2jDsTPw+0|p4Kq)$BeD;SXfwFaTypk?A?rH@r+-PjHQ zRnryhHUo?h2n;=x>jCf|Q;S~=K%fs!$oY~Vuix32UbkcCNRcw+2d-m2aH7XEx$INHtsY=P9x0P_!GKq)XQh(KIIVsQI-YLV+vZa1ai z%j&&Ind?U_UVHZG;t=2vkO%E~yg`>kXsG+SzMf+27zFUZjX-r&R-1WL*!NqHHQG+g zok&0y!p8~4f_%?Z5AUgwzUwbI&;fq-2482NQk7|uvi80 zC@5^w4d@_{FHm-2hq(^Dwj+uqa8(maOB(rF9p?cCe&kasZ$4NVSp2hq7I1fJ*%Rg( zqLyH`h1ELJz+vcUL{mC%yLq?50(d^rkB{F4vj8zlVl1!{`|YSe^dA7o-rruX8fvXpId%yX>KF8;Cmck1NQlF3I}u}~`mV2}{)sVqEENe=4c?Y{9L z<#DT)bY(q%d9^4mNp7PwDW5kQ*u3<*9fx29^JBwdz@z^1UJh{h)tE4)DU+iZ^B`fw zdXwpKQSWcXW?+;@vP5dV4@`_^9lwqSP5<^5N*mHH(VeTdh#VeO51r^P1Y7CC=9`zG z$Tsm^5?S^RUhJgV0VC{HTxuz9-AQJB( zkoOo64F9Y72>(C0&n z$MraAP-w%U!}i&RFFnlhbA6cx{e24pSz_SKlYmb0GbM~iTEY>;RV=mng1RrRTLo3j z`2E6i0Z4t{%aoIob3J-+O{8ZU@D%1q76BTYHN2PYRTOL&aA1YK$JLsBmO)*Pfg>%)3d4b}&+v?u#MMnSfvg#s>Jx$xWs?N@p9=A!B9@tiZTmZ2w+JTP)vsiCfj+B

qqiVB|pijg;w(tyAM zbP1{AL|Gp8c|e{KPd^x=$0H`D14coV=$h|L7IK-iQZAqGUKzdXnd&ZH5Uzmw5DFa0 zWZwDK_Zowf4o8o@%it_0`zHqAkwI*eIQYfLs3#Uo|EuA0YohH-2d+#(TY)2`puWET zQSN~UUN`ZqCjcsy$fqA;ALWye7>+e-A1DZMzQY`b5q<;yeB4l{ME5YDJ-_B#@1UK> zBFu;aQc6#u3u4gbF-tFQb_F6atJkNE}lk@ZA4$S+p zDaI*w&-rz%Y7JnH@V>qeG&JTo!Bz%fhTY8>98D$C(a~81v9c(EVI+W^eC7N-B{w&> zSw;`vC1nk7c^ga$Qrt z_P^9PSZeu5B7`&Q%=wq^b`CRXwCf0mSWm_w>K_h_s!>n7O76nZEn;;N?~}V0jqQe; zEt>*i+6rzDu%CfN3HG5{0igeSWciw~9ffQkyWGyxB*p^Zp2{xDt}wZ)h6@b0!y%$w zQ8m3HMWc`%kGC_Ls5qz!@JhZQ=DZk>l

    GwS@2!ufxNydYp1vLd1r?^*O-9szuU ztMS8G&;FaYEGgzal(+Tz8zy5G)sABe-+VrkuV5g%;~ndt#Lv%N%41?dK0i#SlkhqO zzBn-pBw1s4nxiTzDypOOc?8xJz+OR015oC$P#4W`dl>1k)Y`N z-YlbXJjA)hB>K%xYM%oB3s$<}lPZ&>LV}SM7JS+kXYIw1Y7x~SE3T4IaWg#Qyk2%6 z^8BfYNYdE$<|psD$JWsa1@RtUeN3CvF2SP5AA(w+!8ZjS8kg;p+$95o03M8^c@Ma6XIDr0cda@i_sL`aoHqL)2 z`2TL`5OAtd*urmrkN@Vu5{p-g>U#uOXF>pt$Q1z<2AHIe>j29FD9uMeQ$$`(`~hg( zgG|G3SpyJBT6aefTGkp6(Ta9--%vOt|fU+%q}c7sXR2XJ<#VK{vD6u60%MYxF#uTj-<@dm{|PkIX!eA$74r2FM?BId&xwjeCwnyBno*j^W+WnEA%Bv8 z9Up^CSiTm>sMV!LzVB&;4P4cZ&iYbT!6E^?W3^i_LzA19xKxgUF9h0HqW-pqI z`p$0#X`eCFgm8D%Cwa#4K4*V-fJ~zM4n9Ln*hwikU%UOvq5QOMP-9p}<-<*^K;OV` zFc>R5J@_+nYWutr)YLD%c^K3CVcsE?k07ogz=BYfnG`G|Wak8(yi-orC{`|>BGdTV zz!f8xUo}yo%i(QRJHOXa(hp}Vf2s}YXMyOvFMW#2rq2Ns{j*B0#%Z0MvH(=Tr1BT9 z;XgKyjJ@g&xxr{qKiYn=Q=hau4saF%`8E)l522@Yg{L#Au-DC?ZOx*_8})j_o0J1& zE}bGt?)KuI=%^n{shKvpawh}$Zu9r8`W43CCC6GM-WN2Ie%khJ&n&Zoye`lo1*;LB zZU_f&J$%+up-QgkCpm^J(EUvY-mqpZe+n)zMw@&OSPv=j06;ahKZsamDVh9t2pLa( zs2q(-;iR4ts!R#>1UFQ6?D*CMJ+p||+)Ep{lqH)mMoRj53xC&m0s;roIA_vfH|FPE{F6sUw13wr*RXwy$G{J*%NE5_R7QZ}=} zcgIq9J`_ZmSBsX_2XbYowNbegmrnfqO^t@-!T$MLK2seX9YqsufhYZMZ(l4^hHd*I zlc6nO{^%~oJT-cFSGI!vW7KO)%Z(gh!DJY2T0Vbggix0AZ1^s*6i%mF3S6pK{^!Tp zr>_ul`C5%u;KMD3yAQc3PeK8C_C2)zCNwJr+R#$rmjnHFsvu;9UOh6M-6?Mh{C8PL zm)E>pLw8KBU$>=YFEMcQr;lwjoCcuGEr!1*xniNG5I$m=wM99^HWeF|n`DD`C0^#; zB!aNR+Ci*?(!EiO&B%ZwWr-?cb&B_C4*H^_$ZYEJh`JAVpd}|Cx9TrBJI0-M4v zO+4^cF16*wbNbE$){(bY_Vrhu<(_d?25-2A>?`i#>L6Ot_6xxT;yAib2Y{%`19{AL zI;_seD(nDw16IsO7;(^hWp`?RippaUtE;aEVN6tktwYNvsD1u!vtDzBpA}O=<0xgV zmIefUc8fI1gO;{^m*{@lpH|q{zkOKc>;Z;qvSg?U0Lmto0^{uj+1q|P$TR<6l?O;H z*8G>b1$A1oOPctD?5W3}yGBL*Lx|4{YpU?hdDws+k2&a{OJ+lpm;Y oGkvPPFuH!TI$j1%$RP@IW@-ASVM#j@JxpF%QA43Z?se$@06D879{>OV From 291fbb2cedf67cd8c61ed8f72a3c94c144749553 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 17 Mar 2022 00:25:29 +0100 Subject: [PATCH 002/183] style(kiauh.sh): add copyright notice Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 0a61f54..87f5a08 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -1,6 +1,14 @@ -#!/bin/bash -clear +#!/usr/bin/env bash +# +# KIAUH - Klipper Installation And Update Helper +# https://github.com/th33xitus/kiauh +# +# Copyright (C) 2020 - 2022 Dominik Willner +# +# This file may be distributed under the terms of the GNU GPLv3 license + set -e +clear ### set color variables green=$(echo -en "\e[92m") @@ -72,6 +80,7 @@ title_msg(){ } get_date(){ current_date=$(date +"%y%m%d-%H%M") + export current_date } print_unkown_cmd(){ ERROR_MSG="Invalid command!" From d9f94fa58d862d41414ce0d3d91261f8e0da8be6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 17 Mar 2022 10:48:25 +0100 Subject: [PATCH 003/183] refactor(klipper): merge all klipper functions into one file Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 5 +- scripts/install_klipper.sh | 195 --------------- scripts/klipper.sh | 494 +++++++++++++++++++++++++++++++++++++ scripts/remove.sh | 114 --------- scripts/status.sh | 122 --------- scripts/update.sh | 27 -- 6 files changed, 496 insertions(+), 461 deletions(-) delete mode 100755 scripts/install_klipper.sh create mode 100644 scripts/klipper.sh diff --git a/kiauh.sh b/kiauh.sh index 87f5a08..50a9451 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -55,7 +55,6 @@ INI_FILE=${HOME}/.kiauh.ini BACKUP_DIR=${HOME}/kiauh-backups ### set github repos -KLIPPER_REPO=https://github.com/Klipper3d/klipper.git ARKSINE_REPO=https://github.com/Arksine/klipper.git DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git @@ -87,14 +86,14 @@ print_unkown_cmd(){ } print_msg(){ - if [[ "$ERROR_MSG" != "" ]]; then + if [ -n "${ERROR_MSG}" ]; then echo -e "${red}" echo -e "#########################################################" echo -e " $ERROR_MSG " echo -e "#########################################################" echo -e "${default}" fi - if [ "$CONFIRM_MSG" != "" ]; then + if [ -n "$CONFIRM_MSG" ]; then echo -e "${green}" echo -e "#########################################################" echo -e " $CONFIRM_MSG " diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh deleted file mode 100755 index 4d6ade0..0000000 --- a/scripts/install_klipper.sh +++ /dev/null @@ -1,195 +0,0 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" -KLIPPY_ENV="${HOME}/klippy-env" -KLIPPER_DIR="${HOME}/klipper" -KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" - -klipper_setup_dialog(){ - ### check for existing klipper service installations - SERVICE_FILES="" - INITD_SERVICE_FILES=$(find "/etc/init.d" -regextype posix-extended -regex "/etc/init.d/klipper(-[^0])?[0-9]*") - SYSTEMD_SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])?[0-9]*.service") - [ -n "$INITD_SERVICE_FILES" ] && SERVICE_FILES+="${INITD_SERVICE_FILES}" - [ -n "$SYSTEMD_SERVICE_FILES" ] && SERVICE_FILES+=" ${SYSTEMD_SERVICE_FILES}" - if [ -n "$SERVICE_FILES" ]; then - ERROR_MSG="At least one Klipper service is already installed:" - for service in $SERVICE_FILES; do - ERROR_MSG="${ERROR_MSG}\n ➔ $service" - done && return - fi - - status_msg "Initializing Klipper installation ..." - - ### initial printer.cfg path check - check_klipper_cfg_path - - ### ask for amount of instances to create - top_border - echo -e "| Please select the number of Klipper instances to set |" - echo -e "| up. The number of Klipper instances will determine |" - echo -e "| the amount of printers you can run from this machine. |" - blank_line - echo -e "| ${yellow}WARNING: There is no limit on the number of instances${default} |" - echo -e "| ${yellow}you can set up with this script.${default} |" - bottom_border - count="" - while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of Klipper instances to set up:${default} " count - if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then - warn_msg "Invalid Input!" && echo - else - echo - read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Installing $count Klipper instance(s) ..." - klipper_setup "$count" - break;; - N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting Klipper setup ..." - echo - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - fi - done -} - -install_klipper_packages(){ - ### read PKGLIST from official install script - status_msg "Reading dependencies..." - install_script="${HOME}/klipper/scripts/install-octopi.sh" - #PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g') - PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n') - ### add dbus requirement for DietPi distro - [ -e "/boot/dietpi/.version" ] && PKGLIST+=" dbus" - - for pkg in $PKGLIST; do - echo "${cyan}$pkg${default}" - done - read -r -a PKGLIST <<< "$PKGLIST" - - ### Update system package info - status_msg "Running apt-get update..." - sudo apt-get update --allow-releaseinfo-change - - ### Install desired packages - status_msg "Installing packages..." - sudo apt-get install --yes "${PKGLIST[@]}" -} - -create_klipper_virtualenv(){ - status_msg "Installing python virtual environment..." - # Create virtualenv if it doesn't already exist - [ ! -d "${KLIPPY_ENV}" ] && virtualenv -p python2 "${KLIPPY_ENV}" - # Install/update dependencies - "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt -} - -klipper_setup(){ - INSTANCE_COUNT=$1 - ### checking dependencies - dep=(git) - dependency_check - - ### step 1: clone klipper - status_msg "Downloading Klipper ..." - ### force remove existing klipper dir and clone into fresh klipper dir - [ -d "$KLIPPER_DIR" ] && rm -rf "$KLIPPER_DIR" - cd "${HOME}" && git clone "$KLIPPER_REPO" - status_msg "Download complete!" - - ### step 2: install klipper dependencies and create python virtualenv - status_msg "Installing dependencies ..." - install_klipper_packages - create_klipper_virtualenv - - ### step 3: create shared gcode_files and logs folder - [ ! -d "${HOME}"/gcode_files ] && mkdir -p "${HOME}"/gcode_files - [ ! -d "${HOME}"/klipper_logs ] && mkdir -p "${HOME}"/klipper_logs - - ### step 4: create klipper instances - create_klipper_service - - ### confirm message - if [[ $INSTANCE_COUNT -eq 1 ]]; then - CONFIRM_MSG="Klipper has been set up!" - elif [[ $INSTANCE_COUNT -gt 1 ]]; then - CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!" - fi && print_msg && clear_msg -} - -create_klipper_service(){ - ### get config directory - source_kiauh_ini - - ### set up default values - SINGLE_INST=1 - CFG_PATH="$klipper_cfg_loc" - KL_ENV=$KLIPPY_ENV - KL_DIR=$KLIPPER_DIR - KL_LOG="${HOME}/klipper_logs/klippy.log" - KL_UDS="/tmp/klippy_uds" - P_TMP="/tmp/printer" - P_CFG="$CFG_PATH/printer.cfg" - P_CFG_SRC="${SRCDIR}/kiauh/resources/printer.cfg" - KL_SERV_SRC="${SRCDIR}/kiauh/resources/klipper.service" - KL_SERV_TARGET="$SYSTEMDDIR/klipper.service" - - write_kl_service(){ - [ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH" - ### create a minimal config if there is no printer.cfg - [ ! -f "$P_CFG" ] && cp "$P_CFG_SRC" "$P_CFG" - ### replace placeholder - if [ ! -f $KL_SERV_TARGET ]; then - status_msg "Creating Klipper Service $i ..." - sudo cp "$KL_SERV_SRC" $KL_SERV_TARGET - sudo sed -i "s|%INST%|$i|" $KL_SERV_TARGET - sudo sed -i "s|%USER%|${USER}|" $KL_SERV_TARGET - sudo sed -i "s|%KL_ENV%|$KL_ENV|" $KL_SERV_TARGET - sudo sed -i "s|%KL_DIR%|$KL_DIR|" $KL_SERV_TARGET - sudo sed -i "s|%KL_LOG%|$KL_LOG|" $KL_SERV_TARGET - sudo sed -i "s|%P_CFG%|$P_CFG|" $KL_SERV_TARGET - sudo sed -i "s|%P_TMP%|$P_TMP|" $KL_SERV_TARGET - sudo sed -i "s|%KL_UDS%|$KL_UDS|" $KL_SERV_TARGET - fi - } - - if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then - ### write single instance service - write_kl_service - ### enable instance - sudo systemctl enable klipper.service - ok_msg "Single Klipper instance created!" - ### launching instance - status_msg "Launching Klipper instance ..." - sudo systemctl start klipper - else - i=1 - while [[ $i -le $INSTANCE_COUNT ]]; do - ### rewrite default variables for multi instance cases - CFG_PATH="$klipper_cfg_loc/printer_$i" - KL_SERV_TARGET="$SYSTEMDDIR/klipper-$i.service" - P_TMP="/tmp/printer-$i" - P_CFG="$CFG_PATH/printer.cfg" - KL_LOG="${HOME}/klipper_logs/klippy-$i.log" - KL_UDS="/tmp/klippy_uds-$i" - ### write multi instance service - write_kl_service - ### enable instance - sudo systemctl enable klipper-$i.service - ok_msg "Klipper instance #$i created!" - ### launching instance - status_msg "Launching Klipper instance #$i ..." - sudo systemctl start klipper-$i - - ### raise values by 1 - i=$((i+1)) - done - unset i - fi -} diff --git a/scripts/klipper.sh b/scripts/klipper.sh new file mode 100644 index 0000000..7a9cb8f --- /dev/null +++ b/scripts/klipper.sh @@ -0,0 +1,494 @@ +#!/usr/bin/env bash +# +# KIAUH - Klipper Installation And Update Helper +# https://github.com/th33xitus/kiauh +# +# Copyright (C) 2020 - 2022 Dominik Willner +# +# This file may be distributed under the terms of the GNU GPLv3 license + +### global variables +SYSTEMD="/etc/systemd/system" +INITD="/etc/init.d" +ETCDEF="/etc/default" +KLIPPY_ENV="${HOME}/klippy-env" +KLIPPER_DIR="${HOME}/klipper" +KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" + +#=================================================# +#================ INSTALL KLIPPER ================# +#=================================================# + +### check for existing klipper service installations +function check_klipper_exists() { + local SERVICE_FILES + local INITD_SF + local SYSTEMD_SF + + INITD_SF=$(find "${INITD}" -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*") + SYSTEMD_SF=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])?[0-9]*.service") + + if [ -n "${INITD_SF}" ]; then + SERVICE_FILES+="${INITD_SF}" + fi + if [ -n "${SYSTEMD_SF}" ]; then + SERVICE_FILES+=" ${SYSTEMD_SF}" + fi + + if [ -n "${SERVICE_FILES}" ]; then + ERROR_MSG="At least one Klipper service is already installed:" + for service in $SERVICE_FILES; do + ERROR_MSG="${ERROR_MSG}\n ➔ ${service}" + done && return + fi + + klipper_setup_dialog +} + +function klipper_setup_dialog(){ + status_msg "Initializing Klipper installation ..." + + ### initial printer.cfg path check + check_klipper_cfg_path + + ### ask for amount of instances to create + top_border + echo -e "| Please select the number of Klipper instances to set |" + echo -e "| up. The number of Klipper instances will determine |" + echo -e "| the amount of printers you can run from this machine. |" + blank_line + echo -e "| ${yellow}WARNING: There is no limit on the number of instances${default} |" + echo -e "| ${yellow}you can set up with this script.${default} |" + bottom_border + + local count + while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do + read -p "${cyan}###### Number of Klipper instances to set up:${default} " count + if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then + warn_msg "Invalid Input!\n" + else + echo + read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + status_msg "Installing $count Klipper instance(s) ..." + klipper_setup "$count" + break;; + N|n|No|no) + echo -e "###### > No" + warn_msg "Exiting Klipper setup ...\n" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + fi + done +} + +function install_klipper_packages(){ + ### read PKGLIST from official install script + status_msg "Reading dependencies..." + install_script="${HOME}/klipper/scripts/install-octopi.sh" + #PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g') + PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n') + ### add dbus requirement for DietPi distro + [ -e "/boot/dietpi/.version" ] && PKGLIST+=" dbus" + + for pkg in $PKGLIST; do + echo "${cyan}${pkg}${default}" + done + read -r -a PKGLIST <<< "$PKGLIST" + + ### Update system package info + status_msg "Running apt-get update..." + sudo apt-get update --allow-releaseinfo-change + + ### Install desired packages + status_msg "Installing packages..." + sudo apt-get install --yes "${PKGLIST[@]}" +} + +function create_klipper_virtualenv(){ + status_msg "Installing python virtual environment..." + # Create virtualenv if it doesn't already exist + [ ! -d "${KLIPPY_ENV}" ] && virtualenv -p python2 "${KLIPPY_ENV}" + # Install/update dependencies + "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt +} + +function klipper_setup(){ + INSTANCE_COUNT=$1 + ### checking dependencies + dep=(git) + dependency_check + + ### step 1: clone klipper + status_msg "Downloading Klipper ..." + ### force remove existing klipper dir and clone into fresh klipper dir + [ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}" + cd "${HOME}" && git clone "${KLIPPER_REPO}" + status_msg "Download complete!" + + ### step 2: install klipper dependencies and create python virtualenv + status_msg "Installing dependencies ..." + install_klipper_packages + create_klipper_virtualenv + + ### step 3: create shared gcode_files and logs folder + [ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files" + [ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs" + + ### step 4: create klipper instances + create_klipper_service + + ### confirm message + if [[ ${INSTANCE_COUNT} -eq 1 ]]; then + CONFIRM_MSG="Klipper has been set up!" + elif [[ ${INSTANCE_COUNT} -gt 1 ]]; then + CONFIRM_MSG="${INSTANCE_COUNT} Klipper instances have been set up!" + fi && print_msg && clear_msg +} + +function create_klipper_service(){ + ### get config directory + source_kiauh_ini + + ### set up default values + SINGLE_INST=1 + CFG_PATH="$klipper_cfg_loc" + KL_ENV=$KLIPPY_ENV + KL_DIR=$KLIPPER_DIR + KL_LOG="${HOME}/klipper_logs/klippy.log" + KL_UDS="/tmp/klippy_uds" + P_TMP="/tmp/printer" + P_CFG="$CFG_PATH/printer.cfg" + P_CFG_SRC="${SRCDIR}/kiauh/resources/printer.cfg" + KL_SERV_SRC="${SRCDIR}/kiauh/resources/klipper.service" + KL_SERV_TARGET="${SYSTEMD}/klipper.service" + + write_kl_service(){ + [ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH" + ### create a minimal config if there is no printer.cfg + [ ! -f "$P_CFG" ] && cp "$P_CFG_SRC" "$P_CFG" + ### replace placeholder + if [ ! -f $KL_SERV_TARGET ]; then + status_msg "Creating Klipper Service $i ..." + sudo cp "$KL_SERV_SRC" $KL_SERV_TARGET + sudo sed -i "s|%INST%|$i|" $KL_SERV_TARGET + sudo sed -i "s|%USER%|${USER}|" $KL_SERV_TARGET + sudo sed -i "s|%KL_ENV%|$KL_ENV|" $KL_SERV_TARGET + sudo sed -i "s|%KL_DIR%|$KL_DIR|" $KL_SERV_TARGET + sudo sed -i "s|%KL_LOG%|$KL_LOG|" $KL_SERV_TARGET + sudo sed -i "s|%P_CFG%|$P_CFG|" $KL_SERV_TARGET + sudo sed -i "s|%P_TMP%|$P_TMP|" $KL_SERV_TARGET + sudo sed -i "s|%KL_UDS%|$KL_UDS|" $KL_SERV_TARGET + fi + } + + if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then + ### write single instance service + write_kl_service + ### enable instance + sudo systemctl enable klipper.service + ok_msg "Single Klipper instance created!" + ### launching instance + status_msg "Launching Klipper instance ..." + sudo systemctl start klipper + else + i=1 + while [[ $i -le $INSTANCE_COUNT ]]; do + ### rewrite default variables for multi instance cases + CFG_PATH="$klipper_cfg_loc/printer_$i" + KL_SERV_TARGET="${SYSTEMD}/klipper-$i.service" + P_TMP="/tmp/printer-$i" + P_CFG="$CFG_PATH/printer.cfg" + KL_LOG="${HOME}/klipper_logs/klippy-$i.log" + KL_UDS="/tmp/klippy_uds-$i" + ### write multi instance service + write_kl_service + ### enable instance + sudo systemctl enable klipper-$i.service + ok_msg "Klipper instance #$i created!" + ### launching instance + status_msg "Launching Klipper instance #$i ..." + sudo systemctl start klipper-$i + + ### raise values by 1 + i=$((i+1)) + done + unset i + fi +} + +#================================================# +#================ REMOVE KLIPPER ================# +#================================================# + +function remove_klipper(){ + shopt -s extglob # enable extended globbing + ### ask the user if he wants to uninstall moonraker too. + ###? currently usefull if the user wants to switch from single-instance to multi-instance + FILE="${SYSTEMD}/moonraker?(-*([0-9])).service" + if ls $FILE 2>/dev/null 1>&2; then + while true; do + unset REM_MR + top_border + echo -e "| Do you want to remove Moonraker afterwards? |" + echo -e "| |" + echo -e "| This is useful in case you want to switch from a |" + echo -e "| single-instance to a multi-instance installation, |" + echo -e "| which makes a re-installation of Moonraker necessary. |" + echo -e "| |" + echo -e "| If for any other reason you only want to uninstall |" + echo -e "| Klipper, please select 'No' and continue. |" + bottom_border + read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn + case "$yn" in + Y|y|Yes|yes) + echo -e "###### > Yes" + REM_MR="true" + break;; + N|n|No|no|"") + echo -e "###### > No" + REM_MR="false" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + fi + + ### remove "legacy" klipper SysVinit service + if [ -e "${INITD}/klipper" ]; then + status_msg "Removing Klipper Service ..." + sudo systemctl stop klipper + sudo update-rc.d -f klipper remove + sudo rm -f "${INITD}/klipper" + sudo rm -f "${ETCDEF}/klipper" + ok_msg "Klipper Service removed!" + fi + + ### remove all klipper services + FILE="${SYSTEMD}/klipper?(-*([0-9])).service" + if ls "${FILE}" 2>/dev/null 1>&2; then + status_msg "Removing Klipper Services ..." + for service in $(ls "${FILE}" | cut -d"/" -f5) + do + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" + ok_msg "Done!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "Klipper Service removed!" + fi + + ### remove all logfiles + FILE="${HOME}/klipper_logs/klippy?(-*([0-9])).log" + if ls "${FILE}" 2>/dev/null 1>&2; then + for log in $(ls "${FILE}"); do + status_msg "Removing ${log} ..." + rm -f "${log}" + ok_msg "${log} removed!" + done + fi + + ### remove all UDS + FILE="/tmp/klippy_uds?(-*([0-9]))" + if ls "${FILE}" 2>/dev/null 1>&2; then + for uds in $(ls "${FILE}"); do + status_msg "Removing ${uds} ..." + rm -f "${uds}" + ok_msg "${uds} removed!" + done + fi + + ### remove all tmp-printer + FILE="/tmp/printer?(-*([0-9]))" + if ls "${FILE}" 2>/dev/null 1>&2; then + for tmp_printer in $(ls "${FILE}"); do + status_msg "Removing ${tmp_printer} ..." + rm -f "${tmp_printer}" + ok_msg "${tmp_printer} removed!" + done + fi + + ### removing klipper and klippy-env folders + if [ -d "${KLIPPER_DIR}" ]; then + status_msg "Removing Klipper directory ..." + rm -rf "${KLIPPER_DIR}" && ok_msg "Directory removed!" + fi + if [ -d "${KLIPPY_ENV}" ]; then + status_msg "Removing klippy-env directory ..." + rm -rf "${KLIPPY_ENV}" && ok_msg "Directory removed!" + fi + + CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg + export CONFIRM_MSG + + shopt -u extglob # enable extended globbing + + if [ "${REM_MR}" == "true" ]; then + remove_moonraker && unset REM_MR + fi +} + +#================================================# +#================ UPDATE KLIPPER ================# +#================================================# + +function update_klipper(){ + do_action_service "stop" "klipper" + if [ ! -d "${KLIPPER_DIR}" ]; then + cd "${HOME}" && git clone "${KLIPPER_REPO}" + else + bb4u "klipper" + read_branch + save_klipper_state + status_msg "Updating ${GET_BRANCH}" + cd "${KLIPPER_DIR}" + if [ "$DETACHED_HEAD" == "true" ]; then + git checkout "${GET_BRANCH}" + unset DETACHED_HEAD + fi + ### pull latest files from github + git pull + ### read PKGLIST and install possible new dependencies + install_klipper_packages + ### install possible new python dependencies + KLIPPER_REQ_TXT="${KLIPPER_DIR}/scripts/klippy-requirements.txt" + "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_REQ_TXT}" + fi + update_log_paths "klipper" + ok_msg "Update complete!" + do_action_service "restart" "klipper" +} + +#================================================# +#================ KLIPPER STATUS ================# +#================================================# + +function klipper_status(){ + kcount=0 + klipper_data=( + SERVICE + "${KLIPPER_DIR}" + "${KLIPPY_ENV_DIR}" + ) + + ### count amount of klipper service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls "${SYSTEMD}" | grep -E "^klipper(\-[[:digit:]]+)?\.service$" | wc -l) + + ### a fix to detect an existing "legacy" klipper init.d installation + if [ -f "${INITD}/klipper" ]; then + SERVICE_FILE_COUNT=1 + fi + + ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0] + + ### count+1 for each found data-item from array + for kd in "${klipper_data[@]}" + do + if [ -e "${kd}" ]; then + kcount=$(expr ${kcount} + 1) + fi + done + + ### display status + if [ "$kcount" == "${#klipper_data[*]}" ]; then + KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" ${SERVICE_FILE_COUNT})" + elif [ "$kcount" == 0 ]; then + KLIPPER_STATUS="${red}Not installed!${default} " + else + KLIPPER_STATUS="${yellow}Incomplete!${default} " + fi +} + +### reading the klipper branch the user is currently on +read_branch(){ + if [ -d "${KLIPPER_DIR}/.git" ]; then + cd "${KLIPPER_DIR}" + GET_BRANCH="$(git branch | grep "*" | cut -d"*" -f2 | cut -d" " -f2)" + ### try to fix a detached HEAD state and read the correct branch from the output you get + if [ "$(echo "${GET_BRANCH}" | grep "HEAD" )" ]; then + DETACHED_HEAD="true" + GET_BRANCH=$(git branch | grep "HEAD" | rev | cut -d" " -f1 | rev | cut -d")" -f1 | cut -d"/" -f2) + ### try to identify the branch when the HEAD was detached at a single commit + ### will only work if its either master, scurve-shaping or scurve-smoothing branch + if [[ ${GET_BRANCH} =~ [[:alnum:]] ]]; then + if [ "$(git branch -r --contains "${GET_BRANCH}" | grep "master")" ]; then + GET_BRANCH="master" + elif [ "$(git branch -r --contains "${GET_BRANCH}" | grep "scurve-shaping")" ]; then + GET_BRANCH="scurve-shaping" + elif [ "$(git branch -r --contains "${GET_BRANCH}" | grep "scurve-smoothing")" ]; then + GET_BRANCH="scurve-smoothing" + fi + fi + fi + else + GET_BRANCH="" + fi +} + +#prints the current klipper branch in the main menu +print_branch(){ + read_branch + if [ -n "${GET_BRANCH}" ]; then + PRINT_BRANCH="$(printf "%-16s" "${GET_BRANCH}")" + else + PRINT_BRANCH="${red}--------------${default} " + fi +} + +read_local_klipper_commit(){ + if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPER_DIR}"/.git ]; then + cd "${KLIPPER_DIR}" + LOCAL_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) + else + LOCAL_COMMIT="${NONE}" + fi +} + +read_remote_klipper_commit(){ + read_branch + if [ -n "${GET_BRANCH}" ];then + if [ "${GET_BRANCH}" = "origin/master" ] || [ "${GET_BRANCH}" = "master" ]; then + git fetch origin -q + REMOTE_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + elif [ "${GET_BRANCH}" = "scurve-shaping" ]; then + git fetch dmbutyugin scurve-shaping -q + REMOTE_COMMIT=$(git describe dmbutyugin/scurve-shaping --always --tags | cut -d "-" -f 1,2) + elif [ "${GET_BRANCH}" = "scurve-smoothing" ]; then + git fetch dmbutyugin scurve-smoothing -q + REMOTE_COMMIT=$(git describe dmbutyugin/scurve-smoothing --always --tags | cut -d "-" -f 1,2) + fi + else + REMOTE_COMMIT="${NONE}" + fi +} + +compare_klipper_versions(){ + unset KLIPPER_UPDATE_AVAIL + read_local_klipper_commit && read_remote_klipper_commit + if [ "${LOCAL_COMMIT}" != "${REMOTE_COMMIT}" ]; then + LOCAL_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_COMMIT}")${default}" + REMOTE_COMMIT="${green}$(printf "%-12s" "${REMOTE_COMMIT}")${default}" + # add klipper to the update all array for the update all function in the updater + KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper) + else + LOCAL_COMMIT="${green}$(printf "%-12s" "${LOCAL_COMMIT}")${default}" + REMOTE_COMMIT="${green}$(printf "%-12s" "${REMOTE_COMMIT}")${default}" + KLIPPER_UPDATE_AVAIL="false" + fi + #if detached head was found, force the user with warn message to update klipper + if [ "${DETACHED_HEAD}" == "true" ]; then + LOCAL_COMMIT="${red}$(printf "%-12s" "Need update!")${default}" + fi +} \ No newline at end of file diff --git a/scripts/remove.sh b/scripts/remove.sh index 2f756e3..9e69bf5 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,120 +1,6 @@ ### base variables SYSTEMDDIR="/etc/systemd/system" -remove_klipper(){ - shopt -s extglob # enable extended globbing - ### ask the user if he wants to uninstall moonraker too. - ###? currently usefull if the user wants to switch from single-instance to multi-instance - FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service" - if ls $FILE 2>/dev/null 1>&2; then - while true; do - unset REM_MR - top_border - echo -e "| Do you want to remove Moonraker afterwards? |" - echo -e "| |" - echo -e "| This is useful in case you want to switch from a |" - echo -e "| single-instance to a multi-instance installation, |" - echo -e "| which makes a re-installation of Moonraker necessary. |" - echo -e "| |" - echo -e "| If for any other reason you only want to uninstall |" - echo -e "| Klipper, please select 'No' and continue. |" - bottom_border - read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - echo -e "###### > Yes" - REM_MR="true" - break;; - N|n|No|no|"") - echo -e "###### > No" - REM_MR="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi - - ### remove "legacy" klipper init.d service - if [ -e /etc/init.d/klipper ]; then - status_msg "Removing Klipper Service ..." - sudo systemctl stop klipper - sudo update-rc.d -f klipper remove - sudo rm -f /etc/init.d/klipper - sudo rm -f /etc/default/klipper - ok_msg "Klipper Service removed!" - fi - - ### remove all klipper services - FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service" - if ls $FILE 2>/dev/null 1>&2; then - status_msg "Removing Klipper Services ..." - for service in $(ls $FILE | cut -d"/" -f5) - do - status_msg "Removing $service ..." - sudo systemctl stop $service - sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service - ok_msg "Done!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "Klipper Service removed!" - fi - - ### remove all logfiles - FILE="${HOME}/klipper_logs/klippy?(-*([0-9])).log" - if ls $FILE 2>/dev/null 1>&2; then - for log in $(ls $FILE); do - status_msg "Removing $log ..." - rm -f $log - ok_msg "$log removed!" - done - fi - - ### remove all UDS - FILE="/tmp/klippy_uds?(-*([0-9]))" - if ls $FILE 2>/dev/null 1>&2; then - for uds in $(ls $FILE); do - status_msg "Removing $uds ..." - rm -f $uds - ok_msg "$uds removed!" - done - fi - - ### remove all tmp-printer - FILE="/tmp/printer?(-*([0-9]))" - if ls $FILE 2>/dev/null 1>&2; then - for tmp_printer in $(ls $FILE); do - status_msg "Removing $tmp_printer ..." - rm -f $tmp_printer - ok_msg "$tmp_printer removed!" - done - fi - - ### removing klipper and klippy-env folders - if [ -d $KLIPPER_DIR ]; then - status_msg "Removing Klipper directory ..." - rm -rf $KLIPPER_DIR && ok_msg "Directory removed!" - fi - if [ -d $KLIPPY_ENV ]; then - status_msg "Removing klippy-env directory ..." - rm -rf $KLIPPY_ENV && ok_msg "Directory removed!" - fi - - CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg - shopt -u extglob # enable extended globbing - - if [ "$REM_MR" == "true" ]; then - remove_moonraker && unset REM_MR - fi -} - -############################################################# -############################################################# - remove_moonraker(){ shopt -s extglob # enable extended globbing ### remove "legacy" moonraker init.d service diff --git a/scripts/status.sh b/scripts/status.sh index 9046d27..cd59d4a 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -22,43 +22,6 @@ check_system_updates(){ fi } -klipper_status(){ - kcount=0 - klipper_data=( - SERVICE - $KLIPPER_DIR - $KLIPPY_ENV_DIR - ) - - ### count amount of klipper service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^klipper(\-[[:digit:]]+)?\.service$" | wc -l) - - ### a fix to detect an existing "legacy" klipper init.d installation - if [ -f /etc/init.d/klipper ] && [ -f /etc/init.d/klipper ]; then - SERVICE_FILE_COUNT=1 - fi - - ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0] - - ### count+1 for each found data-item from array - for kd in "${klipper_data[@]}" - do - if [ -e $kd ]; then - kcount=$(expr $kcount + 1) - fi - done - - ### display status - if [ "$kcount" == "${#klipper_data[*]}" ]; then - KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" - elif [ "$kcount" == 0 ]; then - KLIPPER_STATUS="${red}Not installed!${default} " - else - KLIPPER_STATUS="${yellow}Incomplete!${default} " - fi -} - dwc2_status(){ dcount=0 dwc_data=( @@ -262,91 +225,6 @@ MoonrakerTelegramBot_status(){ ############################################################# ############################################################# -### reading the klipper branch the user is currently on -read_branch(){ - if [ -d $KLIPPER_DIR/.git ]; then - cd $KLIPPER_DIR - GET_BRANCH="$(git branch | grep "*" | cut -d"*" -f2 | cut -d" " -f2)" - ### try to fix a detached HEAD state and read the correct branch from the output you get - if [ "$(echo $GET_BRANCH | grep "HEAD" )" ]; then - DETACHED_HEAD="true" - GET_BRANCH=$(git branch | grep "HEAD" | rev | cut -d" " -f1 | rev | cut -d")" -f1 | cut -d"/" -f2) - ### try to identify the branch when the HEAD was detached at a single commit - ### will only work if its either master, scurve-shaping or scurve-smoothing branch - if [[ $GET_BRANCH =~ [[:alnum:]] ]]; then - if [ "$(git branch -r --contains $GET_BRANCH | grep "master")" ]; then - GET_BRANCH="master" - elif [ "$(git branch -r --contains $GET_BRANCH | grep "scurve-shaping")" ]; then - GET_BRANCH="scurve-shaping" - elif [ "$(git branch -r --contains $GET_BRANCH | grep "scurve-smoothing")" ]; then - GET_BRANCH="scurve-smoothing" - fi - fi - fi - else - GET_BRANCH="" - fi -} - -#prints the current klipper branch in the main menu -print_branch(){ - read_branch - if [ ! -z "$GET_BRANCH" ]; then - PRINT_BRANCH="$(printf "%-16s" "$GET_BRANCH")" - else - PRINT_BRANCH="${red}--------------${default} " - fi -} - -read_local_klipper_commit(){ - if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then - cd $KLIPPER_DIR - LOCAL_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - else - LOCAL_COMMIT=$NONE - fi -} - -read_remote_klipper_commit(){ - read_branch - if [ ! -z "$GET_BRANCH" ];then - if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then - git fetch origin -q - REMOTE_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - elif [ "$GET_BRANCH" = "scurve-shaping" ]; then - git fetch dmbutyugin scurve-shaping -q - REMOTE_COMMIT=$(git describe dmbutyugin/scurve-shaping --always --tags | cut -d "-" -f 1,2) - elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then - git fetch dmbutyugin scurve-smoothing -q - REMOTE_COMMIT=$(git describe dmbutyugin/scurve-smoothing --always --tags | cut -d "-" -f 1,2) - fi - else - REMOTE_COMMIT=$NONE - fi -} - -compare_klipper_versions(){ - unset KLIPPER_UPDATE_AVAIL - read_local_klipper_commit && read_remote_klipper_commit - if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then - LOCAL_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_COMMIT")${default}" - REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}" - # add klipper to the update all array for the update all function in the updater - KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper) - else - LOCAL_COMMIT="${green}$(printf "%-12s" "$LOCAL_COMMIT")${default}" - REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}" - KLIPPER_UPDATE_AVAIL="false" - fi - #if detached head was found, force the user with warn message to update klipper - if [ "$DETACHED_HEAD" == "true" ]; then - LOCAL_COMMIT="${red}$(printf "%-12s" "Need update!")${default}" - fi -} - -############################################################# -############################################################# - read_dwc2fk_versions(){ if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then cd $DWC2FK_DIR diff --git a/scripts/update.sh b/scripts/update.sh index ad3be14..f33778f 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -219,33 +219,6 @@ migrate_custompios(){ ok_msg "Migration done!" } -update_klipper(){ - do_action_service "stop" "klipper" - if [ ! -d $KLIPPER_DIR ]; then - cd ${HOME} && git clone $KLIPPER_REPO - else - bb4u "klipper" - read_branch - save_klipper_state - status_msg "Updating $GET_BRANCH" - cd $KLIPPER_DIR - if [ "$DETACHED_HEAD" == "true" ]; then - git checkout $GET_BRANCH - unset DETACHED_HEAD - fi - ### pull latest files from github - git pull - ### read PKGLIST and install possible new dependencies - install_klipper_packages - ### install possible new python dependencies - KLIPPER_REQ_TXT="$KLIPPER_DIR/scripts/klippy-requirements.txt" - $KLIPPY_ENV/bin/pip install -r $KLIPPER_REQ_TXT - fi - update_log_paths "klipper" - ok_msg "Update complete!" - do_action_service "restart" "klipper" -} - update_dwc2fk(){ do_action_service "stop" "dwc" bb4u "dwc2" From 308456df26d50cbb927fac2d2ec0c4bf84e90505 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 01:12:23 +0100 Subject: [PATCH 004/183] feat: add some new utility functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 73 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 50a9451..73d9161 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -1,11 +1,13 @@ #!/usr/bin/env bash -# -# KIAUH - Klipper Installation And Update Helper -# https://github.com/th33xitus/kiauh -# -# Copyright (C) 2020 - 2022 Dominik Willner -# -# This file may be distributed under the terms of the GNU GPLv3 license + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# set -e clear @@ -16,11 +18,12 @@ yellow=$(echo -en "\e[93m") red=$(echo -en "\e[91m") cyan=$(echo -en "\e[96m") default=$(echo -en "\e[39m") +white=$(echo -en "\e[39m") ### sourcing all additional scripts SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" -for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done -for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done +for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . "${script}"; done +for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . "${script}"; done ### set important directories #klipper @@ -64,18 +67,27 @@ NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping -### set some messages +### format some default message types +select_msg() { + echo -e "${white}>>>>>> $1" +} warn_msg(){ - echo -e "${red} $1${default}" + echo -e "${red}>>>>>> $1${white}" } status_msg(){ - echo; echo -e "${yellow}###### $1${default}" + echo; echo -e "${yellow}###### $1${white}" } ok_msg(){ - echo -e "${green}>>>>>> $1${default}" + echo -e "${green}>>>>>> $1${white}" +} +error_msg(){ + echo -e "${red}>>>>>> $1${white}" +} +abort_msg(){ + echo -e "${red}<<<<<< $1${white}" } title_msg(){ - echo -e "${cyan}$1${default}" + echo -e "${cyan}$1${white}" } get_date(){ current_date=$(date +"%y%m%d-%H%M") @@ -84,24 +96,47 @@ get_date(){ print_unkown_cmd(){ ERROR_MSG="Invalid command!" } +invalid_option(){ + ERROR_MSG="Invalid command!" +} print_msg(){ if [ -n "${ERROR_MSG}" ]; then echo -e "${red}" echo -e "#########################################################" - echo -e " $ERROR_MSG " + echo -e " ${ERROR_MSG} " echo -e "#########################################################" - echo -e "${default}" + echo -e "${white}" fi - if [ -n "$CONFIRM_MSG" ]; then + if [ -n "${CONFIRM_MSG}" ]; then echo -e "${green}" echo -e "#########################################################" - echo -e " $CONFIRM_MSG " + echo -e " ${CONFIRM_MSG} " echo -e "#########################################################" - echo -e "${default}" + echo -e "${white}" fi } +print_error(){ + [ -z "${ERROR_MSG}" ] && return + echo -e "${red}" + echo -e "#########################################################" + echo -e " ${ERROR_MSG} " + echo -e "#########################################################" + echo -e "${white}" + unset ERROR_MSG +} + +print_confirm(){ + [ -z "${CONFIRM_MSG}" ] && return + echo -e "${green}" + echo -e "#########################################################" + echo -e " ${CONFIRM_MSG} " + echo -e "#########################################################" + echo -e "${white}" + unset CONFIRM_MSG +} + clear_msg(){ unset CONFIRM_MSG unset ERROR_MSG From 2993d5ed3347982089913e4b5007b9ca1e36831a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 01:13:26 +0100 Subject: [PATCH 005/183] refactor: make `dependency_check()` take an array as first argument Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/functions.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 37180c8..47f264b 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -233,24 +233,25 @@ restart_nginx(){ } dependency_check(){ + local dep="${1}" # dep: array status_msg "Checking for the following dependencies:" #check if package is installed, if not write name into array - for pkg in "${dep[@]}" + for pkg in ${dep} do - echo -e "${cyan}● $pkg ${default}" - if [[ ! $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then - inst+=($pkg) + echo -e "${cyan}● ${pkg} ${default}" + if [[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]]; then + inst+=("${pkg}") fi done #if array is not empty, install packages from array elements - if [ "${#inst[@]}" != "0" ]; then + if [ "${#inst[@]}" -ne 0 ]; then status_msg "Installing the following dependencies:" - for element in ${inst[@]} + for element in "${inst[@]}" do - echo -e "${cyan}● $element ${default}" + echo -e "${cyan}● ${element} ${default}" done echo - sudo apt-get update --allow-releaseinfo-change && sudo apt-get install ${inst[@]} -y + sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${inst[@]}" -y ok_msg "Dependencies installed!" #clearing the array unset inst From cfaa2ddafc57838525f6953f264b68728e8e3613 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 01:15:10 +0100 Subject: [PATCH 006/183] refactor: rename functions.sh to utilities.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/{functions.sh => utilities.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{functions.sh => utilities.sh} (100%) mode change 100755 => 100644 diff --git a/scripts/functions.sh b/scripts/utilities.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/functions.sh rename to scripts/utilities.sh From 61b5ccde000d4b1914f1327ae6d8476cb3ad6ee3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 01:16:04 +0100 Subject: [PATCH 007/183] refactor: full rework of klipper related functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/klipper.service | 13 +- scripts/klipper.sh | 587 ++++++++++++++++---------------------- scripts/ui/main_menu.sh | 12 +- 3 files changed, 263 insertions(+), 349 deletions(-) diff --git a/resources/klipper.service b/resources/klipper.service index 2cb531d..5b2e996 100644 --- a/resources/klipper.service +++ b/resources/klipper.service @@ -1,15 +1,22 @@ -#Systemd service file for klipper +#Systemd Klipper Service + [Unit] -Description=Starts klipper instance %INST% on startup +Description=Starts Klipper instance %INST% on startup +Documentation=https://www.klipper3d.org/ After=network.target +Wants=udev.target [Install] WantedBy=multi-user.target [Service] +Environment=KLIPPER_CONFIG=%CFG% +Environment=KLIPPER_LOG=%LOG% +Environment=KLIPPER_SOCKET=%UDS% +Environment=KLIPPER_PRINTER=%PRINTER% Type=simple User=%USER% RemainAfterExit=yes -ExecStart=%KL_ENV%/bin/python %KL_DIR%/klippy/klippy.py %P_CFG% -I %P_TMP% -l %KL_LOG% -a %KL_UDS% +ExecStart=%ENV%/bin/python %DIR%/klippy/klippy.py ${KLIPPER_CONFIG} -I ${KLIPPER_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPER_SOCKET} Restart=always RestartSec=10 \ No newline at end of file diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 7a9cb8f..1ace414 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash -# -# KIAUH - Klipper Installation And Update Helper -# https://github.com/th33xitus/kiauh -# -# Copyright (C) 2020 - 2022 Dominik Willner -# -# This file may be distributed under the terms of the GNU GPLv3 license + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e ### global variables SYSTEMD="/etc/systemd/system" @@ -14,42 +18,44 @@ ETCDEF="/etc/default" KLIPPY_ENV="${HOME}/klippy-env" KLIPPER_DIR="${HOME}/klipper" KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" +KLIPPER_CONFIG="${HOME}/klipper_config" #=================================================# #================ INSTALL KLIPPER ================# #=================================================# ### check for existing klipper service installations -function check_klipper_exists() { - local SERVICE_FILES - local INITD_SF - local SYSTEMD_SF +function klipper_initd() { + local services + services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*") + echo "${services}" +} - INITD_SF=$(find "${INITD}" -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*") - SYSTEMD_SF=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])?[0-9]*.service") +function klipper_systemd() { + local services + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])?[0-9]*.service") + echo "${services}" +} - if [ -n "${INITD_SF}" ]; then - SERVICE_FILES+="${INITD_SF}" - fi - if [ -n "${SYSTEMD_SF}" ]; then - SERVICE_FILES+=" ${SYSTEMD_SF}" - fi - - if [ -n "${SERVICE_FILES}" ]; then - ERROR_MSG="At least one Klipper service is already installed:" - for service in $SERVICE_FILES; do - ERROR_MSG="${ERROR_MSG}\n ➔ ${service}" - done && return - fi - - klipper_setup_dialog +function klipper_exists() { + local services + [ -n "$(klipper_initd)" ] && services+="$(klipper_initd) " + [ -n "$(klipper_systemd)" ] && services+="$(klipper_systemd)" + echo "${services}" } function klipper_setup_dialog(){ status_msg "Initializing Klipper installation ..." - ### initial printer.cfg path check - check_klipper_cfg_path + ### return early if klipper already exists + if [ -n "$(klipper_exists)" ]; then + ERROR_MSG="At least one Klipper service is already installed:" + for s in $(klipper_exists); do + ERROR_MSG="${ERROR_MSG}\n ➔ ${s}" + done + export ERROR_MSG + print_error && return + fi ### ask for amount of instances to create top_border @@ -57,168 +63,154 @@ function klipper_setup_dialog(){ echo -e "| up. The number of Klipper instances will determine |" echo -e "| the amount of printers you can run from this machine. |" blank_line - echo -e "| ${yellow}WARNING: There is no limit on the number of instances${default} |" - echo -e "| ${yellow}you can set up with this script.${default} |" + echo -e "| ${yellow}WARNING: There is no limit on the number of instances${white} |" + echo -e "| ${yellow}you can set up with this script. Setting up too many${white} |" + echo -e "| ${yellow}Klipper instances can potentially crash your system.${white} |" bottom_border local count - while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of Klipper instances to set up:${default} " count - if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then - warn_msg "Invalid Input!\n" + while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do + read -p "${cyan}###### Number of Klipper instances to set up:${white} " count + if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then + error_msg "Invalid input!\n" else echo - read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn - case "$yn" in + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn + case "${yn}" in Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Installing $count Klipper instance(s) ..." - klipper_setup "$count" + select_msg "Yes" + status_msg "Installing ${count} Klipper instance(s) ..." + klipper_setup "${count}" break;; N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting Klipper setup ...\n" + select_msg "No" + abort_msg "Exiting Klipper setup ...\n" break;; *) - print_unkown_cmd - print_msg && clear_msg;; + invalid_option && print_error + ;; esac fi done } function install_klipper_packages(){ - ### read PKGLIST from official install script - status_msg "Reading dependencies..." - install_script="${HOME}/klipper/scripts/install-octopi.sh" - #PKGLIST=$(grep "PKGLIST=" $install_script | sed 's/PKGLIST//g; s/[$={}\n"]//g') - PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n') - ### add dbus requirement for DietPi distro - [ -e "/boot/dietpi/.version" ] && PKGLIST+=" dbus" + local packages + local install_script="${HOME}/klipper/scripts/install-octopi.sh" - for pkg in $PKGLIST; do - echo "${cyan}${pkg}${default}" - done - read -r -a PKGLIST <<< "$PKGLIST" + status_msg "Reading dependencies..." + # shellcheck disable=SC2016 + packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')" + ### add dbus requirement for DietPi distro + [ -e "/boot/dietpi/.version" ] && packages+=" dbus" + + echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' + read -r -a packages <<< "${packages}" ### Update system package info - status_msg "Running apt-get update..." + status_msg "Updating lists of packages..." sudo apt-get update --allow-releaseinfo-change ### Install desired packages status_msg "Installing packages..." - sudo apt-get install --yes "${PKGLIST[@]}" + sudo apt-get install --yes "${packages[@]}" } function create_klipper_virtualenv(){ status_msg "Installing python virtual environment..." - # Create virtualenv if it doesn't already exist [ ! -d "${KLIPPY_ENV}" ] && virtualenv -p python2 "${KLIPPY_ENV}" - # Install/update dependencies "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt } function klipper_setup(){ - INSTANCE_COUNT=$1 + local instances=${1} ### checking dependencies - dep=(git) - dependency_check + local dep=(git) + dependency_check "${dep[@]}" ### step 1: clone klipper status_msg "Downloading Klipper ..." ### force remove existing klipper dir and clone into fresh klipper dir [ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}" cd "${HOME}" && git clone "${KLIPPER_REPO}" - status_msg "Download complete!" ### step 2: install klipper dependencies and create python virtualenv - status_msg "Installing dependencies ..." install_klipper_packages create_klipper_virtualenv - ### step 3: create shared gcode_files and logs folder + ### step 3: create gcode_files and logs folder [ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files" [ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs" ### step 4: create klipper instances - create_klipper_service + create_klipper_service "${instances}" + + ### step 5: enable and start all instances + do_action_service "enable" "klipper" + do_action_service "start" "klipper" ### confirm message - if [[ ${INSTANCE_COUNT} -eq 1 ]]; then + if [[ ${instances} -eq 1 ]]; then CONFIRM_MSG="Klipper has been set up!" - elif [[ ${INSTANCE_COUNT} -gt 1 ]]; then - CONFIRM_MSG="${INSTANCE_COUNT} Klipper instances have been set up!" - fi && print_msg && clear_msg + elif [[ ${instances} -gt 1 ]]; then + CONFIRM_MSG="${instances} Klipper instances have been set up!" + fi + export CONFIRM_MSG + print_confirm && return +} + +function write_klipper_service(){ + local i=${1} cfg_dir=${2} cfg=${3} log=${4} printer=${5} uds=${6} service=${7} + local service_template="${SRCDIR}/kiauh/resources/klipper.service" + local cfg_template="${SRCDIR}/kiauh/resources/printer.cfg" + + ### create a config directory if it doesn't exist + [ ! -d "${cfg_dir}" ] && mkdir -p "${cfg_dir}" + + ### create a minimal config if there is no printer.cfg + [ ! -f "${cfg}" ] && cp "${cfg_template}" "${cfg}" + + ### replace all placeholders + if [ ! -f "${service}" ]; then + status_msg "Creating Klipper Service ${i} ..." + sudo cp "${service_template}" "${service}" + + [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" + [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" + sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${KLIPPY_ENV}|; s|%DIR%|${KLIPPER_DIR}|" "${service}" + sudo sed -i "s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${printer}|; s|%UDS%|${uds}|" "${service}" + fi } function create_klipper_service(){ - ### get config directory - source_kiauh_ini - - ### set up default values - SINGLE_INST=1 - CFG_PATH="$klipper_cfg_loc" - KL_ENV=$KLIPPY_ENV - KL_DIR=$KLIPPER_DIR - KL_LOG="${HOME}/klipper_logs/klippy.log" - KL_UDS="/tmp/klippy_uds" - P_TMP="/tmp/printer" - P_CFG="$CFG_PATH/printer.cfg" - P_CFG_SRC="${SRCDIR}/kiauh/resources/printer.cfg" - KL_SERV_SRC="${SRCDIR}/kiauh/resources/klipper.service" - KL_SERV_TARGET="${SYSTEMD}/klipper.service" - - write_kl_service(){ - [ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH" - ### create a minimal config if there is no printer.cfg - [ ! -f "$P_CFG" ] && cp "$P_CFG_SRC" "$P_CFG" - ### replace placeholder - if [ ! -f $KL_SERV_TARGET ]; then - status_msg "Creating Klipper Service $i ..." - sudo cp "$KL_SERV_SRC" $KL_SERV_TARGET - sudo sed -i "s|%INST%|$i|" $KL_SERV_TARGET - sudo sed -i "s|%USER%|${USER}|" $KL_SERV_TARGET - sudo sed -i "s|%KL_ENV%|$KL_ENV|" $KL_SERV_TARGET - sudo sed -i "s|%KL_DIR%|$KL_DIR|" $KL_SERV_TARGET - sudo sed -i "s|%KL_LOG%|$KL_LOG|" $KL_SERV_TARGET - sudo sed -i "s|%P_CFG%|$P_CFG|" $KL_SERV_TARGET - sudo sed -i "s|%P_TMP%|$P_TMP|" $KL_SERV_TARGET - sudo sed -i "s|%KL_UDS%|$KL_UDS|" $KL_SERV_TARGET - fi - } - - if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then + local instances=${1} + if [ "${instances}" -eq 1 ]; then + local i="" + local cfg_dir="${KLIPPER_CONFIG}" + local cfg="${cfg_dir}/printer.cfg" + local log="${HOME}/klipper_logs/klippy.log" + local printer="/tmp/printer" + local uds="/tmp/klippy_uds" + local service="${SYSTEMD}/klipper.service" ### write single instance service - write_kl_service - ### enable instance - sudo systemctl enable klipper.service + write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" ok_msg "Single Klipper instance created!" - ### launching instance - status_msg "Launching Klipper instance ..." - sudo systemctl start klipper - else - i=1 - while [[ $i -le $INSTANCE_COUNT ]]; do - ### rewrite default variables for multi instance cases - CFG_PATH="$klipper_cfg_loc/printer_$i" - KL_SERV_TARGET="${SYSTEMD}/klipper-$i.service" - P_TMP="/tmp/printer-$i" - P_CFG="$CFG_PATH/printer.cfg" - KL_LOG="${HOME}/klipper_logs/klippy-$i.log" - KL_UDS="/tmp/klippy_uds-$i" + elif [ "${instances}" -gt 1 ]; then + local i=1 + while [[ "${i}" -le "${instances}" ]]; do + local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" + local cfg="${cfg_dir}/printer.cfg" + local log="${HOME}/klipper_logs/klippy-${i}.log" + local printer="/tmp/printer-${i}" + local uds="/tmp/klippy_uds-${i}" + local service="${SYSTEMD}/klipper-${i}.service" ### write multi instance service - write_kl_service - ### enable instance - sudo systemctl enable klipper-$i.service - ok_msg "Klipper instance #$i created!" - ### launching instance - status_msg "Launching Klipper instance #$i ..." - sudo systemctl start klipper-$i - - ### raise values by 1 + write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + ok_msg "Klipper instance #${i} created!" i=$((i+1)) - done - unset i + done && unset i + else + return 1 fi } @@ -226,117 +218,93 @@ function create_klipper_service(){ #================ REMOVE KLIPPER ================# #================================================# +function remove_klipper_sysvinit() { + [ ! -e "${INITD}/klipper" ] && return + status_msg "Removing Klipper SysVinit service ..." + sudo systemctl stop klipper + sudo update-rc.d -f klipper remove + sudo rm -f "${INITD}/klipper" "${ETCDEF}/klipper" + ok_msg "Klipper SysVinit service removed!" +} + +function remove_klipper_systemd() { + [ -z "$(klipper_systemd)" ] && return + status_msg "Removing Klipper Systemd Services ..." + for service in $(klipper_systemd | cut -d"/" -f5) + do + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" + ok_msg "Done!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "Klipper Service removed!" +} + +function remove_klipper_logs() { + local files + files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/klippy(-[^0])?[0-9]*\.log(.*)?") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_klipper_uds() { + local files + files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[^0])?[0-9]*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_klipper_printer() { + local files + files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[^0])?[0-9]*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_klipper_dir() { + [ ! -d "${KLIPPER_DIR}" ] && return + status_msg "Removing Klipper directory ..." + rm -rf "${KLIPPER_DIR}" + ok_msg "Directory removed!" +} + +function remove_klipper_env() { + [ ! -d "${KLIPPY_ENV}" ] && return + status_msg "Removing klippy-env directory ..." + rm -rf "${KLIPPY_ENV}" + ok_msg "Directory removed!" +} + function remove_klipper(){ - shopt -s extglob # enable extended globbing - ### ask the user if he wants to uninstall moonraker too. - ###? currently usefull if the user wants to switch from single-instance to multi-instance - FILE="${SYSTEMD}/moonraker?(-*([0-9])).service" - if ls $FILE 2>/dev/null 1>&2; then - while true; do - unset REM_MR - top_border - echo -e "| Do you want to remove Moonraker afterwards? |" - echo -e "| |" - echo -e "| This is useful in case you want to switch from a |" - echo -e "| single-instance to a multi-instance installation, |" - echo -e "| which makes a re-installation of Moonraker necessary. |" - echo -e "| |" - echo -e "| If for any other reason you only want to uninstall |" - echo -e "| Klipper, please select 'No' and continue. |" - bottom_border - read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - echo -e "###### > Yes" - REM_MR="true" - break;; - N|n|No|no|"") - echo -e "###### > No" - REM_MR="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi + remove_klipper_sysvinit + remove_klipper_systemd + remove_klipper_logs + remove_klipper_uds + remove_klipper_printer + remove_klipper_dir + remove_klipper_env - ### remove "legacy" klipper SysVinit service - if [ -e "${INITD}/klipper" ]; then - status_msg "Removing Klipper Service ..." - sudo systemctl stop klipper - sudo update-rc.d -f klipper remove - sudo rm -f "${INITD}/klipper" - sudo rm -f "${ETCDEF}/klipper" - ok_msg "Klipper Service removed!" - fi - - ### remove all klipper services - FILE="${SYSTEMD}/klipper?(-*([0-9])).service" - if ls "${FILE}" 2>/dev/null 1>&2; then - status_msg "Removing Klipper Services ..." - for service in $(ls "${FILE}" | cut -d"/" -f5) - do - status_msg "Removing ${service} ..." - sudo systemctl stop "${service}" - sudo systemctl disable "${service}" - sudo rm -f "${SYSTEMD}/${service}" - ok_msg "Done!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "Klipper Service removed!" - fi - - ### remove all logfiles - FILE="${HOME}/klipper_logs/klippy?(-*([0-9])).log" - if ls "${FILE}" 2>/dev/null 1>&2; then - for log in $(ls "${FILE}"); do - status_msg "Removing ${log} ..." - rm -f "${log}" - ok_msg "${log} removed!" - done - fi - - ### remove all UDS - FILE="/tmp/klippy_uds?(-*([0-9]))" - if ls "${FILE}" 2>/dev/null 1>&2; then - for uds in $(ls "${FILE}"); do - status_msg "Removing ${uds} ..." - rm -f "${uds}" - ok_msg "${uds} removed!" - done - fi - - ### remove all tmp-printer - FILE="/tmp/printer?(-*([0-9]))" - if ls "${FILE}" 2>/dev/null 1>&2; then - for tmp_printer in $(ls "${FILE}"); do - status_msg "Removing ${tmp_printer} ..." - rm -f "${tmp_printer}" - ok_msg "${tmp_printer} removed!" - done - fi - - ### removing klipper and klippy-env folders - if [ -d "${KLIPPER_DIR}" ]; then - status_msg "Removing Klipper directory ..." - rm -rf "${KLIPPER_DIR}" && ok_msg "Directory removed!" - fi - if [ -d "${KLIPPY_ENV}" ]; then - status_msg "Removing klippy-env directory ..." - rm -rf "${KLIPPY_ENV}" && ok_msg "Directory removed!" - fi - - CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg + CONFIRM_MSG=" Klipper was successfully removed!" && print_confirm export CONFIRM_MSG - - shopt -u extglob # enable extended globbing - - if [ "${REM_MR}" == "true" ]; then - remove_moonraker && unset REM_MR - fi } #================================================# @@ -349,21 +317,14 @@ function update_klipper(){ cd "${HOME}" && git clone "${KLIPPER_REPO}" else bb4u "klipper" - read_branch save_klipper_state - status_msg "Updating ${GET_BRANCH}" + status_msg "Updating Klipper ..." cd "${KLIPPER_DIR}" - if [ "$DETACHED_HEAD" == "true" ]; then - git checkout "${GET_BRANCH}" - unset DETACHED_HEAD - fi - ### pull latest files from github git pull ### read PKGLIST and install possible new dependencies install_klipper_packages ### install possible new python dependencies - KLIPPER_REQ_TXT="${KLIPPER_DIR}/scripts/klippy-requirements.txt" - "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_REQ_TXT}" + "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt" fi update_log_paths "klipper" ok_msg "Update complete!" @@ -374,121 +335,67 @@ function update_klipper(){ #================ KLIPPER STATUS ================# #================================================# -function klipper_status(){ - kcount=0 - klipper_data=( - SERVICE - "${KLIPPER_DIR}" - "${KLIPPY_ENV_DIR}" - ) - - ### count amount of klipper service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls "${SYSTEMD}" | grep -E "^klipper(\-[[:digit:]]+)?\.service$" | wc -l) - - ### a fix to detect an existing "legacy" klipper init.d installation - if [ -f "${INITD}/klipper" ]; then - SERVICE_FILE_COUNT=1 +function get_klipper_status(){ + local sf_count status + sf_count="$(klipper_systemd | wc -w)" + ### detect an existing "legacy" klipper init.d installation + if [ "$(klipper_systemd | wc -w)" -eq 0 ] \ + && [ "$(klipper_initd | wc -w)" -ge 1 ]; then + sf_count=1 fi ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0] + local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}") + [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" ### count+1 for each found data-item from array - for kd in "${klipper_data[@]}" + local filecount=0 + for data in "${data_arr[@]}" do - if [ -e "${kd}" ]; then - kcount=$(expr ${kcount} + 1) - fi + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - ### display status - if [ "$kcount" == "${#klipper_data[*]}" ]; then - KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" ${SERVICE_FILE_COUNT})" - elif [ "$kcount" == 0 ]; then - KLIPPER_STATUS="${red}Not installed!${default} " + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " else - KLIPPER_STATUS="${yellow}Incomplete!${default} " + status="${yellow}Incomplete!${white} " fi + echo "${status}" } -### reading the klipper branch the user is currently on -read_branch(){ - if [ -d "${KLIPPER_DIR}/.git" ]; then - cd "${KLIPPER_DIR}" - GET_BRANCH="$(git branch | grep "*" | cut -d"*" -f2 | cut -d" " -f2)" - ### try to fix a detached HEAD state and read the correct branch from the output you get - if [ "$(echo "${GET_BRANCH}" | grep "HEAD" )" ]; then - DETACHED_HEAD="true" - GET_BRANCH=$(git branch | grep "HEAD" | rev | cut -d" " -f1 | rev | cut -d")" -f1 | cut -d"/" -f2) - ### try to identify the branch when the HEAD was detached at a single commit - ### will only work if its either master, scurve-shaping or scurve-smoothing branch - if [[ ${GET_BRANCH} =~ [[:alnum:]] ]]; then - if [ "$(git branch -r --contains "${GET_BRANCH}" | grep "master")" ]; then - GET_BRANCH="master" - elif [ "$(git branch -r --contains "${GET_BRANCH}" | grep "scurve-shaping")" ]; then - GET_BRANCH="scurve-shaping" - elif [ "$(git branch -r --contains "${GET_BRANCH}" | grep "scurve-smoothing")" ]; then - GET_BRANCH="scurve-smoothing" - fi - fi - fi - else - GET_BRANCH="" - fi -} - -#prints the current klipper branch in the main menu -print_branch(){ - read_branch - if [ -n "${GET_BRANCH}" ]; then - PRINT_BRANCH="$(printf "%-16s" "${GET_BRANCH}")" - else - PRINT_BRANCH="${red}--------------${default} " - fi -} - -read_local_klipper_commit(){ +function get_local_klipper_commit(){ if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPER_DIR}"/.git ]; then cd "${KLIPPER_DIR}" - LOCAL_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" else - LOCAL_COMMIT="${NONE}" + commit="${NONE}" fi + echo "${commit}" } -read_remote_klipper_commit(){ - read_branch - if [ -n "${GET_BRANCH}" ];then - if [ "${GET_BRANCH}" = "origin/master" ] || [ "${GET_BRANCH}" = "master" ]; then - git fetch origin -q - REMOTE_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - elif [ "${GET_BRANCH}" = "scurve-shaping" ]; then - git fetch dmbutyugin scurve-shaping -q - REMOTE_COMMIT=$(git describe dmbutyugin/scurve-shaping --always --tags | cut -d "-" -f 1,2) - elif [ "${GET_BRANCH}" = "scurve-smoothing" ]; then - git fetch dmbutyugin scurve-smoothing -q - REMOTE_COMMIT=$(git describe dmbutyugin/scurve-smoothing --always --tags | cut -d "-" -f 1,2) - fi +function get_remote_klipper_commit(){ + if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPER_DIR}"/.git ]; then + cd "${KLIPPER_DIR}" + git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) else - REMOTE_COMMIT="${NONE}" + commit="${NONE}" fi + echo "${commit}" } -compare_klipper_versions(){ +function compare_klipper_versions(){ unset KLIPPER_UPDATE_AVAIL - read_local_klipper_commit && read_remote_klipper_commit - if [ "${LOCAL_COMMIT}" != "${REMOTE_COMMIT}" ]; then - LOCAL_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_COMMIT}")${default}" - REMOTE_COMMIT="${green}$(printf "%-12s" "${REMOTE_COMMIT}")${default}" + if [ "$(get_local_klipper_commit)" != "$(get_remote_klipper_commit)" ]; then + LOCAL_COMMIT="${yellow}$(printf "%-12s" "$(get_local_klipper_commit)")${default}" + REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remote_klipper_commit)")${default}" # add klipper to the update all array for the update all function in the updater KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper) else - LOCAL_COMMIT="${green}$(printf "%-12s" "${LOCAL_COMMIT}")${default}" - REMOTE_COMMIT="${green}$(printf "%-12s" "${REMOTE_COMMIT}")${default}" + LOCAL_COMMIT="${green}$(printf "%-12s" "$(get_remote_klipper_commit)")${default}" + REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remote_klipper_commit)")${default}" KLIPPER_UPDATE_AVAIL="false" fi - #if detached head was found, force the user with warn message to update klipper - if [ "${DETACHED_HEAD}" == "true" ]; then - LOCAL_COMMIT="${red}$(printf "%-12s" "Need update!")${default}" - fi } \ No newline at end of file diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index ff991a0..a543f99 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -3,9 +3,9 @@ main_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr - echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|" - echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|" - echo -e "| 1) [Install] | |" + echo -e "| 0) [Upload Log] | Klipper: $(get_klipper_status)|" + echo -e "| | |" + echo -e "| 1) [Install] |--------------------------------|" echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" echo -e "| 3) [Remove] | |" echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" @@ -47,7 +47,7 @@ main_menu(){ fi #check install status print_kiauh_version - klipper_status +# klipper_status moonraker_status dwc2_status fluidd_status @@ -55,7 +55,7 @@ main_menu(){ octoprint_status klipperscreen_status MoonrakerTelegramBot_status - print_branch +# print_branch print_msg && clear_msg main_ui while true; do @@ -83,7 +83,7 @@ main_menu(){ 6) clear && settings_menu && break;; Q|q) echo -e "${green}###### Happy printing! ######${default}"; echo - exit -1;; + exit 0;; *) deny_action "main_ui";; esac From 6ff55a9ea76ab26487bbfb810e9b72b7ef6fed12 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 13:39:53 +0100 Subject: [PATCH 008/183] fix(klipper.sh): fix typo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 1ace414..5b6cc80 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -79,7 +79,7 @@ function klipper_setup_dialog(){ case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" - status_msg "Installing ${count} Klipper instance(s) ..." + status_msg "Installing ${count} Klipper instance(s) ... \n" klipper_setup "${count}" break;; N|n|No|no) From 9eab46f02a8f53461f3f356164344c04c747782f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 13:46:18 +0100 Subject: [PATCH 009/183] fix(klipper.sh): fix typo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 5b6cc80..a915ebb 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -111,7 +111,7 @@ function install_klipper_packages(){ status_msg "Updating lists of packages..." sudo apt-get update --allow-releaseinfo-change - ### Install desired packages + ### Install required packages status_msg "Installing packages..." sudo apt-get install --yes "${packages[@]}" } From 85b12cf77a0c621494f2474bf489f10a568b87df Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 13:50:43 +0100 Subject: [PATCH 010/183] refactor(klipper.sh): always create a clean virtualenv Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index a915ebb..ab713f4 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -118,7 +118,9 @@ function install_klipper_packages(){ function create_klipper_virtualenv(){ status_msg "Installing python virtual environment..." - [ ! -d "${KLIPPY_ENV}" ] && virtualenv -p python2 "${KLIPPY_ENV}" + ### always create a clean virtualenv + [ -d "${KLIPPY_ENV}" ] && rm -rf "${KLIPPY_ENV}" + virtualenv -p python2 "${KLIPPY_ENV}" "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt } From 1494005630cab203b77773d50f95a133e778699e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 14:05:25 +0100 Subject: [PATCH 011/183] fix(klipper.sh): correct shebang Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index ab713f4..808f092 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash #=======================================================================# # Copyright (C) 2020 - 2022 Dominik Willner # From 87fded584f56c5898680df2129311dd791cf2f9a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 14:09:44 +0100 Subject: [PATCH 012/183] refactor(klipper.sh): remove function call that will be obsolete soon Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 808f092..b90c5b6 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -319,10 +319,8 @@ function update_klipper(){ cd "${HOME}" && git clone "${KLIPPER_REPO}" else bb4u "klipper" - save_klipper_state status_msg "Updating Klipper ..." - cd "${KLIPPER_DIR}" - git pull + cd "${KLIPPER_DIR}" && git pull ### read PKGLIST and install possible new dependencies install_klipper_packages ### install possible new python dependencies From b75167928defbd9ceaae00411b2ce0021d9508bf Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 14:44:09 +0100 Subject: [PATCH 013/183] fix(klipper.sh): single brackets for test Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index b90c5b6..9270eb6 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -199,7 +199,7 @@ function create_klipper_service(){ ok_msg "Single Klipper instance created!" elif [ "${instances}" -gt 1 ]; then local i=1 - while [[ "${i}" -le "${instances}" ]]; do + while [ "${i}" -le "${instances}" ]; do local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" local cfg="${cfg_dir}/printer.cfg" local log="${HOME}/klipper_logs/klippy-${i}.log" From 44093314419e13f12b0a97883c2b96c7d20d70e1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 19:22:15 +0100 Subject: [PATCH 014/183] refactor(kiauh.sh): no global confirm / error message anymore Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 10 ++++------ scripts/klipper.sh | 11 +++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 73d9161..92692a3 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -118,23 +118,21 @@ print_msg(){ } print_error(){ - [ -z "${ERROR_MSG}" ] && return + [ -z "${1}" ] && return echo -e "${red}" echo -e "#########################################################" - echo -e " ${ERROR_MSG} " + echo -e " ${1} " echo -e "#########################################################" echo -e "${white}" - unset ERROR_MSG } print_confirm(){ - [ -z "${CONFIRM_MSG}" ] && return + [ -z "${1}" ] && return echo -e "${green}" echo -e "#########################################################" - echo -e " ${CONFIRM_MSG} " + echo -e " ${1} " echo -e "#########################################################" echo -e "${white}" - unset CONFIRM_MSG } clear_msg(){ diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 9270eb6..4976d87 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -153,12 +153,11 @@ function klipper_setup(){ ### confirm message if [[ ${instances} -eq 1 ]]; then - CONFIRM_MSG="Klipper has been set up!" + local confirm="Klipper has been set up!" elif [[ ${instances} -gt 1 ]]; then - CONFIRM_MSG="${instances} Klipper instances have been set up!" + local confirm="${instances} Klipper instances have been set up!" fi - export CONFIRM_MSG - print_confirm && return + print_confirm "${confirm}" && return } function write_klipper_service(){ @@ -305,8 +304,8 @@ function remove_klipper(){ remove_klipper_dir remove_klipper_env - CONFIRM_MSG=" Klipper was successfully removed!" && print_confirm - export CONFIRM_MSG + local confirm="Klipper was successfully removed!" + print_confirm "${confirm}" && return } #================================================# From 8257e95c467826ea52520a665ecccff34668e5d5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 19:23:54 +0100 Subject: [PATCH 015/183] style(kiauh.sh): remove whitespace Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 92692a3..820f014 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -121,7 +121,7 @@ print_error(){ [ -z "${1}" ] && return echo -e "${red}" echo -e "#########################################################" - echo -e " ${1} " + echo -e " ${1} " echo -e "#########################################################" echo -e "${white}" } @@ -130,7 +130,7 @@ print_confirm(){ [ -z "${1}" ] && return echo -e "${green}" echo -e "#########################################################" - echo -e " ${1} " + echo -e " ${1} " echo -e "#########################################################" echo -e "${white}" } From b20e9455ffd3915121ad932c6bca8b43a4c00df4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 22:12:08 +0100 Subject: [PATCH 016/183] style(kiauh.sh): save line of code Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 4976d87..336e4e4 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -349,8 +349,7 @@ function get_klipper_status(){ ### count+1 for each found data-item from array local filecount=0 - for data in "${data_arr[@]}" - do + for data in "${data_arr[@]}"; do [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done From 067ea360b09602647fba6a31c6218a03f808df24 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 22:15:05 +0100 Subject: [PATCH 017/183] style(kiauh.sh): typo in comment Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 336e4e4..3d3d3e7 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -343,7 +343,7 @@ function get_klipper_status(){ sf_count=1 fi - ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed + ### remove the "SERVICE" entry from the data array if a klipper service is installed local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}") [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" From c8629edcea9bc55f91c33d4e8a7cd3b39237e95c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 22:45:03 +0100 Subject: [PATCH 018/183] refactor(moonraker.sh): full rewrite Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/moonraker.service | 8 +- scripts/install_moonraker.sh | 321 ---------------------- scripts/moonraker.sh | 506 +++++++++++++++++++++++++++++++++++ scripts/remove.sh | 73 ----- scripts/status.sh | 59 ---- scripts/ui/main_menu.sh | 4 +- scripts/update.sh | 20 -- 7 files changed, 514 insertions(+), 477 deletions(-) delete mode 100755 scripts/install_moonraker.sh create mode 100644 scripts/moonraker.sh diff --git a/resources/moonraker.service b/resources/moonraker.service index 8ab0126..01d9ab5 100644 --- a/resources/moonraker.service +++ b/resources/moonraker.service @@ -1,16 +1,20 @@ -#Systemd service file for moonraker +#Systemd Moonraker Service + [Unit] Description=Starts Moonraker %INST% on startup +Documentation=https://moonraker.readthedocs.io/ After=network.target [Install] WantedBy=multi-user.target [Service] +Environment=MOONRAKER_CONF=%CFG% +Environment=MOONRAKER_LOG=%LOG% Type=simple SupplementaryGroups=moonraker-admin User=%USER% RemainAfterExit=yes -ExecStart=%MR_ENV%/bin/python %MR_DIR%/moonraker/moonraker.py -l %MR_LOG% -c %MR_CONF% +ExecStart=%ENV%/bin/python %DIR%/moonraker/moonraker.py -c ${MOONRAKER_CONF} -l ${MOONRAKER_LOG} Restart=always RestartSec=10 \ No newline at end of file diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh deleted file mode 100755 index 1196ad5..0000000 --- a/scripts/install_moonraker.sh +++ /dev/null @@ -1,321 +0,0 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" -MOONRAKER_ENV="${HOME}/moonraker-env" -MOONRAKER_DIR="${HOME}/moonraker" -MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" - -system_check_moonraker(){ - ### python 3 check - status_msg "Your Python 3 version is: $(python3 --version)" - major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) - minor=$(python3 --version | cut -d"." -f2) - if [ "$major" -ge 3 ] && [ "$minor" -ge 7 ]; then - py_chk_ok="true" - else - py_chk_ok="false" - fi -} - -moonraker_setup_dialog(){ - ### check for existing moonraker service installations - SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service") - if [ -n "$SERVICE_FILES" ]; then - ERROR_MSG="At least one Moonraker service is already installed:" - for service in $SERVICE_FILES; do - ERROR_MSG="${ERROR_MSG}\n ➔ $service" - done && return - fi - - status_msg "Initializing Moonraker installation ..." - ### checking system for python3.7+ - system_check_moonraker - ### exit moonraker setup if python versioncheck fails - if [ $py_chk_ok = "false" ]; then - ERROR_MSG="Versioncheck failed! Python 3.7 or newer required!\n" - ERROR_MSG="${ERROR_MSG} Please upgrade Python." - print_msg && clear_msg && return - fi - - ### count amount of klipper services - SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])+[0-9]*.service") - if [ -f /etc/init.d/klipper ] || [ -f /etc/systemd/system/klipper.service ]; then - KLIPPER_COUNT=1 - elif [ -n "$SERVICE_FILES" ]; then - KLIPPER_COUNT=$(echo "$SERVICE_FILES" | wc -l) - fi - - ### initial moonraker.conf path check - check_klipper_cfg_path - - top_border - if [[ $KLIPPER_COUNT -eq 1 ]]; then - printf "|${green}%-55s${default}|\n" " 1 Klipper instance was found!" - elif [[ $KLIPPER_COUNT -gt 1 ]]; then - printf "|${green}%-55s${default}|\n" " $KLIPPER_COUNT Klipper instances were found!" - else - echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" - fi - echo -e "| Usually you need one Moonraker instance per Klipper |" - echo -e "| instance. Though you can install as many as you wish. |" - bottom_border - echo - count="" - while [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of Moonraker instances to set up:${default} " count - if [[ ! ($count =~ ^[1-9]+((0)+)?$) ]]; then - warn_msg "Invalid Input!\n" - else - echo - read -p "${cyan}###### Install $count instance(s)? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Installing Moonraker ...\n" - moonraker_setup "$count" - break;; - N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting Moonraker setup ...\n" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - fi - done -} - -moonraker_setup(){ - INSTANCE_COUNT=$1 - ### checking dependencies - dep=(wget curl unzip dfu-util virtualenv) - ### additional deps for kiauh compatibility for armbian - dep+=(libjpeg-dev zlib1g-dev) - dependency_check - - ### step 1: clone moonraker - status_msg "Downloading Moonraker ..." - ### force remove existing moonraker dir and clone into fresh moonraker dir - [ -d "$MOONRAKER_DIR" ] && rm -rf "$MOONRAKER_DIR" - cd "${HOME}" && git clone $MOONRAKER_REPO - ok_msg "Download complete!" - - ### step 2: install moonraker dependencies and create python virtualenv - status_msg "Installing dependencies ..." - install_moonraker_packages - create_moonraker_virtualenv - - ### step 3: create moonraker.conf folder and moonraker.confs - create_moonraker_conf - - ### step 4: create final moonraker instances - create_moonraker_service - - ### step 5: create polkit rules for moonraker - moonraker_polkit - - ### confirm message - if [[ $INSTANCE_COUNT -eq 1 ]]; then - CONFIRM_MSG="Moonraker has been set up!" - elif [[ $INSTANCE_COUNT -gt 1 ]]; then - CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!" - fi && print_msg && clear_msg - - ### display moonraker ips to the user - print_mr_ip_list; echo -} - -install_moonraker_packages(){ - ### read PKGLIST from official install script - status_msg "Reading dependencies..." - install_script="${HOME}/moonraker/scripts/install-moonraker.sh" - PKGLIST=$(grep "PKGLIST=" "$install_script" | sed 's/PKGLIST//g; s/[$"{}=]//g; s/\s\s*/ /g' | tr -d '\n') - for pkg in $PKGLIST; do - echo "${cyan}$pkg${default}" - done - read -r -a PKGLIST <<< "$PKGLIST" - - ### Update system package info - status_msg "Running apt-get update..." - sudo apt-get update --allow-releaseinfo-change - - ### Install desired packages - status_msg "Installing packages..." - sudo apt-get install --yes "${PKGLIST[@]}" -} - -create_moonraker_virtualenv(){ - status_msg "Installing python virtual environment..." - - ### If venv exists and user prompts a rebuild, then do so - if [ -d "$MOONRAKER_ENV" ] && [ "$REBUILD_ENV" = "y" ]; then - status_msg "Removing old virtualenv" - rm -rf "$MOONRAKER_ENV" - fi - - if [ ! -d "$MOONRAKER_ENV" ]; then - virtualenv -p /usr/bin/python3 "$MOONRAKER_ENV" - fi - - ### Install/update dependencies - "$MOONRAKER_ENV"/bin/pip install -r "$MOONRAKER_DIR"/scripts/moonraker-requirements.txt -} - -create_moonraker_service(){ - ### get config directory - source_kiauh_ini - - ### set up default values - SINGLE_INST=1 - CFG_PATH="$klipper_cfg_loc" - MR_ENV=$MOONRAKER_ENV - MR_DIR=$MOONRAKER_DIR - MR_LOG="${HOME}/klipper_logs/moonraker.log" - MR_CONF="$CFG_PATH/moonraker.conf" - MR_SERV_SRC="${SRCDIR}/kiauh/resources/moonraker.service" - MR_SERV_TARGET="$SYSTEMDDIR/moonraker.service" - - write_mr_service(){ - if [ ! -f $MR_SERV_TARGET ]; then - status_msg "Creating Moonraker Service $i ..." - sudo cp "$MR_SERV_SRC" $MR_SERV_TARGET - sudo sed -i "s|%INST%|$i|" $MR_SERV_TARGET - sudo sed -i "s|%USER%|${USER}|" $MR_SERV_TARGET - sudo sed -i "s|%MR_ENV%|$MR_ENV|" $MR_SERV_TARGET - sudo sed -i "s|%MR_DIR%|$MR_DIR|" $MR_SERV_TARGET - sudo sed -i "s|%MR_LOG%|$MR_LOG|" $MR_SERV_TARGET - sudo sed -i "s|%MR_CONF%|$MR_CONF|" $MR_SERV_TARGET - fi - } - - if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then - ### write single instance service - write_mr_service - ### enable instance - do_action_service "enable" "moonraker" - ok_msg "Single Moonraker instance created!" - ### launching instance - do_action_service "start" "moonraker" - else - i=1 - while [[ $i -le $INSTANCE_COUNT ]]; do - ### rewrite default variables for multi instance cases - CFG_PATH="$klipper_cfg_loc/printer_$i" - MR_SERV_TARGET="$SYSTEMDDIR/moonraker-$i.service" - MR_CONF="$CFG_PATH/moonraker.conf" - MR_LOG="${HOME}/klipper_logs/moonraker-$i.log" - ### write multi instance service - write_mr_service - ### enable instance - do_action_service "enable" "moonraker-$i" - ok_msg "Moonraker instance #$i created!" - ### launching instance - do_action_service "start" "moonraker-$i" - ### raise values by 1 - i=$((i+1)) - done - unset i - - ### enable mainsails remoteMode if mainsail is found - if [ -d "$MAINSAIL_DIR" ]; then - status_msg "Mainsail installation found!" - status_msg "Enabling Mainsail remoteMode ..." - enable_mainsail_remotemode - ok_msg "Mainsails remoteMode enabled!" - fi - fi -} - -create_moonraker_conf(){ - ### get config directory - source_kiauh_ini - - ### set up default values - SINGLE_INST=1 - PORT=7125 - CFG_PATH="$klipper_cfg_loc" - LOG_PATH="${HOME}/klipper_logs" - MR_CONF="$CFG_PATH/moonraker.conf" - MR_DB="${HOME}/.moonraker_database" - KLIPPY_UDS="/tmp/klippy_uds" - MR_CONF_SRC="${SRCDIR}/kiauh/resources/moonraker.conf" - mr_ip_list=() - IP=$(hostname -I | cut -d" " -f1) - LAN="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" - - write_mr_conf(){ - [ ! -d "$CFG_PATH" ] && mkdir -p "$CFG_PATH" - if [ ! -f "$MR_CONF" ]; then - status_msg "Creating moonraker.conf in $CFG_PATH ..." - cp "$MR_CONF_SRC" "$MR_CONF" - sed -i "s|%PORT%|$PORT|" "$MR_CONF" - sed -i "s|%CFG%|$CFG_PATH|" "$MR_CONF" - sed -i "s|%LOG%|$LOG_PATH|" "$MR_CONF" - sed -i "s|%MR_DB%|$MR_DB|" "$MR_CONF" - sed -i "s|%UDS%|$KLIPPY_UDS|" "$MR_CONF" - # if host ip is not in the default ip ranges, replace placeholder - # otherwise remove placeholder from config - if ! grep -q "$LAN" "$MR_CONF"; then - sed -i "s|%LAN%|$LAN|" "$MR_CONF" - else - sed -i "/%LAN%/d" "$MR_CONF" - fi - sed -i "s|%USER%|${USER}|g" "$MR_CONF" - ok_msg "moonraker.conf created!" - else - warn_msg "There is already a file called 'moonraker.conf'!" - warn_msg "Skipping..." - fi - } - - if [[ $SINGLE_INST -eq $INSTANCE_COUNT ]]; then - ### write single instance config - write_mr_conf - mr_ip_list+=("$IP:$PORT") - else - i=1 - while [[ $i -le $INSTANCE_COUNT ]]; do - ### rewrite default variables for multi instance cases - CFG_PATH="$klipper_cfg_loc/printer_$i" - MR_CONF="$CFG_PATH/moonraker.conf" - MR_DB="${HOME}/.moonraker_database_$i" - KLIPPY_UDS="/tmp/klippy_uds-$i" - - ### write multi instance config - write_mr_conf - mr_ip_list+=("$IP:$PORT") - - ### raise values by 1 - PORT=$((PORT+1)) - i=$((i+1)) - done - unset PORT && unset i - fi -} - -print_mr_ip_list(){ - i=1 - for ip in "${mr_ip_list[@]}"; do - echo -e " ${cyan}● Instance $i:${default} $ip" - i=$((i + 1)) - done -} - -### introduced due to -### https://github.com/Arksine/moonraker/issues/349 -### https://github.com/Arksine/moonraker/pull/346 -moonraker_polkit(){ - SYSTEMDDIR="/etc/systemd/system" - MOONRAKER_SERVICES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service") - for service in $MOONRAKER_SERVICES; do - HAS_SUPP="$( grep -cm1 "SupplementaryGroups=moonraker-admin" "$service" || true )" - if [ "$HAS_SUPP" -eq 0 ]; then - status_msg "Adding moonraker-admin supplementary group to $service ..." - sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "$service" \ - && ok_msg "Adding moonraker-admin supplementary group successfull!" - fi - done - ### execute moonrakers policykit-rules script - "${HOME}"/moonraker/scripts/set-policykit-rules.sh - sudo systemctl daemon-reload -} \ No newline at end of file diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh new file mode 100644 index 0000000..491b825 --- /dev/null +++ b/scripts/moonraker.sh @@ -0,0 +1,506 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +SYSTEMD="/etc/systemd/system" +INITD="/etc/init.d" +ETCDEF="/etc/default" +MOONRAKER_ENV="${HOME}/moonraker-env" +MOONRAKER_DIR="${HOME}/moonraker" +MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" + +#===================================================# +#================ INSTALL MOONRAKER ================# +#===================================================# + +function system_check_moonraker(){ + local major minor + ### python 3 check + status_msg "Your Python 3 version is: $(python3 --version)" + major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) + minor=$(python3 --version | cut -d"." -f2) + if [ "${major}" -ge 3 ] && [ "${minor}" -ge 7 ]; then + echo "true" + else + echo "false" + fi +} + +function moonraker_systemd() { + local services + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service") + echo "${services}" +} + +function moonraker_setup_dialog(){ + status_msg "Initializing Moonraker installation ..." + + ### return early if moonraker already exists + if [ -n "$(moonraker_systemd)" ]; then + ERROR_MSG="At least one Moonraker service is already installed:" + for service in $(moonraker_systemd); do + ERROR_MSG="${ERROR_MSG}\n ➔ ${service}" + done + export ERROR_MSG + print_error && return + fi + + ### return early if python version check fails + if [ "$(system_check_moonraker)" == "false" ]; then + ERROR_MSG="Versioncheck failed! Python 3.7 or newer required!\n" + ERROR_MSG="${ERROR_MSG} Please upgrade Python." + export ERROR_MSG + print_error && return + fi + + top_border + if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then + printf "|${green}%-55s${default}|\n" " 1 Klipper instance was found!" + elif [ "$(klipper_systemd | wc -w)" -gt 1 ]; then + printf "|${green}%-55s${default}|\n" " $(klipper_systemd | wc -w) Klipper instances were found!" + else + echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" + fi + echo -e "| Usually you need one Moonraker instance per Klipper |" + echo -e "| instance. Though you can install as many as you wish. |" + bottom_border + + local count + while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do + read -p "${cyan}###### Number of Moonraker instances to set up:${default} " count + if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then + error_msg "Invalid Input!\n" + else + echo + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${default} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + status_msg "Installing ${count} Moonraker instance(s) ... \n" + moonraker_setup "${count}" + break;; + N|n|No|no) + select_msg"No" + error_msg "Exiting Moonraker setup ...\n" + break;; + *) + invalid_option && print_error + ;; + esac + fi + done +} + +function install_moonraker_packages(){ + local packages + local install_script="${HOME}/moonraker/scripts/install-moonraker.sh" + + ### read PKGLIST from official install script + status_msg "Reading dependencies..." + # shellcheck disable=SC2016 + packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')" + + echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' + read -r -a packages <<< "${packages}" + + ### Update system package info + status_msg "Updating lists of packages..." + sudo apt-get update --allow-releaseinfo-change + + ### Install required packages + status_msg "Installing packages..." + sudo apt-get install --yes "${packages[@]}" +} + +function create_moonraker_virtualenv(){ + status_msg "Installing python virtual environment..." + ### always create a clean virtualenv + [ -d "${MOONRAKER_ENV}" ] && rm -rf "${MOONRAKER_ENV}" + virtualenv -p /usr/bin/python3 "${MOONRAKER_ENV}" + "${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt" +} + +function moonraker_setup(){ + local instances=${1} + ### checking dependencies + dep=(wget curl unzip dfu-util virtualenv) + ### additional required dependencies on armbian + dep+=(libjpeg-dev zlib1g-dev) + dependency_check "${dep[@]}" + + ### step 1: clone moonraker + status_msg "Downloading Moonraker ..." + ### force remove existing moonraker dir and clone into fresh moonraker dir + [ -d "${MOONRAKER_DIR}" ] && rm -rf "${MOONRAKER_DIR}" + cd "${HOME}" && git clone "${MOONRAKER_REPO}" + + ### step 2: install moonraker dependencies and create python virtualenv + status_msg "Installing dependencies ..." + install_moonraker_packages + create_moonraker_virtualenv + + ### step 3: create moonraker.conf + create_moonraker_conf "${instances}" + + ### step 4: create moonraker instances + create_moonraker_service "${instances}" + + ### step 5: create polkit rules for moonraker + moonraker_polkit + + ### step 6: enable and start all instances + do_action_service "enable" "moonraker" + do_action_service "start" "moonraker" + + ### confirm message + if [[ ${instances} -eq 1 ]]; then + CONFIRM_MSG="Moonraker has been set up!" + elif [[ ${instances} -gt 1 ]]; then + CONFIRM_MSG="${instances} Moonraker instances have been set up!" + fi + export CONFIRM_MSG + print_confirm + + print_mr_ip_list "${mr_ip_list}" + return +} + +function write_moonraker_service(){ + local i=${1} cfg_dir=${2} cfg=${3} log=${4} service=${5} + local service_template="${SRCDIR}/kiauh/resources/moonraker.service" + + ### replace all placeholders + if [ ! -f "${service}" ]; then + status_msg "Creating Moonraker Service ${i} ..." + sudo cp "${service_template}" "${service}" + + [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" + [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" + sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}" + sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}" + fi + } + +function create_moonraker_service(){ + local instances=${1} + if [ "${instances}" -eq 1 ]; then + local i="" + local cfg_dir="${KLIPPER_CONFIG}" + local cfg="${cfg_dir}/moonraker.conf" + local log="${HOME}/klipper_logs/moonraker.log" + local service="${SYSTEMD}/moonraker.service" + ### write single instance service + write_moonraker_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${service}" + ok_msg "Single Moonraker instance created!" + elif [ "${instances}" -gt 1 ]; then + local i=1 + while [ "${i}" -le "${instances}" ]; do + local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" + local cfg="${cfg_dir}/moonraker.conf" + local log="${HOME}/klipper_logs/moonraker-${i}.log" + local service="${SYSTEMD}/moonraker-${i}.service" + ### write multi instance service + write_moonraker_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${service}" + ok_msg "Moonraker instance #${i} created!" + i=$((i+1)) + done && unset i + ### enable mainsails remoteMode if mainsail is found + if [ -d "${MAINSAIL_DIR}" ]; then + status_msg "Mainsail installation found!" + status_msg "Enabling Mainsail remoteMode ..." + enable_mainsail_remotemode + ok_msg "Mainsails remoteMode enabled!" + fi + else + return 1 + fi +} + +function write_moonraker_conf(){ + local cfg_dir=${1} cfg=${2} port=${3} log=${4} db=${5} uds=${6} lan=${7} + local conf_template="${SRCDIR}/kiauh/resources/moonraker.conf" + [ ! -d "${cfg_dir}" ] && mkdir -p "${cfg_dir}" + + if [ ! -f "${cfg}" ]; then + status_msg "Creating moonraker.conf in ${cfg_dir} ..." + cp "${conf_template}" "${cfg}" + sed -i "s|%USER%|${USER}|g" "${cfg}" + sed -i "s|%CFG%|${cfg_dir}|; s|%PORT%|${port}|; s|%LOG%|${log}|; s|%DB%|${db}|; s|%UDS%|${uds}|" "${cfg}" + # if host ip is not in the default ip ranges replace placeholder, + # otherwise remove placeholder from config + if ! grep -q "${lan}" "${cfg}"; then + sed -i "s|%LAN%|${lan}|" "${cfg}" + else + sed -i "/%LAN%/d" "${cfg}" + fi + ok_msg "moonraker.conf created!" + else + status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..." + fi +} + +function create_moonraker_conf(){ + local instances=${1} + local log="${HOME}/klipper_logs" + local mr_ip_list=() + local ip lan + + ip=$(hostname -I | cut -d" " -f1) + lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" + + if [ "${instances}" -eq 1 ]; then + local cfg_dir="${KLIPPER_CONFIG}" + local cfg="${cfg_dir}/moonraker.conf" + local port=7125 + local db="${HOME}/.moonraker_database" + local uds="/tmp/klippy_uds" + ### write single instance config + write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" + mr_ip_list+=("${ip}:${port}") + elif [ "${instances}" -gt 1 ]; then + local i=1 + while [ "${i}" -le "${instances}" ]; do + local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" + local cfg="${cfg_dir}/moonraker.conf" + local port=7125 + local db="${HOME}/.moonraker_database_${i}" + local uds="/tmp/klippy_uds-${i}" + ### write multi instance config + write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" + mr_ip_list+=("${ip}:${port}") + port=$((port+1)) + i=$((i+1)) + done && unset port i + else + return 1 + fi + export mr_ip_list +} + +function print_mr_ip_list(){ + local ips=${1} + local i=0 + for ip in "${ips[@]}"; do + echo -e " ${cyan}● Instance $((i + 1)):${white} ${ip}" + done +} + +### introduced due to +### https://github.com/Arksine/moonraker/issues/349 +### https://github.com/Arksine/moonraker/pull/346 +function moonraker_polkit(){ + local has_sup + ### check for required SupplementaryGroups entry in service files + ### write it to the service if it doesn't exist + for service in $(moonraker_systemd); do + has_sup="$(grep "SupplementaryGroups=moonraker-admin" "${service}")" + if [ -z "${has_sup}" ]; then + status_msg "Adding moonraker-admin supplementary group to ${service} ..." + sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "${service}" + ok_msg "Adding moonraker-admin supplementary group successfull!" + fi + done + [ -z "${has_sup}" ] && echo "reloading services!!!" && sudo systemctl daemon-reload + ### execute moonrakers policykit-rules script + /bin/bash "${HOME}/moonraker/scripts/set-policykit-rules.sh" +} + +#==================================================# +#================ REMOVE MOONRAKER ================# +#==================================================# + +function remove_moonraker_sysvinit() { + [ ! -e "${INITD}/moonraker" ] && return + status_msg "Removing Moonraker SysVinit service ..." + sudo systemctl stop moonraker + sudo update-rc.d -f moonraker remove + sudo rm -f "${INITD}/moonraker" "${ETCDEF}/moonraker" + ok_msg "Moonraker SysVinit service removed!" +} + +function remove_moonraker_systemd() { + [ -z "$(moonraker_systemd)" ] && return + status_msg "Removing Moonraker Systemd Services ..." + local files + for service in $(moonraker_systemd | cut -d"/" -f5) + do + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" + ok_msg "Done!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "Moonraker Services removed!" +} + +function remove_moonraker_logs() { + local files + files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/moonraker(-[^0])?[0-9]*\.log(.*)?") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_moonraker_api_key() { + ### remove legacy api key + if [ -e "${HOME}/.klippy_api_key" ]; then + status_msg "Removing legacy API Key ..." + rm "${HOME}/.klippy_api_key" + ok_msg "Done!" + fi + ### remove api key + if [ -e "${HOME}/.moonraker_api_key" ]; then + status_msg "Removing API Key ..." + rm "${HOME}/.moonraker_api_key" + ok_msg "Done!" + fi +} + +function remove_moonraker_dir() { + [ ! -d "${MOONRAKER_DIR}" ] && return + status_msg "Removing Moonraker directory ..." + rm -rf "${MOONRAKER_DIR}" + ok_msg "Directory removed!" +} + +function remove_moonraker_env() { + [ ! -d "${MOONRAKER_ENV}" ] && return + status_msg "Removing moonraker-env directory ..." + rm -rf "${MOONRAKER_ENV}" + ok_msg "Directory removed!" +} + +function remove_moonraker_polkit() { + status_msg "Removing all Moonraker PolicyKit rules ..." + /bin/bash "${HOME}/moonraker/scripts/set-policykit-rules.sh" --clear + ok_msg "Done!" +} + +#TODO this is technically not moonraker but rather webinterface related configs, so this should be refactored. +function remove_moonraker_nginx() { + if [[ -e "${NGINX_CONFD}/upstreams.conf" || -e "${NGINX_CONFD}/common_vars.conf" ]]; then + status_msg "Removing Moonraker NGINX configuration ..." + sudo rm -f "${NGINX_CONFD}/upstreams.conf" "${NGINX_CONFD}/common_vars.conf" + ok_msg "Moonraker NGINX configuration removed!" + fi +} + + +function remove_moonraker(){ + remove_moonraker_sysvinit + remove_moonraker_systemd + remove_moonraker_logs + remove_moonraker_api_key + remove_moonraker_dir + remove_moonraker_env + remove_moonraker_polkit + remove_moonraker_nginx + + confirm="Moonraker was successfully removed!" + print_confirm "${confirm}" && return +} + +#==================================================# +#================ UPDATE MOONRAKER ================# +#==================================================# + +function update_moonraker(){ + do_action_service "stop" "moonraker" + if [ ! -d "${MOONRAKER_DIR}" ]; then + cd "${HOME}" && git clone "${MOONRAKER_REPO}" + else + bb4u "moonraker" + status_msg "Updating Moonraker ..." + cd "${MOONRAKER_DIR}" && git pull + ### read PKGLIST and install possible new dependencies + install_moonraker_packages + ### install possible new python dependencies + "${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt" + fi + ### required due to https://github.com/Arksine/moonraker/issues/349 + moonraker_polkit + + update_log_paths "moonraker" + ok_msg "Update complete!" + do_action_service "restart" "moonraker" +} + +#==================================================# +#================ MOONRAKER STATUS ================# +#==================================================# + +function get_moonraker_status(){ + local sf_count status + sf_count="$(moonraker_systemd | wc -w)" + + ### remove the "SERVICE" entry from the data array if a moonraker service is installed + local data_arr=(SERVICE "${MOONRAKER_DIR}" "${MOONRAKER_ENV}") + [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" + + ### count+1 for each found data-item from array + local filecount=0 + for data in "${data_arr[@]}"; do + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) + done + + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " + else + status="${yellow}Incomplete!${white} " + fi + echo "${status}" +} + +function get_local_moonraker_commit(){ + if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_DIR}"/.git ]; then + cd "${MOONRAKER_DIR}" + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" + else + commit="${NONE}" + fi + echo "${commit}" +} + +function get_remote_moonraker_commit(){ + if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_DIR}"/.git ]; then + cd "${MOONRAKER_DIR}" + git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + else + commit="${NONE}" + fi + echo "${commit}" +} + +function compare_moonraker_versions(){ + unset MOONRAKER_UPDATE_AVAIL + if [ "$(get_local_moonraker_commit)" != "$(get_remote_moonraker_commit)" ]; then + LOCAL_COMMIT="${yellow}$(printf "%-12s" "$(get_local_moonraker_commit)")${white}" + REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remotemoonrakerr_commit)")${white}" + # add klipper to the update all array for the update all function in the updater + MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker) + else + LOCAL_COMMIT="${green}$(printf "%-12s" "$(get_remote_moonraker_commit)")${white}" + REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remote_moonraker_commit)")${white}" + KLIPPER_UPDATE_AVAIL="false" + fi +} diff --git a/scripts/remove.sh b/scripts/remove.sh index 9e69bf5..0fd8a37 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,79 +1,6 @@ ### base variables SYSTEMDDIR="/etc/systemd/system" -remove_moonraker(){ - shopt -s extglob # enable extended globbing - ### remove "legacy" moonraker init.d service - if [ -f /etc/init.d/moonraker ]; then - status_msg "Removing Moonraker Service ..." - sudo systemctl stop moonraker - sudo update-rc.d -f moonraker remove - sudo rm -f /etc/init.d/moonraker - sudo rm -f /etc/default/moonraker - ok_msg "Moonraker Service removed!" - fi - - ### remove all moonraker services - FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service" - if ls $FILE 2>/dev/null 1>&2; then - status_msg "Removing Moonraker Services ..." - for service in $(ls $FILE | cut -d"/" -f5) - do - status_msg "Removing $service ..." - sudo systemctl stop $service - sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service - ok_msg "Done!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "Moonraker Service removed!" - fi - - ### remove all logfiles - FILE="${HOME}/klipper_logs/moonraker?(-*([0-9])).log" - if ls $FILE 2>/dev/null 1>&2; then - for log in $(ls $FILE); do - status_msg "Removing $log ..." - rm -f $log - ok_msg "$log removed!" - done - fi - - ### remove moonraker nginx config - if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then - status_msg "Removing Moonraker NGINX configuration ..." - sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!" - fi - - ### remove legacy api key - if [ -e ${HOME}/.klippy_api_key ]; then - status_msg "Removing legacy API Key ..." && rm ${HOME}/.klippy_api_key && ok_msg "Done!" - fi - - ### remove api key - if [ -e ${HOME}/.moonraker_api_key ]; then - status_msg "Removing API Key ..." && rm ${HOME}/.moonraker_api_key && ok_msg "Done!" - fi - - ### removing moonraker and moonraker-env folder - if [ -d $MOONRAKER_DIR ]; then - status_msg "Removing Moonraker directory ..." - rm -rf $MOONRAKER_DIR && ok_msg "Directory removed!" - fi - if [ -d $MOONRAKER_ENV ]; then - status_msg "Removing moonraker-env directory ..." - rm -rf $MOONRAKER_ENV && ok_msg "Directory removed!" - fi - - CONFIRM_MSG=" Moonraker was successfully removed!" - shopt -u extglob # disable extended globbing -} - -############################################################# -############################################################# - remove_dwc2(){ ### remove "legacy" init.d service if [ -e /etc/init.d/dwc ]; then diff --git a/scripts/status.sh b/scripts/status.sh index cd59d4a..1d3ec35 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -54,38 +54,6 @@ dwc2_status(){ fi } -moonraker_status(){ - mrcount=0 - moonraker_data=( - SERVICE - $MOONRAKER_DIR - $MOONRAKER_ENV_DIR - ) - - ### count amount of moonraker service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^moonraker(\-[[:digit:]]+)?\.service$" | wc -l) - - ### remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset moonraker_data[0] - - ### count+1 for each found data-item from array - for mrd in "${moonraker_data[@]}" - do - if [ -e $mrd ]; then - mrcount=$(expr $mrcount + 1) - fi - done - - ### display status - if [ "$mrcount" == "${#moonraker_data[*]}" ]; then - MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" - elif [ "$mrcount" == 0 ]; then - MOONRAKER_STATUS="${red}Not installed!${default} " - else - MOONRAKER_STATUS="${yellow}Incomplete!${default} " - fi -} - mainsail_status(){ mcount=0 mainsail_data=( @@ -294,33 +262,6 @@ compare_dwc2_versions(){ ############################################################# ############################################################# -read_moonraker_versions(){ - if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_DIR/.git ]; then - cd $MOONRAKER_DIR - git fetch origin master -q - LOCAL_MOONRAKER_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_MOONRAKER_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_MOONRAKER_COMMIT=$NONE - REMOTE_MOONRAKER_COMMIT=$NONE - fi -} - -compare_moonraker_versions(){ - unset MOONRAKER_UPDATE_AVAIL - read_moonraker_versions - if [ "$LOCAL_MOONRAKER_COMMIT" != "$REMOTE_MOONRAKER_COMMIT" ]; then - LOCAL_MOONRAKER_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_MOONRAKER_COMMIT")${default}" - REMOTE_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_COMMIT")${default}" - # add moonraker to the update all array for the update all function in the updater - MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker) - else - LOCAL_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_COMMIT")${default}" - REMOTE_MOONRAKER_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_COMMIT")${default}" - MOONRAKER_UPDATE_AVAIL="false" - fi -} - read_local_mainsail_version(){ unset MAINSAIL_VER_FOUND if [ -e $MAINSAIL_DIR/.version ]; then diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index a543f99..f630cb3 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -6,7 +6,7 @@ main_ui(){ echo -e "| 0) [Upload Log] | Klipper: $(get_klipper_status)|" echo -e "| | |" echo -e "| 1) [Install] |--------------------------------|" - echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" + echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" echo -e "| 3) [Remove] | |" echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" @@ -48,7 +48,7 @@ main_menu(){ #check install status print_kiauh_version # klipper_status - moonraker_status +# moonraker_status dwc2_status fluidd_status mainsail_status diff --git a/scripts/update.sh b/scripts/update.sh index f33778f..b3cc6d2 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -251,26 +251,6 @@ update_fluidd(){ symlink_webui_nginx_log "fluidd" } -update_moonraker(){ - do_action_service "stop" "moonraker" - bb4u "moonraker" - status_msg "Updating Moonraker ..." - ### pull latest files from github - cd "$MOONRAKER_DIR" && git pull - ### read PKGLIST and install possible new dependencies - install_moonraker_packages - ### install possible new python dependencies - MR_REQ_TXT="$MOONRAKER_DIR/scripts/moonraker-requirements.txt" - "$MOONRAKER_ENV"/bin/pip install -r "$MR_REQ_TXT" - update_log_paths "moonraker" - - ### required due to https://github.com/Arksine/moonraker/issues/349 - moonraker_polkit - - ok_msg "Update complete!" - do_action_service "restart" "moonraker" -} - update_klipperscreen(){ stop_klipperscreen cd $KLIPPERSCREEN_DIR From cd902cfcd736840847ce8ab1d0899a48b8dac4bc Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 19 Mar 2022 23:30:07 +0100 Subject: [PATCH 019/183] refactor(ui): beginning of UI improvements Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 33 +++++++++++++++------------------ scripts/moonraker.sh | 16 ++++++++++------ scripts/status.sh | 18 +++++++++--------- scripts/ui/install_menu.sh | 19 +++++++++---------- scripts/ui/update_menu.sh | 10 +++++----- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 3d3d3e7..b38193e 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -364,36 +364,33 @@ function get_klipper_status(){ } function get_local_klipper_commit(){ - if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPER_DIR}"/.git ]; then - cd "${KLIPPER_DIR}" - commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" - else - commit="${NONE}" - fi + [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPER_DIR}"/.git ] && return + cd "${KLIPPER_DIR}" + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" echo "${commit}" } function get_remote_klipper_commit(){ - if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPER_DIR}"/.git ]; then - cd "${KLIPPER_DIR}" - git fetch origin -q - commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - commit="${NONE}" - fi + [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPER_DIR}"/.git ] && return + cd "${KLIPPER_DIR}" && git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) echo "${commit}" } function compare_klipper_versions(){ unset KLIPPER_UPDATE_AVAIL - if [ "$(get_local_klipper_commit)" != "$(get_remote_klipper_commit)" ]; then - LOCAL_COMMIT="${yellow}$(printf "%-12s" "$(get_local_klipper_commit)")${default}" - REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remote_klipper_commit)")${default}" + local versions local_ver remote_ver + local_ver="$(get_local_klipper_commit)" + remote_ver="$(get_remote_klipper_commit)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" # add klipper to the update all array for the update all function in the updater KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper) else - LOCAL_COMMIT="${green}$(printf "%-12s" "$(get_remote_klipper_commit)")${default}" - REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remote_klipper_commit)")${default}" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" KLIPPER_UPDATE_AVAIL="false" fi + echo "${versions}" } \ No newline at end of file diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 491b825..f1ef049 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -493,14 +493,18 @@ function get_remote_moonraker_commit(){ function compare_moonraker_versions(){ unset MOONRAKER_UPDATE_AVAIL - if [ "$(get_local_moonraker_commit)" != "$(get_remote_moonraker_commit)" ]; then - LOCAL_COMMIT="${yellow}$(printf "%-12s" "$(get_local_moonraker_commit)")${white}" - REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remotemoonrakerr_commit)")${white}" + local versions local_ver remote_ver + local_ver="$(get_local_moonraker_commit)" + remote_ver="$(get_remote_moonraker_commit)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" # add klipper to the update all array for the update all function in the updater MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker) else - LOCAL_COMMIT="${green}$(printf "%-12s" "$(get_remote_moonraker_commit)")${white}" - REMOTE_COMMIT="${green}$(printf "%-12s" "$(get_remote_moonraker_commit)")${white}" - KLIPPER_UPDATE_AVAIL="false" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" + MOONRAKER_UPDATE_AVAIL="false" fi + echo "${versions}" } diff --git a/scripts/status.sh b/scripts/status.sh index 1d3ec35..e85ca18 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -435,13 +435,13 @@ NONE="${red}$(printf "%-12s" "--------")${default}" ui_print_versions(){ unset update_arr check_system_updates - compare_klipper_versions - compare_dwc2fk_versions - compare_dwc2_versions - compare_moonraker_versions - compare_mainsail_versions - compare_fluidd_versions - compare_klipperscreen_versions - compare_MoonrakerTelegramBot_versions - compare_pgc_versions +# compare_klipper_versions +# compare_dwc2fk_versions +# compare_dwc2_versions +# compare_moonraker_versions +# compare_mainsail_versions +# compare_fluidd_versions +# compare_klipperscreen_versions +# compare_MoonrakerTelegramBot_versions +# compare_pgc_versions } diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 5c8fc13..0eda727 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -6,17 +6,16 @@ install_ui(){ echo -e "| all necessary dependencies for the various | " echo -e "| functions on a completely fresh system. | " hr - echo -e "| Firmware: | Touchscreen GUI: | " - echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " - echo -e "| | | " - echo -e "| Klipper API: | Other: | " - echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | " - echo -e "| | 7) [OctoPrint] | " - echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | " - echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | " - echo -e "| 4) [Fluidd] | | " - echo -e "| | Webcam: | " + echo -e "| Firmware & API: | Other: | " + echo -e "| 1) [Klipper] | 6) [Duet Web Control] | " + echo -e "| 2) [Moonraker] | 7) [OctoPrint] | " + echo -e "| | 8) [PrettyGCode] | " + echo -e "| Klipper Webinterface: | 9) [Telegram Bot] | " + echo -e "| 3) [Mainsail] | | " + echo -e "| 4) [Fluidd] | Webcam: | " echo -e "| | 10) [MJPG-Streamer] | " + echo -e "| Touchscreen GUI: | | " + echo -e "| 5) [KlipperScreen] | | " back_footer } diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 0d23c74..85d30d9 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -6,12 +6,12 @@ update_ui(){ echo -e "| 0) $BB4U_STATUS| " hr echo -e "| a) [Update all] | | | " - echo -e "| | Local Vers: | Remote Vers: | " - echo -e "| Klipper/Klipper API: |---------------|--------------| " - echo -e "| 1) [Klipper] | $LOCAL_COMMIT | $REMOTE_COMMIT | " - echo -e "| 2) [Moonraker] | $LOCAL_MOONRAKER_COMMIT | $REMOTE_MOONRAKER_COMMIT | " + echo -e "| | Installed: | Latest: | " + echo -e "| Klipper & API : |---------------|--------------| " + echo -e "| 1) [Klipper] |$(compare_klipper_versions)| " + echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)| " echo -e "| | | | " - echo -e "| Klipper Webinterface: |---------------|--------------| " + echo -e "| Webinterface: |---------------|--------------| " echo -e "| 3) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | " echo -e "| 4) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | " echo -e "| | | | " From 7e7692d5b3144940d328e2e994983ca6513dcfaf Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:22:06 +0100 Subject: [PATCH 020/183] refactor: klipperscreen Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/install_klipperscreen.sh | 39 ------- scripts/klipperscreen.sh | 189 +++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 39 deletions(-) delete mode 100755 scripts/install_klipperscreen.sh create mode 100644 scripts/klipperscreen.sh diff --git a/scripts/install_klipperscreen.sh b/scripts/install_klipperscreen.sh deleted file mode 100755 index a9262de..0000000 --- a/scripts/install_klipperscreen.sh +++ /dev/null @@ -1,39 +0,0 @@ -install_klipperscreen(){ - python3_check - if [ $py_chk_ok = "true" ]; then - source_kiauh_ini - #KlipperScreen main installation - klipperscreen_setup - #after install actions - restart_klipperscreen - else - ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." - print_msg && clear_msg - fi -} - -python3_check(){ - status_msg "Your Python 3 version is: $(python3 --version)" - major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) - minor=$(python3 --version | cut -d"." -f2) - if [ $major -ge 3 ] && [ $minor -ge 7 ]; then - ok_msg "Python version ok!" - py_chk_ok="true" - else - py_chk_ok="false" - fi -} - -klipperscreen_setup(){ - dep=(wget curl unzip dfu-util) - dependency_check - status_msg "Downloading KlipperScreen ..." - # force remove existing KlipperScreen dir - [ -d $KLIPPERSCREEN_DIR ] && rm -rf $KLIPPERSCREEN_DIR - # clone into fresh KlipperScreen dir - cd ${HOME} && git clone $KLIPPERSCREEN_REPO - ok_msg "Download complete!" - status_msg "Installing KlipperScreen ..." - $KLIPPERSCREEN_DIR/scripts/KlipperScreen-install.sh - ok_msg "KlipperScreen successfully installed!" -} diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh new file mode 100644 index 0000000..146c889 --- /dev/null +++ b/scripts/klipperscreen.sh @@ -0,0 +1,189 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +SYSTEMD="/etc/systemd/system" +KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" +KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" +KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git +KLIPPER_CONFIG="${HOME}/klipper_config" + +#===================================================# +#============== INSTALL KLIPPERSCREEN ==============# +#===================================================# + +install_klipperscreen(){ + python3_check + if [ "${py_chk_ok}" = "true" ]; then + klipperscreen_setup + restart_klipperscreen + else + ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." + print_msg && clear_msg + fi +} + +python3_check(){ + status_msg "Your Python 3 version is: $(python3 --version)" + major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) + minor=$(python3 --version | cut -d"." -f2) + if [ "${major}" -ge 3 ] && [ "${minor}" -ge 7 ]; then + ok_msg "Python version ok!" + py_chk_ok="true" + else + py_chk_ok="false" + fi +} + +klipperscreen_setup(){ + dep=(wget curl unzip dfu-util) + dependency_check + status_msg "Downloading KlipperScreen ..." + # force remove existing KlipperScreen dir + [ -d "${KLIPPERSCREEN_DIR}" ] && rm -rf "${KLIPPERSCREEN_DIR}" + # clone into fresh KlipperScreen dir + cd "${HOME}" && git clone "${KLIPPERSCREEN_REPO}" + ok_msg "Download complete!" + status_msg "Installing KlipperScreen ..." + /bin/bash "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-install.sh" + ok_msg "KlipperScreen successfully installed!" +} + +#===================================================# +#=============== REMOVE KLIPPERSCREEN ==============# +#===================================================# + +remove_klipperscreen(){ + source_kiauh_ini + + ### remove KlipperScreen dir + if [ -d "${KLIPPERSCREEN_DIR}" ]; then + status_msg "Removing KlipperScreen directory ..." + rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!" + fi + + ### remove KlipperScreen VENV dir + if [ -d "${KLIPPERSCREEN_ENV_DIR}" ]; then + status_msg "Removing KlipperScreen VENV directory ..." + rm -rf "${KLIPPERSCREEN_ENV_DIR}" && ok_msg "Directory removed!" + fi + + ### remove KlipperScreen service + if [ -e "${SYSTEMD}/KlipperScreen.service" ]; then + status_msg "Removing KlipperScreen service ..." + sudo systemctl stop KlipperScreen + sudo systemctl disable KlipperScreen + sudo rm -f "${SYSTEMD}/KlipperScreen.service" + ###reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "KlipperScreen Service removed!" + fi + + ### remove KlipperScreen log + if [ -e "/tmp/KlipperScreen.log" ]; then + status_msg "Removing KlipperScreen log file ..." + rm -f "/tmp/KlipperScreen.log" && ok_msg "File removed!" + fi + + ### remove KlipperScreen log symlink in config dir + + if [ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]; then + status_msg "Removing KlipperScreen log symlink ..." + rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!" + fi + + CONFIRM_MSG="KlipperScreen successfully removed!" +} + +#===================================================# +#=============== UPDATE KLIPPERSCREEN ==============# +#===================================================# + +update_klipperscreen(){ + stop_klipperscreen + cd "${KLIPPERSCREEN_DIR}" + KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) + git pull origin master -q && ok_msg "Fetch successfull!" + git checkout -f master && ok_msg "Checkout successfull" + #KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt) + if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${KLIPPERSCREEN_OLDREQ_MD5SUM}" ]]; then + status_msg "New dependecies detected..." + PYTHONDIR="${HOME}/.KlipperScreen-env" + "${PYTHONDIR}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" + ok_msg "Dependencies have been installed!" + fi + ok_msg "Update complete!" + start_klipperscreen +} + +#===================================================# +#=============== KLIPPERSCREEN STATUS ==============# +#===================================================# + +klipperscreen_status(){ + klsccount=0 + klipperscreen_data=( + SERVICE + "${KLIPPERSCREEN_DIR}" + "${KLIPPERSCREEN_ENV_DIR}" + ) + + ### count amount of klipperscreen_data service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l) + + ### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed + [ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "klipperscreen_data[0]" + + #count+1 for each found data-item from array + for klscd in "${klipperscreen_data[@]}" + do + if [ -e "${klscd}" ]; then + klsccount=$((klsccount + 1)) + fi + done + if [ "${klsccount}" == "${#klipperscreen_data[*]}" ]; then + KLIPPERSCREEN_STATUS="${green}Installed!${default} " + elif [ "${klsccount}" == 0 ]; then + KLIPPERSCREEN_STATUS="${red}Not installed!${default} " + else + KLIPPERSCREEN_STATUS="${yellow}Incomplete!${default} " + fi +} + +read_klipperscreen_versions(){ + if [ -d "${KLIPPERSCREEN_DIR}" ] && [ -d "${KLIPPERSCREEN_DIR}/.git" ]; then + cd "${KLIPPERSCREEN_DIR}" + git fetch origin master -q + LOCAL_KLIPPERSCREEN_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) + REMOTE_KLIPPERSCREEN_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + else + LOCAL_KLIPPERSCREEN_COMMIT="${NONE}" + REMOTE_KLIPPERSCREEN_COMMIT="${NONE}" + fi +} + +compare_klipperscreen_versions(){ + unset KLIPPERSCREEN_UPDATE_AVAIL + read_klipperscreen_versions + if [ "${LOCAL_KLIPPERSCREEN_COMMIT}" != "${REMOTE_KLIPPERSCREEN_COMMIT}" ]; then + LOCAL_KLIPPERSCREEN_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${default}" + REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${default}" + KLIPPERSCREEN_UPDATE_AVAIL="true" + update_arr+=(update_klipperscreen) + else + LOCAL_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${default}" + REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${default}" + KLIPPERSCREEN_UPDATE_AVAIL="false" + fi +} From 9188460e4839209ed6bfc39d61114a6e21edf9bb Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:22:19 +0100 Subject: [PATCH 021/183] refactor: moonraker-telegram-bot Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker-telegram-bot.sh | 165 ++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 scripts/moonraker-telegram-bot.sh diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh new file mode 100644 index 0000000..220dacf --- /dev/null +++ b/scripts/moonraker-telegram-bot.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +SYSTEMD="/etc/systemd/system" +MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env +MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot +NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git +KLIPPER_CONFIG="${HOME}/klipper_config" + +#===================================================# +#=========== REMOVE MOONRAKERTELEGRAMBOT ===========# +#===================================================# + +install_MoonrakerTelegramBot(){ + MoonrakerTelegramBot_setup + restart_MoonrakerTelegramBot +} + +MoonrakerTelegramBot_setup(){ + source_kiauh_ini + export klipper_cfg_loc + dep=(virtualenv) + dependency_check + status_msg "Downloading MoonrakerTelegramBot ..." + #force remove existing MoonrakerTelegramBot dir + [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" + #clone into fresh MoonrakerTelegramBot dir + cd "${HOME}" && git clone "${NLEF_REPO}" + ok_msg "Download complete!" + status_msg "Installing MoonrakerTelegramBot ..." + /bin/bash "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/install.sh" + echo; ok_msg "MoonrakerTelegramBot successfully installed!" +} + + +#===================================================# +#=========== REMOVE MOONRAKERTELEGRAMBOT ===========# +#===================================================# + +remove_MoonrakerTelegramBot(){ + ### remove MoonrakerTelegramBot dir + if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]; then + status_msg "Removing MoonrakerTelegramBot directory ..." + rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" && ok_msg "Directory removed!" + fi + + ### remove MoonrakerTelegramBot VENV dir + if [ -d "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" ]; then + status_msg "Removing MoonrakerTelegramBot VENV directory ..." + rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" && ok_msg "Directory removed!" + fi + + ### remove MoonrakerTelegramBot service + if [ -e "${SYSTEMD}/moonraker-telegram-bot.service" ]; then + status_msg "Removing MoonrakerTelegramBot service ..." + sudo systemctl stop moonraker-telegram-bot + sudo systemctl disable moonraker-telegram-bot + sudo rm -f "${SYSTEMD}/moonraker-telegram-bot.service" + ###reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "MoonrakerTelegramBot Service removed!" + fi + + ### remove MoonrakerTelegramBot log + if [ -e "/tmp/telegram.log" ] || [ -e "${HOME}/klipper_logs/telegram.log" ]; then + status_msg "Removing MoonrakerTelegramBot log file ..." + rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" && ok_msg "File removed!" + fi + + ### remove MoonrakerTelegramBot log symlink in config dir + + if [ -e "${KLIPPER_CONFIG}/telegram.log" ]; then + status_msg "Removing MoonrakerTelegramBot log symlink ..." + rm -f "${KLIPPER_CONFIG}/telegram.log" && ok_msg "File removed!" + fi + + CONFIRM_MSG="MoonrakerTelegramBot successfully removed!" +} + +#===================================================# +#=========== UPDATE MOONRAKERTELEGRAMBOT ===========# +#===================================================# + +update_MoonrakerTelegramBot(){ + export KLIPPER_CONFIG + stop_MoonrakerTelegramBot + cd "${MOONRAKER_TELEGRAM_BOT_DIR}" + git pull + /bin/bash "./scripts/install.sh" + ok_msg "Update complete!" + start_MoonrakerTelegramBot +} + +#===================================================# +#=========== MOONRAKERTELEGRAMBOT STATUS ===========# +#===================================================# + +MoonrakerTelegramBot_status(){ + mtbcount=0 + MoonrakerTelegramBot_data=( + SERVICE + "${MOONRAKER_TELEGRAM_BOT_DIR}" + "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" + ) + + ### count amount of MoonrakerTelegramBot_data service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker-telegram-bot" | wc -l) + + ### remove the "SERVICE" entry from the MoonrakerTelegramBot_data array if a MoonrakerTelegramBot service is installed + [ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "MoonrakerTelegramBot_data[0]" + + #count+1 for each found data-item from array + for mtbd in "${MoonrakerTelegramBot_data[@]}" + do + if [ -e "${mtbd}" ]; then + mtbcount=$((mtbcount + 1)) + fi + done + if [ "${mtbcount}" == "${#MoonrakerTelegramBot_data[*]}" ]; then + MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${default} " + elif [ "${mtbcount}" == 0 ]; then + MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${default} " + else + MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${default} " + fi +} + +read_MoonrakerTelegramBot_versions(){ + if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]; then + cd "${MOONRAKER_TELEGRAM_BOT_DIR}" + git fetch origin master -q + LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) + REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + else + LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${NONE}" + REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${NONE}" + fi +} + +compare_MoonrakerTelegramBot_versions(){ + unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL + read_MoonrakerTelegramBot_versions + if [ "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}" != "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}" ]; then + LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" + REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" + # add moonraker telegram bot to the update all array for the update all function in the updater + MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_MoonrakerTelegramBot) + else + LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" + REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" + MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false" + fi +} From 43021cbb83582078d23ee6a2181fa2d981cb5ae0 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:22:32 +0100 Subject: [PATCH 022/183] refactor: klipperscreen & moonraker-telegram-bot Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/install_moonraker-telegram-bot.sh | 23 ----- scripts/remove.sh | 86 ---------------- scripts/status.sh | 115 ---------------------- scripts/update.sh | 28 ------ 4 files changed, 252 deletions(-) delete mode 100644 scripts/install_moonraker-telegram-bot.sh diff --git a/scripts/install_moonraker-telegram-bot.sh b/scripts/install_moonraker-telegram-bot.sh deleted file mode 100644 index 13d3e02..0000000 --- a/scripts/install_moonraker-telegram-bot.sh +++ /dev/null @@ -1,23 +0,0 @@ -install_MoonrakerTelegramBot(){ - source_kiauh_ini - #MoonrakerTelegramBot main installation - MoonrakerTelegramBot_setup - #after install actions - restart_MoonrakerTelegramBot -} - -MoonrakerTelegramBot_setup(){ - source_kiauh_ini - export klipper_cfg_loc - dep=(virtualenv) - dependency_check - status_msg "Downloading MoonrakerTelegramBot ..." - #force remove existing MoonrakerTelegramBot dir - [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] && rm -rf $MOONRAKER_TELEGRAM_BOT_DIR - #clone into fresh MoonrakerTelegramBot dir - cd ${HOME} && git clone $NLEF_REPO - ok_msg "Download complete!" - status_msg "Installing MoonrakerTelegramBot ..." - $MOONRAKER_TELEGRAM_BOT_DIR/scripts/install.sh - echo; ok_msg "MoonrakerTelegramBot successfully installed!" -} diff --git a/scripts/remove.sh b/scripts/remove.sh index 0fd8a37..f30d969 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -190,92 +190,6 @@ remove_nginx(){ fi } -remove_klipperscreen(){ - source_kiauh_ini - - ### remove KlipperScreen dir - if [ -d $KLIPPERSCREEN_DIR ]; then - status_msg "Removing KlipperScreen directory ..." - rm -rf $KLIPPERSCREEN_DIR && ok_msg "Directory removed!" - fi - - ### remove KlipperScreen VENV dir - if [ -d $KLIPPERSCREEN_ENV_DIR ]; then - status_msg "Removing KlipperScreen VENV directory ..." - rm -rf $KLIPPERSCREEN_ENV_DIR && ok_msg "Directory removed!" - fi - - ### remove KlipperScreen service - if [ -e /etc/systemd/system/KlipperScreen.service ]; then - status_msg "Removing KlipperScreen service ..." - sudo systemctl stop KlipperScreen - sudo systemctl disable KlipperScreen - sudo rm -f $SYSTEMDDIR/KlipperScreen.service - ###reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "KlipperScreen Service removed!" - fi - - ### remove KlipperScreen log - if [ -e /tmp/KlipperScreen.log ]; then - status_msg "Removing KlipperScreen log file ..." - rm -f /tmp/KlipperScreen.log && ok_msg "File removed!" - fi - - ### remove KlipperScreen log symlink in config dir - - if [ -e $klipper_cfg_loc/KlipperScreen.log ]; then - status_msg "Removing KlipperScreen log symlink ..." - rm -f $klipper_cfg_loc/KlipperScreen.log && ok_msg "File removed!" - fi - - CONFIRM_MSG="KlipperScreen successfully removed!" -} - -remove_MoonrakerTelegramBot(){ - source_kiauh_ini - - ### remove MoonrakerTelegramBot dir - if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ]; then - status_msg "Removing MoonrakerTelegramBot directory ..." - rm -rf $MOONRAKER_TELEGRAM_BOT_DIR && ok_msg "Directory removed!" - fi - - ### remove MoonrakerTelegramBot VENV dir - if [ -d $MOONRAKER_TELEGRAM_BOT_ENV_DIR ]; then - status_msg "Removing MoonrakerTelegramBot VENV directory ..." - rm -rf $MOONRAKER_TELEGRAM_BOT_ENV_DIR && ok_msg "Directory removed!" - fi - - ### remove MoonrakerTelegramBot service - if [ -e /etc/systemd/system/moonraker-telegram-bot.service ]; then - status_msg "Removing MoonrakerTelegramBot service ..." - sudo systemctl stop moonraker-telegram-bot - sudo systemctl disable moonraker-telegram-bot - sudo rm -f $SYSTEMDDIR/moonraker-telegram-bot.service - ###reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "MoonrakerTelegramBot Service removed!" - fi - - ### remove MoonrakerTelegramBot log - if [ -e /tmp/telegram.log ] || [ -e ${HOME}/klipper_logs/telegram.log ]; then - status_msg "Removing MoonrakerTelegramBot log file ..." - rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" && ok_msg "File removed!" - fi - - ### remove MoonrakerTelegramBot log symlink in config dir - - if [ -e $klipper_cfg_loc/telegram.log ]; then - status_msg "Removing MoonrakerTelegramBot log symlink ..." - rm -f $klipper_cfg_loc/telegram.log && ok_msg "File removed!" - fi - - CONFIRM_MSG="MoonrakerTelegramBot successfully removed!" -} - remove_mjpg-streamer(){ ### remove MJPG-Streamer service if [ -e $SYSTEMDDIR/webcamd.service ]; then diff --git a/scripts/status.sh b/scripts/status.sh index e85ca18..6710b21 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -130,66 +130,6 @@ octoprint_status(){ fi } -klipperscreen_status(){ - klsccount=0 - klipperscreen_data=( - SERVICE - $KLIPPERSCREEN_DIR - $KLIPPERSCREEN_ENV_DIR - ) - - ### count amount of klipperscreen_data service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l) - - ### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset klipperscreen_data[0] - - #count+1 for each found data-item from array - for klscd in "${klipperscreen_data[@]}" - do - if [ -e $klscd ]; then - klsccount=$(expr $klsccount + 1) - fi - done - if [ "$klsccount" == "${#klipperscreen_data[*]}" ]; then - KLIPPERSCREEN_STATUS="${green}Installed!${default} " - elif [ "$klsccount" == 0 ]; then - KLIPPERSCREEN_STATUS="${red}Not installed!${default} " - else - KLIPPERSCREEN_STATUS="${yellow}Incomplete!${default} " - fi -} - -MoonrakerTelegramBot_status(){ - mtbcount=0 - MoonrakerTelegramBot_data=( - SERVICE - $MOONRAKER_TELEGRAM_BOT_DIR - $MOONRAKER_TELEGRAM_BOT_ENV_DIR - ) - - ### count amount of MoonrakerTelegramBot_data service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker-telegram-bot" | wc -l) - - ### remove the "SERVICE" entry from the MoonrakerTelegramBot_data array if a MoonrakerTelegramBot service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset MoonrakerTelegramBot_data[0] - - #count+1 for each found data-item from array - for mtbd in "${MoonrakerTelegramBot_data[@]}" - do - if [ -e $mtbd ]; then - mtbcount=$(expr $mtbcount + 1) - fi - done - if [ "$mtbcount" == "${#MoonrakerTelegramBot_data[*]}" ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${default} " - elif [ "$mtbcount" == 0 ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${default} " - else - MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${default} " - fi -} - ############################################################# ############################################################# @@ -340,61 +280,6 @@ compare_fluidd_versions(){ fi } -read_klipperscreen_versions(){ - if [ -d $KLIPPERSCREEN_DIR ] && [ -d $KLIPPERSCREEN_DIR/.git ]; then - cd $KLIPPERSCREEN_DIR - git fetch origin master -q - LOCAL_KLIPPERSCREEN_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_KLIPPERSCREEN_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_KLIPPERSCREEN_COMMIT=$NONE - REMOTE_KLIPPERSCREEN_COMMIT=$NONE - fi -} - -compare_klipperscreen_versions(){ - unset KLIPPERSCREEN_UPDATE_AVAIL - read_klipperscreen_versions - if [ "$LOCAL_KLIPPERSCREEN_COMMIT" != "$REMOTE_KLIPPERSCREEN_COMMIT" ]; then - LOCAL_KLIPPERSCREEN_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_KLIPPERSCREEN_COMMIT")${default}" - REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "$REMOTE_KLIPPERSCREEN_COMMIT")${default}" - KLIPPERSCREEN_UPDATE_AVAIL="true" - update_arr+=(update_klipperscreen) - else - LOCAL_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "$LOCAL_KLIPPERSCREEN_COMMIT")${default}" - REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "$REMOTE_KLIPPERSCREEN_COMMIT")${default}" - KLIPPERSCREEN_UPDATE_AVAIL="false" - fi -} - -read_MoonrakerTelegramBot_versions(){ - if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] && [ -d $MOONRAKER_TELEGRAM_BOT_DIR/.git ]; then - cd $MOONRAKER_TELEGRAM_BOT_DIR - git fetch origin master -q - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$NONE - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$NONE - fi -} - -compare_MoonrakerTelegramBot_versions(){ - unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL - read_MoonrakerTelegramBot_versions - if [ "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT" != "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT" ]; then - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}" - # add moonraker telegram bot to the update all array for the update all function in the updater - MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_MoonrakerTelegramBot) - else - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "$REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT")${default}" - MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false" - fi -} - - ############################################################# ############################################################# diff --git a/scripts/update.sh b/scripts/update.sh index b3cc6d2..69f0058 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -251,23 +251,6 @@ update_fluidd(){ symlink_webui_nginx_log "fluidd" } -update_klipperscreen(){ - stop_klipperscreen - cd $KLIPPERSCREEN_DIR - KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1) - git pull origin master -q && ok_msg "Fetch successfull!" - git checkout -f master && ok_msg "Checkout successfull" - #KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt) - if [[ $(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt | cut -d " " -f1) != $KLIPPERSCREEN_OLDREQ_MD5SUM ]]; then - status_msg "New dependecies detected..." - PYTHONDIR="${HOME}/.KlipperScreen-env" - $PYTHONDIR/bin/pip install -r $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt - ok_msg "Dependencies have been installed!" - fi - ok_msg "Update complete!" - start_klipperscreen -} - update_pgc_for_klipper(){ PGC_DIR="${HOME}/pgcode" status_msg "Updating PrettyGCode for Klipper ..." @@ -275,17 +258,6 @@ update_pgc_for_klipper(){ ok_msg "Update complete!" } -update_MoonrakerTelegramBot(){ - source_kiauh_ini - export klipper_cfg_loc - stop_MoonrakerTelegramBot - cd $MOONRAKER_TELEGRAM_BOT_DIR - git pull - ./scripts/install.sh - ok_msg "Update complete!" - start_MoonrakerTelegramBot -} - update_system(){ status_msg "Updating System ..." sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y From 81a70457735acc8b5a76c942fa685e6031039735 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:25:40 +0100 Subject: [PATCH 023/183] refactor: remove mainsailOS & fluiddPi migration helper Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 41 -------------- scripts/update.sh | 103 ------------------------------------ 2 files changed, 144 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index b07bc19..6b80384 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -16,8 +16,6 @@ advanced_ui(){ echo -e "| 4) [Flash only] | Extensions: | " echo -e "| 5) [Build + Flash] | 9) [Shell Command] | " echo -e "| 6) [Get MCU ID] | | " - echo -e "| | CustomPiOS: | " - echo -e "| | 10) [Migration Helper] | " back_footer } @@ -63,8 +61,6 @@ advanced_menu(){ advanced_ui;; 9) do_action "setup_gcode_shell_command" "advanced_ui";; - 10) - do_action "migration_menu";; B|b) clear; main_menu; break;; *) @@ -140,40 +136,3 @@ switch_menu(){ ERROR_MSG="No Klipper directory found! Download Klipper first!" fi } - -############################################################# -############################################################# - -migration_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~ [ CustomPiOS Migration ] ~~~~~~~~~~") | " - hr - echo -e "| This function will help you to migrate a vanilla | " - echo -e "| MainsailOS or FluiddPi image to a newer state. | " - blank_line - echo -e "| Only use this function if you use MainsailOS 0.4.0 | " - echo -e "| or lower, or FluiddPi v1.13.0 or lower. | " - blank_line - echo -e "| Please have a look at the KIAUH changelog for more | " - echo -e "| details on what this function will do. | " - hr - echo -e "| | " - echo -e "| 1) [Migrate MainsailOS] | " - echo -e "| 2) [Migrate FluiddPi] | " - echo -e "| | " - back_footer -} - -migration_menu(){ - print_msg && clear_msg - migration_ui - while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 1) migrate_custompios "mainsail"; migration_menu;; - 2) migrate_custompios "fluiddpi"; migration_menu;; - B|b) clear; advanced_menu; break;; - *) print_unkown_cmd; migration_menu;; - esac - done -} diff --git a/scripts/update.sh b/scripts/update.sh index 69f0058..b6a0939 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -116,109 +116,6 @@ update_log_paths(){ shopt -u extglob # disable extended globbing } -migrate_custompios(){ - ### migrate vanilla mainsailOS 0.4.0 / fluiddPI v1.13.0 - ### and older to be in sync with newer releases - WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" - MJPG_SERV_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/etc/systemd/system/webcamd.service" - KL_SERV_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/klipper/filesystem/root/etc/systemd/system/klipper.service" - NGINX_CFG1="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mainsail/filesystem/root/etc/nginx/conf.d/upstreams.conf" - NGINX_CFG2="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mainsail/filesystem/root/etc/nginx/sites-available/mainsail" - LOG_ROTATE_KLIPPER="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/klipper/filesystem/root/etc/logrotate.d/klipper" - LOG_ROTATE_MOONRAKER="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/moonraker/filesystem/root/etc/logrotate.d/moonraker" - LOG_ROTATE_WEBCAMD="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/etc/logrotate.d/webcamd" - - if [ "$1" == "mainsail" ]; then - OS_VER="MainsailOS" - MACRO_CFG="mainsail.cfg" - fi - if [ "$1" == "fluiddpi" ]; then - OS_VER="FluiddPi" - MACRO_CFG="client_macros.cfg" - fi - if [ ! -f "/boot/$1.txt" ] || [ ! -f "/etc/init.d/klipper" ]; then - # abort function if there is no sign of an old CustomPiOS anymore - ERROR_MSG="No vanilla $OS_VER found. Aborting..." && return 0 - fi - status_msg "Starting migration of $OS_VER... Please wait..." - if [ -d "${HOME}/klipper_logs" ]; then - # delete an existing klipper_logs directory - # shouldn't be there in the first place if its a true vanilla CustomPiOS - status_msg "Recreate '~/klipper_logs' directory..." - rm -rf "${HOME}/klipper_logs" && mkdir "${HOME}/klipper_logs" - ok_msg "OK!" - fi - if [ -f "/boot/$1.txt" ]; then - # replace old webcamd.service and webcamd - status_msg "Migrating MJPG-Streamer..." - sudo systemctl stop webcamd - sudo rm -f "/etc/systemd/system/webcamd.service" - sudo rm -f "/root/bin/webcamd" - sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd" - sudo wget $MJPG_SERV_SRC -O "/etc/systemd/system/webcamd.service" - sudo sed -i "s/MainsailOS/$OS_VER/" "/etc/systemd/system/webcamd.service" - sudo chmod +x "/usr/local/bin/webcamd" - # move mainsail.txt/fluiddpi.txt from boot to klipper_config and rename it - sudo mv "/boot/$1.txt" "${HOME}/klipper_config/webcam.txt" - sudo chown pi:pi "${HOME}/klipper_config/webcam.txt" - sudo systemctl daemon-reload - sudo systemctl restart webcamd - ok_msg "OK!" - fi - if [ -f "/etc/init.d/klipper" ] && [ ! -f "/etc/systemd/system/klipper.service" ]; then - # replace klipper SysVinit service with systemd service - status_msg "Migrating Klipper Service..." - sudo systemctl stop klipper - sudo update-rc.d -f klipper remove - sudo rm -f "/etc/init.d/klipper" - sudo rm -f "/etc/default/klipper" - sudo wget $KL_SERV_SRC -O "/etc/systemd/system/klipper.service" - sudo systemctl enable klipper.service - sudo systemctl daemon-reload - sudo systemctl restart klipper - ok_msg "OK!" - fi - if [ -f "/etc/systemd/system/moonraker.service" ]; then - # update new log path in existing moonraker service - status_msg "Updating Moonraker Service..." - sudo systemctl stop moonraker - update_log_paths "moonraker" - sudo systemctl restart moonraker - ok_msg "OK!" - fi - if [ -f "/etc/nginx/conf.d/upstreams.conf" ]; then - [ "$1" == "mainsail" ] && cfg="mainsail" - [ "$1" == "fluiddpi" ] && cfg="fluidd" - # update nginx upstreams.conf and mainsail/fluidd config file - status_msg "Updating NGINX configurations..." - sudo systemctl stop nginx - sudo rm -f "/etc/nginx/conf.d/upstreams.conf" - sudo rm -f "/etc/nginx/sites-available/$cfg" - sudo wget $NGINX_CFG1 -O "/etc/nginx/conf.d/upstreams.conf" - sudo wget $NGINX_CFG2 -O "/etc/nginx/sites-available/$cfg" - sudo sed -i "s/mainsail/$cfg/g" "/etc/nginx/sites-available/$cfg" - sudo systemctl restart nginx - ok_msg "OK!" - fi - if [ -f "${HOME}/klipper_config/$MACRO_CFG" ]; then - # update macro files - status_msg "Updating $MACRO_CFG ..." - MACRO_CFG_PATH="${HOME}/klipper_config/$MACRO_CFG" - sed -i "/SAVE_GCODE_STATE NAME=PAUSE_state/d" $MACRO_CFG_PATH - sed -i "/RESTORE_GCODE_STATE NAME=PAUSE_state/d" $MACRO_CFG_PATH - ok_msg "OK!" - fi - if [ -d "/etc/logrotate.d" ]; then - # download logrotate configs - status_msg "Setting up logrotations..." - sudo wget $LOG_ROTATE_KLIPPER -O "/etc/logrotate.d/klipper" - sudo wget $LOG_ROTATE_MOONRAKER -O "/etc/logrotate.d/moonraker" - sudo wget $LOG_ROTATE_WEBCAMD -O "/etc/logrotate.d/webcamd" - ok_msg "OK!" - fi - ok_msg "Migration done!" -} - update_dwc2fk(){ do_action_service "stop" "dwc" bb4u "dwc2" From 4793968d457706374070fc3d1703cc45cb74e019 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:42:14 +0100 Subject: [PATCH 024/183] refactor: rough refactor of DWC2 Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/{install_dwc2.sh => dwc2.sh} | 212 ++++++++++++++++++++++++++- scripts/remove.sh | 58 -------- scripts/status.sh | 104 ------------- scripts/update.sh | 16 -- 4 files changed, 208 insertions(+), 182 deletions(-) rename scripts/{install_dwc2.sh => dwc2.sh} (62%) mode change 100755 => 100644 diff --git a/scripts/install_dwc2.sh b/scripts/dwc2.sh old mode 100755 new mode 100644 similarity index 62% rename from scripts/install_dwc2.sh rename to scripts/dwc2.sh index 89e5097..107bc43 --- a/scripts/install_dwc2.sh +++ b/scripts/dwc2.sh @@ -1,7 +1,27 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" -DWC_ENV="${HOME}/dwc-env" -DWC2_DIR="${HOME}/duetwebcontrol" +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +SYSTEMD="/etc/systemd/system" +DWC_ENV_DIR=${HOME}/dwc-env +DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket +DWC2_DIR=${HOME}/duetwebcontrol +DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git +KLIPPER_CONFIG="${HOME}/klipper_config" + +#=================================================# +#================= INSTALL DWC2 ==================# +#=================================================# system_check_dwc(){ ### check system for an installed octoprint service @@ -387,4 +407,188 @@ dwc_cfg_creation(){ INSTANCE=$(expr $INSTANCE + 1) done fi +} + +#=================================================# +#================= REMOVE DWC2 ===================# +#=================================================# + +remove_dwc2(){ + ### remove "legacy" init.d service + if [ -e /etc/init.d/dwc ]; then + status_msg "Removing DWC2-for-Klipper-Socket Service ..." + sudo systemctl stop dwc + sudo update-rc.d -f dwc remove + sudo rm -f /etc/init.d/dwc + sudo rm -f /etc/default/dwc + ok_msg "DWC2-for-Klipper-Socket Service removed!" + fi + + ### remove all dwc services + if ls /etc/systemd/system/dwc*.service 2>/dev/null 1>&2; then + status_msg "Removing DWC2-for-Klipper-Socket Services ..." + for service in $(ls /etc/systemd/system/dwc*.service | cut -d"/" -f5) + do + status_msg "Removing $service ..." + sudo systemctl stop $service + sudo systemctl disable $service + sudo rm -f $SYSTEMDDIR/$service + ok_msg "Done!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "DWC2-for-Klipper-Socket Service removed!" + fi + + ### remove all logfiles + if ls /tmp/dwc*.log 2>/dev/null 1>&2; then + for logfile in $(ls /tmp/dwc*.log) + do + status_msg "Removing $logfile ..." + rm -f $logfile + ok_msg "File '$logfile' removed!" + done + fi + + ### removing the rest of the folders + if [ -d $DWC2FK_DIR ]; then + status_msg "Removing DWC2-for-Klipper-Socket directory ..." + rm -rf $DWC2FK_DIR && ok_msg "Directory removed!" + fi + if [ -d $DWC_ENV_DIR ]; then + status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..." + rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!" + fi + if [ -d $DWC2_DIR ]; then + status_msg "Removing DWC2 directory ..." + rm -rf $DWC2_DIR && ok_msg "Directory removed!" + fi + + ### remove dwc2_port from ~/.kiauh.ini + sed -i "/^dwc2_port=/d" $INI_FILE + + CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!" +} + +#=================================================# +#================= UPDATE DWC2 ===================# +#=================================================# + +update_dwc2fk(){ + do_action_service "stop" "dwc" + bb4u "dwc2" + if [ ! -d $DWC2FK_DIR ]; then + cd ${HOME} && git clone $DWC2FK_REPO + else + cd $DWC2FK_DIR && git pull + fi + do_action_service "start" "dwc" +} + +update_dwc2(){ + bb4u "dwc2" + download_dwc_webui +} + +#=================================================# +#================= DWC2 STATUS ===================# +#=================================================# + +dwc2_status(){ + dcount=0 + dwc_data=( + SERVICE + $DWC2_DIR + $DWC2FK_DIR + $DWC_ENV_DIR + ) + + ### count amount of dwc service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^dwc(\-[[:digit:]]+)?\.service$" | wc -l) + + ### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0] + + #count+1 for each found data-item from array + for dd in "${dwc_data[@]}" + do + if [ -e $dd ]; then + dcount=$(expr $dcount + 1) + fi + done + + if [ "$dcount" == "${#dwc_data[*]}" ]; then + DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" + elif [ "$dcount" == 0 ]; then + DWC2_STATUS="${red}Not installed!${default} " + else + DWC2_STATUS="${yellow}Incomplete!${default} " + fi +} + +read_dwc2fk_versions(){ + if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then + cd $DWC2FK_DIR + git fetch origin master -q + LOCAL_DWC2FK_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) + REMOTE_DWC2FK_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + else + LOCAL_DWC2FK_COMMIT=$NONE + REMOTE_DWC2FK_COMMIT=$NONE + fi +} + +compare_dwc2fk_versions(){ + unset DWC2FK_UPDATE_AVAIL + read_dwc2fk_versions + if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then + LOCAL_DWC2FK_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}" + REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}" + # add dwc2fk to the update all array for the update all function in the updater + DWC2FK_UPDATE_AVAIL="true" && update_arr+=(update_dwc2fk) + else + LOCAL_DWC2FK_COMMIT="${green}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}" + REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}" + DWC2FK_UPDATE_AVAIL="false" + fi +} + +read_local_dwc2_version(){ + unset DWC2_VER_FOUND + if [ -e $DWC2_DIR/.version ]; then + DWC2_VER_FOUND="true" + DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/.version) + else + DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER + fi +} + +read_remote_dwc2_version(){ + #remote checks don't work without curl installed! + if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then + DWC2_REMOTE_VER=$NONE + else + get_dwc_ver + DWC2_REMOTE_VER=$DWC2_VERSION + fi +} + +compare_dwc2_versions(){ + unset DWC2_UPDATE_AVAIL + read_local_dwc2_version && read_remote_dwc2_version + if [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER == $DWC2_REMOTE_VER ]]; then + #printf fits the string for displaying it in the ui to a total char length of 12 + DWC2_LOCAL_VER="${green}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}" + DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" + elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then + DWC2_LOCAL_VER="${yellow}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}" + DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" + # add dwc to the update all array for the update all function in the updater + DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2) + else + DWC2_LOCAL_VER=$NONE + DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" + DWC2_UPDATE_AVAIL="false" + fi } \ No newline at end of file diff --git a/scripts/remove.sh b/scripts/remove.sh index f30d969..5f9d8cc 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,64 +1,6 @@ ### base variables SYSTEMDDIR="/etc/systemd/system" -remove_dwc2(){ - ### remove "legacy" init.d service - if [ -e /etc/init.d/dwc ]; then - status_msg "Removing DWC2-for-Klipper-Socket Service ..." - sudo systemctl stop dwc - sudo update-rc.d -f dwc remove - sudo rm -f /etc/init.d/dwc - sudo rm -f /etc/default/dwc - ok_msg "DWC2-for-Klipper-Socket Service removed!" - fi - - ### remove all dwc services - if ls /etc/systemd/system/dwc*.service 2>/dev/null 1>&2; then - status_msg "Removing DWC2-for-Klipper-Socket Services ..." - for service in $(ls /etc/systemd/system/dwc*.service | cut -d"/" -f5) - do - status_msg "Removing $service ..." - sudo systemctl stop $service - sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service - ok_msg "Done!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "DWC2-for-Klipper-Socket Service removed!" - fi - - ### remove all logfiles - if ls /tmp/dwc*.log 2>/dev/null 1>&2; then - for logfile in $(ls /tmp/dwc*.log) - do - status_msg "Removing $logfile ..." - rm -f $logfile - ok_msg "File '$logfile' removed!" - done - fi - - ### removing the rest of the folders - if [ -d $DWC2FK_DIR ]; then - status_msg "Removing DWC2-for-Klipper-Socket directory ..." - rm -rf $DWC2FK_DIR && ok_msg "Directory removed!" - fi - if [ -d $DWC_ENV_DIR ]; then - status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..." - rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!" - fi - if [ -d $DWC2_DIR ]; then - status_msg "Removing DWC2 directory ..." - rm -rf $DWC2_DIR && ok_msg "Directory removed!" - fi - - ### remove dwc2_port from ~/.kiauh.ini - sed -i "/^dwc2_port=/d" $INI_FILE - - CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!" -} - ############################################################# ############################################################# diff --git a/scripts/status.sh b/scripts/status.sh index 6710b21..082f272 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -22,38 +22,6 @@ check_system_updates(){ fi } -dwc2_status(){ - dcount=0 - dwc_data=( - SERVICE - $DWC2_DIR - $DWC2FK_DIR - $DWC_ENV_DIR - ) - - ### count amount of dwc service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^dwc(\-[[:digit:]]+)?\.service$" | wc -l) - - ### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0] - - #count+1 for each found data-item from array - for dd in "${dwc_data[@]}" - do - if [ -e $dd ]; then - dcount=$(expr $dcount + 1) - fi - done - - if [ "$dcount" == "${#dwc_data[*]}" ]; then - DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" - elif [ "$dcount" == 0 ]; then - DWC2_STATUS="${red}Not installed!${default} " - else - DWC2_STATUS="${yellow}Incomplete!${default} " - fi -} - mainsail_status(){ mcount=0 mainsail_data=( @@ -130,78 +98,6 @@ octoprint_status(){ fi } -############################################################# -############################################################# - -read_dwc2fk_versions(){ - if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then - cd $DWC2FK_DIR - git fetch origin master -q - LOCAL_DWC2FK_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_DWC2FK_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_DWC2FK_COMMIT=$NONE - REMOTE_DWC2FK_COMMIT=$NONE - fi -} - -compare_dwc2fk_versions(){ - unset DWC2FK_UPDATE_AVAIL - read_dwc2fk_versions - if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then - LOCAL_DWC2FK_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}" - REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}" - # add dwc2fk to the update all array for the update all function in the updater - DWC2FK_UPDATE_AVAIL="true" && update_arr+=(update_dwc2fk) - else - LOCAL_DWC2FK_COMMIT="${green}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}" - REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}" - DWC2FK_UPDATE_AVAIL="false" - fi -} - -read_local_dwc2_version(){ - unset DWC2_VER_FOUND - if [ -e $DWC2_DIR/.version ]; then - DWC2_VER_FOUND="true" - DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/.version) - else - DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER - fi -} - -read_remote_dwc2_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - DWC2_REMOTE_VER=$NONE - else - get_dwc_ver - DWC2_REMOTE_VER=$DWC2_VERSION - fi -} - -compare_dwc2_versions(){ - unset DWC2_UPDATE_AVAIL - read_local_dwc2_version && read_remote_dwc2_version - if [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER == $DWC2_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - DWC2_LOCAL_VER="${green}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}" - DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" - elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then - DWC2_LOCAL_VER="${yellow}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}" - DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" - # add dwc to the update all array for the update all function in the updater - DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2) - else - DWC2_LOCAL_VER=$NONE - DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" - DWC2_UPDATE_AVAIL="false" - fi -} - -############################################################# -############################################################# - read_local_mainsail_version(){ unset MAINSAIL_VER_FOUND if [ -e $MAINSAIL_DIR/.version ]; then diff --git a/scripts/update.sh b/scripts/update.sh index b6a0939..f4e69ca 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -116,22 +116,6 @@ update_log_paths(){ shopt -u extglob # disable extended globbing } -update_dwc2fk(){ - do_action_service "stop" "dwc" - bb4u "dwc2" - if [ ! -d $DWC2FK_DIR ]; then - cd ${HOME} && git clone $DWC2FK_REPO - else - cd $DWC2FK_DIR && git pull - fi - do_action_service "start" "dwc" -} - -update_dwc2(){ - bb4u "dwc2" - download_dwc_webui -} - update_mainsail(){ bb4u "mainsail" status_msg "Updating Mainsail ..." From 69793c923a74399546d6eddda2fb11ee11b6ad04 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:46:21 +0100 Subject: [PATCH 025/183] refactor(dwc): remove unnecessary variable Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/dwc2.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/dwc2.sh b/scripts/dwc2.sh index 107bc43..5efd4dc 100644 --- a/scripts/dwc2.sh +++ b/scripts/dwc2.sh @@ -17,7 +17,6 @@ DWC_ENV_DIR=${HOME}/dwc-env DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket DWC2_DIR=${HOME}/duetwebcontrol DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git -KLIPPER_CONFIG="${HOME}/klipper_config" #=================================================# #================= INSTALL DWC2 ==================# From e070c4b010a6e4a09d5562a363adf741efbc19ed Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:48:48 +0100 Subject: [PATCH 026/183] refactor: rough refactor of octoprint functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- .../{install_octoprint.sh => octoprint.sh} | 105 +++++++++++++++++- scripts/remove.sh | 44 -------- scripts/status.sh | 30 ----- 3 files changed, 101 insertions(+), 78 deletions(-) rename scripts/{install_octoprint.sh => octoprint.sh} (68%) mode change 100755 => 100644 diff --git a/scripts/install_octoprint.sh b/scripts/octoprint.sh old mode 100755 new mode 100644 similarity index 68% rename from scripts/install_octoprint.sh rename to scripts/octoprint.sh index c48bf57..7d5913f --- a/scripts/install_octoprint.sh +++ b/scripts/octoprint.sh @@ -1,7 +1,24 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +SYSTEMD="/etc/systemd/system" OCTOPRINT_ENV="${HOME}/OctoPrint" +#=================================================# +#=============== INSTALL OCTOPRINT ===============# +#=================================================# + octoprint_setup_dialog(){ status_msg "Initializing OctoPrint installation ..." @@ -103,7 +120,7 @@ add_to_groups(){ create_single_octoprint_startscript(){ ### create single instance systemd service file -sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint.service" << OCTOPRINT +sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint.service" << OCTOPRINT [Unit] Description=Starts OctoPrint on startup After=network-online.target @@ -123,7 +140,7 @@ OCTOPRINT create_multi_octoprint_startscript(){ ### create multi instance systemd service file -sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint-$INSTANCE.service" << OCTOPRINT +sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint-$INSTANCE.service" << OCTOPRINT [Unit] Description=Starts OctoPrint instance $INSTANCE on startup After=network-online.target @@ -274,3 +291,83 @@ print_op_ip_list(){ i=$((i + 1)) done } + +#=================================================# +#=============== REMOVE OCTOPRINT ================# +#=================================================# + +remove_octoprint(){ + ###remove all octoprint services + if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then + status_msg "Removing OctoPrint Services ..." + for service in $(ls /etc/systemd/system/octoprint*.service | cut -d"/" -f5) + do + status_msg "Removing $service ..." + sudo systemctl stop $service + sudo systemctl disable $service + sudo rm -f $SYSTEMDDIR/$service + ok_msg "OctoPrint Service removed!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + fi + + ### remove sudoers file + if [ -f /etc/sudoers.d/octoprint-shutdown ]; then + sudo rm -rf /etc/sudoers.d/octoprint-shutdown + fi + + ### remove OctoPrint directory + if [ -d ${HOME}/OctoPrint ]; then + status_msg "Removing OctoPrint directory ..." + rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!" + fi + + ###remove .octoprint directories + if ls -d ${HOME}/.octoprint* 2>/dev/null 1>&2; then + for folder in $(ls -d ${HOME}/.octoprint*) + do + status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!" + done + fi + + ### remove octoprint_port from ~/.kiauh.ini + sed -i "/^octoprint_port=/d" $INI_FILE + + CONFIRM_MSG=" OctoPrint successfully removed!" +} + +#=================================================# +#=============== OCTOPRINT STATUS ================# +#=================================================# + +octoprint_status(){ + ocount=0 + octoprint_data=( + SERVICE + $OCTOPRINT_DIR + ) + ### count amount of octoprint service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^octoprint(\-[[:digit:]]+)?\.service$" | wc -l) + + ### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0] + + #count+1 for each found data-item from array + for op in "${octoprint_data[@]}" + do + if [ -e $op ]; then + ocount=$(expr $ocount + 1) + fi + done + + ### display status + if [ "$ocount" == "${#octoprint_data[*]}" ]; then + OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" + elif [ "$ocount" == 0 ]; then + OCTOPRINT_STATUS="${red}Not installed!${default} " + else + OCTOPRINT_STATUS="${yellow}Incomplete!${default} " + fi +} diff --git a/scripts/remove.sh b/scripts/remove.sh index 5f9d8cc..1d02b61 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -70,50 +70,6 @@ remove_fluidd(){ CONFIRM_MSG="Fluidd successfully removed!" } -############################################################# -############################################################# - -remove_octoprint(){ - ###remove all octoprint services - if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then - status_msg "Removing OctoPrint Services ..." - for service in $(ls /etc/systemd/system/octoprint*.service | cut -d"/" -f5) - do - status_msg "Removing $service ..." - sudo systemctl stop $service - sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service - ok_msg "OctoPrint Service removed!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - fi - - ### remove sudoers file - if [ -f /etc/sudoers.d/octoprint-shutdown ]; then - sudo rm -rf /etc/sudoers.d/octoprint-shutdown - fi - - ### remove OctoPrint directory - if [ -d ${HOME}/OctoPrint ]; then - status_msg "Removing OctoPrint directory ..." - rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!" - fi - - ###remove .octoprint directories - if ls -d ${HOME}/.octoprint* 2>/dev/null 1>&2; then - for folder in $(ls -d ${HOME}/.octoprint*) - do - status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!" - done - fi - - ### remove octoprint_port from ~/.kiauh.ini - sed -i "/^octoprint_port=/d" $INI_FILE - - CONFIRM_MSG=" OctoPrint successfully removed!" -} ############################################################# ############################################################# diff --git a/scripts/status.sh b/scripts/status.sh index 082f272..2a58183 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -68,36 +68,6 @@ fluidd_status(){ fi } -octoprint_status(){ - ocount=0 - octoprint_data=( - SERVICE - $OCTOPRINT_DIR - ) - ### count amount of octoprint service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^octoprint(\-[[:digit:]]+)?\.service$" | wc -l) - - ### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0] - - #count+1 for each found data-item from array - for op in "${octoprint_data[@]}" - do - if [ -e $op ]; then - ocount=$(expr $ocount + 1) - fi - done - - ### display status - if [ "$ocount" == "${#octoprint_data[*]}" ]; then - OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" - elif [ "$ocount" == 0 ]; then - OCTOPRINT_STATUS="${red}Not installed!${default} " - else - OCTOPRINT_STATUS="${yellow}Incomplete!${default} " - fi -} - read_local_mainsail_version(){ unset MAINSAIL_VER_FOUND if [ -e $MAINSAIL_DIR/.version ]; then From 7d669c29a6f5f7880ca136cbd2ebdfdddc01db4f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Mar 2022 21:52:48 +0100 Subject: [PATCH 027/183] chore(kiauh.sh): clean up redundances Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 820f014..cc718d2 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -25,44 +25,20 @@ SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . "${script}"; done for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . "${script}"; done -### set important directories -#klipper -KLIPPER_DIR=${HOME}/klipper -KLIPPY_ENV=${HOME}/klippy-env #nginx NGINX_SA=/etc/nginx/sites-available NGINX_SE=/etc/nginx/sites-enabled NGINX_CONFD=/etc/nginx/conf.d -#moonraker -MOONRAKER_DIR=${HOME}/moonraker -MOONRAKER_ENV=${HOME}/moonraker-env #mainsail MAINSAIL_DIR=${HOME}/mainsail #fluidd FLUIDD_DIR=${HOME}/fluidd -#dwc2 -DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket -DWC_ENV_DIR=${HOME}/dwc-env -DWC2_DIR=${HOME}/duetwebcontrol -#octoprint -OCTOPRINT_DIR=${HOME}/OctoPrint -OCTOPRINT_CFG_DIR=${HOME}/.octoprint -#KlipperScreen -KLIPPERSCREEN_DIR=${HOME}/KlipperScreen -KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env -#MoonrakerTelegramBot -MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot -MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env #misc INI_FILE=${HOME}/.kiauh.ini BACKUP_DIR=${HOME}/kiauh-backups ### set github repos -ARKSINE_REPO=https://github.com/Arksine/klipper.git DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git -DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git -KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git -NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git #branches BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping From 01c15c91c736dd957284c13508293ffc7f4ec59e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 17:18:59 +0200 Subject: [PATCH 028/183] style(flash_klipper.sh): fix some shellcheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/{flash_mcu.sh => flash_klipper.sh} | 123 +++++++++++---------- 1 file changed, 67 insertions(+), 56 deletions(-) rename scripts/{flash_mcu.sh => flash_klipper.sh} (68%) mode change 100755 => 100644 diff --git a/scripts/flash_mcu.sh b/scripts/flash_klipper.sh old mode 100755 new mode 100644 similarity index 68% rename from scripts/flash_mcu.sh rename to scripts/flash_klipper.sh index 28bbaf7..1f9409c --- a/scripts/flash_mcu.sh +++ b/scripts/flash_klipper.sh @@ -1,10 +1,21 @@ #!/bin/bash +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + show_flash_method_help(){ top_border echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |" hr - echo -e "| ${cyan}Regular flashing method:${default} |" + echo -e "| ${cyan}Regular flashing method:${white} |" echo -e "| The default method to flash controller boards which |" echo -e "| are connected and updated over USB and not by placing |" echo -e "| a compiled firmware file onto an internal SD-Card. |" @@ -13,7 +24,7 @@ show_flash_method_help(){ echo -e "| - Arduino Mega 2560 |" echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |" blank_line - echo -e "| ${cyan}Updating via SD-Card Update:${default} |" + echo -e "| ${cyan}Updating via SD-Card Update:${white} |" echo -e "| Many popular controller boards ship with a bootloader |" echo -e "| capable of updating the firmware via SD-Card. |" echo -e "| Choose this method if your controller board supports |" @@ -29,8 +40,8 @@ show_flash_method_help(){ blank_line back_footer while true; do - read -p "${cyan}###### Please select:${default} " choice - case "$choice" in + read -p "${cyan}###### Please select:${white} " choice + case "${choice}" in B|b) clear && print_header select_flash_method @@ -56,19 +67,19 @@ select_flash_method(){ blank_line back_help_footer while true; do - read -p "${cyan}###### Please select:${default} " choice - case "$choice" in + read -p "${cyan}###### Please select:${white} " choice + case "${choice}" in 1) echo -e "###### > Regular flashing method" select_mcu_connection select_mcu_id - [[ "$CONFIRM_FLASH" == true ]] && flash_mcu + [[ "${CONFIRM_FLASH}" == true ]] && flash_mcu break;; 2) echo -e "###### > SD-Card Update" select_mcu_connection select_mcu_id - [[ "$CONFIRM_FLASH" == true ]] && flash_mcu_sd + [[ "${CONFIRM_FLASH}" == true ]] && flash_mcu_sd break;; B|b) advanced_menu @@ -87,39 +98,39 @@ select_flash_method(){ select_mcu_id(){ if [ ${#mcu_list[@]} -ge 1 ]; then top_border - echo -e "| ${red}!!! ATTENTION !!!${default} |" + echo -e "| ${red}!!! ATTENTION !!!${white} |" hr echo -e "| Make sure, to select the correct MCU! |" - echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |" + echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |" bottom_border - echo -e "${cyan}###### List of available MCU:${default}" + echo -e "${cyan}###### List of available MCU:${white}" ### list all mcus id=0 - for mcu in ${mcu_list[@]}; do + for mcu in "${mcu_list[@]}"; do let id++ - echo -e " $id) $mcu" + echo -e " ${id}) ${mcu}" done ### verify user input sel_index="" - while [[ ! ($sel_index =~ ^[1-9]+$) ]] || [ "$sel_index" -gt "$id" ]; do + while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${id}" ]; do echo - read -p "${cyan}###### Select MCU to flash:${default} " sel_index - if [[ ! ($sel_index =~ ^[1-9]+$) ]]; then + read -p "${cyan}###### Select MCU to flash:${white} " sel_index + if [[ ! (${sel_index} =~ ^[1-9]+$) ]]; then warn_msg "Invalid input!" - elif [ "$sel_index" -lt 1 ] || [ "$sel_index" -gt "$id" ]; then - warn_msg "Please select a number between 1 and $id!" + elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${id}" ]; then + warn_msg "Please select a number between 1 and ${id}!" fi mcu_index=$(echo $((sel_index - 1))) - selected_mcu_id="${mcu_list[$mcu_index]}" + selected_mcu_id="${mcu_list[${mcu_index}]}" done ### confirm selection while true; do - echo -e "\n###### You selected:\n ● MCU #$sel_index: $selected_mcu_id\n" - read -p "${cyan}###### Continue? (Y/n):${default} " yn + echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n" + read -p "${cyan}###### Continue? (Y/n):${white} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" - status_msg "Flashing $selected_mcu_id ..." + status_msg "Flashing ${selected_mcu_id} ..." CONFIRM_FLASH=true break;; N|n|No|no) @@ -136,7 +147,7 @@ select_mcu_id(){ flash_mcu(){ do_action_service "stop" "klipper" - make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" + make flash FLASH_DEVICE="${mcu_list[${mcu_index}]}" ### evaluate exit code of make flash if [ ! $? -eq 0 ]; then warn_msg "Flashing failed!" @@ -152,8 +163,8 @@ flash_mcu_sd(){ ### write each supported board to the array to make it selectable board_list=() - for board in $("$flash_script" -l | tail -n +2); do - board_list+=($board) + for board in $("${flash_script}" -l | tail -n +2); do + board_list+=("${board}") done i=0 @@ -164,11 +175,11 @@ flash_mcu_sd(){ echo -e "| The following boards are currently supported: |" hr ### display all supported boards to the user - for board in ${board_list[@]}; do - if [ $i -lt 10 ]; then - printf "| $i) %-50s|\n" "${board_list[$i]}" + for board in "${board_list[@]}"; do + if [ "${i}" -lt 10 ]; then + printf "| ${i}) %-50s|\n" "${board_list[${i}]}" else - printf "| $i) %-49s|\n" "${board_list[$i]}" + printf "| ${i}) %-49s|\n" "${board_list[${i}]}" fi i=$((i + 1)) done @@ -176,11 +187,11 @@ flash_mcu_sd(){ ### make the user select one of the boards while true; do - read -p "${cyan}###### Please select board type:${default} " choice - if [ "$choice" = "q" ] || [ "$choice" = "Q" ]; then + read -p "${cyan}###### Please select board type:${white} " choice + if [ "${choice}" = "q" ] || [ "${choice}" = "Q" ]; then clear && advanced_menu && break - elif [ "$choice" -le ${#board_list[@]} ]; then - selected_board="${board_list[$choice]}" + elif [ "${choice}" -le ${#board_list[@]} ]; then + selected_board="${board_list[${choice}]}" break else clear && print_header @@ -196,11 +207,11 @@ flash_mcu_sd(){ blank_line echo -e "| If you are unsure, stick to the default 250000! |" bottom_border - echo -e "${cyan}###### Please set the baud rate:${default} " + echo -e "${cyan}###### Please set the baud rate:${white} " unset baud_rate - while [[ ! $baud_rate =~ ^[0-9]+$ ]]; do + while [[ ! ${baud_rate} =~ ^[0-9]+$ ]]; do read -e -i "250000" -e baud_rate - selected_baud_rate=$baud_rate + selected_baud_rate=${baud_rate} break done break @@ -208,7 +219,7 @@ flash_mcu_sd(){ ###flash process do_action_service "stop" "klipper" - "$flash_script" -b "$selected_baud_rate" "$selected_mcu_id" "$selected_board" + /bin/bash "${flash_script}" -b "${selected_baud_rate}" "${selected_mcu_id}" "${selected_board}" ### evaluate exit code of flash-sdcard.sh execution if [ ! $? -eq 0 ]; then warn_msg "Flashing failed!" @@ -220,8 +231,8 @@ flash_mcu_sd(){ } build_fw(){ - if [ -d "$KLIPPER_DIR" ]; then - cd "$KLIPPER_DIR" + if [ -d "${KLIPPER_DIR}" ]; then + cd "${KLIPPER_DIR}" status_msg "Initializing firmware build ..." dep=(build-essential dpkg-dev make) dependency_check @@ -237,15 +248,15 @@ build_fw(){ select_mcu_connection(){ echo top_border - echo -e "| ${yellow}Make sure to have the controller board connected now!${default} |" + echo -e "| ${yellow}Make sure to have the controller board connected now!${white} |" blank_line echo -e "| How is the controller board connected to the host? |" echo -e "| 1) USB |" echo -e "| 2) UART |" bottom_border while true; do - read -p "${cyan}###### Connection method:${default} " choice - case "$choice" in + read -p "${cyan}###### Connection method:${white} " choice + case "${choice}" in 1) retrieve_id "USB" break;; @@ -273,12 +284,12 @@ retrieve_id(){ mcu_count=1 [ "$1" = "USB" ] && path="/dev/serial/by-id/*" [ "$1" = "UART" ] && path="/dev/ttyAMA0" - if [[ "$(ls $path)" != "" ]] ; then - for mcu in $path; do - declare "mcu_id_$mcu_count"="$mcu" - mcu_id="mcu_id_$mcu_count" + if [[ "$(ls "${path}")" != "" ]] ; then + for mcu in ${path}; do + declare "mcu_id_${mcu_count}"="${mcu}" + mcu_id="mcu_id_${mcu_count}" mcu_list+=("${!mcu_id}") - echo -e " ● ($1) MCU #$mcu_count: ${cyan}$mcu${default}\n" + echo -e " ● ($1) MCU #${mcu_count}: ${cyan}${mcu}${white}\n" let mcu_count++ done fi 2>/dev/null @@ -295,30 +306,30 @@ check_usergroup_dialout(){ else group_tty=true fi - if [ "$group_dialout" == "false" ] || [ "$group_tty" == "false" ] ; then + if [ "${group_dialout}" == "false" ] || [ "${group_tty}" == "false" ] ; then top_border - echo -e "| ${yellow}WARNING: Your current user is not in group:${default} |" - [ "$group_tty" == "false" ] && echo -e "| ${yellow}● tty${default} |" - [ "$group_dialout" == "false" ] && echo -e "| ${yellow}● dialout${default} |" + echo -e "| ${yellow}WARNING: Your current user is not in group:${white} |" + [ "${group_tty}" == "false" ] && echo -e "| ${yellow}● tty${white} |" + [ "${group_dialout}" == "false" ] && echo -e "| ${yellow}● dialout${white} |" blank_line echo -e "| It is possible that you won't be able to successfully |" echo -e "| flash without your user being a member of that group. |" echo -e "| If you want to add the current user to the group(s) |" echo -e "| listed above, answer with 'Y'. Else skip with 'n'. |" blank_line - echo -e "| ${yellow}INFO:${default} |" - echo -e "| ${yellow}Relog required for group assignments to take effect!${default} |" + echo -e "| ${yellow}INFO:${white} |" + echo -e "| ${yellow}Relog required for group assignments to take effect!${white} |" bottom_border while true; do - read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${default} " yn + read -p "${cyan}###### Add user '${USER}' to group(s) now? (Y/n):${white} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" status_msg "Adding user '${USER}' to group(s) ..." - if [ "$group_tty" == "false" ]; then + if [ "${group_tty}" == "false" ]; then sudo usermod -a -G tty "${USER}" && ok_msg "Group 'tty' assigned!" fi - if [ "$group_dialout" == "false" ]; then + if [ "${group_dialout}" == "false" ]; then sudo usermod -a -G dialout "${USER}" && ok_msg "Group 'dialout' assigned!" fi ok_msg "You need to relog/restart for the group(s) to be applied!" && exit 0;; From 5c6b5fed96f24986b4325dd2d09fb8bdd857eefe Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 17:32:32 +0200 Subject: [PATCH 029/183] refactor(mjpg-streamer.sh): merge code and fix shellsheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- ...tall_mjpg-streamer.sh => mjpg-streamer.sh} | 86 +++++++++++++++---- scripts/remove.sh | 31 ------- 2 files changed, 69 insertions(+), 48 deletions(-) rename scripts/{install_mjpg-streamer.sh => mjpg-streamer.sh} (57%) mode change 100755 => 100644 diff --git a/scripts/install_mjpg-streamer.sh b/scripts/mjpg-streamer.sh old mode 100755 new mode 100644 similarity index 57% rename from scripts/install_mjpg-streamer.sh rename to scripts/mjpg-streamer.sh index bc52c43..03700e0 --- a/scripts/install_mjpg-streamer.sh +++ b/scripts/mjpg-streamer.sh @@ -1,19 +1,36 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + ### base variables -SYSTEMDDIR="/etc/systemd/system" +SYSTEMD="/etc/systemd/system" WEBCAMD_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" WEBCAM_TXT_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" +#=================================================# +#============= INSTALL MJPG-STREAMER =============# +#=================================================# + install_mjpg-streamer(){ check_klipper_cfg_path source_kiauh_ini ### set default values MJPG_SERV_SRC="${SRCDIR}/kiauh/resources/webcamd.service" - MJPG_SERV_TARGET="$SYSTEMDDIR/webcamd.service" - WEBCAM_TXT="$klipper_cfg_loc/webcam.txt" + MJPG_SERV_TARGET="${SYSTEMD}/webcamd.service" + WEBCAM_TXT="${KLIPPER_CONFIG}/webcam.txt" ### if there is a webcamd.service -> exit - if [ -f $MJPG_SERV_TARGET ]; then + if [ -f "${MJPG_SERV_TARGET}" ]; then ERROR_MSG="Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!" print_msg && clear_msg && return fi @@ -53,23 +70,23 @@ install_mjpg-streamer(){ EOT - sudo wget $WEBCAMD_SRC -O "/usr/local/bin/webcamd" - sudo sed -i "/^config_dir=/ s|=.*|=$klipper_cfg_loc|" /usr/local/bin/webcamd + sudo wget "${WEBCAMD_SRC}" -O "/usr/local/bin/webcamd" + sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /usr/local/bin/webcamd sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd sudo chmod +x /usr/local/bin/webcamd ### step 4: create webcam.txt config file - [ ! -d "$klipper_cfg_loc" ] && mkdir -p "$klipper_cfg_loc" - if [ ! -f "$WEBCAM_TXT" ]; then + [ ! -d "${KLIPPER_CONFIG}" ] && mkdir -p "${KLIPPER_CONFIG}" + if [ ! -f "${WEBCAM_TXT}" ]; then status_msg "Creating webcam.txt config file ..." - wget $WEBCAM_TXT_SRC -O "$WEBCAM_TXT" + wget "${WEBCAM_TXT_SRC}" -O "${WEBCAM_TXT}" ok_msg "Done!" fi ### step 5: create systemd service status_msg "Creating MJPG-Streamer service ..." - sudo cp "$MJPG_SERV_SRC" $MJPG_SERV_TARGET - sudo sed -i "s|%USER%|${USER}|" $MJPG_SERV_TARGET + sudo cp "${MJPG_SERV_SRC}" "${MJPG_SERV_TARGET}" + sudo sed -i "s|%USER%|${USER}|" "${MJPG_SERV_TARGET}" ok_msg "MJPG-Streamer service created!" ### step 6: enabling and starting mjpg-streamer service @@ -106,7 +123,7 @@ EOF ### step 7: check if user is in group "video" usergroup_changed=false USER_IN_VIDEO_GROUP=$(groups "${USER}" | grep "video") - if [ -z "$USER_IN_VIDEO_GROUP" ]; then + if [ -z "${USER_IN_VIDEO_GROUP}" ]; then status_msg "Adding user ${USER} to group 'video' ..." sudo usermod -a -G video "${USER}" && ok_msg "Done!" usergroup_changed=true @@ -116,7 +133,7 @@ EOF ### confirm message CONFIRM_MSG="MJPG-Streamer has been set up!" - if [ "$usergroup_changed" == true ]; then + if [ "${usergroup_changed}" == true ]; then CONFIRM_MSG="${CONFIRM_MSG}\n ${yellow}INFO: Your User was added to a new group!${green}" CONFIRM_MSG="${CONFIRM_MSG}\n ${yellow}You need to relog/restart for the group to be applied!${green}" fi @@ -124,9 +141,44 @@ EOF ### print webcam ip adress/url IP=$(hostname -I | cut -d" " -f1) - WEBCAM_IP="http://$IP:8080/?action=stream" - WEBCAM_URL="http://$IP/webcam/?action=stream" - echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_IP" - echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_URL" + WEBCAM_IP="http://${IP}:8080/?action=stream" + WEBCAM_URL="http://${IP}/webcam/?action=stream" + echo -e " ${cyan}● Webcam URL:${white} ${WEBCAM_IP}" + echo -e " ${cyan}● Webcam URL:${white} ${WEBCAM_URL}" echo +} + +#=================================================# +#============== REMOVE MJPG-STREAMER =============# +#=================================================# + +remove_mjpg-streamer(){ + ### remove MJPG-Streamer service + if [ -e "${SYSTEMD}/webcamd.service" ]; then + status_msg "Removing MJPG-Streamer service ..." + sudo systemctl stop webcamd && sudo systemctl disable webcamd + sudo rm -f "${SYSTEMD}/webcamd.service" + ###reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "MJPG-Streamer Service removed!" + fi + + ### remove webcamd from /usr/local/bin + if [ -e "/usr/local/bin/webcamd" ]; then + sudo rm -f "/usr/local/bin/webcamd" + fi + + ### remove MJPG-Streamer directory + if [ -d "${HOME}/mjpg-streamer" ]; then + status_msg "Removing MJPG-Streamer directory ..." + rm -rf "${HOME}/mjpg-streamer" + ok_msg "MJPG-Streamer directory removed!" + fi + + ### remove webcamd log and symlink + [ -f "/var/log/webcamd.log" ] && sudo rm -f "/var/log/webcamd.log" + [ -L "${HOME}/klipper_logs/webcamd.log" ] && rm -f "${HOME}/klipper_logs/webcamd.log" + + CONFIRM_MSG="MJPG-Streamer successfully removed!" } \ No newline at end of file diff --git a/scripts/remove.sh b/scripts/remove.sh index 1d02b61..e9d3685 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -88,37 +88,6 @@ remove_nginx(){ fi } -remove_mjpg-streamer(){ - ### remove MJPG-Streamer service - if [ -e $SYSTEMDDIR/webcamd.service ]; then - status_msg "Removing MJPG-Streamer service ..." - sudo systemctl stop webcamd && sudo systemctl disable webcamd - sudo rm -f $SYSTEMDDIR/webcamd.service - ###reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "MJPG-Streamer Service removed!" - fi - - ### remove webcamd from /usr/local/bin - if [ -e "/usr/local/bin/webcamd" ]; then - sudo rm -f "/usr/local/bin/webcamd" - fi - - ### remove MJPG-Streamer directory - if [ -d ${HOME}/mjpg-streamer ]; then - status_msg "Removing MJPG-Streamer directory ..." - rm -rf ${HOME}/mjpg-streamer - ok_msg "MJPG-Streamer directory removed!" - fi - - ### remove webcamd log and symlink - [ -f "/var/log/webcamd.log" ] && sudo rm -f "/var/log/webcamd.log" - [ -L "${HOME}/klipper_logs/webcamd.log" ] && rm -f "${HOME}/klipper_logs/webcamd.log" - - CONFIRM_MSG="MJPG-Streamer successfully removed!" -} - remove_prettygcode(){ pgconf="/etc/nginx/sites-available/pgcode.local.conf" pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" From fb69cc0357d4cc14b7fb38a120e6458e405f1be1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 17:47:26 +0200 Subject: [PATCH 030/183] refactor(utilities.sh): fix some shellsheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 197 +++++++++++++++++++++++-------------------- 1 file changed, 105 insertions(+), 92 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 47f264b..fed6e5d 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -1,26 +1,39 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + ### base variables -SYSTEMDDIR="/etc/systemd/system" +SYSTEMD="/etc/systemd/system" # setting up some frequently used functions check_euid(){ - if [ "$EUID" -eq 0 ] + if [ "${EUID}" -eq 0 ] then echo -e "${red}" top_border echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |" bottom_border - echo -e "${default}" + echo -e "${white}" exit 1 fi } check_klipper_cfg_path(){ source_kiauh_ini - if [ -z $klipper_cfg_loc ]; then + if [ -z "${klipper_cfg_loc}" ]; then echo top_border - echo -e "| ${red}!!! WARNING !!!${default} |" - echo -e "| ${red}No Klipper configuration directory set!${default} |" + echo -e "| ${red}!!! WARNING !!!${white} |" + echo -e "| ${red}No Klipper configuration directory set!${white} |" hr echo -e "| Before we can continue, KIAUH needs to know where |" echo -e "| you want your printer configuration to be. |" @@ -35,26 +48,26 @@ check_klipper_cfg_path(){ change_klipper_cfg_path(){ source_kiauh_ini - old_klipper_cfg_loc="$klipper_cfg_loc" + old_klipper_cfg_loc="${klipper_cfg_loc}" EXAMPLE_FOLDER=$(printf "%s/your_config_folder" "${HOME}") while true; do top_border - echo -e "| ${red}IMPORTANT:${default} |" + echo -e "| ${red}IMPORTANT:${white} |" echo -e "| Please enter the new path in the following format: |" - printf "| ${yellow}%-51s${default} |\n" "$EXAMPLE_FOLDER" + printf "| ${yellow}%-51s${white} |\n" "${EXAMPLE_FOLDER}" blank_line echo -e "| By default 'klipper_config' is recommended! |" bottom_border echo - echo -e "${cyan}###### Please set the Klipper config directory:${default} " - if [ -z "$old_klipper_cfg_loc" ]; then + echo -e "${cyan}###### Please set the Klipper config directory:${white} " + if [ -z "${old_klipper_cfg_loc}" ]; then read -e -i "/home/${USER}/klipper_config" -e new_klipper_cfg_loc else - read -e -i "$old_klipper_cfg_loc" -e new_klipper_cfg_loc + read -e -i "${old_klipper_cfg_loc}" -e new_klipper_cfg_loc fi echo - read -p "${cyan}###### Set config directory to '${yellow}$new_klipper_cfg_loc${cyan}' ? (Y/n):${default} " yn - case "$yn" in + read -p "${cyan}###### Set config directory to '${yellow}${new_klipper_cfg_loc}${cyan}' ? (Y/n):${white} " yn + case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" @@ -62,8 +75,8 @@ change_klipper_cfg_path(){ backup_klipper_config_dir ### write new location to kiauh.ini - sed -i "s|klipper_cfg_loc=$old_klipper_cfg_loc|klipper_cfg_loc=$new_klipper_cfg_loc|" $INI_FILE - status_msg "Directory set to '$new_klipper_cfg_loc'!" + sed -i "s|klipper_cfg_loc=${old_klipper_cfg_loc}|klipper_cfg_loc=${new_klipper_cfg_loc}|" "${INI_FILE}" + status_msg "Directory set to '${new_klipper_cfg_loc}'!" ### write new location to klipper and moonraker service set_klipper_cfg_path @@ -86,51 +99,51 @@ set_klipper_cfg_path(){ do_action_service "stop" "moonraker" ### copy config files to new klipper config folder - if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then - if [ ! -d "$new_klipper_cfg_loc" ]; then - status_msg "Copy config files to '$new_klipper_cfg_loc' ..." - mkdir -p "$new_klipper_cfg_loc" - cd $old_klipper_cfg_loc - cp -r -v ./* "$new_klipper_cfg_loc" + if [ -n "${old_klipper_cfg_loc}" ] && [ -d "${old_klipper_cfg_loc}" ]; then + if [ ! -d "${new_klipper_cfg_loc}" ]; then + status_msg "Copy config files to '${new_klipper_cfg_loc}' ..." + mkdir -p "${new_klipper_cfg_loc}" + cd "${old_klipper_cfg_loc}" + cp -r -v ./* "${new_klipper_cfg_loc}" ok_msg "Done!" fi fi - SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/klipper(-[^0])+[0-9]*.service") + SERVICE_FILES=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])+[0-9]*.service") ### handle single klipper instance service file - if [ -f $SYSTEMDDIR/klipper.service ]; then + if [ -f "${SYSTEMD}/klipper.service" ]; then status_msg "Configuring Klipper for new path ..." - sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer.cfg|klippy.py $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service + sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer.cfg|klippy.py ${new_klipper_cfg_loc}/printer.cfg|" "${SYSTEMD}/klipper.service" ok_msg "OK!" - elif [ -n "$SERVICE_FILES" ]; then + elif [ -n "${SERVICE_FILES}" ]; then ### handle multi klipper instance service file status_msg "Configuring Klipper for new path ..." - for service in $SERVICE_FILES; do - sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer_|klippy.py $new_klipper_cfg_loc/printer_|" "$service" + for service in ${SERVICE_FILES}; do + sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer_|klippy.py ${new_klipper_cfg_loc}/printer_|" "${service}" done ok_msg "OK!" fi - SERVICE_FILES=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])+[0-9]*.service") + SERVICE_FILES=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])+[0-9]*.service") ### handle single moonraker instance service and moonraker.conf file - if [ -f $SYSTEMDDIR/moonraker.service ]; then + if [ -f "${SYSTEMD}/moonraker.service" ]; then status_msg "Configuring Moonraker for new path ..." - sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c $new_klipper_cfg_loc/moonraker.conf|" $SYSTEMDDIR/moonraker.service + sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c ${new_klipper_cfg_loc}/moonraker.conf|" "${SYSTEMD}/moonraker.service" ### replace old file path with new one in moonraker.conf - sed -i -r "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf + sed -i -r "/config_path:/ s|config_path:.*|config_path: ${new_klipper_cfg_loc}|" "${new_klipper_cfg_loc}/moonraker.conf" ok_msg "OK!" - elif [ -n "$SERVICE_FILES" ]; then + elif [ -n "${SERVICE_FILES}" ]; then ### handle multi moonraker instance service file status_msg "Configuring Moonraker for new path ..." - for service in $SERVICE_FILES; do - sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" "$service" + for service in ${SERVICE_FILES}; do + sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c ${new_klipper_cfg_loc}/printer_|" "${service}" done - MR_CONFS=$(find "$new_klipper_cfg_loc" -regextype posix-extended -regex "$new_klipper_cfg_loc/printer_[1-9]+/moonraker.conf") + MR_CONFS=$(find "${new_klipper_cfg_loc}" -regextype posix-extended -regex "${new_klipper_cfg_loc}/printer_[1-9]+/moonraker.conf") ### replace old file path with new one in moonraker.conf - for moonraker_conf in $MR_CONFS; do - loc=$(echo "$moonraker_conf" | rev | cut -d"/" -f2- | rev) - sed -i -r "/config_path:/ s|config_path:.*|config_path: $loc|" "$moonraker_conf" + for moonraker_conf in ${MR_CONFS}; do + loc=$(echo "${moonraker_conf}" | rev | cut -d"/" -f2- | rev) + sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${moonraker_conf}" done ok_msg "OK!" fi @@ -149,7 +162,7 @@ source_kiauh_ini(){ do_action_service(){ shopt -s extglob # enable extended globbing - SERVICES="$SYSTEMDDIR/$2?(-*([0-9])).service" + SERVICES="${SYSTEMD}/$2?(-*([0-9])).service" ### set a variable for the ok and status messages [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting" [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping" @@ -157,11 +170,11 @@ do_action_service(){ [ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling" [ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling" - if ls $SERVICES 2>/dev/null 1>&2; then - for service in $(ls $SERVICES | rev | cut -d"/" -f1 | rev); do - status_msg "$ACTION2 $service ..." - sudo systemctl $1 "$service" - ok_msg "$service $ACTION1!" + if ls "${SERVICES}" 2>/dev/null 1>&2; then + for service in $(ls "${SERVICES}" | rev | cut -d"/" -f1 | rev); do + status_msg "${ACTION2} ${service} ..." + sudo systemctl "${1}" "${service}" + ok_msg "${service} ${ACTION1}!" done fi shopt -u extglob # disable extended globbing @@ -189,9 +202,9 @@ read_octoprint_service_status(){ return 0 fi if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then - OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service " + OPRINT_SERVICE_STATUS="${red}[Disable]${white} OctoPrint Service " else - OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service " + OPRINT_SERVICE_STATUS="${green}[Enable]${white} OctoPrint Service " fi } @@ -238,7 +251,7 @@ dependency_check(){ #check if package is installed, if not write name into array for pkg in ${dep} do - echo -e "${cyan}● ${pkg} ${default}" + echo -e "${cyan}● ${pkg} ${white}" if [[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]]; then inst+=("${pkg}") fi @@ -248,7 +261,7 @@ dependency_check(){ status_msg "Installing the following dependencies:" for element in "${inst[@]}" do - echo -e "${cyan}● ${element} ${default}" + echo -e "${cyan}● ${element} ${white}" done echo sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${inst[@]}" -y @@ -263,14 +276,14 @@ dependency_check(){ print_error(){ for data in "${data_arr[@]}" do - if [ ! -e $data ]; then + if [ ! -e "${data}" ]; then data_count+=(0) else data_count+=(1) fi done sum=$(IFS=+; echo "$((${data_count[*]}))") - if [ $sum -eq 0 ]; then + if [ "${sum}" -eq 0 ]; then ERROR_MSG="Looks like $1 was already removed!\n Skipping..." else ERROR_MSG="" @@ -285,21 +298,21 @@ setup_gcode_shell_command(){ echo -e "| before you continue and remember that potential risks |" echo -e "| can be involved after installing this extension! |" blank_line - echo -e "| ${red}You accept that you are doing this on your own risk!${default} |" + echo -e "| ${red}You accept that you are doing this on your own risk!${white} |" bottom_border while true; do - read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn - case "$yn" in + read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn + case "${yn}" in Y|y|Yes|yes|"") - if [ -d $KLIPPER_DIR/klippy/extras ]; then + if [ -d "${KLIPPER_DIR}/klippy/extras" ]; then status_msg "Installing gcode shell command extension ..." - if [ -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py ]; then + if [ -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]; then warn_msg "There is already a file named 'gcode_shell_command.py'\nin the destination location!" while true; do - read -p "${cyan}###### Do you want to overwrite it? (Y/n):${default} " yn - case "$yn" in + read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn + case "${yn}" in Y|y|Yes|yes|"") - rm -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py + rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" install_gcode_shell_command break;; N|n|No|no) @@ -324,38 +337,38 @@ setup_gcode_shell_command(){ install_gcode_shell_command(){ do_action_service "stop" "klipper" - status_msg "Copy 'gcode_shell_command.py' to '$KLIPPER_DIR/klippy/extras' ..." - cp ${SRCDIR}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras + status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..." + cp "${SRCDIR}/kiauh/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras" while true; do echo - read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${default} " yn - case "$yn" in + read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${white} " yn + case "${yn}" in Y|y|Yes|yes|"") status_msg "Copy shell_command.cfg ..." ### create a backup of the config folder backup_klipper_config_dir ### handle single printer.cfg - if [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/shell_command.cfg ]; then + if [ -f "${klipper_cfg_loc}/printer.cfg" ] && [ ! -f "${klipper_cfg_loc}/shell_command.cfg" ]; then ### copy shell_command.cfg to config location - cp ${SRCDIR}/kiauh/resources/shell_command.cfg $klipper_cfg_loc - ok_msg "$klipper_cfg_loc/shell_command.cfg created!" + cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${klipper_cfg_loc}" + ok_msg "${klipper_cfg_loc}/shell_command.cfg created!" ### write the include to the very first line of the printer.cfg - sed -i "1 i [include shell_command.cfg]" $klipper_cfg_loc/printer.cfg + sed -i "1 i [include shell_command.cfg]" "${klipper_cfg_loc}/printer.cfg" fi ### handle multi printer.cfg - if ls $klipper_cfg_loc/printer_* 2>/dev/null 1>&2; then - for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do - path=$(echo $config | rev | cut -d"/" -f2- | rev) - if [ ! -f $path/shell_command.cfg ]; then + if ls "${klipper_cfg_loc}"/printer_* 2>/dev/null 1>&2; then + for config in $(find ${klipper_cfg_loc}/printer_*/printer.cfg); do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/shell_command.cfg" ]; then ### copy shell_command.cfg to config location - cp ${SRCDIR}/kiauh/resources/shell_command.cfg $path - ok_msg "$path/shell_command.cfg created!" + cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${path}" + ok_msg "${path}/shell_command.cfg created!" ### write the include to the very first line of the printer.cfg - sed -i "1 i [include shell_command.cfg]" $path/printer.cfg + sed -i "1 i [include shell_command.cfg]" "${path}/printer.cfg" fi done fi @@ -370,8 +383,8 @@ install_gcode_shell_command(){ create_minimal_cfg(){ #create a minimal default config - if [ "$SEL_DEF_CFG" = "true" ]; then - cat <<- EOF >> $PRINTER_CFG + if [ "${SEL_DEF_CFG}" = "true" ]; then + cat <<- EOF >> "${PRINTER_CFG}" [mcu] serial: @@ -391,30 +404,30 @@ EOF init_ini(){ ### copy an existing kiauh.ini to its new location to keep all possible saved values - if [ -f ${SRCDIR}/kiauh/kiauh.ini ] && [ ! -f $INI_FILE ]; then - cp ${SRCDIR}/kiauh/kiauh.ini $INI_FILE + if [ -f "${SRCDIR}/kiauh/kiauh.ini" ] && [ ! -f "${INI_FILE}" ]; then + cp "${SRCDIR}/kiauh/kiauh.ini" "${INI_FILE}" fi - if [ ! -f $INI_FILE ]; then - echo -e "#don't edit this file if you don't know what you are doing...\c" > $INI_FILE + if [ ! -f "${INI_FILE}" ]; then + echo -e "#don't edit this file if you don't know what you are doing...\c" > "${INI_FILE}" fi - if [ ! $(grep -E "^backup_before_update=." $INI_FILE) ]; then - echo -e "\nbackup_before_update=false\c" >> $INI_FILE + if [ ! $(grep -E "^backup_before_update=." "${INI_FILE}") ]; then + echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}" fi - if [ ! $(grep -E "^previous_origin_state=[[:alnum:]]" $INI_FILE) ]; then - echo -e "\nprevious_origin_state=0\c" >> $INI_FILE + if [ ! $(grep -E "^previous_origin_state=[[:alnum:]]" "${INI_FILE}") ]; then + echo -e "\nprevious_origin_state=0\c" >> "${INI_FILE}" fi - if [ ! $(grep -E "^previous_smoothing_state=[[:alnum:]]" $INI_FILE) ]; then - echo -e "\nprevious_smoothing_state=0\c" >> $INI_FILE + if [ ! $(grep -E "^previous_smoothing_state=[[:alnum:]]" "${INI_FILE}") ]; then + echo -e "\nprevious_smoothing_state=0\c" >> "${INI_FILE}" fi - if [ ! $(grep -E "^previous_shaping_state=[[:alnum:]]" $INI_FILE) ]; then - echo -e "\nprevious_shaping_state=0\c" >> $INI_FILE + if [ ! $(grep -E "^previous_shaping_state=[[:alnum:]]" "${INI_FILE}") ]; then + echo -e "\nprevious_shaping_state=0\c" >> "${INI_FILE}" fi - if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then - echo -e "\nlogupload_accepted=false\c" >> $INI_FILE + if [ ! $(grep -E "^logupload_accepted=." "${INI_FILE}") ]; then + echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}" fi ###add empty klipper config path if missing - if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then - echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE + if [ ! $(grep -E "^klipper_cfg_loc=" "${INI_FILE}") ]; then + echo -e "\nklipper_cfg_loc=\c" >> "${INI_FILE}" fi fetch_webui_ports } From a1e7be19604389935755d58f9f679395519abdc6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 17:57:59 +0200 Subject: [PATCH 031/183] refactor(pretty_gcode.sh): merge pgc code and fix some shellsheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/install_pgc_for_klipper.sh | 37 --------- scripts/pretty_gcode.sh | 116 +++++++++++++++++++++++++++++ scripts/remove.sh | 15 ---- scripts/status.sh | 31 -------- scripts/update.sh | 7 -- 5 files changed, 116 insertions(+), 90 deletions(-) delete mode 100755 scripts/install_pgc_for_klipper.sh create mode 100644 scripts/pretty_gcode.sh diff --git a/scripts/install_pgc_for_klipper.sh b/scripts/install_pgc_for_klipper.sh deleted file mode 100755 index 36982be..0000000 --- a/scripts/install_pgc_for_klipper.sh +++ /dev/null @@ -1,37 +0,0 @@ -### base variables -PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" -PGC_DIR="${HOME}/pgcode" - -install_pgc_for_klipper(){ - pgconfsrc="$PGC_DIR/pgcode.local.conf" - pgconf="/etc/nginx/sites-available/pgcode.local.conf" - pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" - pgc_default_port="7136" - - status_msg "Installing PrettyGCode for Klipper ..." - ### let the user decide which port is used - echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: $pgc_default_port)${default} " - read -e -p "${cyan}###### Port:${default} " -i "$pgc_default_port" pgc_custom_port - ### check nginx dependency - dep=(nginx) - dependency_check - ### clone repo - [ -d $PGC_DIR ] && rm -rf $PGC_DIR - cd ${HOME} && git clone $PGC_FOR_KLIPPER_REPO - ### copy nginx config into destination directory - sudo cp $pgconfsrc $pgconf - ### replace default pi user in case the user is called different - sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" $pgconf - ### replace default port - if [ $pgc_custom_port != $pgc_default_port ]; then - sudo sed -i "s|listen $pgc_default_port;|listen $pgc_custom_port;|" $pgconf - sudo sed -i "s|listen \[::\]:$pgc_default_port;|listen \[::\]:$pgc_custom_port;|" $pgconf - fi - ### create symlink - [ ! -L $pgconfsl ] && sudo ln -s $pgconf $pgconfsl - sudo systemctl restart nginx - ### show URI - pgc_uri="http://$(hostname -I | cut -d" " -f1):$pgc_custom_port" - echo -e "${cyan}\n● Accessible via:${default} $pgc_uri" - ok_msg "PrettyGCode for Klipper installed!\n" -} \ No newline at end of file diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh new file mode 100644 index 0000000..0cf342c --- /dev/null +++ b/scripts/pretty_gcode.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### base variables +PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" +PGC_DIR="${HOME}/pgcode" + +#=================================================# +#================== INSTALL PGC ==================# +#=================================================# + +install_pgc_for_klipper(){ + pgconfsrc="${PGC_DIR}/pgcode.local.conf" + pgconf="/etc/nginx/sites-available/pgcode.local.conf" + pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" + pgc_default_port="7136" + + status_msg "Installing PrettyGCode for Klipper ..." + ### let the user decide which port is used + echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: ${pgc_default_port})${white} " + read -e -p "${cyan}###### Port:${white} " -i "${pgc_default_port}" pgc_custom_port + ### check nginx dependency + dep=(nginx) + dependency_check + ### clone repo + [ -d "${PGC_DIR}" ] && rm -rf "${PGC_DIR}" + cd "${HOME}" && git clone "${PGC_FOR_KLIPPER_REPO}" + ### copy nginx config into destination directory + sudo cp "${pgconfsrc}" "${pgconf}" + ### replace default pi user in case the user is called different + sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" "${pgconf}" + ### replace default port + if [ "${pgc_custom_port}" != "${pgc_default_port}" ]; then + sudo sed -i "s|listen ${pgc_default_port};|listen ${pgc_custom_port};|" "${pgconf}" + sudo sed -i "s|listen \[::\]:${pgc_default_port};|listen \[::\]:${pgc_custom_port};|" "${pgconf}" + fi + ### create symlink + [ ! -L "${pgconfsl}" ] && sudo ln -s "${pgconf}" "${pgconfsl}" + sudo systemctl restart nginx + ### show URI + pgc_uri="http://$(hostname -I | cut -d" " -f1):${pgc_custom_port}" + echo -e "${cyan}\n● Accessible via:${white} ${pgc_uri}" + ok_msg "PrettyGCode for Klipper installed!\n" +} + +#=================================================# +#=================== REMOVE PGC ==================# +#=================================================# + +remove_prettygcode(){ + pgconf="/etc/nginx/sites-available/pgcode.local.conf" + pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" + if [ -d "${HOME}/pgcode" ] || [ -f "${pgconf}" ] || [ -L "${pgconfsl}" ]; then + status_msg "Removing PrettyGCode for Klipper ..." + rm -rf "${HOME}/pgcode" + sudo rm -f "${pgconf}" + sudo rm -f "${pgconfsl}" + sudo systemctl restart nginx + CONFIRM_MSG="PrettyGCode for Klipper successfully removed!" + else + ERROR_MSG="PrettyGCode for Klipper not found!\n Skipping..." + fi +} + +#=================================================# +#=================== UPDATE PGC ==================# +#=================================================# + +update_pgc_for_klipper(){ + PGC_DIR="${HOME}/pgcode" + status_msg "Updating PrettyGCode for Klipper ..." + cd "${PGC_DIR}" && git pull + ok_msg "Update complete!" +} + +#=================================================# +#=================== PGC STATUS ==================# +#=================================================# + +read_pgc_versions(){ + PGC_DIR="${HOME}/pgcode" + if [ -d "${PGC_DIR}" ] && [ -d "${PGC_DIR}/.git" ]; then + cd "${PGC_DIR}" + git fetch origin main -q + LOCAL_PGC_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) + REMOTE_PGC_COMMIT=$(git describe origin/main --always --tags | cut -d "-" -f 1,2) + else + LOCAL_PGC_COMMIT=${NONE} + REMOTE_PGC_COMMIT=${NONE} + fi +} + +compare_pgc_versions(){ + unset PGC_UPDATE_AVAIL + read_pgc_versions + if [ "${LOCAL_PGC_COMMIT}" != "${REMOTE_PGC_COMMIT}" ]; then + LOCAL_PGC_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_PGC_COMMIT}")${white}" + REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "${REMOTE_PGC_COMMIT}")${white}" + # add PGC to the update all array for the update all function in the updater + PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper) + else + LOCAL_PGC_COMMIT="${green}$(printf "%-12s" "${LOCAL_PGC_COMMIT}")${white}" + REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "${REMOTE_PGC_COMMIT}")${white}" + PGC_UPDATE_AVAIL="false" + fi +} \ No newline at end of file diff --git a/scripts/remove.sh b/scripts/remove.sh index e9d3685..6e8fa6c 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -87,18 +87,3 @@ remove_nginx(){ ERROR_MSG=" Looks like Nginx was already removed!\n Skipping..." fi } - -remove_prettygcode(){ - pgconf="/etc/nginx/sites-available/pgcode.local.conf" - pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" - if [ -d ${HOME}/pgcode ] || [ -f $pgconf ] || [ -L $pgconfsl ]; then - status_msg "Removing PrettyGCode for Klipper ..." - rm -rf ${HOME}/pgcode - sudo rm -f $pgconf - sudo rm -f $pgconfsl - sudo systemctl restart nginx - CONFIRM_MSG="PrettyGCode for Klipper successfully removed!" - else - ERROR_MSG="PrettyGCode for Klipper not found!\n Skipping..." - fi -} diff --git a/scripts/status.sh b/scripts/status.sh index 2a58183..7b03370 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -149,37 +149,6 @@ compare_fluidd_versions(){ ############################################################# ############################################################# -read_pgc_versions(){ - PGC_DIR="${HOME}/pgcode" - if [ -d $PGC_DIR ] && [ -d $PGC_DIR/.git ]; then - cd $PGC_DIR - git fetch origin main -q - LOCAL_PGC_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_PGC_COMMIT=$(git describe origin/main --always --tags | cut -d "-" -f 1,2) - else - LOCAL_PGC_COMMIT=$NONE - REMOTE_PGC_COMMIT=$NONE - fi -} - -compare_pgc_versions(){ - unset PGC_UPDATE_AVAIL - read_pgc_versions - if [ "$LOCAL_PGC_COMMIT" != "$REMOTE_PGC_COMMIT" ]; then - LOCAL_PGC_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_PGC_COMMIT")${default}" - REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "$REMOTE_PGC_COMMIT")${default}" - # add PGC to the update all array for the update all function in the updater - PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper) - else - LOCAL_PGC_COMMIT="${green}$(printf "%-12s" "$LOCAL_PGC_COMMIT")${default}" - REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "$REMOTE_PGC_COMMIT")${default}" - PGC_UPDATE_AVAIL="false" - fi -} - -############################################################# -############################################################# - #display this as placeholder if no version/commit could be fetched NONE="${red}$(printf "%-12s" "--------")${default}" diff --git a/scripts/update.sh b/scripts/update.sh index f4e69ca..7d87a60 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -132,13 +132,6 @@ update_fluidd(){ symlink_webui_nginx_log "fluidd" } -update_pgc_for_klipper(){ - PGC_DIR="${HOME}/pgcode" - status_msg "Updating PrettyGCode for Klipper ..." - cd $PGC_DIR && git pull - ok_msg "Update complete!" -} - update_system(){ status_msg "Updating System ..." sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y From 76ea886b95868f4bbf053239d078db8e868bebb4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 18:12:41 +0200 Subject: [PATCH 032/183] style(install_klipper_webui.sh): fix some shellsheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/install_klipper_webui.sh | 271 ++++++++++++++++--------------- 1 file changed, 142 insertions(+), 129 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 31f29a2..e9c7335 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" @@ -38,7 +51,7 @@ get_user_selection_mjpg-streamer(){ echo -e "| Install MJGP-Streamer for webcam support? |" bottom_border read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" INSTALL_MJPG="true" @@ -75,7 +88,7 @@ get_user_selection_kiauh_macros(){ echo -e "| add the recommended example macros to your config. |" bottom_border read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" ADD_KIAUH_MACROS="true" @@ -108,18 +121,18 @@ install_webui(){ [ "$1" == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " ### exit mainsail/fluidd setup if moonraker not found - if [ $moonraker_chk_ok = "false" ]; then + if [ "${moonraker_chk_ok}" = "false" ]; then ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!" print_msg && clear_msg && return 0 fi - status_msg "Initializing $IF_NAME1 installation ..." + status_msg "Initializing ${IF_NAME1} installation ..." ### check for other enabled web interfaces unset SET_LISTEN_PORT detect_enabled_sites ### check if another site already listens to port 80 - $1_port_check + "${1}"_port_check ### ask user to install mjpg-streamer if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then @@ -127,46 +140,46 @@ install_webui(){ fi ### ask user to install the recommended webinterface macros - if ! ls "$klipper_cfg_loc"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "$klipper_cfg_loc"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then - get_user_selection_kiauh_macros "$IF_NAME2" + if ! ls "${klipper_cfg_loc}"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "${klipper_cfg_loc}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then + get_user_selection_kiauh_macros "${IF_NAME2}" fi ### create /etc/nginx/conf.d/upstreams.conf set_upstream_nginx_cfg ### create /etc/nginx/sites-available/ - set_nginx_cfg "$1" + set_nginx_cfg "${1}" ### symlink nginx log - symlink_webui_nginx_log "$1" + symlink_webui_nginx_log "${1}" ### copy the kiauh_macros.cfg to the config location install_kiauh_macros ### install mainsail/fluidd - $1_setup + "${1}"_setup ### install mjpg-streamer - [ "$INSTALL_MJPG" = "true" ] && install_mjpg-streamer + [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer fetch_webui_ports #WIP ### confirm message - CONFIRM_MSG="$IF_NAME1 has been set up!" + CONFIRM_MSG="${IF_NAME1} has been set up!" print_msg && clear_msg } symlink_webui_nginx_log(){ LPATH="${HOME}/klipper_logs" - UI_ACCESS_LOG="/var/log/nginx/$1-access.log" - UI_ERROR_LOG="/var/log/nginx/$1-error.log" - [ ! -d "$LPATH" ] && mkdir -p "$LPATH" - if [ -f "$UI_ACCESS_LOG" ] && [ ! -L "$LPATH/$1-access.log" ]; then - status_msg "Creating symlink for $UI_ACCESS_LOG ..." - ln -s "$UI_ACCESS_LOG" "$LPATH" + UI_ACCESS_LOG="/var/log/nginx/${1}-access.log" + UI_ERROR_LOG="/var/log/nginx/${1}-error.log" + [ ! -d "${LPATH}" ] && mkdir -p "${LPATH}" + if [ -f "${UI_ACCESS_LOG}" ] && [ ! -L "${LPATH}/${1}-access.log" ]; then + status_msg "Creating symlink for ${UI_ACCESS_LOG} ..." + ln -s "${UI_ACCESS_LOG}" "${LPATH}" ok_msg "OK!" fi - if [ -f "$UI_ERROR_LOG" ] && [ ! -L "$LPATH/$1-error.log" ]; then - status_msg "Creating symlink for $UI_ERROR_LOG ..." - ln -s "$UI_ERROR_LOG" "$LPATH" + if [ -f "${UI_ERROR_LOG}" ] && [ ! -L "${LPATH}/${1}-error.log" ]; then + status_msg "Creating symlink for ${UI_ERROR_LOG} ..." + ln -s "${UI_ERROR_LOG}" "${LPATH}" ok_msg "OK!" fi } @@ -174,30 +187,30 @@ symlink_webui_nginx_log(){ install_kiauh_macros(){ source_kiauh_ini ### copy kiauh_macros.cfg - if [ "$ADD_KIAUH_MACROS" = "true" ]; then + if [ "${ADD_KIAUH_MACROS}" = "true" ]; then ### create a backup of the config folder backup_klipper_config_dir ### handle multi printer.cfg - if ls "$klipper_cfg_loc"/printer_* 2>/dev/null 1>&2; then - for config in $(find $klipper_cfg_loc/printer_*/printer.cfg); do - path=$(echo "$config" | rev | cut -d"/" -f2- | rev) - if [ ! -f "$path/kiauh_macros.cfg" ]; then + if ls "${klipper_cfg_loc}"/printer_* 2>/dev/null 1>&2; then + for config in $(find ${klipper_cfg_loc}/printer_*/printer.cfg); do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/kiauh_macros.cfg" ]; then ### copy kiauh_macros.cfg to config location status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$path" + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "$path/printer.cfg" - ok_msg "$path/kiauh_macros.cfg created!" + sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" + ok_msg "${path}/kiauh_macros.cfg created!" fi done ### handle single printer.cfg - elif [ -f "$klipper_cfg_loc/printer.cfg" ] && [ ! -f "$klipper_cfg_loc/kiauh_macros.cfg" ]; then + elif [ -f "${klipper_cfg_loc}/printer.cfg" ] && [ ! -f "${klipper_cfg_loc}/kiauh_macros.cfg" ]; then ### copy kiauh_macros.cfg to config location status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "$klipper_cfg_loc" + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${klipper_cfg_loc}" ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "$klipper_cfg_loc/printer.cfg" - ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!" + sed -i "1 i [include kiauh_macros.cfg]" "${klipper_cfg_loc}/printer.cfg" + ok_msg "${klipper_cfg_loc}/kiauh_macros.cfg created!" fi ### restart klipper service to parse the modified printer.cfg do_action_service "restart" "klipper" @@ -205,19 +218,19 @@ install_kiauh_macros(){ } mainsail_port_check(){ - if [ "$MAINSAIL_ENABLED" = "false" ]; then - if [ "$SITE_ENABLED" = "true" ]; then + if [ "${MAINSAIL_ENABLED}" = "false" ]; then + if [ "${SITE_ENABLED}" = "true" ]; then status_msg "Detected other enabled interfaces:" - [ "$OCTOPRINT_ENABLED" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: $OCTOPRINT_PORT${default}" - [ "$FLUIDD_ENABLED" = "true" ] && echo -e " ${cyan}● Fluidd - Port: $FLUIDD_PORT${default}" - [ "$DWC2_ENABLED" = "true" ] && echo -e " ${cyan}● DWC2 - Port: $DWC2_PORT${default}" - if [ "$FLUIDD_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then + [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" + [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${default}" + [ "${DWC2_ENABLED}" = "true" ] && echo -e " ${cyan}● DWC2 - Port: ${DWC2_PORT}${default}" + if [ "${FLUIDD_PORT}" = "80" ] || [ "${DWC2_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then PORT_80_BLOCKED="true" select_mainsail_port fi else DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) - SET_LISTEN_PORT=$DEFAULT_PORT + SET_LISTEN_PORT=${DEFAULT_PORT} fi SET_NGINX_CFG="true" else @@ -226,19 +239,19 @@ mainsail_port_check(){ } fluidd_port_check(){ - if [ "$FLUIDD_ENABLED" = "false" ]; then - if [ "$SITE_ENABLED" = "true" ]; then + if [ "${FLUIDD_ENABLED}" = "false" ]; then + if [ "${SITE_ENABLED}" = "true" ]; then status_msg "Detected other enabled interfaces:" - [ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port: $OCTOPRINT_PORT${default}" - [ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port: $MAINSAIL_PORT${default}" - [ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port: $DWC2_PORT${default}" - if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then + [ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" + [ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${default}" + [ "${DWC2_ENABLED}" = "true" ] && echo " ${cyan}● DWC2 - Port: ${DWC2_PORT}${default}" + if [ "${MAINSAIL_PORT}" = "80" ] || [ "${DWC2_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then PORT_80_BLOCKED="true" select_fluidd_port fi else DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) - SET_LISTEN_PORT=$DEFAULT_PORT + SET_LISTEN_PORT=${DEFAULT_PORT} fi SET_NGINX_CFG="true" else @@ -247,16 +260,16 @@ fluidd_port_check(){ } select_mainsail_port(){ - if [ "$PORT_80_BLOCKED" = "true" ]; then + if [ "${PORT_80_BLOCKED}" = "true" ]; then echo top_border echo -e "| ${red}!!!WARNING!!!${default} |" echo -e "| ${red}You need to choose a different port for Mainsail!${default} |" echo -e "| ${red}The following web interface is listening at port 80:${default} |" blank_line - [ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" - [ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |" - [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" + [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" + [ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |" + [ "${DWC2_PORT}" = "80" ] && echo "| ● DWC2 |" blank_line echo -e "| Make sure you don't choose a port which was already |" echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" @@ -267,9 +280,9 @@ select_mainsail_port(){ bottom_border while true; do read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then - echo "Setting port $NEW_PORT for Mainsail!" - SET_LISTEN_PORT=$NEW_PORT + if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${DWC2_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then + echo "Setting port ${NEW_PORT} for Mainsail!" + SET_LISTEN_PORT=${NEW_PORT} break else echo "That port is already taken! Select a different one!" @@ -279,16 +292,16 @@ select_mainsail_port(){ } select_fluidd_port(){ - if [ "$PORT_80_BLOCKED" = "true" ]; then + if [ "${PORT_80_BLOCKED}" = "true" ]; then echo top_border echo -e "| ${red}!!!WARNING!!!${default} |" echo -e "| ${red}You need to choose a different port for Fluidd!${default} |" echo -e "| ${red}The following web interface is listening at port 80:${default} |" blank_line - [ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" - [ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" - [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" + [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" + [ "${MAINSAIL_PORT}" = "80" ] && echo "| ● Mainsail |" + [ "${DWC2_PORT}" = "80" ] && echo "| ● DWC2 |" blank_line echo -e "| Make sure you don't choose a port which was already |" echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" @@ -299,9 +312,9 @@ select_fluidd_port(){ bottom_border while true; do read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then - echo "Setting port $NEW_PORT for Fluidd!" - SET_LISTEN_PORT=$NEW_PORT + if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${DWC2_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then + echo "Setting port ${NEW_PORT} for Fluidd!" + SET_LISTEN_PORT=${NEW_PORT} break else echo "That port is already taken! Select a different one!" @@ -311,22 +324,22 @@ select_fluidd_port(){ } get_mainsail_ver(){ - MAINSAIL_VERSION=$(curl -s $MAINSAIL_REPO_API | grep tag_name | cut -d'"' -f4 | head -1) + MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) } get_fluidd_ver(){ - FLUIDD_VERSION=$(curl -s $FLUIDD_REPO_API | grep tag_name | cut -d'"' -f4 | head -1) + FLUIDD_VERSION=$(curl -s "${FLUIDD_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) } mainsail_setup(){ ### get mainsail download url - MAINSAIL_DL_URL=$(curl -s $MAINSAIL_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1) + MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) ### remove existing and create fresh mainsail folder, then download mainsail - [ -d "$MAINSAIL_DIR" ] && rm -rf "$MAINSAIL_DIR" - mkdir "$MAINSAIL_DIR" && cd $MAINSAIL_DIR - status_msg "Downloading Mainsail $MAINSAIL_VERSION ..." - wget "$MAINSAIL_DL_URL" && ok_msg "Download complete!" + [ -d "${MAINSAIL_DIR}" ] && rm -rf "${MAINSAIL_DIR}" + mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" + status_msg "Downloading Mainsail ${MAINSAIL_VERSION} ..." + wget "${MAINSAIL_DL_URL}" && ok_msg "Download complete!" ### extract archive status_msg "Extracting archive ..." @@ -343,19 +356,19 @@ mainsail_setup(){ } enable_mainsail_remotemode(){ - rm -f "$MAINSAIL_DIR/config.json" - echo -e "{\n \"remoteMode\":true\n}" >> "$MAINSAIL_DIR/config.json" + rm -f "${MAINSAIL_DIR}/config.json" + echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" } fluidd_setup(){ ### get fluidd download url - FLUIDD_DL_URL=$(curl -s $FLUIDD_REPO_API | grep browser_download_url | cut -d'"' -f4 | head -1) + FLUIDD_DL_URL=$(curl -s "${FLUIDD_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) ### remove existing and create fresh fluidd folder, then download fluidd - [ -d "$FLUIDD_DIR" ] && rm -rf "$FLUIDD_DIR" - mkdir "$FLUIDD_DIR" && cd $FLUIDD_DIR - status_msg "Downloading Fluidd $FLUIDD_VERSION ..." - wget "$FLUIDD_DL_URL" && ok_msg "Download complete!" + [ -d "${FLUIDD_DIR}" ] && rm -rf "${FLUIDD_DIR}" + mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}" + status_msg "Downloading Fluidd ${FLUIDD_VERSION} ..." + wget "${FLUIDD_DL_URL}" && ok_msg "Download complete!" ### extract archive status_msg "Extracting archive ..." @@ -369,19 +382,19 @@ fluidd_setup(){ set_upstream_nginx_cfg(){ get_date ### backup existing nginx configs - [ ! -d "$BACKUP_DIR/nginx_cfg" ] && mkdir -p "$BACKUP_DIR/nginx_cfg" - [ -f "$NGINX_CONFD/upstreams.conf" ] && sudo mv "$NGINX_CONFD/upstreams.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_upstreams.conf" - [ -f "$NGINX_CONFD/common_vars.conf" ] && sudo mv "$NGINX_CONFD/common_vars.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_common_vars.conf" + [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" + [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" + [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" ### transfer ownership of backed up files from root to ${USER} for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown "${USER}" "$BACKUP_DIR/nginx_cfg/$log" + sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/$log" done ### copy nginx configs to target destination - if [ ! -f "$NGINX_CONFD/upstreams.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "$NGINX_CONFD" + if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then + sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "${NGINX_CONFD}" fi - if [ ! -f "$NGINX_CONFD/common_vars.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "$NGINX_CONFD" + if [ ! -f "${NGINX_CONFD}/common_vars.conf" ]; then + sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "${NGINX_CONFD}" fi } @@ -391,15 +404,15 @@ fetch_webui_ports(){ WEBIFS=(mainsail fluidd octoprint dwc2) for interface in "${WEBIFS[@]}"; do if [ -f "/etc/nginx/sites-available/${interface}" ]; then - port=$(grep -E "listen" "/etc/nginx/sites-available/$interface" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) - if [ ! -n "$(grep -E "${interface}_port" "$INI_FILE")" ]; then - sed -i '$a'"${interface}_port=${port}" "$INI_FILE" + port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) + if [ ! -n "$(grep -E "${interface}_port" "${INI_FILE}")" ]; then + sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" else - sed -i "/^${interface}_port/d" "$INI_FILE" - sed -i '$a'"${interface}_port=${port}" "$INI_FILE" + sed -i "/^${interface}_port/d" "${INI_FILE}" + sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" fi else - sed -i "/^${interface}_port/d" "$INI_FILE" + sed -i "/^${interface}_port/d" "${INI_FILE}" fi done } @@ -412,55 +425,55 @@ match_nginx_configs(){ fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) status_msg "Checking validity of NGINX configurations ..." - if [ -e "$mainsail_nginx_cfg" ]; then - mainsail_webcams=$(grep -E "mjpgstreamer" "$mainsail_nginx_cfg" | wc -l) + if [ -e "${mainsail_nginx_cfg}" ]; then + mainsail_webcams=$(grep -E "mjpgstreamer" "${mainsail_nginx_cfg}" | wc -l) fi - if [ -e "$fluidd_nginx_cfg" ]; then - fluidd_webcams=$(grep -E "mjpgstreamer" "$fluidd_nginx_cfg" | wc -l) + if [ -e "${fluidd_nginx_cfg}" ]; then + fluidd_webcams=$(grep -E "mjpgstreamer" "${fluidd_nginx_cfg}" | wc -l) fi ### check for outdated upstreams.conf - if [[ "$upstreams_webcams" -lt "$mainsail_webcams" ]] || [[ "$upstreams_webcams" -lt "$fluidd_webcams" ]]; then + if [[ "${upstreams_webcams}" -lt "${mainsail_webcams}" ]] || [[ "${upstreams_webcams}" -lt "${fluidd_webcams}" ]]; then status_msg "Outdated upstreams.conf found! Updating ..." - sudo rm -f "$NGINX_CONFD/upstreams.conf" - sudo rm -f "$NGINX_CONFD/common_vars.conf" + sudo rm -f "${NGINX_CONFD}/upstreams.conf" + sudo rm -f "${NGINX_CONFD}/common_vars.conf" set_upstream_nginx_cfg cfg_updated="true" fi ### check for outdated mainsail config - if [ -e "$mainsail_nginx_cfg" ]; then - if [[ "$upstreams_webcams" -gt "$mainsail_webcams" ]]; then + if [ -e "${mainsail_nginx_cfg}" ]; then + if [[ "${upstreams_webcams}" -gt "${mainsail_webcams}" ]]; then status_msg "Outdated Mainsail config found! Updating ..." - sudo rm -f "$mainsail_nginx_cfg" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "$mainsail_nginx_cfg" - sudo sed -i "s/<>/mainsail/g" "$mainsail_nginx_cfg" - sudo sed -i "/root/s/pi/${USER}/" "$mainsail_nginx_cfg" - sudo sed -i "s/listen\s[0-9]*;/listen $mainsail_port;/" "$mainsail_nginx_cfg" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$mainsail_port;/" "$mainsail_nginx_cfg" + sudo rm -f "${mainsail_nginx_cfg}" + sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}" + sudo sed -i "s/<>/mainsail/g" "${mainsail_nginx_cfg}" + sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}" + sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}" + sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}" cfg_updated="true" && ok_msg "Done!" fi fi ### check for outdated fluidd config - if [ -e "$fluidd_nginx_cfg" ]; then - if [[ "$upstreams_webcams" -gt "$fluidd_webcams" ]]; then + if [ -e "${fluidd_nginx_cfg}" ]; then + if [[ "${upstreams_webcams}" -gt "${fluidd_webcams}" ]]; then status_msg "Outdated Fluidd config found! Updating ..." - sudo rm -f "$fluidd_nginx_cfg" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "$fluidd_nginx_cfg" - sudo sed -i "s/<>/fluidd/g" "$fluidd_nginx_cfg" - sudo sed -i "/root/s/pi/${USER}/" "$fluidd_nginx_cfg" - sudo sed -i "s/listen\s[0-9]*;/listen $fluidd_port;/" "$fluidd_nginx_cfg" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$fluidd_port;/" "$fluidd_nginx_cfg" + sudo rm -f "${fluidd_nginx_cfg}" + sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}" + sudo sed -i "s/<>/fluidd/g" "${fluidd_nginx_cfg}" + sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}" + sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}" + sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}" cfg_updated="true" && ok_msg "Done!" fi fi ### only restart nginx if configs were updated - if [ "$cfg_updated" == "true" ]; then + if [ "${cfg_updated}" == "true" ]; then restart_nginx && unset cfg_updated fi } process_octoprint_dialog(){ #ask user to disable octoprint when its service was found - if [ "$OCTOPRINT_ENABLED" = "true" ]; then + if [ "${OCTOPRINT_ENABLED}" = "true" ]; then while true; do echo top_border @@ -471,7 +484,7 @@ process_octoprint_dialog(){ echo -e "| pected behavior of the Klipper Webinterfaces. |" bottom_border read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" status_msg "Stopping OctoPrint ..." @@ -492,19 +505,19 @@ process_octoprint_dialog(){ process_disruptive_services(){ #handle haproxy service - if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then + if [ "${DISABLE_HAPROXY}" = "true" ] || [ "${REMOVE_HAPROXY}" = "true" ]; then if systemctl is-active haproxy -q; then status_msg "Stopping haproxy service ..." sudo systemctl stop haproxy && ok_msg "Service stopped!" fi ### disable haproxy - if [ "$DISABLE_HAPROXY" = "true" ]; then + if [ "${DISABLE_HAPROXY}" = "true" ]; then status_msg "Disabling haproxy ..." sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" ### remove haproxy - if [ "$REMOVE_HAPROXY" = "true" ]; then + if [ "${REMOVE_HAPROXY}" = "true" ]; then status_msg "Removing haproxy ..." sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" fi @@ -512,19 +525,19 @@ process_disruptive_services(){ fi ### handle lighttpd service - if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then + if [ "${DISABLE_LIGHTTPD}" = "true" ] || [ "${REMOVE_LIGHTTPD}" = "true" ]; then if systemctl is-active lighttpd -q; then status_msg "Stopping lighttpd service ..." sudo systemctl stop lighttpd && ok_msg "Service stopped!" fi ### disable lighttpd - if [ "$DISABLE_LIGHTTPD" = "true" ]; then + if [ "${DISABLE_LIGHTTPD}" = "true" ]; then status_msg "Disabling lighttpd ..." sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" ### remove lighttpd - if [ "$REMOVE_LIGHTTPD" = "true" ]; then + if [ "${REMOVE_LIGHTTPD}" = "true" ]; then status_msg "Removing lighttpd ..." sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" fi @@ -532,19 +545,19 @@ process_disruptive_services(){ fi ### handle apache2 service - if [ "$DISABLE_APACHE2" = "true" ] || [ "$REMOVE_APACHE2" = "true" ]; then + if [ "${DISABLE_APACHE2}" = "true" ] || [ "${REMOVE_APACHE2}" = "true" ]; then if systemctl is-active apache2 -q; then status_msg "Stopping apache2 service ..." sudo systemctl stop apache2 && ok_msg "Service stopped!" fi ### disable lighttpd - if [ "$DISABLE_APACHE2" = "true" ]; then + if [ "${DISABLE_APACHE2}" = "true" ]; then status_msg "Disabling lighttpd ..." sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!" ### remove lighttpd - if [ "$REMOVE_APACHE2" = "true" ]; then + if [ "${REMOVE_APACHE2}" = "true" ]; then status_msg "Removing apache2 ..." sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!" fi @@ -554,19 +567,19 @@ process_disruptive_services(){ process_services_dialog(){ #notify user about haproxy or lighttpd services found and possible issues - if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ] || [ "$APACHE2_FOUND" = "true" ]; then + if [ "${HAPROXY_FOUND}" = "true" ] || [ "${LIGHTTPD_FOUND}" = "true" ] || [ "${APACHE2_FOUND}" = "true" ]; then while true; do echo top_border echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" hr - if [ "$HAPROXY_FOUND" = "true" ]; then + if [ "${HAPROXY_FOUND}" = "true" ]; then echo -e "| ● haproxy |" fi - if [ "$LIGHTTPD_FOUND" = "true" ]; then + if [ "${LIGHTTPD_FOUND}" = "true" ]; then echo -e "| ● lighttpd |" fi - if [ "$APACHE2_FOUND" = "true" ]; then + if [ "${APACHE2_FOUND}" = "true" ]; then echo -e "| ● apache2 |" fi hr @@ -578,7 +591,7 @@ process_services_dialog(){ echo -e "| ${red}3) Skip this step (not recommended)${default} |" bottom_border read -p "${cyan}###### Please choose:${default} " action - case "$action" in + case "${action}" in 1) echo -e "###### > Remove packages" REMOVE_HAPROXY="true" From 7b7de05390a54394210f3ee0c45d9f560096a7e4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 18:24:19 +0200 Subject: [PATCH 033/183] refactor(klipper.sh): fix errors Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index b38193e..b78fcac 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -49,12 +49,11 @@ function klipper_setup_dialog(){ ### return early if klipper already exists if [ -n "$(klipper_exists)" ]; then - ERROR_MSG="At least one Klipper service is already installed:" + local error="At least one Klipper service is already installed:" for s in $(klipper_exists); do - ERROR_MSG="${ERROR_MSG}\n ➔ ${s}" + error="${error}\n ➔ ${s}" done - export ERROR_MSG - print_error && return + print_error "${error}" && return fi ### ask for amount of instances to create @@ -87,7 +86,7 @@ function klipper_setup_dialog(){ abort_msg "Exiting Klipper setup ...\n" break;; *) - invalid_option && print_error + print_error "Invalid command!" ;; esac fi From cac2a633289db0c1079beebf43091e8db61ebd89 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 18:39:27 +0200 Subject: [PATCH 034/183] refactor(moonraker.sh): fix errors & confirms Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index f1ef049..c4eb948 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -47,20 +47,18 @@ function moonraker_setup_dialog(){ ### return early if moonraker already exists if [ -n "$(moonraker_systemd)" ]; then - ERROR_MSG="At least one Moonraker service is already installed:" + local error="At least one Moonraker service is already installed:" for service in $(moonraker_systemd); do - ERROR_MSG="${ERROR_MSG}\n ➔ ${service}" + error="${error}\n ➔ ${service}" done - export ERROR_MSG - print_error && return + print_error "${error}" && return fi ### return early if python version check fails if [ "$(system_check_moonraker)" == "false" ]; then - ERROR_MSG="Versioncheck failed! Python 3.7 or newer required!\n" - ERROR_MSG="${ERROR_MSG} Please upgrade Python." - export ERROR_MSG - print_error && return + local error="Versioncheck failed! Python 3.7 or newer required!\n" + error="${error} Please upgrade Python." + print_error "${error}" && return fi top_border @@ -164,12 +162,11 @@ function moonraker_setup(){ ### confirm message if [[ ${instances} -eq 1 ]]; then - CONFIRM_MSG="Moonraker has been set up!" + local confirm="Moonraker has been set up!" elif [[ ${instances} -gt 1 ]]; then - CONFIRM_MSG="${instances} Moonraker instances have been set up!" + local confirm="${instances} Moonraker instances have been set up!" fi - export CONFIRM_MSG - print_confirm + print_confirm "${confirm}" print_mr_ip_list "${mr_ip_list}" return @@ -413,7 +410,7 @@ function remove_moonraker(){ remove_moonraker_polkit remove_moonraker_nginx - confirm="Moonraker was successfully removed!" + local confirm="Moonraker was successfully removed!" print_confirm "${confirm}" && return } From 71dab2ae6ab0ac3a6f44d522d2e96c51b235dce2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 18:40:57 +0200 Subject: [PATCH 035/183] refactor(klipper.sh): calling pip Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index b78fcac..f307c64 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -322,7 +322,7 @@ function update_klipper(){ ### read PKGLIST and install possible new dependencies install_klipper_packages ### install possible new python dependencies - "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt" + /bin/bash "${KLIPPY_ENV}/bin/pip" install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt" fi update_log_paths "klipper" ok_msg "Update complete!" From 99604b60b9b406c630e29d55976b1c689769691c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 19:28:48 +0200 Subject: [PATCH 036/183] refactor(moonraker.sh): fix throwing error Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index c4eb948..544ceb7 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -92,7 +92,7 @@ function moonraker_setup_dialog(){ error_msg "Exiting Moonraker setup ...\n" break;; *) - invalid_option && print_error + print_error "Invalid command!" ;; esac fi From 40b277ddbbbcf0b18d7f10264cd29affaf91a568 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 19:29:05 +0200 Subject: [PATCH 037/183] refactor(utilities.sh): remove unused function Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index fed6e5d..ccc0f2f 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -273,23 +273,6 @@ dependency_check(){ fi } -print_error(){ - for data in "${data_arr[@]}" - do - if [ ! -e "${data}" ]; then - data_count+=(0) - else - data_count+=(1) - fi - done - sum=$(IFS=+; echo "$((${data_count[*]}))") - if [ "${sum}" -eq 0 ]; then - ERROR_MSG="Looks like $1 was already removed!\n Skipping..." - else - ERROR_MSG="" - fi -} - setup_gcode_shell_command(){ echo top_border From b69c7e6b596a2e1e5f8c43a52d1f0550220086b4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 21:28:09 +0200 Subject: [PATCH 038/183] refactor(backup.sh): fix some shellcheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 1 - scripts/backup.sh | 176 +++++++++++++++++++++++++--------------------- 2 files changed, 96 insertions(+), 81 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index cc718d2..ebf6130 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -35,7 +35,6 @@ MAINSAIL_DIR=${HOME}/mainsail FLUIDD_DIR=${HOME}/fluidd #misc INI_FILE=${HOME}/.kiauh.ini -BACKUP_DIR=${HOME}/kiauh-backups ### set github repos DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git diff --git a/scripts/backup.sh b/scripts/backup.sh index e0f6901..97058fa 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,37 +1,53 @@ -check_for_backup_dir(){ - if [ ! -d $BACKUP_DIR ]; then +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +BACKUP_DIR="${HOME}/kiauh-backups" + +function check_for_backup_dir(){ + if [ ! -d "${BACKUP_DIR}" ]; then status_msg "Create KIAUH backup directory ..." - mkdir -p $BACKUP_DIR && ok_msg "Directory created!" + mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!" fi } -toggle_backups(){ +function toggle_backups(){ source_kiauh_ini - if [ "$backup_before_update" = "true" ]; then - sed -i '/backup_before_update=/s/true/false/' $INI_FILE - BB4U_STATUS="${green}[Enable]${default} backups before updating " + if [ "${backup_before_update}" = "true" ]; then + sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}" + BB4U_STATUS="${green}[Enable]${white} backups before updating " CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !" fi - if [ "$backup_before_update" = "false" ]; then - sed -i '/backup_before_update=/s/false/true/' $INI_FILE - BB4U_STATUS="${red}[Disable]${default} backups before updating " + if [ "${backup_before_update}" = "false" ]; then + sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}" + BB4U_STATUS="${red}[Disable]${white} backups before updating " CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !" fi } -bb4u(){ +function bb4u(){ source_kiauh_ini - if [ "$backup_before_update" = "true" ]; then - backup_$1 + if [ "${backup_before_update}" = "true" ]; then + backup_"${1}" fi } -read_bb4u_stat(){ +function read_bb4u_stat(){ source_kiauh_ini - if [ ! "$backup_before_update" = "true" ]; then - BB4U_STATUS="${green}[Enable]${default} backups before updating " + if [ ! "${backup_before_update}" = "true" ]; then + BB4U_STATUS="${green}[Enable]${white} backups before updating " else - BB4U_STATUS="${red}[Disable]${default} backups before updating " + BB4U_STATUS="${red}[Disable]${white} backups before updating " fi } @@ -39,28 +55,28 @@ read_bb4u_stat(){ #******************************************************************************# ################################################################################ -backup_printer_cfg(){ +function backup_printer_cfg(){ check_for_backup_dir - if [ -f $PRINTER_CFG ]; then + if [ -f "${PRINTER_CFG}" ]; then get_date - status_msg "Timestamp: $current_date" + status_msg "Timestamp: ${current_date}" status_msg "Create backup of printer.cfg ..." - cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!" + cp "${PRINTER_CFG}" "${BACKUP_DIR}/printer.cfg.${current_date}.backup" && ok_msg "Backup complete!" else ok_msg "No printer.cfg found! Skipping backup ..." fi } -backup_klipper_config_dir(){ +function backup_klipper_config_dir(){ source_kiauh_ini check_for_backup_dir - if [ -d "$klipper_cfg_loc" ]; then + if [ -d "${klipper_cfg_loc}" ]; then get_date - status_msg "Timestamp: $current_date" + status_msg "Timestamp: ${current_date}" status_msg "Create backup of the Klipper config directory ..." - config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" - mkdir -p $BACKUP_DIR/$config_folder_name/$current_date - cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!" + config_folder_name="$(echo "${klipper_cfg_loc}" | rev | cut -d"/" -f1 | rev)" + mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" + cp -r "${klipper_cfg_loc}" "${_}" && ok_msg "Backup complete!" echo else ok_msg "No config directory found! Skipping backup ..." @@ -68,16 +84,16 @@ backup_klipper_config_dir(){ fi } -backup_moonraker_database(){ +function backup_moonraker_database(){ check_for_backup_dir if ls -d ${HOME}/.moonraker_database* 2>/dev/null 1>&2; then get_date - status_msg "Timestamp: $current_date" - mkdir -p "$BACKUP_DIR/mr_db_backup/$current_date" + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/mr_db_backup/${current_date}" for database in $(ls -d ${HOME}/.moonraker_database*) do - status_msg "Create backup of $database ..." - cp -r $database "$BACKUP_DIR/mr_db_backup/$current_date" + status_msg "Create backup of ${database} ..." + cp -r "${database}" "${BACKUP_DIR}/mr_db_backup/${current_date}" ok_msg "Done!" done ok_msg "Backup complete!\n" @@ -86,110 +102,110 @@ backup_moonraker_database(){ fi } -backup_klipper(){ - if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then +function backup_klipper(){ + if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPY_ENV}" ]; then status_msg "Creating Klipper backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/klipper-backups/"$current_date" - cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!" + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}" + cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" && ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!" + print_error "Can't backup klipper and/or klipper-env directory! Not found!" fi } -backup_dwc2(){ - if [ -d $DWC2FK_DIR ] && [ -d $DWC_ENV_DIR ] && [ -d $DWC2_DIR ]; then +function backup_dwc2(){ + if [ -d "${DWC2FK_DIR}" ] && [ -d "${DWC_ENV_DIR}" ] && [ -d "${DWC2_DIR}" ]; then status_msg "Creating DWC2 Web UI backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/dwc2-backups/"$current_date" - cp -r $DWC2FK_DIR $_ && cp -r $DWC_ENV_DIR $_ && cp -r $DWC2_DIR $_ + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/dwc2-backups/${current_date}" + cp -r "${DWC2FK_DIR}" "${_}" && cp -r "${DWC_ENV_DIR}" "${_}" && cp -r "${DWC2_DIR}" "${_}" ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!" + print_error "Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!" fi } -backup_mainsail(){ - if [ -d $MAINSAIL_DIR ]; then +function backup_mainsail(){ + if [ -d "${MAINSAIL_DIR}" ]; then status_msg "Creating Mainsail backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date" - cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!" + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}" + cp -r "${MAINSAIL_DIR}" "${_}" && ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup mainsail directory! Not found!" + print_error "Can't backup mainsail directory! Not found!" fi } -backup_fluidd(){ - if [ -d $FLUIDD_DIR ]; then +function backup_fluidd(){ + if [ -d "${FLUIDD_DIR}" ]; then status_msg "Creating Fluidd backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/fluidd-backups/"$current_date" - cp -r $FLUIDD_DIR $_ && ok_msg "Backup complete!" + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}" + cp -r "${FLUIDD_DIR}" "${_}" && ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup fluidd directory! Not found!" + print_error "Can't backup fluidd directory! Not found!" fi } -backup_moonraker(){ - if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV ]; then +function backup_moonraker(){ + if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_ENV}" ]; then status_msg "Creating Moonraker backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date" - cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV $_ && ok_msg "Backup complete!" + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}" + cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" && ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!" + print_error "Can't backup moonraker and/or moonraker-env directory! Not found!" fi } -backup_octoprint(){ - if [ -d $OCTOPRINT_DIR ] && [ -d $OCTOPRINT_CFG_DIR ]; then +function backup_octoprint(){ + if [ -d "${OCTOPRINT_DIR}" ] && [ -d "${OCTOPRINT_CFG_DIR}" ]; then status_msg "Creating OctoPrint backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/octoprint-backups/"$current_date" - cp -r $OCTOPRINT_DIR $_ && cp -r $OCTOPRINT_CFG_DIR $_ + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}" + cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}" ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup OctoPrint and/or .octoprint directory!\n Not found!" + print_error "Can't backup OctoPrint and/or .octoprint directory!\n Not found!" fi } -backup_klipperscreen(){ - if [ -d $KLIPPERSCREEN_DIR ] ; then +function backup_klipperscreen(){ + if [ -d "${KLIPPERSCREEN_DIR}" ] ; then status_msg "Creating KlipperScreen backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/klipperscreen-backups/"$current_date" - cp -r $KLIPPERSCREEN_DIR $_ + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}" + cp -r "${KLIPPERSCREEN_DIR}" "${_}" ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup KlipperScreen directory!\n Not found!" + print_error "Can't backup KlipperScreen directory!\n Not found!" fi } -backup_MoonrakerTelegramBot(){ - if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] ; then +function backup_MoonrakerTelegramBot(){ + if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] ; then status_msg "Creating MoonrakerTelegramBot backup ..." check_for_backup_dir get_date - status_msg "Timestamp: $current_date" - mkdir -p $BACKUP_DIR/MoonrakerTelegramBot-backups/"$current_date" - cp -r $MOONRAKER_TELEGRAM_BOT_DIR $_ + status_msg "Timestamp: ${current_date}" + mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}" + cp -r "${MOONRAKER_TELEGRAM_BOT_DIR}" "${_}" ok_msg "Backup complete!" else - ERROR_MSG=" Can't backup MoonrakerTelegramBot directory!\n Not found!" + print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!" fi } From e26a34b316c14231f047c901cc7cdde2ae657771 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Apr 2022 23:44:50 +0200 Subject: [PATCH 039/183] feat(logging): first very simple logging implementation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 7 +++++-- scripts/utilities.sh | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index f307c64..f55adb9 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -48,9 +48,12 @@ function klipper_setup_dialog(){ status_msg "Initializing Klipper installation ..." ### return early if klipper already exists - if [ -n "$(klipper_exists)" ]; then + local klipper_services + klipper_services=$(klipper_exists) + if [ -n "${klipper_services}" ]; then local error="At least one Klipper service is already installed:" - for s in $(klipper_exists); do + for s in ${klipper_services}; do + log "Found Klipper service: ${s}" error="${error}\n ➔ ${s}" done print_error "${error}" && return diff --git a/scripts/utilities.sh b/scripts/utilities.sh index ccc0f2f..d6fa4fb 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -13,6 +13,7 @@ set -e ### base variables SYSTEMD="/etc/systemd/system" +LOGFILE="/tmp/kiauh.log" # setting up some frequently used functions check_euid(){ @@ -27,6 +28,15 @@ check_euid(){ fi } +function timestamp() { + date +"[%F %T]" +} + +function log() { + local message="${1}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" +} + check_klipper_cfg_path(){ source_kiauh_ini if [ -z "${klipper_cfg_loc}" ]; then From 6272f99f105c68f6ad561625fee68a1c87824f44 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 00:27:42 +0200 Subject: [PATCH 040/183] refactor!: removing support for DWC Signed-off-by: Dominik Willner th33xitus@gmail.com --- README.md | 2 - docs/changelog.md | 4 +- docs/features.md | 4 +- resources/dwc2_nginx.cfg | 26 - scripts/backup.sh | 14 - .../dwc-start.sh | 54 -- .../install-debian.sh | 106 ---- .../install-octopi.sh | 106 ---- .../uninstall-debian.sh | 41 -- .../uninstall-octopi.sh | 45 -- scripts/dwc2.sh | 593 ------------------ scripts/install_klipper_webui.sh | 14 +- scripts/network_functions.sh | 10 +- scripts/status.sh | 2 - scripts/ui/backup_menu.sh | 9 +- scripts/ui/install_menu.sh | 24 +- scripts/ui/main_menu.sh | 9 +- scripts/ui/remove_menu.sh | 27 +- scripts/ui/update_menu.sh | 24 +- scripts/update.sh | 6 - scripts/upload_log.sh | 5 - 21 files changed, 47 insertions(+), 1078 deletions(-) delete mode 100644 resources/dwc2_nginx.cfg delete mode 100755 scripts/dwc2-for-klipper-socket-installer/dwc-start.sh delete mode 100755 scripts/dwc2-for-klipper-socket-installer/install-debian.sh delete mode 100755 scripts/dwc2-for-klipper-socket-installer/install-octopi.sh delete mode 100755 scripts/dwc2-for-klipper-socket-installer/uninstall-debian.sh delete mode 100755 scripts/dwc2-for-klipper-socket-installer/uninstall-octopi.sh delete mode 100644 scripts/dwc2.sh diff --git a/README.md b/README.md index 01dadc4..fa3c826 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,6 @@ For more information or instructions to the various components KIAUH can install * 🌙[Moonraker](https://github.com/Arksine/moonraker) by [Arksine](https://github.com/Arksine) * 💨[Mainsail](https://github.com/mainsail-crew/mainsail) by [mainsail-crew](https://github.com/mainsail-crew) * 🌊[Fluidd](https://github.com/fluidd-core/fluidd) by [fluidd-core](https://github.com/fluidd-core) -* 🕸️[Duet Web Control](https://github.com/Duet3D/DuetWebControl) by [Duet3D](https://github.com/Duet3D) -* 🕸️[DWC2-for-Klipper-Socket](https://github.com/Stephan3/dwc2-for-klipper-socket) by [Stephan3](https://github.com/Stephan3) * 🖥️[KlipperScreen](https://github.com/jordanruthe/KlipperScreen) by [jordanruthe](https://github.com/jordanruthe) * 🐙[OctoPrint](https://github.com/OctoPrint/OctoPrint) by [OctoPrint](https://github.com/OctoPrint) * 🔬[PrettyGCode](https://github.com/Kragrathea/pgcode) by [Kragrathea](https://github.com/Kragrathea) diff --git a/docs/changelog.md b/docs/changelog.md index f52de83..e0f63bd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -114,9 +114,9 @@ Each service gets its corresponding instance added to the service filename. --> moonraker-2.service --> moonraker-n.service ``` -* The same service file rules from above apply to DWC and OctoPrint even though only Klipper and Moonraker are shown in this example. +* The same service file rules from above apply to OctoPrint even though only Klipper and Moonraker are shown in this example. -* You can start, stop and restart all Klipper, Moonraker, DWC and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on. +* You can start, stop and restart all Klipper, Moonraker and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on. * KIAUH v3.0 relocated its ini-file. It is now a hidden file in the users home-directory calles `.kiauh.ini`. This has the benefit of keeping all values in that file between possible re-installations of KIAUH. Otherwise that file would be lost. diff --git a/docs/features.md b/docs/features.md index c55714a..620ab1e 100644 --- a/docs/features.md +++ b/docs/features.md @@ -16,13 +16,13 @@ That means: - adding the serial port `/tmp/printer` - set the behavior to "Cancel any ongoing prints but stay connected to the printer" - **Enable/Disable OctoPrint Service:**\ -Usefull when using DWC2/Mainsail/Fluidd and OctoPrint at the same time to prevent them interfering with each other +Usefull when using Mainsail/Fluidd and OctoPrint at the same time to prevent them interfering with each other - **Installing a G-Code Shell Command extension:**\ For further information about that extension please see the [G-Code Shell Command Extension Doc](gcode_shell_command.md) - **Uploading logfiles:**\ -You can directly upload logfiles like klippy.log, moonraker.log and dwc2.log from the KIAUH main menu for providing them for troubleshooting purposes. +You can directly upload logfiles like klippy.log and moonraker.log from the KIAUH main menu for providing them for troubleshooting purposes. to be continued... diff --git a/resources/dwc2_nginx.cfg b/resources/dwc2_nginx.cfg deleted file mode 100644 index ef7d7bc..0000000 --- a/resources/dwc2_nginx.cfg +++ /dev/null @@ -1,26 +0,0 @@ -map $http_upgrade $connection_upgrade { - default upgrade; - '' close; -} - -upstream dwc2 { - server 127.0.0.1:4750; -} - -server { - listen 80; - #listen [::]:80; - - location / { - proxy_pass http://dwc2/; - proxy_set_header Host $http_host; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - #proxy_set_header X-Script-Name /; - proxy_http_version 1.1; - client_max_body_size 0; - } -} \ No newline at end of file diff --git a/scripts/backup.sh b/scripts/backup.sh index 97058fa..edc0b94 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -115,20 +115,6 @@ function backup_klipper(){ fi } -function backup_dwc2(){ - if [ -d "${DWC2FK_DIR}" ] && [ -d "${DWC_ENV_DIR}" ] && [ -d "${DWC2_DIR}" ]; then - status_msg "Creating DWC2 Web UI backup ..." - check_for_backup_dir - get_date - status_msg "Timestamp: ${current_date}" - mkdir -p "${BACKUP_DIR}/dwc2-backups/${current_date}" - cp -r "${DWC2FK_DIR}" "${_}" && cp -r "${DWC_ENV_DIR}" "${_}" && cp -r "${DWC2_DIR}" "${_}" - ok_msg "Backup complete!" - else - print_error "Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!" - fi -} - function backup_mainsail(){ if [ -d "${MAINSAIL_DIR}" ]; then status_msg "Creating Mainsail backup ..." diff --git a/scripts/dwc2-for-klipper-socket-installer/dwc-start.sh b/scripts/dwc2-for-klipper-socket-installer/dwc-start.sh deleted file mode 100755 index 1a75c5d..0000000 --- a/scripts/dwc2-for-klipper-socket-installer/dwc-start.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# System startup script for dwc2-for-klipper-socket - -### BEGIN INIT INFO -# Provides: dwc2-for-klipper-socket -# Required-Start: $local_fs -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: dwc2-for-klipper-socket daemon -# Description: Starts the dwc2-for-klipper-socket daemon. -### END INIT INFO - -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -DESC="dwc2-for-klipper-socket daemon" -NAME="dwc2-for-klipper-socket" -DEFAULTS_FILE=/etc/default/dwc -PIDFILE=/var/run/dwc.pid - -. /lib/lsb/init-functions - -# Read defaults file -[ -r $DEFAULTS_FILE ] && . $DEFAULTS_FILE - -case "$1" in -start) log_daemon_msg "Starting dwc2-for-klipper-socket" $NAME - start-stop-daemon --start --quiet --exec $DWC_EXEC \ - --background --pidfile $PIDFILE --make-pidfile \ - --chuid $DWC_USER --user $DWC_USER \ - -- $DWC_ARGS - log_end_msg $? - ;; -stop) log_daemon_msg "Stopping dwc2-for-klipper-socket" $NAME - killproc -p $PIDFILE $DWC_EXEC - RETVAL=$? - [ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE - log_end_msg $RETVAL - ;; -restart) log_daemon_msg "Restarting dwc2-for-klipper-socket" $NAME - $0 stop - $0 start - ;; -reload|force-reload) - log_daemon_msg "Reloading configuration not supported" $NAME - log_end_msg 1 - ;; -status) - status_of_proc -p $PIDFILE $DWC_EXEC $NAME && exit 0 || exit $? - ;; -*) log_action_msg "Usage: /etc/init.d/dwc {start|stop|status|restart|reload|force-reload}" - exit 2 - ;; -esac -exit 0 \ No newline at end of file diff --git a/scripts/dwc2-for-klipper-socket-installer/install-debian.sh b/scripts/dwc2-for-klipper-socket-installer/install-debian.sh deleted file mode 100755 index 8012c58..0000000 --- a/scripts/dwc2-for-klipper-socket-installer/install-debian.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash -# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running -# Raspbian/Raspberry Pi OS based distributions. - -# https://github.com/Stephan3/dwc2-for-klipper-socket.git - -PYTHONDIR="${HOME}/dwc-env" -SYSTEMDDIR="/etc/systemd/system" -DWC_USER=${USER} - -# Step 1: Verify Klipper has been installed -check_klipper() -{ - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - echo "Klipper service found!" - else - echo "Klipper service not found, please install Klipper first" - exit -1 - fi - -} - -# Step 2: Install packages -install_packages() -{ - PKGLIST="python3-virtualenv python3-dev python3-tornado" - - # Update system package info - report_status "Running apt-get update..." - sudo apt-get update --allow-releaseinfo-change - - # Install desired packages - report_status "Installing packages..." - sudo apt-get install --yes ${PKGLIST} -} - -# Step 3: Create python virtual environment -create_virtualenv() -{ - report_status "Updating python virtual environment..." - - # Create virtualenv if it doesn't already exist - [ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR} - - # Install/update dependencies - ${PYTHONDIR}/bin/pip install tornado==6.0.4 -} - -# Step 4: Install startup script -install_script(){ - report_status "Installing system start script..." - sudo /bin/sh -c "cat > $SYSTEMDDIR/dwc.service" << EOF -#Systemd service file for DWC -[Unit] -Description=dwc_webif -After=network.target - -[Install] -WantedBy=multi-user.target - -[Service] -Type=simple -User=$DWC_USER -RemainAfterExit=yes -ExecStart=${PYTHONDIR}/bin/python3 ${SRCDIR}/web_dwc2.py -Restart=always -RestartSec=10 -EOF -# Use systemctl to enable the klipper systemd service script - sudo systemctl enable dwc.service -} - -# Step 5: Start DWC service -start_software() -{ - report_status "Launching dwc2-for-klipper-socket..." - sudo systemctl start dwc -} - -# Helper functions -report_status() -{ - echo -e "\n\n###### $1" -} - -verify_ready() -{ - if [ "$EUID" -eq 0 ]; then - echo "This script must not run as root" - exit -1 - fi -} - -# Force script to exit if an error occurs -set -e - -# Find SRCDIR from the pathname of this script -SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" - -# Run installation steps defined above -verify_ready -check_klipper -install_packages -create_virtualenv -install_script -start_software \ No newline at end of file diff --git a/scripts/dwc2-for-klipper-socket-installer/install-octopi.sh b/scripts/dwc2-for-klipper-socket-installer/install-octopi.sh deleted file mode 100755 index 92dd280..0000000 --- a/scripts/dwc2-for-klipper-socket-installer/install-octopi.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash -# This script installs dwc2-for-klipper-socket on a Raspberry Pi machine running -# Raspbian/Raspberry Pi OS based distributions. - -# https://github.com/Stephan3/dwc2-for-klipper-socket.git - -PYTHONDIR="${HOME}/dwc-env" - -# Step 1: Verify Klipper has been installed -check_klipper() -{ - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - echo "Klipper service found!" - else - echo "Klipper service not found, please install Klipper first" - exit -1 - fi - -} - -# Step 2: Install packages -install_packages() -{ - PKGLIST="python3-virtualenv python3-dev python3-tornado" - - # Update system package info - report_status "Running apt-get update..." - sudo apt-get update --allow-releaseinfo-change - - # Install desired packages - report_status "Installing packages..." - sudo apt-get install --yes ${PKGLIST} -} - -# Step 3: Create python virtual environment -create_virtualenv() -{ - report_status "Updating python virtual environment..." - - # Create virtualenv if it doesn't already exist - [ ! -d ${PYTHONDIR} ] && virtualenv -p /usr/bin/python3 ${PYTHONDIR} - - # Install/update dependencies - ${PYTHONDIR}/bin/pip install tornado==6.0.4 -} - -# Step 4: Install startup script -install_script(){ - report_status "Installing system start script..." - sudo cp "${SRCDIR}/scripts/dwc-start.sh" /etc/init.d/dwc - sudo update-rc.d dwc defaults -} - -# Step 5: Install startup script config -install_config(){ - DEFAULTS_FILE=/etc/default/dwc - [ -f $DEFAULTS_FILE ] && return - - report_status "Installing system start configuration..." - sudo /bin/sh -c "cat > $DEFAULTS_FILE" < # -# # -# This file is part of KIAUH - Klipper Installation And Update Helper # -# https://github.com/th33xitus/kiauh # -# # -# This file may be distributed under the terms of the GNU GPLv3 license # -#=======================================================================# - -set -e - -### global variables -SYSTEMD="/etc/systemd/system" -DWC_ENV_DIR=${HOME}/dwc-env -DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket -DWC2_DIR=${HOME}/duetwebcontrol -DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git - -#=================================================# -#================= INSTALL DWC2 ==================# -#=================================================# - -system_check_dwc(){ - ### check system for an installed octoprint service - if systemctl is-enabled octoprint.service -q 2>/dev/null; then - OCTOPRINT_ENABLED="true" - fi -} - -dwc_setup_dialog(){ - status_msg "Initializing Duet Web Control installation ..." - - ### check system for several requirements before initializing the dwc2 installation - system_check_dwc - - ### check for existing klipper service installations - if [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then - ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0 - fi - - ### count amount of klipper services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - INSTANCE_COUNT=1 - else - INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) - fi - - ### initial config path check - check_klipper_cfg_path - - ### ask user how to handle OctoPrint, Haproxy and Lighttpd - process_octoprint_dialog_dwc2 - process_services_dialog - - ### instance confirmation dialog - while true; do - echo - top_border - if [ "$INSTANCE_COUNT" -gt 1 ]; then - printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" - else - echo -e "| 1 Klipper instance was found! | " - fi - echo -e "| You need one DWC instance per Klipper instance. | " - bottom_border - echo - read -p "${cyan}###### Create $INSTANCE_COUNT DWC instances? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Creating $INSTANCE_COUNT DWC instances ..." - dwc_setup - break;; - N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting DWC setup ..." - echo - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -###TODO for future: should be some kind of shared function between moonraker and this installer, since it does the same -process_octoprint_dialog_dwc2(){ - ### ask user to disable octoprint when its service was found - if [ "$OCTOPRINT_ENABLED" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" - hr - echo -e "| You might consider disabling the OctoPrint service, |" - echo -e "| since an active OctoPrint service may lead to unex- |" - echo -e "| pected behavior of Duet Web Control for Klipper. |" - bottom_border - read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Stopping OctoPrint ..." - sudo systemctl stop octoprint && ok_msg "OctoPrint service stopped!" - status_msg "Disabling OctoPrint ..." - sudo systemctl disable octoprint && ok_msg "OctoPrint service disabled!" - break;; - N|n|No|no) - echo -e "###### > No" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi - status_msg "Installation will start now! Please wait ..." -} - -############################################################# -############################################################# - -get_dwc_ver(){ - DWC2_VERSION=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4) -} - -dwc_setup(){ - ### get printer config directory - source_kiauh_ini - DWC_CONF_LOC="$klipper_cfg_loc" - - ### check dependencies - dep=(git wget gzip tar curl) - dependency_check - - ### step 1: get dwc2-for-klipper - status_msg "Downloading DWC2-for-Klipper-Socket ..." - cd "${HOME}" && git clone "$DWC2FK_REPO" - ok_msg "Download complete!" - - ### step 2: install dwc2 dependencies and create python virtualenv - status_msg "Installing dependencies ..." - install_dwc_packages - create_dwc_virtualenv - - ### step 3: create dwc2.cfg folder and dwc2.cfg - [ ! -d "$DWC_CONF_LOC" ] && mkdir -p "$DWC_CONF_LOC" - dwc_cfg_creation - - ### step 4: download Duet Web Control - download_dwc_webui - - ### step 5: create dwc instances - INSTANCE=1 - if [ "$INSTANCE_COUNT" -eq $INSTANCE ]; then - create_single_dwc_instance - else - #create_multi_dwc_instance - create_multi_dwc_instance - fi -} - -download_dwc_webui(){ - #get Duet Web Control - GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4) - status_msg "Downloading DWC2 Web UI ..." - [ ! -d "$DWC2_DIR" ] && mkdir -p "$DWC2_DIR" - cd "$DWC2_DIR" && wget "$GET_DWC2_URL" - ok_msg "Download complete!" - status_msg "Extracting archive ..." - unzip -q -o *.zip - for f_ in $(find . | grep '.gz') - do - gunzip -f "${f_}" - done - ok_msg "Done!" - status_msg "Writing DWC version to file ..." - echo "$GET_DWC2_URL" | cut -d/ -f8 > "$DWC2_DIR/.version" - ok_msg "Done!" - status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" && ok_msg "Duet Web Control installed!" -} - -############################################################################################## -#********************************************************************************************# -############################################################################################## - -install_dwc_packages() -{ - PKGLIST="python3-virtualenv python3-dev python3-tornado" - - # Update system package info - status_msg "Running apt-get update..." - sudo apt-get update --allow-releaseinfo-change - - # Install desired packages - status_msg "Installing packages..." - sudo apt-get install --yes "${PKGLIST}" -} - -create_dwc_virtualenv() -{ - status_msg "Installing python virtual environment..." - - # Create virtualenv if it doesn't already exist - [ ! -d "${DWC_ENV}" ] && virtualenv -p /usr/bin/python3 "${DWC_ENV}" - - # Install/update dependencies - "${DWC_ENV}"/bin/pip install tornado==6.0.4 -} - -create_single_dwc_startscript(){ - ### create systemd service file - sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC -[Unit] -Description=DuetWebControl -After=network.target -[Install] -WantedBy=multi-user.target -[Service] -Type=simple -User=${USER} -RemainAfterExit=yes -ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG} -Restart=always -RestartSec=10 -DWC -} - -create_multi_dwc_startscript(){ - ### create systemd service file - sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc-$INSTANCE.service" << DWC -[Unit] -Description=DuetWebControl -After=network.target -[Install] -WantedBy=multi-user.target -[Service] -Type=simple -User=${USER} -RemainAfterExit=yes -ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG} -Restart=always -RestartSec=10 -DWC -} - -create_single_dwcfk_cfg(){ -### create single instance config file -/bin/sh -c "cat > $DWC_CONF_LOC/dwc2.cfg" << DWCCFG -[webserver] -listen_adress: 0.0.0.0 -web_root: ${HOME}/duetwebcontrol -port: ${PORT} - -[reply_filters] -regex: - max_accel: \d+.\d+ - max_accel_to_decel: \d+.\d+ - square_corner_velocity: \d+.\d+ - max_velocity: \d+.\d+ -DWCCFG -} - -create_multi_dwcfk_cfg(){ -### create single instance config file -/bin/sh -c "cat > $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" << DWCCFG -[webserver] -listen_adress: 0.0.0.0 -web_root: ${HOME}/duetwebcontrol -port: ${PORT} - -[reply_filters] -regex: - max_accel: \d+.\d+ - max_accel_to_decel: \d+.\d+ - square_corner_velocity: \d+.\d+ - max_velocity: \d+.\d+ -DWCCFG -} - -############################################################################################## -#********************************************************************************************# -############################################################################################## - -print_dwc_ip_list(){ - i=1 - for ip in ${dwc_ip_list[@]}; do - echo -e " ${cyan}● Instance $i:${default} $ip" - i=$((i + 1)) - done -} - -create_single_dwc_instance(){ - status_msg "Setting up 1 Duet Web Control instance ..." - - ### single instance variables - DWC_LOG=/tmp/dwc.log - DWC_CFG="$DWC_CONF_LOC/dwc2.cfg" - - ### create instance - status_msg "Creating single DWC instance ..." - create_single_dwc_startscript - - ### enable instance - sudo systemctl enable dwc.service - ok_msg "Single DWC instance created!" - - ### launching instance - status_msg "Launching DWC instance ..." - sudo systemctl start dwc - - ### confirm message - CONFIRM_MSG="Single DWC instance has been set up!" - print_msg && clear_msg - - ### display moonraker ip to the user - print_dwc_ip_list; echo -} - -create_multi_dwc_instance(){ - status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..." - while [ $INSTANCE -le "$INSTANCE_COUNT" ]; do - ### multi instance variables - DWC_LOG=/tmp/dwc-$INSTANCE.log - DWC_CFG="$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" - - ### create instance - status_msg "Creating instance #$INSTANCE ..." - create_multi_dwc_startscript - - ### enable instance - sudo systemctl enable dwc-$INSTANCE.service - ok_msg "DWC instance $INSTANCE created!" - - ### launching instance - status_msg "Launching DWC instance $INSTANCE ..." - sudo systemctl start dwc-$INSTANCE - - ### instance counter +1 - INSTANCE=$(expr $INSTANCE + 1) - done - - ### confirm message - CONFIRM_MSG="$INSTANCE_COUNT DWC instances has been set up!" - print_msg && clear_msg - - ### display moonraker ip to the user - print_dwc_ip_list; echo -} - -dwc_cfg_creation(){ - ### default dwc port - DEFAULT_PORT=4750 - - ### get printer config directory - source_kiauh_ini - DWC_CONF_LOC="$klipper_cfg_loc" - - ### reset instances back to 1 again - INSTANCE=1 - - ### declare empty array for ips which get displayed to the user at the end of the setup - HOSTNAME=$(hostname -I | cut -d" " -f1) - dwc_ip_list=() - - ### create single instance dwc2.cfg file - if [ "$INSTANCE_COUNT" -eq $INSTANCE ]; then - ### set port - PORT=$DEFAULT_PORT - - ### write the ip and port to the ip list for displaying it later to the user - dwc_ip_list+=("$HOSTNAME:$PORT") - - status_msg "Creating dwc2.cfg in $DWC_CONF_LOC" - [ ! -d "$DWC_CONF_LOC" ] && mkdir -p "$DWC_CONF_LOC" - if [ ! -f "$DWC_CONF_LOC/dwc2.cfg" ]; then - create_single_dwcfk_cfg && ok_msg "dwc2.cfg created!" - else - warn_msg "There is already a file called 'dwc2.cfg'!" - warn_msg "Skipping..." - fi - - ### create multi instance moonraker.conf files - else - while [ $INSTANCE -le "$INSTANCE_COUNT" ]; do - ### set each instance to its own port - PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1) - - ### write the ip and port to the ip list for displaying it later to the user - dwc_ip_list+=("$HOSTNAME:$PORT") - - ### start the creation of each instance - status_msg "Creating dwc2.cfg for instance #$INSTANCE" - [ ! -d "$DWC_CONF_LOC/printer_$INSTANCE" ] && mkdir -p "$DWC_CONF_LOC/printer_$INSTANCE" - if [ ! -f "$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" ]; then - create_multi_dwcfk_cfg && ok_msg "dwc2.cfg created!" - else - warn_msg "There is already a file called 'dwc2.cfg'!" - warn_msg "Skipping..." - fi - - ### raise instance counter by 1 - INSTANCE=$(expr $INSTANCE + 1) - done - fi -} - -#=================================================# -#================= REMOVE DWC2 ===================# -#=================================================# - -remove_dwc2(){ - ### remove "legacy" init.d service - if [ -e /etc/init.d/dwc ]; then - status_msg "Removing DWC2-for-Klipper-Socket Service ..." - sudo systemctl stop dwc - sudo update-rc.d -f dwc remove - sudo rm -f /etc/init.d/dwc - sudo rm -f /etc/default/dwc - ok_msg "DWC2-for-Klipper-Socket Service removed!" - fi - - ### remove all dwc services - if ls /etc/systemd/system/dwc*.service 2>/dev/null 1>&2; then - status_msg "Removing DWC2-for-Klipper-Socket Services ..." - for service in $(ls /etc/systemd/system/dwc*.service | cut -d"/" -f5) - do - status_msg "Removing $service ..." - sudo systemctl stop $service - sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service - ok_msg "Done!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "DWC2-for-Klipper-Socket Service removed!" - fi - - ### remove all logfiles - if ls /tmp/dwc*.log 2>/dev/null 1>&2; then - for logfile in $(ls /tmp/dwc*.log) - do - status_msg "Removing $logfile ..." - rm -f $logfile - ok_msg "File '$logfile' removed!" - done - fi - - ### removing the rest of the folders - if [ -d $DWC2FK_DIR ]; then - status_msg "Removing DWC2-for-Klipper-Socket directory ..." - rm -rf $DWC2FK_DIR && ok_msg "Directory removed!" - fi - if [ -d $DWC_ENV_DIR ]; then - status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..." - rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!" - fi - if [ -d $DWC2_DIR ]; then - status_msg "Removing DWC2 directory ..." - rm -rf $DWC2_DIR && ok_msg "Directory removed!" - fi - - ### remove dwc2_port from ~/.kiauh.ini - sed -i "/^dwc2_port=/d" $INI_FILE - - CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!" -} - -#=================================================# -#================= UPDATE DWC2 ===================# -#=================================================# - -update_dwc2fk(){ - do_action_service "stop" "dwc" - bb4u "dwc2" - if [ ! -d $DWC2FK_DIR ]; then - cd ${HOME} && git clone $DWC2FK_REPO - else - cd $DWC2FK_DIR && git pull - fi - do_action_service "start" "dwc" -} - -update_dwc2(){ - bb4u "dwc2" - download_dwc_webui -} - -#=================================================# -#================= DWC2 STATUS ===================# -#=================================================# - -dwc2_status(){ - dcount=0 - dwc_data=( - SERVICE - $DWC2_DIR - $DWC2FK_DIR - $DWC_ENV_DIR - ) - - ### count amount of dwc service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^dwc(\-[[:digit:]]+)?\.service$" | wc -l) - - ### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0] - - #count+1 for each found data-item from array - for dd in "${dwc_data[@]}" - do - if [ -e $dd ]; then - dcount=$(expr $dcount + 1) - fi - done - - if [ "$dcount" == "${#dwc_data[*]}" ]; then - DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" - elif [ "$dcount" == 0 ]; then - DWC2_STATUS="${red}Not installed!${default} " - else - DWC2_STATUS="${yellow}Incomplete!${default} " - fi -} - -read_dwc2fk_versions(){ - if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then - cd $DWC2FK_DIR - git fetch origin master -q - LOCAL_DWC2FK_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_DWC2FK_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_DWC2FK_COMMIT=$NONE - REMOTE_DWC2FK_COMMIT=$NONE - fi -} - -compare_dwc2fk_versions(){ - unset DWC2FK_UPDATE_AVAIL - read_dwc2fk_versions - if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then - LOCAL_DWC2FK_COMMIT="${yellow}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}" - REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}" - # add dwc2fk to the update all array for the update all function in the updater - DWC2FK_UPDATE_AVAIL="true" && update_arr+=(update_dwc2fk) - else - LOCAL_DWC2FK_COMMIT="${green}$(printf "%-12s" "$LOCAL_DWC2FK_COMMIT")${default}" - REMOTE_DWC2FK_COMMIT="${green}$(printf "%-12s" "$REMOTE_DWC2FK_COMMIT")${default}" - DWC2FK_UPDATE_AVAIL="false" - fi -} - -read_local_dwc2_version(){ - unset DWC2_VER_FOUND - if [ -e $DWC2_DIR/.version ]; then - DWC2_VER_FOUND="true" - DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/.version) - else - DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER - fi -} - -read_remote_dwc2_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - DWC2_REMOTE_VER=$NONE - else - get_dwc_ver - DWC2_REMOTE_VER=$DWC2_VERSION - fi -} - -compare_dwc2_versions(){ - unset DWC2_UPDATE_AVAIL - read_local_dwc2_version && read_remote_dwc2_version - if [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER == $DWC2_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - DWC2_LOCAL_VER="${green}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}" - DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" - elif [[ $DWC2_VER_FOUND = "true" ]] && [[ $DWC2_LOCAL_VER != $DWC2_REMOTE_VER ]]; then - DWC2_LOCAL_VER="${yellow}$(printf "%-12s" "$DWC2_LOCAL_VER")${default}" - DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" - # add dwc to the update all array for the update all function in the updater - DWC2_UPDATE_AVAIL="true" && update_arr+=(update_dwc2) - else - DWC2_LOCAL_VER=$NONE - DWC2_REMOTE_VER="${green}$(printf "%-12s" "$DWC2_REMOTE_VER")${default}" - DWC2_UPDATE_AVAIL="false" - fi -} \ No newline at end of file diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index e9c7335..1d102e7 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -223,8 +223,7 @@ mainsail_port_check(){ status_msg "Detected other enabled interfaces:" [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${default}" - [ "${DWC2_ENABLED}" = "true" ] && echo -e " ${cyan}● DWC2 - Port: ${DWC2_PORT}${default}" - if [ "${FLUIDD_PORT}" = "80" ] || [ "${DWC2_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then + if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then PORT_80_BLOCKED="true" select_mainsail_port fi @@ -244,8 +243,7 @@ fluidd_port_check(){ status_msg "Detected other enabled interfaces:" [ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" [ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${default}" - [ "${DWC2_ENABLED}" = "true" ] && echo " ${cyan}● DWC2 - Port: ${DWC2_PORT}${default}" - if [ "${MAINSAIL_PORT}" = "80" ] || [ "${DWC2_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then + if [ "${MAINSAIL_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then PORT_80_BLOCKED="true" select_fluidd_port fi @@ -269,7 +267,6 @@ select_mainsail_port(){ blank_line [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" [ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |" - [ "${DWC2_PORT}" = "80" ] && echo "| ● DWC2 |" blank_line echo -e "| Make sure you don't choose a port which was already |" echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" @@ -280,7 +277,7 @@ select_mainsail_port(){ bottom_border while true; do read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${DWC2_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then + if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then echo "Setting port ${NEW_PORT} for Mainsail!" SET_LISTEN_PORT=${NEW_PORT} break @@ -301,7 +298,6 @@ select_fluidd_port(){ blank_line [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" [ "${MAINSAIL_PORT}" = "80" ] && echo "| ● Mainsail |" - [ "${DWC2_PORT}" = "80" ] && echo "| ● DWC2 |" blank_line echo -e "| Make sure you don't choose a port which was already |" echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" @@ -312,7 +308,7 @@ select_fluidd_port(){ bottom_border while true; do read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${DWC2_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then + if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then echo "Setting port ${NEW_PORT} for Fluidd!" SET_LISTEN_PORT=${NEW_PORT} break @@ -401,7 +397,7 @@ set_upstream_nginx_cfg(){ fetch_webui_ports(){ ### read listen ports from possible installed interfaces ### and write them to ~/.kiauh.ini - WEBIFS=(mainsail fluidd octoprint dwc2) + WEBIFS=(mainsail fluidd octoprint) for interface in "${WEBIFS[@]}"; do if [ -f "/etc/nginx/sites-available/${interface}" ]; then port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 23fb554..4ba9a52 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -59,14 +59,6 @@ detect_enabled_sites(){ else FLUIDD_ENABLED="false" fi - if [ -e /etc/nginx/sites-enabled/dwc2 ]; then - SITE_ENABLED="true" && DWC2_ENABLED="true" - read_listen_port "dwc2" - DWC2_PORT=$LISTEN_PORT - #echo "debug: DWC2 listens on port: $DWC2_PORT" - else - DWC2_ENABLED="false" - fi if [ -e /etc/nginx/sites-enabled/octoprint ]; then SITE_ENABLED="true" && OCTOPRINT_ENABLED="true" read_listen_port "octoprint" @@ -84,7 +76,7 @@ create_custom_hostname(){ echo -e "| that name to open the Interface in your browser. |" echo -e "| |" echo -e "| E.g.: If you set the hostname to 'my-printer' you |" - echo -e "| can open DWC2/Mainsail/Fluidd/Octoprint by |" + echo -e "| can open Mainsail / Fluidd / Octoprint by |" echo -e "| browsing to: http://my-printer.local |" bottom_border while true; do diff --git a/scripts/status.sh b/scripts/status.sh index 7b03370..5048cef 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -156,8 +156,6 @@ ui_print_versions(){ unset update_arr check_system_updates # compare_klipper_versions -# compare_dwc2fk_versions -# compare_dwc2_versions # compare_moonraker_versions # compare_mainsail_versions # compare_fluidd_versions diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index 4c612ae..9d320d6 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -12,9 +12,8 @@ backup_ui(){ echo -e "| | 6) [KlipperScreen] | " echo -e "| Klipper API: | | " echo -e "| 2) [Moonraker] | Other: | " - echo -e "| 3) [Moonraker DB] | 7) [Duet Web Control] | " - echo -e "| | 8) [OctoPrint] | " - echo -e "| | 9) [MoonrakerTelegramBot] | " + echo -e "| 3) [Moonraker DB] | 7) [OctoPrint] | " + echo -e "| | 8) [MoonrakerTelegramBot] | " back_footer } @@ -38,10 +37,8 @@ backup_menu(){ 6) do_action "backup_klipperscreen" "backup_ui";; 7) - do_action "backup_dwc2" "backup_ui";; - 8) do_action "backup_octoprint" "backup_ui";; - 9) + 8) do_action "backup_MoonrakerTelegramBot" "backup_ui";; B|b) clear; main_menu; break;; diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 0eda727..813e527 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -1,19 +1,19 @@ install_ui(){ top_border - echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " + echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | " hr echo -e "| You need this menu usually only for installing | " echo -e "| all necessary dependencies for the various | " echo -e "| functions on a completely fresh system. | " hr echo -e "| Firmware & API: | Other: | " - echo -e "| 1) [Klipper] | 6) [Duet Web Control] | " - echo -e "| 2) [Moonraker] | 7) [OctoPrint] | " - echo -e "| | 8) [PrettyGCode] | " - echo -e "| Klipper Webinterface: | 9) [Telegram Bot] | " - echo -e "| 3) [Mainsail] | | " - echo -e "| 4) [Fluidd] | Webcam: | " - echo -e "| | 10) [MJPG-Streamer] | " + echo -e "| 1) [Klipper] | 6) [OctoPrint] | " + echo -e "| 2) [Moonraker] | 7) [PrettyGCode] | " + echo -e "| | 8) [Telegram Bot] | " + echo -e "| Klipper Webinterface: | | " + echo -e "| 3) [Mainsail] | Webcam: | " + echo -e "| 4) [Fluidd] | 9) [MJPG-Streamer] | " + echo -e "| | | " echo -e "| Touchscreen GUI: | | " echo -e "| 5) [KlipperScreen] | | " back_footer @@ -35,14 +35,12 @@ install_menu(){ 5) do_action "install_klipperscreen" "install_ui";; 6) - do_action "dwc_setup_dialog" "install_ui";; - 7) do_action "octoprint_setup_dialog" "install_ui";; - 8) + 7) do_action "install_pgc_for_klipper" "install_ui";; - 9) + 8) do_action "install_MoonrakerTelegramBot" "install_ui";; - 10) + 9) do_action "install_mjpg-streamer" "install_ui";; B|b) clear; main_menu; break;; diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index f630cb3..bf8c1ea 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -13,8 +13,7 @@ main_ui(){ echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" echo -e "| | |" - echo -e "| | DWC2: $DWC2_STATUS|" - echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" + echo -e "| ${cyan}${KIAUH_VER}${white}| Octoprint: $OCTOPRINT_STATUS|" quit_footer } @@ -49,7 +48,6 @@ main_menu(){ print_kiauh_version # klipper_status # moonraker_status - dwc2_status fluidd_status mainsail_status octoprint_status @@ -60,16 +58,13 @@ main_menu(){ main_ui while true; do read -p "${cyan}Perform action:${default} " action; echo - case "$action" in + case "${action}" in "start klipper") do_action_service "start" "klipper"; main_ui;; "stop klipper") do_action_service "stop" "klipper"; main_ui;; "restart klipper") do_action_service "restart" "klipper"; main_ui;; "start moonraker") do_action_service "start" "moonraker"; main_ui;; "stop moonraker") do_action_service "stop" "moonraker"; main_ui;; "restart moonraker")do_action_service "restart" "moonraker"; main_ui;; - "start dwc") do_action_service "start" "dwc"; main_ui;; - "stop dwc") do_action_service "stop" "dwc"; main_ui;; - "restart dwc") do_action_service "restart" "dwc"; main_ui;; "start octoprint") do_action_service "start" "octoprint"; main_ui;; "stop octoprint") do_action_service "stop" "octoprint"; main_ui;; "restart octoprint") do_action_service "restart" "octoprint"; main_ui;; diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 9df4e9f..c7a6f7e 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -1,6 +1,6 @@ remove_ui(){ top_border - echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " + echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} | " hr echo -e "| Directories which remain untouched: | " echo -e "| --> Your printer configuration directory | " @@ -11,13 +11,12 @@ remove_ui(){ echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " echo -e "| | | " echo -e "| Klipper API: | Other: | " - echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | " - echo -e "| | 7) [OctoPrint] | " - echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | " - echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | " - echo -e "| 4) [Fluidd] | | " - echo -e "| | 10) [MJPG-Streamer] | " - echo -e "| | 11) [NGINX] | " + echo -e "| 2) [Moonraker] | 6) [OctoPrint] | " + echo -e "| | 7) [PrettyGCode] | " + echo -e "| Klipper Webinterface: | 9) [Telegram Bot] | " + echo -e "| 3) [Mainsail] | | " + echo -e "| 4) [Fluidd] | 9) [MJPG-Streamer] | " + echo -e "| | 10) [NGINX] | " back_footer } @@ -25,7 +24,7 @@ remove_menu(){ do_action "" "remove_ui" while true; do read -p "${cyan}Perform action:${default} " action; echo - case "$action" in + case "${action}" in 1) do_action "remove_klipper" "remove_ui";; 2) @@ -37,16 +36,14 @@ remove_menu(){ 5) do_action "remove_klipperscreen" "remove_ui";; 6) - do_action "remove_dwc2" "remove_ui";; - 7) do_action "remove_octoprint" "remove_ui";; - 8) + 7) do_action "remove_prettygcode" "remove_ui";; - 9) + 8) do_action "remove_MoonrakerTelegramBot" "remove_ui";; - 10) + 9) do_action "remove_mjpg-streamer" "remove_ui";; - 11) + 10) do_action "remove_nginx" "remove_ui";; B|b) clear; main_menu; break;; diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 85d30d9..5a926c2 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -1,9 +1,9 @@ update_ui(){ ui_print_versions top_border - echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " + echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} | " hr - echo -e "| 0) $BB4U_STATUS| " + echo -e "| 0) ${BB4U_STATUS}| " hr echo -e "| a) [Update all] | | | " echo -e "| | Installed: | Latest: | " @@ -19,12 +19,10 @@ update_ui(){ echo -e "| 5) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | " echo -e "| | | | " echo -e "| Other: |---------------|--------------| " - echo -e "| 6) [DWC2-for-Klipper] | $LOCAL_DWC2FK_COMMIT | $REMOTE_DWC2FK_COMMIT | " - echo -e "| 7) [DWC2 Web UI] | $DWC2_LOCAL_VER | $DWC2_REMOTE_VER | " - echo -e "| 8) [PrettyGCode] | $LOCAL_PGC_COMMIT | $REMOTE_PGC_COMMIT | " - echo -e "| 9) [Telegram Bot] | $LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT | $REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT | " + echo -e "| 6) [PrettyGCode] | $LOCAL_PGC_COMMIT | $REMOTE_PGC_COMMIT | " + echo -e "| 7) [Telegram Bot] | $LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT | $REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT | " echo -e "| |------------------------------| " - echo -e "| 10) [System] | $DISPLAY_SYS_UPDATE | " + echo -e "| 8) [System] | $DISPLAY_SYS_UPDATE | " back_footer } @@ -32,8 +30,8 @@ update_menu(){ read_bb4u_stat do_action "" "update_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in + read -p "${cyan}Perform action:${white} " action; echo + case "${action}" in 0) do_action "toggle_backups" "update_ui";; 1) @@ -47,14 +45,10 @@ update_menu(){ 5) do_action "update_klipperscreen" "update_ui";; 6) - do_action "update_dwc2fk" "update_ui";; - 7) - do_action "update_dwc2" "update_ui";; - 8) do_action "update_pgc_for_klipper" "update_ui";; - 9) + 7) do_action "update_MoonrakerTelegramBot" "update_ui";; - 10) + 8) do_action "update_system" "update_ui";; a) do_action "update_all" "update_ui";; diff --git a/scripts/update.sh b/scripts/update.sh index 7d87a60..b08c83e 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -21,12 +21,6 @@ update_all(){ if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then echo -e "| ${cyan}● Klipper${default} |" fi - if [ "$DWC2FK_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● DWC2-for-Klipper-Socket${default} |" - fi - if [ "$DWC2_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Duet Web Control${default} |" - fi if [ "$MOONRAKER_UPDATE_AVAIL" = "true" ]; then echo -e "| ${cyan}● Moonraker${default} |" fi diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 7c2234b..eaa959b 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -55,11 +55,6 @@ upload_selection(){ logfiles+=($mr_log) done fi - if ls /tmp/dwc2*.log 2>/dev/null 1>&2; then - for dwc_log in $(find /tmp/dwc2*.log); do - logfiles+=($dwc_log) - done - fi ### draw interface i=0 From 518cf3acd7c9b08780d7901a5daa5f58b8c61516 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:31:28 +0200 Subject: [PATCH 041/183] style: add copyright header Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 13 +++++++++++++ scripts/ui/backup_menu.sh | 13 +++++++++++++ scripts/ui/general_ui.sh | 13 +++++++++++++ scripts/ui/main_menu.sh | 13 +++++++++++++ scripts/ui/remove_menu.sh | 13 +++++++++++++ scripts/ui/settings_menu.sh | 13 +++++++++++++ scripts/ui/update_menu.sh | 13 +++++++++++++ 7 files changed, 91 insertions(+) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 6b80384..c09906b 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + advanced_ui(){ top_border echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index 9d320d6..6495333 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + backup_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index 459b29f..e46f859 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + #ui total width = 57 chars top_border(){ echo -e "/=======================================================\\" diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index bf8c1ea..117d8df 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + main_ui(){ #[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder top_border diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index c7a6f7e..4ad2420 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} | " diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 0537941..7e9ddef 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + settings_ui(){ source_kiauh_ini top_border diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 5a926c2..c18ec4e 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + update_ui(){ ui_print_versions top_border From f63de4dcaae13bfb41976b9837145453b3d7fb6f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:32:38 +0200 Subject: [PATCH 042/183] refactor(fluidd.sh): refactor fluidd functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 271 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 scripts/fluidd.sh diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh new file mode 100644 index 0000000..5096bb8 --- /dev/null +++ b/scripts/fluidd.sh @@ -0,0 +1,271 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +FLUIDD_DIR="${HOME}/fluidd" +FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" +KLIPPER_CONFIG="${HOME}/klipper_config" + +#===================================================# +#================== INSTALL FLUIDD =================# +#===================================================# + +function install_fluidd(){ + ### exit early if moonraker not found + if [ -z "$(moonraker_systemd)" ]; then + local error="Moonraker service not found!\n Please install Moonraker first!" + print_error "${error}" && return + fi + ### checking dependencies + local dep=(nginx) + dependency_check "${dep[@]}" + ### check if moonraker is already installed + system_check_webui + ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found + process_octoprint_dialog + process_services_dialog + ### process possible disruptive services + process_disruptive_services + + status_msg "Initializing Fluidd installation ..." + ### check for other enabled web interfaces + unset SET_LISTEN_PORT + detect_enabled_sites + + ### check if another site already listens to port 80 + fluidd_port_check + + ### ask user to install mjpg-streamer + if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then + get_user_selection_mjpg-streamer + fi + + ### ask user to install the recommended webinterface macros + if ! ls "${KLIPPER_CONFIG}/kiauh_macros.cfg" 2>/dev/null 1>&2 || ! ls "${KLIPPER_CONFIG}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then + get_user_selection_kiauh_macros "Fluidd " + fi + ### create /etc/nginx/conf.d/upstreams.conf + set_upstream_nginx_cfg + ### create /etc/nginx/sites-available/ + set_nginx_cfg "fluidd" + + ### symlink nginx log + symlink_webui_nginx_log "fluidd" + + ### copy the kiauh_macros.cfg to the config location + install_kiauh_macros + + ### install mainsail/fluidd + fluidd_setup + + ### install mjpg-streamer + [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer + + fetch_webui_ports #WIP + + ### confirm message + print_confirm "Fluidd has been set up!" +} + +function fluidd_setup(){ + ### get fluidd download url + FLUIDD_DL_URL=$(curl -s "${FLUIDD_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) + + ### remove existing and create fresh fluidd folder, then download fluidd + [ -d "${FLUIDD_DIR}" ] && rm -rf "${FLUIDD_DIR}" + mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}" + status_msg "Downloading Fluidd ${FLUIDD_VERSION} ..." + wget "${FLUIDD_DL_URL}" && ok_msg "Download complete!" + + ### extract archive + status_msg "Extracting archive ..." + unzip -q -o *.zip && ok_msg "Done!" + + ### delete downloaded zip + status_msg "Remove downloaded archive ..." + rm -rf *.zip && ok_msg "Done!" +} + +#===================================================# +#================== REMOVE FLUIDD ==================# +#===================================================# + +function remove_fluidd(){ + ### remove fluidd dir + if [ -d "${FLUIDD_DIR}" ]; then + status_msg "Removing Fluidd directory ..." + rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!" + fi + + ### remove fluidd config for nginx + if [ -e "/etc/nginx/sites-available/fluidd" ]; then + status_msg "Removing Fluidd configuration for Nginx ..." + sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!" + fi + + ### remove fluidd symlink for nginx + if [ -L /etc/nginx/sites-enabled/fluidd ]; then + status_msg "Removing Fluidd Symlink for Nginx ..." + sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" + fi + + ### remove mainsail nginx logs and log symlinks + for log in $(find /var/log/nginx -name "fluidd*"); do + sudo rm -f "${log}" + done + for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do + rm -f "${log}" + done + + ### remove fluidd_port from ~/.kiauh.ini + sed -i "/^fluidd_port=/d" "${INI_FILE}" + + print_confirm "Fluidd successfully removed!" +} + +#===================================================# +#================== UPDATE FLUIDD ==================# +#===================================================# + +update_fluidd(){ + bb4u "fluidd" + status_msg "Updating Fluidd ..." + fluidd_setup + match_nginx_configs + symlink_webui_nginx_log "fluidd" +} + +#===================================================# +#================== FLUIDD STATUS ==================# +#===================================================# + +function get_fluidd_ver(){ + FLUIDD_VERSION=$(curl -s "${FLUIDD_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) +} + +function fluidd_status(){ + fcount=0 + fluidd_data=( + $FLUIDD_DIR + $NGINX_SA/fluidd + $NGINX_SE/fluidd + ) + #count+1 for each found data-item from array + for fd in "${fluidd_data[@]}" + do + if [ -e $fd ]; then + fcount=$(expr $fcount + 1) + fi + done + if [ "$fcount" == "${#fluidd_data[*]}" ]; then + FLUIDD_STATUS="${green}Installed!${default} " + elif [ "$fcount" == 0 ]; then + FLUIDD_STATUS="${red}Not installed!${default} " + else + FLUIDD_STATUS="${yellow}Incomplete!${default} " + fi +} + +function read_local_fluidd_version(){ + unset FLUIDD_VER_FOUND + if [ -e "${FLUIDD_DIR}/.version" ]; then + FLUIDD_VER_FOUND="true" + FLUIDD_LOCAL_VER=$(head -n 1 "${FLUIDD_DIR}/.version") + else + FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER + fi +} + +function read_remote_fluidd_version(){ + #remote checks don't work without curl installed! + if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then + FLUIDD_REMOTE_VER=${NONE} + else + get_fluidd_ver + FLUIDD_REMOTE_VER=${FLUIDD_VERSION} + fi +} + +function compare_fluidd_versions(){ + unset FLUIDD_UPDATE_AVAIL + read_local_fluidd_version && read_remote_fluidd_version + if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then + #printf fits the string for displaying it in the ui to a total char length of 12 + FLUIDD_LOCAL_VER="${green}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" + FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" + elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then + FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" + FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" + # add fluidd to the update all array for the update all function in the updater + FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) + else + FLUIDD_LOCAL_VER=$NONE + FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" + FLUIDD_UPDATE_AVAIL="false" + fi +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +function fluidd_port_check(){ + if [ "${FLUIDD_ENABLED}" = "false" ]; then + if [ "${SITE_ENABLED}" = "true" ]; then + status_msg "Detected other enabled interfaces:" + [ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" + [ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${default}" + if [ "${MAINSAIL_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then + PORT_80_BLOCKED="true" + select_fluidd_port + fi + else + DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + SET_LISTEN_PORT=${DEFAULT_PORT} + fi + SET_NGINX_CFG="true" + else + SET_NGINX_CFG="false" + fi +} + +function select_fluidd_port(){ + if [ "${PORT_80_BLOCKED}" = "true" ]; then + echo + top_border + echo -e "| ${red}!!!WARNING!!!${default} |" + echo -e "| ${red}You need to choose a different port for Fluidd!${default} |" + echo -e "| ${red}The following web interface is listening at port 80:${default} |" + blank_line + [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" + [ "${MAINSAIL_PORT}" = "80" ] && echo "| ● Mainsail |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| use ports in the range of 4750 or above! |" + blank_line + echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| input. So make sure to choose a valid port! |" + bottom_border + while true; do + read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then + echo "Setting port ${NEW_PORT} for Fluidd!" + SET_LISTEN_PORT=${NEW_PORT} + break + else + echo "That port is already taken! Select a different one!" + fi + done + fi +} \ No newline at end of file From cf23105ebe298392f25f64f0c6605538c2fb4347 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:33:42 +0200 Subject: [PATCH 043/183] refactor(mainsail.sh): refactor mainsail functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/install_klipper_webui.sh | 612 ------------------------------- scripts/mainsail.sh | 397 ++++++++++++++++++++ scripts/ms_theme_installer.sh | 114 ------ scripts/remove.sh | 89 ----- scripts/status.sh | 124 ------- scripts/update.sh | 16 - 6 files changed, 397 insertions(+), 955 deletions(-) delete mode 100755 scripts/install_klipper_webui.sh create mode 100644 scripts/mainsail.sh delete mode 100755 scripts/ms_theme_installer.sh delete mode 100755 scripts/remove.sh diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh deleted file mode 100755 index 1d102e7..0000000 --- a/scripts/install_klipper_webui.sh +++ /dev/null @@ -1,612 +0,0 @@ -#!/bin/bash - -#=======================================================================# -# Copyright (C) 2020 - 2022 Dominik Willner # -# # -# This file is part of KIAUH - Klipper Installation And Update Helper # -# https://github.com/th33xitus/kiauh # -# # -# This file may be distributed under the terms of the GNU GPLv3 license # -#=======================================================================# - -set -e - -MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" -FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" - -system_check_webui(){ - ### check system for installed moonraker service - if ls /etc/systemd/system/moonraker.service 2>/dev/null 1>&2 || ls /etc/systemd/system | grep -q -E "moonraker-[[:digit:]]+.service"; then - moonraker_chk_ok="true" - else - moonraker_chk_ok="false" - fi - - ### check system for an installed and enabled octoprint service - if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then - OCTOPRINT_ENABLED="true" - fi - - ### check system for an installed haproxy service - if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then - HAPROXY_FOUND="true" - fi - - ### check system for an installed lighttpd service - if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then - LIGHTTPD_FOUND="true" - fi - - ### check system for an installed apache2 service - if [[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]]; then - APACHE2_FOUND="true" - fi -} - -get_user_selection_mjpg-streamer(){ - while true; do - unset INSTALL_MJPG - echo - top_border - echo -e "| Install MJGP-Streamer for webcam support? |" - bottom_border - read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - INSTALL_MJPG="true" - break;; - N|n|No|no) - echo -e "###### > No" - INSTALL_MJPG="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -get_user_selection_kiauh_macros(){ - #ask user for webui default macros - while true; do - unset ADD_KIAUH_MACROS - echo - top_border - echo -e "| It is recommended to have some important macros set |" - echo -e "| up in your printer configuration to have $1|" - echo -e "| fully functional and working. |" - blank_line - echo -e "| Those macros are: |" - echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |" - echo -e "| ${cyan}● [gcode_macro RESUME]${default} |" - echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |" - blank_line - echo -e "| If you already have these macros in your config file |" - echo -e "| you can skip this step and choose 'no'. |" - echo -e "| Otherwise you should consider to answer with 'yes' to |" - echo -e "| add the recommended example macros to your config. |" - bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - ADD_KIAUH_MACROS="true" - break;; - N|n|No|no) - echo -e "###### > No" - ADD_KIAUH_MACROS="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -install_webui(){ - source_kiauh_ini - ### checking dependencies - dep=(nginx) - dependency_check - ### check if moonraker is already installed - system_check_webui - ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found - process_octoprint_dialog - process_services_dialog - ### process possible disruptive services - process_disruptive_services - - [ "$1" == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail " - [ "$1" == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " - - ### exit mainsail/fluidd setup if moonraker not found - if [ "${moonraker_chk_ok}" = "false" ]; then - ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!" - print_msg && clear_msg && return 0 - fi - - status_msg "Initializing ${IF_NAME1} installation ..." - ### check for other enabled web interfaces - unset SET_LISTEN_PORT - detect_enabled_sites - - ### check if another site already listens to port 80 - "${1}"_port_check - - ### ask user to install mjpg-streamer - if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then - get_user_selection_mjpg-streamer - fi - - ### ask user to install the recommended webinterface macros - if ! ls "${klipper_cfg_loc}"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "${klipper_cfg_loc}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then - get_user_selection_kiauh_macros "${IF_NAME2}" - fi - ### create /etc/nginx/conf.d/upstreams.conf - set_upstream_nginx_cfg - ### create /etc/nginx/sites-available/ - set_nginx_cfg "${1}" - - ### symlink nginx log - symlink_webui_nginx_log "${1}" - - ### copy the kiauh_macros.cfg to the config location - install_kiauh_macros - - ### install mainsail/fluidd - "${1}"_setup - - ### install mjpg-streamer - [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer - - fetch_webui_ports #WIP - - ### confirm message - CONFIRM_MSG="${IF_NAME1} has been set up!" - print_msg && clear_msg -} - -symlink_webui_nginx_log(){ - LPATH="${HOME}/klipper_logs" - UI_ACCESS_LOG="/var/log/nginx/${1}-access.log" - UI_ERROR_LOG="/var/log/nginx/${1}-error.log" - [ ! -d "${LPATH}" ] && mkdir -p "${LPATH}" - if [ -f "${UI_ACCESS_LOG}" ] && [ ! -L "${LPATH}/${1}-access.log" ]; then - status_msg "Creating symlink for ${UI_ACCESS_LOG} ..." - ln -s "${UI_ACCESS_LOG}" "${LPATH}" - ok_msg "OK!" - fi - if [ -f "${UI_ERROR_LOG}" ] && [ ! -L "${LPATH}/${1}-error.log" ]; then - status_msg "Creating symlink for ${UI_ERROR_LOG} ..." - ln -s "${UI_ERROR_LOG}" "${LPATH}" - ok_msg "OK!" - fi -} - -install_kiauh_macros(){ - source_kiauh_ini - ### copy kiauh_macros.cfg - if [ "${ADD_KIAUH_MACROS}" = "true" ]; then - ### create a backup of the config folder - backup_klipper_config_dir - ### handle multi printer.cfg - if ls "${klipper_cfg_loc}"/printer_* 2>/dev/null 1>&2; then - for config in $(find ${klipper_cfg_loc}/printer_*/printer.cfg); do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [ ! -f "${path}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" - ok_msg "${path}/kiauh_macros.cfg created!" - fi - done - ### handle single printer.cfg - elif [ -f "${klipper_cfg_loc}/printer.cfg" ] && [ ! -f "${klipper_cfg_loc}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${klipper_cfg_loc}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${klipper_cfg_loc}/printer.cfg" - ok_msg "${klipper_cfg_loc}/kiauh_macros.cfg created!" - fi - ### restart klipper service to parse the modified printer.cfg - do_action_service "restart" "klipper" - fi -} - -mainsail_port_check(){ - if [ "${MAINSAIL_ENABLED}" = "false" ]; then - if [ "${SITE_ENABLED}" = "true" ]; then - status_msg "Detected other enabled interfaces:" - [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" - [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${default}" - if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then - PORT_80_BLOCKED="true" - select_mainsail_port - fi - else - DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) - SET_LISTEN_PORT=${DEFAULT_PORT} - fi - SET_NGINX_CFG="true" - else - SET_NGINX_CFG="false" - fi -} - -fluidd_port_check(){ - if [ "${FLUIDD_ENABLED}" = "false" ]; then - if [ "${SITE_ENABLED}" = "true" ]; then - status_msg "Detected other enabled interfaces:" - [ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" - [ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${default}" - if [ "${MAINSAIL_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then - PORT_80_BLOCKED="true" - select_fluidd_port - fi - else - DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) - SET_LISTEN_PORT=${DEFAULT_PORT} - fi - SET_NGINX_CFG="true" - else - SET_NGINX_CFG="false" - fi -} - -select_mainsail_port(){ - if [ "${PORT_80_BLOCKED}" = "true" ]; then - echo - top_border - echo -e "| ${red}!!!WARNING!!!${default} |" - echo -e "| ${red}You need to choose a different port for Mainsail!${default} |" - echo -e "| ${red}The following web interface is listening at port 80:${default} |" - blank_line - [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" - [ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |" - blank_line - echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" - echo -e "| use ports in the range of 4750 or above! |" - blank_line - echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" - echo -e "| input. So make sure to choose a valid port! |" - bottom_border - while true; do - read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then - echo "Setting port ${NEW_PORT} for Mainsail!" - SET_LISTEN_PORT=${NEW_PORT} - break - else - echo "That port is already taken! Select a different one!" - fi - done - fi -} - -select_fluidd_port(){ - if [ "${PORT_80_BLOCKED}" = "true" ]; then - echo - top_border - echo -e "| ${red}!!!WARNING!!!${default} |" - echo -e "| ${red}You need to choose a different port for Fluidd!${default} |" - echo -e "| ${red}The following web interface is listening at port 80:${default} |" - blank_line - [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" - [ "${MAINSAIL_PORT}" = "80" ] && echo "| ● Mainsail |" - blank_line - echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" - echo -e "| use ports in the range of 4750 or above! |" - blank_line - echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" - echo -e "| input. So make sure to choose a valid port! |" - bottom_border - while true; do - read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then - echo "Setting port ${NEW_PORT} for Fluidd!" - SET_LISTEN_PORT=${NEW_PORT} - break - else - echo "That port is already taken! Select a different one!" - fi - done - fi -} - -get_mainsail_ver(){ - MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) -} - -get_fluidd_ver(){ - FLUIDD_VERSION=$(curl -s "${FLUIDD_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) -} - -mainsail_setup(){ - ### get mainsail download url - MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) - - ### remove existing and create fresh mainsail folder, then download mainsail - [ -d "${MAINSAIL_DIR}" ] && rm -rf "${MAINSAIL_DIR}" - mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" - status_msg "Downloading Mainsail ${MAINSAIL_VERSION} ..." - wget "${MAINSAIL_DL_URL}" && ok_msg "Download complete!" - - ### extract archive - status_msg "Extracting archive ..." - unzip -q -o *.zip && ok_msg "Done!" - - ### delete downloaded zip - status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" - - ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode - if [ $(ls /etc/systemd/system/moonraker* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then - enable_mainsail_remotemode - fi -} - -enable_mainsail_remotemode(){ - rm -f "${MAINSAIL_DIR}/config.json" - echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" -} - -fluidd_setup(){ - ### get fluidd download url - FLUIDD_DL_URL=$(curl -s "${FLUIDD_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) - - ### remove existing and create fresh fluidd folder, then download fluidd - [ -d "${FLUIDD_DIR}" ] && rm -rf "${FLUIDD_DIR}" - mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}" - status_msg "Downloading Fluidd ${FLUIDD_VERSION} ..." - wget "${FLUIDD_DL_URL}" && ok_msg "Download complete!" - - ### extract archive - status_msg "Extracting archive ..." - unzip -q -o *.zip && ok_msg "Done!" - - ### delete downloaded zip - status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" -} - -set_upstream_nginx_cfg(){ - get_date - ### backup existing nginx configs - [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" - [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" - [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" - ### transfer ownership of backed up files from root to ${USER} - for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/$log" - done - ### copy nginx configs to target destination - if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "${NGINX_CONFD}" - fi - if [ ! -f "${NGINX_CONFD}/common_vars.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "${NGINX_CONFD}" - fi -} - -fetch_webui_ports(){ - ### read listen ports from possible installed interfaces - ### and write them to ~/.kiauh.ini - WEBIFS=(mainsail fluidd octoprint) - for interface in "${WEBIFS[@]}"; do - if [ -f "/etc/nginx/sites-available/${interface}" ]; then - port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) - if [ ! -n "$(grep -E "${interface}_port" "${INI_FILE}")" ]; then - sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" - else - sed -i "/^${interface}_port/d" "${INI_FILE}" - sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" - fi - else - sed -i "/^${interface}_port/d" "${INI_FILE}" - fi - done -} - -match_nginx_configs(){ - ### reinstall nginx configs if the amount of upstreams don't match anymore - source_kiauh_ini - cfg_updated="false" - mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" - fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" - upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) - status_msg "Checking validity of NGINX configurations ..." - if [ -e "${mainsail_nginx_cfg}" ]; then - mainsail_webcams=$(grep -E "mjpgstreamer" "${mainsail_nginx_cfg}" | wc -l) - fi - if [ -e "${fluidd_nginx_cfg}" ]; then - fluidd_webcams=$(grep -E "mjpgstreamer" "${fluidd_nginx_cfg}" | wc -l) - fi - ### check for outdated upstreams.conf - if [[ "${upstreams_webcams}" -lt "${mainsail_webcams}" ]] || [[ "${upstreams_webcams}" -lt "${fluidd_webcams}" ]]; then - status_msg "Outdated upstreams.conf found! Updating ..." - sudo rm -f "${NGINX_CONFD}/upstreams.conf" - sudo rm -f "${NGINX_CONFD}/common_vars.conf" - set_upstream_nginx_cfg - cfg_updated="true" - fi - ### check for outdated mainsail config - if [ -e "${mainsail_nginx_cfg}" ]; then - if [[ "${upstreams_webcams}" -gt "${mainsail_webcams}" ]]; then - status_msg "Outdated Mainsail config found! Updating ..." - sudo rm -f "${mainsail_nginx_cfg}" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}" - sudo sed -i "s/<>/mainsail/g" "${mainsail_nginx_cfg}" - sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}" - sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}" - cfg_updated="true" && ok_msg "Done!" - fi - fi - ### check for outdated fluidd config - if [ -e "${fluidd_nginx_cfg}" ]; then - if [[ "${upstreams_webcams}" -gt "${fluidd_webcams}" ]]; then - status_msg "Outdated Fluidd config found! Updating ..." - sudo rm -f "${fluidd_nginx_cfg}" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}" - sudo sed -i "s/<>/fluidd/g" "${fluidd_nginx_cfg}" - sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}" - sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}" - cfg_updated="true" && ok_msg "Done!" - fi - fi - ### only restart nginx if configs were updated - if [ "${cfg_updated}" == "true" ]; then - restart_nginx && unset cfg_updated - fi -} - -process_octoprint_dialog(){ - #ask user to disable octoprint when its service was found - if [ "${OCTOPRINT_ENABLED}" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" - hr - echo -e "| You might consider disabling the OctoPrint service, |" - echo -e "| since an active OctoPrint service may lead to unex- |" - echo -e "| pected behavior of the Klipper Webinterfaces. |" - bottom_border - read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Stopping OctoPrint ..." - do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!" - status_msg "Disabling OctoPrint ..." - do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!" - break;; - N|n|No|no) - echo -e "###### > No" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -} - -process_disruptive_services(){ - #handle haproxy service - if [ "${DISABLE_HAPROXY}" = "true" ] || [ "${REMOVE_HAPROXY}" = "true" ]; then - if systemctl is-active haproxy -q; then - status_msg "Stopping haproxy service ..." - sudo systemctl stop haproxy && ok_msg "Service stopped!" - fi - - ### disable haproxy - if [ "${DISABLE_HAPROXY}" = "true" ]; then - status_msg "Disabling haproxy ..." - sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" - - ### remove haproxy - if [ "${REMOVE_HAPROXY}" = "true" ]; then - status_msg "Removing haproxy ..." - sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" - fi - fi - fi - - ### handle lighttpd service - if [ "${DISABLE_LIGHTTPD}" = "true" ] || [ "${REMOVE_LIGHTTPD}" = "true" ]; then - if systemctl is-active lighttpd -q; then - status_msg "Stopping lighttpd service ..." - sudo systemctl stop lighttpd && ok_msg "Service stopped!" - fi - - ### disable lighttpd - if [ "${DISABLE_LIGHTTPD}" = "true" ]; then - status_msg "Disabling lighttpd ..." - sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" - - ### remove lighttpd - if [ "${REMOVE_LIGHTTPD}" = "true" ]; then - status_msg "Removing lighttpd ..." - sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" - fi - fi - fi - - ### handle apache2 service - if [ "${DISABLE_APACHE2}" = "true" ] || [ "${REMOVE_APACHE2}" = "true" ]; then - if systemctl is-active apache2 -q; then - status_msg "Stopping apache2 service ..." - sudo systemctl stop apache2 && ok_msg "Service stopped!" - fi - - ### disable lighttpd - if [ "${DISABLE_APACHE2}" = "true" ]; then - status_msg "Disabling lighttpd ..." - sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!" - - ### remove lighttpd - if [ "${REMOVE_APACHE2}" = "true" ]; then - status_msg "Removing apache2 ..." - sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!" - fi - fi - fi -} - -process_services_dialog(){ - #notify user about haproxy or lighttpd services found and possible issues - if [ "${HAPROXY_FOUND}" = "true" ] || [ "${LIGHTTPD_FOUND}" = "true" ] || [ "${APACHE2_FOUND}" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" - hr - if [ "${HAPROXY_FOUND}" = "true" ]; then - echo -e "| ● haproxy |" - fi - if [ "${LIGHTTPD_FOUND}" = "true" ]; then - echo -e "| ● lighttpd |" - fi - if [ "${APACHE2_FOUND}" = "true" ]; then - echo -e "| ● apache2 |" - fi - hr - echo -e "| Having those packages installed can lead to unwanted |" - echo -e "| behaviour. It is recommend to remove those packages. |" - echo -e "| |" - echo -e "| 1) Remove packages (recommend) |" - echo -e "| 2) Disable only (may cause issues) |" - echo -e "| ${red}3) Skip this step (not recommended)${default} |" - bottom_border - read -p "${cyan}###### Please choose:${default} " action - case "${action}" in - 1) - echo -e "###### > Remove packages" - REMOVE_HAPROXY="true" - REMOVE_LIGHTTPD="true" - REMOVE_APACHE2="true" - break;; - 2) - echo -e "###### > Disable only" - DISABLE_HAPROXY="true" - DISABLE_LIGHTTPD="true" - DISABLE_APACHE2="true" - break;; - 3) - echo -e "###### > Skip" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -} diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh new file mode 100644 index 0000000..b58757e --- /dev/null +++ b/scripts/mainsail.sh @@ -0,0 +1,397 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +MAINSAIL_DIR="${HOME}/mainsail" +MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" +KLIPPER_CONFIG="${HOME}/klipper_config" + +#===================================================# +#================= INSTALL MAINSAIL ================# +#===================================================# + +function install_mainsail(){ + ### exit early if moonraker not found + if [ -z "$(moonraker_systemd)" ]; then + local error="Moonraker service not found!\n Please install Moonraker first!" + print_error "${error}" && return + fi + ### checking dependencies + local dep=(nginx) + dependency_check "${dep[@]}" + ### check if moonraker is already installed + system_check_webui + ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found + process_octoprint_dialog + process_services_dialog + ### process possible disruptive services + process_disruptive_services + + status_msg "Initializing Mainsail installation ..." + ### check for other enabled web interfaces + unset SET_LISTEN_PORT + detect_enabled_sites + + ### check if another site already listens to port 80 + mainsail_port_check + + ### ask user to install mjpg-streamer + if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then + get_user_selection_mjpg-streamer + fi + + ### ask user to install the recommended webinterface macros + if ! ls "${KLIPPER_CONFIG}/kiauh_macros.cfg" 2>/dev/null 1>&2 || ! ls "${KLIPPER_CONFIG}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then + get_user_selection_kiauh_macros "Mainsail " + fi + ### create /etc/nginx/conf.d/upstreams.conf + set_upstream_nginx_cfg + ### create /etc/nginx/sites-available/ + set_nginx_cfg "mainsail" + + ### symlink nginx log + symlink_webui_nginx_log "mainsail" + + ### copy the kiauh_macros.cfg to the config location + install_kiauh_macros + + ### install mainsail/fluidd + mainsail_setup + + ### install mjpg-streamer + [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer + + fetch_webui_ports #WIP + + ### confirm message + print_confirm "Mainsail has been set up!" +} + +function mainsail_setup(){ + ### get mainsail download url + MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) + + ### remove existing and create fresh mainsail folder, then download mainsail + [ -d "${MAINSAIL_DIR}" ] && rm -rf "${MAINSAIL_DIR}" + mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" + status_msg "Downloading Mainsail ${MAINSAIL_VERSION} ..." + wget "${MAINSAIL_DL_URL}" && ok_msg "Download complete!" + + ### extract archive + status_msg "Extracting archive ..." + unzip -q -o *.zip && ok_msg "Done!" + + ### delete downloaded zip + status_msg "Remove downloaded archive ..." + rm -rf *.zip && ok_msg "Done!" + + ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode + if [ $(ls /etc/systemd/system/moonraker* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then + enable_mainsail_remotemode + fi +} + +#===================================================# +#================= REMOVE MAINSAIL =================# +#===================================================# + +function remove_mainsail(){ + ### remove mainsail dir + if [ -d "${MAINSAIL_DIR}" ]; then + status_msg "Removing Mainsail directory ..." + rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!" + fi + + ### remove mainsail config for nginx + if [ -e "/etc/nginx/sites-available/mainsail" ]; then + status_msg "Removing Mainsail configuration for Nginx ..." + sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!" + fi + + ### remove mainsail symlink for nginx + if [ -L "/etc/nginx/sites-enabled/mainsail" ]; then + status_msg "Removing Mainsail Symlink for Nginx ..." + sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!" + fi + + ### remove mainsail nginx logs and log symlinks + for log in $(find /var/log/nginx -name "mainsail*"); do + sudo rm -f "${log}" + done + for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do + rm -f "${log}" + done + + ### remove mainsail_port from ~/.kiauh.ini + sed -i "/^mainsail_port=/d" "${INI_FILE}" + + print_confirm "Mainsail successfully removed!" +} + +#===================================================# +#================= UPDATE MAINSAIL =================# +#===================================================# + +function update_mainsail(){ + bb4u "mainsail" + status_msg "Updating Mainsail ..." + mainsail_setup + match_nginx_configs + symlink_webui_nginx_log "mainsail" +} + +#===================================================# +#================= MAINSAIL STATUS =================# +#===================================================# + +function get_mainsail_ver(){ + MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) +} + +function mainsail_status(){ + mcount=0 + mainsail_data=( + $MAINSAIL_DIR + $NGINX_SA/mainsail + $NGINX_SE/mainsail + ) + #count+1 for each found data-item from array + for md in "${mainsail_data[@]}" + do + if [ -e $md ]; then + mcount=$(expr $mcount + 1) + fi + done + if [ "$mcount" == "${#mainsail_data[*]}" ]; then + MAINSAIL_STATUS="${green}Installed!${default} " + elif [ "$mcount" == 0 ]; then + MAINSAIL_STATUS="${red}Not installed!${default} " + else + MAINSAIL_STATUS="${yellow}Incomplete!${default} " + fi +} + +function read_local_mainsail_version(){ + unset MAINSAIL_VER_FOUND + if [ -e "${MAINSAIL_DIR}/.version" ]; then + MAINSAIL_VER_FOUND="true" + MAINSAIL_LOCAL_VER=$(head -n 1 "${MAINSAIL_DIR}/.version") + else + MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER + fi +} + +function read_remote_mainsail_version(){ + #remote checks don't work without curl installed! + if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then + MAINSAIL_REMOTE_VER=$NONE + else + get_mainsail_ver + MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION + fi +} + +function compare_mainsail_versions(){ + unset MAINSAIL_UPDATE_AVAIL + read_local_mainsail_version && read_remote_mainsail_version + if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then + #printf fits the string for displaying it in the ui to a total char length of 12 + MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then + MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + # add mainsail to the update all array for the update all function in the updater + MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) + else + MAINSAIL_LOCAL_VER=$NONE + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_UPDATE_AVAIL="false" + fi +} + +#================================================# +#=========== MAINSAIL THEME INSTALLER ===========# +#================================================# + +function get_theme_list(){ + theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" + theme_csv=$(curl -s -L $theme_csv_url) + unset t_name + unset t_note + unset t_auth + unset t_url + i=0 + while IFS="," read -r col1 col2 col3 col4; do + t_name+=("$col1") + t_note+=("$col2") + t_auth+=("$col3") + t_url+=("$col4") + if [ ! "$col1" == "name" ]; then + printf "| $i) %-50s|\n" "[$col1]" + fi + i=$((i+1)) + done <<< "$theme_csv" +} + +function ms_theme_ui(){ + top_border + echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " + hr + echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " + echo -e "| https://docs.mainsail.xyz/theming/themes | " + blank_line + echo -e "| ${yellow}Important note:${default} | " + echo -e "| Installing a theme from this menu will overwrite an | " + echo -e "| already installed theme or modified custom.css file! | " + hr + get_theme_list # dynamically generate the themelist from a csv file + echo -e "| | " + echo -e "| R) [Remove Theme] | " + back_footer +} + +function ms_theme_menu(){ + ms_theme_ui + while true; do + read -p "${cyan}Install theme:${default} " a; echo + if [ "$a" = "b" ] || [ "$a" = "B" ]; then + clear && advanced_menu && break + elif [ "$a" = "r" ] || [ "$a" = "R" ]; then + ms_theme_delete + ms_theme_menu + elif [ "$a" -le ${#t_url[@]} ]; then + ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" + ms_theme_menu + else + clear && print_header + ERROR_MSG="Invalid command!" && print_msg && clear_msg + ms_theme_menu + fi + done + ms_theme_menu +} + +function check_select_printer(){ + unset printer_num + + ### get klipper cfg loc and set default .theme folder loc + check_klipper_cfg_path + THEME_PATH="$klipper_cfg_loc" + + ### check if there is more than one moonraker instance and if yes + ### ask the user to select the printer he wants to install/remove the theme + MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l) + if [[ $MR_SERVICE_COUNT -gt 1 ]]; then + top_border + echo -e "| More than one printer was found on this system! | " + echo -e "| Please select the printer to which you want to | " + echo -e "| apply the previously selected action. | " + bottom_border + read -p "${cyan}Select printer:${default} " printer_num + + ### rewrite the .theme path matching the selected printer + THEME_PATH="$klipper_cfg_loc/printer_$printer_num" + fi + + ### create the cfg folder if there is none yet + [ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH" +} + +function ms_theme_install(){ + THEME_URL="https://github.com/$1/$2" + + ### check and select printer if there is more than 1 + check_select_printer + + ### download all files + status_msg "Installing $3 ..." + status_msg "Please wait ..." + + [ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme" + cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" + + ok_msg "Theme installation complete!" + [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}" + ok_msg "Please remember to delete your browser cache!\n" +} + +function ms_theme_delete(){ + check_select_printer + if [ -d "$THEME_PATH/.theme" ]; then + status_msg "Removing Theme ..." + rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n" + else + status_msg "No Theme installed!\n" + fi +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +function mainsail_port_check(){ + if [ "${MAINSAIL_ENABLED}" = "false" ]; then + if [ "${SITE_ENABLED}" = "true" ]; then + status_msg "Detected other enabled interfaces:" + [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" + [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${default}" + if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then + PORT_80_BLOCKED="true" + select_mainsail_port + fi + else + DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + SET_LISTEN_PORT=${DEFAULT_PORT} + fi + SET_NGINX_CFG="true" + else + SET_NGINX_CFG="false" + fi +} + +function select_mainsail_port(){ + if [ "${PORT_80_BLOCKED}" = "true" ]; then + echo + top_border + echo -e "| ${red}!!!WARNING!!!${default} |" + echo -e "| ${red}You need to choose a different port for Mainsail!${default} |" + echo -e "| ${red}The following web interface is listening at port 80:${default} |" + blank_line + [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" + [ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| use ports in the range of 4750 or above! |" + blank_line + echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| input. So make sure to choose a valid port! |" + bottom_border + while true; do + read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then + echo "Setting port ${NEW_PORT} for Mainsail!" + SET_LISTEN_PORT=${NEW_PORT} + break + else + echo "That port is already taken! Select a different one!" + fi + done + fi +} + +function enable_mainsail_remotemode(){ + rm -f "${MAINSAIL_DIR}/config.json" + echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" +} \ No newline at end of file diff --git a/scripts/ms_theme_installer.sh b/scripts/ms_theme_installer.sh deleted file mode 100755 index 0346366..0000000 --- a/scripts/ms_theme_installer.sh +++ /dev/null @@ -1,114 +0,0 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" - -get_theme_list(){ - theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" - theme_csv=$(curl -s -L $theme_csv_url) - unset t_name - unset t_note - unset t_auth - unset t_url - i=0 - while IFS="," read -r col1 col2 col3 col4; do - t_name+=("$col1") - t_note+=("$col2") - t_auth+=("$col3") - t_url+=("$col4") - if [ ! "$col1" == "name" ]; then - printf "| $i) %-50s|\n" "[$col1]" - fi - i=$((i+1)) - done <<< "$theme_csv" -} - -ms_theme_ui(){ - top_border - echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " - hr - echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " - echo -e "| https://docs.mainsail.xyz/theming/themes | " - blank_line - echo -e "| ${yellow}Important note:${default} | " - echo -e "| Installing a theme from this menu will overwrite an | " - echo -e "| already installed theme or modified custom.css file! | " - hr - get_theme_list # dynamically generate the themelist from a csv file - echo -e "| | " - echo -e "| R) [Remove Theme] | " - back_footer -} - -ms_theme_menu(){ - ms_theme_ui - while true; do - read -p "${cyan}Install theme:${default} " a; echo - if [ "$a" = "b" ] || [ "$a" = "B" ]; then - clear && advanced_menu && break - elif [ "$a" = "r" ] || [ "$a" = "R" ]; then - ms_theme_delete - ms_theme_menu - elif [ "$a" -le ${#t_url[@]} ]; then - ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" - ms_theme_menu - else - clear && print_header - ERROR_MSG="Invalid command!" && print_msg && clear_msg - ms_theme_menu - fi - done - ms_theme_menu -} - -check_select_printer(){ - unset printer_num - - ### get klipper cfg loc and set default .theme folder loc - check_klipper_cfg_path - THEME_PATH="$klipper_cfg_loc" - - ### check if there is more than one moonraker instance and if yes - ### ask the user to select the printer he wants to install/remove the theme - MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l) - if [[ $MR_SERVICE_COUNT -gt 1 ]]; then - top_border - echo -e "| More than one printer was found on this system! | " - echo -e "| Please select the printer to which you want to | " - echo -e "| apply the previously selected action. | " - bottom_border - read -p "${cyan}Select printer:${default} " printer_num - - ### rewrite the .theme path matching the selected printer - THEME_PATH="$klipper_cfg_loc/printer_$printer_num" - fi - - ### create the cfg folder if there is none yet - [ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH" -} - -ms_theme_install(){ - THEME_URL="https://github.com/$1/$2" - - ### check and select printer if there is more than 1 - check_select_printer - - ### download all files - status_msg "Installing $3 ..." - status_msg "Please wait ..." - - [ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme" - cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" - - ok_msg "Theme installation complete!" - [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}" - ok_msg "Please remember to delete your browser cache!\n" -} - -ms_theme_delete(){ - check_select_printer - if [ -d "$THEME_PATH/.theme" ]; then - status_msg "Removing Theme ..." - rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n" - else - status_msg "No Theme installed!\n" - fi -} diff --git a/scripts/remove.sh b/scripts/remove.sh deleted file mode 100755 index 6e8fa6c..0000000 --- a/scripts/remove.sh +++ /dev/null @@ -1,89 +0,0 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" - -############################################################# -############################################################# - -remove_mainsail(){ - ### remove mainsail dir - if [ -d $MAINSAIL_DIR ]; then - status_msg "Removing Mainsail directory ..." - rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!" - fi - - ### remove mainsail config for nginx - if [ -e /etc/nginx/sites-available/mainsail ]; then - status_msg "Removing Mainsail configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!" - fi - - ### remove mainsail symlink for nginx - if [ -L /etc/nginx/sites-enabled/mainsail ]; then - status_msg "Removing Mainsail Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!" - fi - - ### remove mainsail nginx logs and log symlinks - for log in $(find /var/log/nginx -name "mainsail*"); do - sudo rm -f $log - done - for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do - rm -f $log - done - - ### remove mainsail_port from ~/.kiauh.ini - sed -i "/^mainsail_port=/d" $INI_FILE - - CONFIRM_MSG="Mainsail successfully removed!" -} - -remove_fluidd(){ - ### remove fluidd dir - if [ -d $FLUIDD_DIR ]; then - status_msg "Removing Fluidd directory ..." - rm -rf $FLUIDD_DIR && ok_msg "Directory removed!" - fi - - ### remove fluidd config for nginx - if [ -e /etc/nginx/sites-available/fluidd ]; then - status_msg "Removing Fluidd configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!" - fi - - ### remove fluidd symlink for nginx - if [ -L /etc/nginx/sites-enabled/fluidd ]; then - status_msg "Removing Fluidd Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" - fi - - ### remove mainsail nginx logs and log symlinks - for log in $(find /var/log/nginx -name "fluidd*"); do - sudo rm -f $log - done - for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do - rm -f $log - done - - ### remove fluidd_port from ~/.kiauh.ini - sed -i "/^fluidd_port=/d" $INI_FILE - - CONFIRM_MSG="Fluidd successfully removed!" -} - - -############################################################# -############################################################# - -remove_nginx(){ - if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then - status_msg "Stopping Nginx service ..." - sudo systemctl stop nginx && sudo systemctl disable nginx - ok_msg "Service stopped and disabled!" - status_msg "Purging Nginx from system ..." - sudo apt-get purge nginx nginx-common -y - sudo update-rc.d -f nginx remove - CONFIRM_MSG=" Nginx successfully removed!" - else - ERROR_MSG=" Looks like Nginx was already removed!\n Skipping..." - fi -} diff --git a/scripts/status.sh b/scripts/status.sh index 5048cef..c3a1fad 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -22,130 +22,6 @@ check_system_updates(){ fi } -mainsail_status(){ - mcount=0 - mainsail_data=( - $MAINSAIL_DIR - $NGINX_SA/mainsail - $NGINX_SE/mainsail - ) - #count+1 for each found data-item from array - for md in "${mainsail_data[@]}" - do - if [ -e $md ]; then - mcount=$(expr $mcount + 1) - fi - done - if [ "$mcount" == "${#mainsail_data[*]}" ]; then - MAINSAIL_STATUS="${green}Installed!${default} " - elif [ "$mcount" == 0 ]; then - MAINSAIL_STATUS="${red}Not installed!${default} " - else - MAINSAIL_STATUS="${yellow}Incomplete!${default} " - fi -} - -fluidd_status(){ - fcount=0 - fluidd_data=( - $FLUIDD_DIR - $NGINX_SA/fluidd - $NGINX_SE/fluidd - ) - #count+1 for each found data-item from array - for fd in "${fluidd_data[@]}" - do - if [ -e $fd ]; then - fcount=$(expr $fcount + 1) - fi - done - if [ "$fcount" == "${#fluidd_data[*]}" ]; then - FLUIDD_STATUS="${green}Installed!${default} " - elif [ "$fcount" == 0 ]; then - FLUIDD_STATUS="${red}Not installed!${default} " - else - FLUIDD_STATUS="${yellow}Incomplete!${default} " - fi -} - -read_local_mainsail_version(){ - unset MAINSAIL_VER_FOUND - if [ -e $MAINSAIL_DIR/.version ]; then - MAINSAIL_VER_FOUND="true" - MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/.version) - else - MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER - fi -} - -read_remote_mainsail_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - MAINSAIL_REMOTE_VER=$NONE - else - get_mainsail_ver - MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION - fi -} - -compare_mainsail_versions(){ - unset MAINSAIL_UPDATE_AVAIL - read_local_mainsail_version && read_remote_mainsail_version - if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" - elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then - MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" - # add mainsail to the update all array for the update all function in the updater - MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) - else - MAINSAIL_LOCAL_VER=$NONE - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" - MAINSAIL_UPDATE_AVAIL="false" - fi -} - -read_local_fluidd_version(){ - unset FLUIDD_VER_FOUND - if [ -e $FLUIDD_DIR/.version ]; then - FLUIDD_VER_FOUND="true" - FLUIDD_LOCAL_VER=$(head -n 1 $FLUIDD_DIR/.version) - else - FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER - fi -} - -read_remote_fluidd_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - FLUIDD_REMOTE_VER=$NONE - else - get_fluidd_ver - FLUIDD_REMOTE_VER=$FLUIDD_VERSION - fi -} - -compare_fluidd_versions(){ - unset FLUIDD_UPDATE_AVAIL - read_local_fluidd_version && read_remote_fluidd_version - if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - FLUIDD_LOCAL_VER="${green}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then - FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - # add fluidd to the update all array for the update all function in the updater - FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) - else - FLUIDD_LOCAL_VER=$NONE - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - FLUIDD_UPDATE_AVAIL="false" - fi -} - ############################################################# ############################################################# diff --git a/scripts/update.sh b/scripts/update.sh index b08c83e..b6828fe 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -110,22 +110,6 @@ update_log_paths(){ shopt -u extglob # disable extended globbing } -update_mainsail(){ - bb4u "mainsail" - status_msg "Updating Mainsail ..." - mainsail_setup - match_nginx_configs - symlink_webui_nginx_log "mainsail" -} - -update_fluidd(){ - bb4u "fluidd" - status_msg "Updating Fluidd ..." - fluidd_setup - match_nginx_configs - symlink_webui_nginx_log "fluidd" -} - update_system(){ status_msg "Updating System ..." sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y From af34b363efe3bc68154c7c86b7813fedbce2d912 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:34:29 +0200 Subject: [PATCH 044/183] refactor(nginx.sh): refactor nginx functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/nginx.sh | 236 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 scripts/nginx.sh diff --git a/scripts/nginx.sh b/scripts/nginx.sh new file mode 100644 index 0000000..3d015e6 --- /dev/null +++ b/scripts/nginx.sh @@ -0,0 +1,236 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +#===================================================# +#=================== REMOVE NGINX ==================# +#===================================================# + +remove_nginx(){ + if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then + status_msg "Stopping Nginx service ..." + sudo systemctl stop nginx && sudo systemctl disable nginx + ok_msg "Service stopped and disabled!" + status_msg "Purging Nginx from system ..." + sudo apt-get purge nginx nginx-common -y + sudo update-rc.d -f nginx remove + print_confirm "Nginx successfully removed!" + else + print_error "Looks like Nginx was already removed!\n Skipping..." + fi +} + +#===================================================# +#===================== HELPERS =====================# +#===================================================# + +function set_upstream_nginx_cfg(){ + get_date + ### backup existing nginx configs + [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" + [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" + [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" + ### transfer ownership of backed up files from root to ${USER} + for log in $(ls "$BACKUP_DIR/nginx_cfg"); do + sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/$log" + done + ### copy nginx configs to target destination + if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then + sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "${NGINX_CONFD}" + fi + if [ ! -f "${NGINX_CONFD}/common_vars.conf" ]; then + sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "${NGINX_CONFD}" + fi +} + +function symlink_webui_nginx_log(){ + local LPATH="${HOME}/klipper_logs" + local UI_ACCESS_LOG="/var/log/nginx/${1}-access.log" + local UI_ERROR_LOG="/var/log/nginx/${1}-error.log" + [ ! -d "${LPATH}" ] && mkdir -p "${LPATH}" + if [ -f "${UI_ACCESS_LOG}" ] && [ ! -L "${LPATH}/${1}-access.log" ]; then + status_msg "Creating symlink for ${UI_ACCESS_LOG} ..." + ln -s "${UI_ACCESS_LOG}" "${LPATH}" + ok_msg "OK!" + fi + if [ -f "${UI_ERROR_LOG}" ] && [ ! -L "${LPATH}/${1}-error.log" ]; then + status_msg "Creating symlink for ${UI_ERROR_LOG} ..." + ln -s "${UI_ERROR_LOG}" "${LPATH}" + ok_msg "OK!" + fi +} + +function match_nginx_configs(){ + ### reinstall nginx configs if the amount of upstreams don't match anymore + source_kiauh_ini + cfg_updated="false" + mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" + fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" + upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) + status_msg "Checking validity of NGINX configurations ..." + if [ -e "${mainsail_nginx_cfg}" ]; then + mainsail_webcams=$(grep -E "mjpgstreamer" "${mainsail_nginx_cfg}" | wc -l) + fi + if [ -e "${fluidd_nginx_cfg}" ]; then + fluidd_webcams=$(grep -E "mjpgstreamer" "${fluidd_nginx_cfg}" | wc -l) + fi + ### check for outdated upstreams.conf + if [[ "${upstreams_webcams}" -lt "${mainsail_webcams}" ]] || [[ "${upstreams_webcams}" -lt "${fluidd_webcams}" ]]; then + status_msg "Outdated upstreams.conf found! Updating ..." + sudo rm -f "${NGINX_CONFD}/upstreams.conf" + sudo rm -f "${NGINX_CONFD}/common_vars.conf" + set_upstream_nginx_cfg + cfg_updated="true" + fi + ### check for outdated mainsail config + if [ -e "${mainsail_nginx_cfg}" ]; then + if [[ "${upstreams_webcams}" -gt "${mainsail_webcams}" ]]; then + status_msg "Outdated Mainsail config found! Updating ..." + sudo rm -f "${mainsail_nginx_cfg}" + sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}" + sudo sed -i "s/<>/mainsail/g" "${mainsail_nginx_cfg}" + sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}" + sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}" + sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}" + cfg_updated="true" && ok_msg "Done!" + fi + fi + ### check for outdated fluidd config + if [ -e "${fluidd_nginx_cfg}" ]; then + if [[ "${upstreams_webcams}" -gt "${fluidd_webcams}" ]]; then + status_msg "Outdated Fluidd config found! Updating ..." + sudo rm -f "${fluidd_nginx_cfg}" + sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}" + sudo sed -i "s/<>/fluidd/g" "${fluidd_nginx_cfg}" + sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}" + sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}" + sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}" + cfg_updated="true" && ok_msg "Done!" + fi + fi + ### only restart nginx if configs were updated + if [ "${cfg_updated}" == "true" ]; then + restart_nginx && unset cfg_updated + fi +} + +function process_disruptive_services(){ + #handle haproxy service + if [ "${DISABLE_HAPROXY}" = "true" ] || [ "${REMOVE_HAPROXY}" = "true" ]; then + if systemctl is-active haproxy -q; then + status_msg "Stopping haproxy service ..." + sudo systemctl stop haproxy && ok_msg "Service stopped!" + fi + + ### disable haproxy + if [ "${DISABLE_HAPROXY}" = "true" ]; then + status_msg "Disabling haproxy ..." + sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" + + ### remove haproxy + if [ "${REMOVE_HAPROXY}" = "true" ]; then + status_msg "Removing haproxy ..." + sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" + fi + fi + fi + + ### handle lighttpd service + if [ "${DISABLE_LIGHTTPD}" = "true" ] || [ "${REMOVE_LIGHTTPD}" = "true" ]; then + if systemctl is-active lighttpd -q; then + status_msg "Stopping lighttpd service ..." + sudo systemctl stop lighttpd && ok_msg "Service stopped!" + fi + + ### disable lighttpd + if [ "${DISABLE_LIGHTTPD}" = "true" ]; then + status_msg "Disabling lighttpd ..." + sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" + + ### remove lighttpd + if [ "${REMOVE_LIGHTTPD}" = "true" ]; then + status_msg "Removing lighttpd ..." + sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" + fi + fi + fi + + ### handle apache2 service + if [ "${DISABLE_APACHE2}" = "true" ] || [ "${REMOVE_APACHE2}" = "true" ]; then + if systemctl is-active apache2 -q; then + status_msg "Stopping apache2 service ..." + sudo systemctl stop apache2 && ok_msg "Service stopped!" + fi + + ### disable lighttpd + if [ "${DISABLE_APACHE2}" = "true" ]; then + status_msg "Disabling lighttpd ..." + sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!" + + ### remove lighttpd + if [ "${REMOVE_APACHE2}" = "true" ]; then + status_msg "Removing apache2 ..." + sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!" + fi + fi + fi +} + +function process_services_dialog(){ + #notify user about haproxy or lighttpd services found and possible issues + if [ "${HAPROXY_FOUND}" = "true" ] || [ "${LIGHTTPD_FOUND}" = "true" ] || [ "${APACHE2_FOUND}" = "true" ]; then + while true; do + echo + top_border + echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" + hr + if [ "${HAPROXY_FOUND}" = "true" ]; then + echo -e "| ● haproxy |" + fi + if [ "${LIGHTTPD_FOUND}" = "true" ]; then + echo -e "| ● lighttpd |" + fi + if [ "${APACHE2_FOUND}" = "true" ]; then + echo -e "| ● apache2 |" + fi + hr + echo -e "| Having those packages installed can lead to unwanted |" + echo -e "| behaviour. It is recommend to remove those packages. |" + echo -e "| |" + echo -e "| 1) Remove packages (recommend) |" + echo -e "| 2) Disable only (may cause issues) |" + echo -e "| ${red}3) Skip this step (not recommended)${default} |" + bottom_border + read -p "${cyan}###### Please choose:${default} " action + case "${action}" in + 1) + echo -e "###### > Remove packages" + REMOVE_HAPROXY="true" + REMOVE_LIGHTTPD="true" + REMOVE_APACHE2="true" + break;; + 2) + echo -e "###### > Disable only" + DISABLE_HAPROXY="true" + DISABLE_LIGHTTPD="true" + DISABLE_APACHE2="true" + break;; + 3) + echo -e "###### > Skip" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + fi +} \ No newline at end of file From 6b5ba42a97ff3729a1a05b951f965666709dad08 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:34:46 +0200 Subject: [PATCH 045/183] style: add copyright header Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/install_menu.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 813e527..a7d27c7 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + install_ui(){ top_border echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | " @@ -29,9 +42,9 @@ install_menu(){ 2) do_action "moonraker_setup_dialog" "install_ui";; 3) - do_action "install_webui mainsail" "install_ui";; + do_action "install_mainsail" "install_ui";; 4) - do_action "install_webui fluidd" "install_ui";; + do_action "install_fluidd" "install_ui";; 5) do_action "install_klipperscreen" "install_ui";; 6) From aaa82e6097eb6e3e4c7ee60a29a306efc2e31747 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:35:04 +0200 Subject: [PATCH 046/183] style: remove comments Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index edc0b94..e7b6dfa 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -51,10 +51,6 @@ function read_bb4u_stat(){ fi } -################################################################################ -#******************************************************************************# -################################################################################ - function backup_printer_cfg(){ check_for_backup_dir if [ -f "${PRINTER_CFG}" ]; then From aa2639a7d2211cda931255b4772fe464913054f8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:35:34 +0200 Subject: [PATCH 047/183] refactor: remove redundant global variables Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index ebf6130..e82adfc 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -29,10 +29,6 @@ for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . "${script}"; done NGINX_SA=/etc/nginx/sites-available NGINX_SE=/etc/nginx/sites-enabled NGINX_CONFD=/etc/nginx/conf.d -#mainsail -MAINSAIL_DIR=${HOME}/mainsail -#fluidd -FLUIDD_DIR=${HOME}/fluidd #misc INI_FILE=${HOME}/.kiauh.ini From 6d7bda0d174123dd3c1259351a75028c86fc773e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:36:00 +0200 Subject: [PATCH 048/183] refactor: utilities Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 185 ++++++++++++++++++++++++++++++++----------- 1 file changed, 139 insertions(+), 46 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index d6fa4fb..dcfe364 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -190,34 +190,6 @@ do_action_service(){ shopt -u extglob # disable extended globbing } -toggle_octoprint_service(){ - if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then - do_action_service "stop" "octoprint" - do_action_service "disable" "octoprint" - sleep 2 - CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !" - elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then - do_action_service "enable" "octoprint" - do_action_service "start" "octoprint" - sleep 2 - CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !" - else - ERROR_MSG=" You cannot activate a service that does not exist!" - fi -} - -read_octoprint_service_status(){ - unset OPRINT_SERVICE_STATUS - if [ ! -f "/etc/systemd/system/octoprint.service" ]; then - return 0 - fi - if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then - OPRINT_SERVICE_STATUS="${red}[Disable]${white} OctoPrint Service " - else - OPRINT_SERVICE_STATUS="${green}[Enable]${white} OctoPrint Service " - fi -} - start_klipperscreen(){ status_msg "Starting KlipperScreen Service ..." sudo systemctl start KlipperScreen && ok_msg "KlipperScreen Service started!" @@ -374,27 +346,148 @@ install_gcode_shell_command(){ do_action_service "restart" "klipper" } -create_minimal_cfg(){ - #create a minimal default config - if [ "${SEL_DEF_CFG}" = "true" ]; then - cat <<- EOF >> "${PRINTER_CFG}" - [mcu] - serial: - - [printer] - kinematics: none - max_velocity: 1 - max_accel: 1 - - [virtual_sdcard] - path: ~/sdcard - - [pause_resume] - [display_status] -EOF +function install_kiauh_macros(){ + ### copy kiauh_macros.cfg + if [ "${ADD_KIAUH_MACROS}" = "true" ]; then + ### create a backup of the config folder + backup_klipper_config_dir + ### handle multi printer.cfg + if ls "${KLIPPER_CONFIG}"/printer_* 2>/dev/null 1>&2; then + for config in $(find ${KLIPPER_CONFIG}/printer_*/printer.cfg); do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/kiauh_macros.cfg" ]; then + ### copy kiauh_macros.cfg to config location + status_msg "Creating macro config file ..." + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" + ok_msg "${path}/kiauh_macros.cfg created!" + fi + done + ### handle single printer.cfg + elif [ -f "${KLIPPER_CONFIG}/printer.cfg" ] && [ ! -f "${KLIPPER_CONFIG}/kiauh_macros.cfg" ]; then + ### copy kiauh_macros.cfg to config location + status_msg "Creating macro config file ..." + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${KLIPPER_CONFIG}" + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" "${KLIPPER_CONFIG}/printer.cfg" + ok_msg "${KLIPPER_CONFIG}/kiauh_macros.cfg created!" + fi + ### restart klipper service to parse the modified printer.cfg + do_action_service "restart" "klipper" fi } +function system_check_webui(){ + ### check system for an installed and enabled octoprint service + if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then + OCTOPRINT_ENABLED="true" + fi + + ### check system for an installed haproxy service + if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then + HAPROXY_FOUND="true" + fi + + ### check system for an installed lighttpd service + if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then + LIGHTTPD_FOUND="true" + fi + + ### check system for an installed apache2 service + if [[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]]; then + APACHE2_FOUND="true" + fi +} + +function get_user_selection_kiauh_macros(){ + #ask user for webui default macros + while true; do + unset ADD_KIAUH_MACROS + echo + top_border + echo -e "| It is recommended to have some important macros set |" + echo -e "| up in your printer configuration to have $1|" + echo -e "| fully functional and working. |" + blank_line + echo -e "| Those macros are: |" + echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |" + echo -e "| ${cyan}● [gcode_macro RESUME]${default} |" + echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |" + blank_line + echo -e "| If you already have these macros in your config file |" + echo -e "| you can skip this step and choose 'no'. |" + echo -e "| Otherwise you should consider to answer with 'yes' to |" + echo -e "| add the recommended example macros to your config. |" + bottom_border + read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn + case "${yn}" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + ADD_KIAUH_MACROS="true" + break;; + N|n|No|no) + echo -e "###### > No" + ADD_KIAUH_MACROS="false" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done +} + +function process_octoprint_dialog(){ + #ask user to disable octoprint when its service was found + if [ "${OCTOPRINT_ENABLED}" = "true" ]; then + while true; do + echo + top_border + echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" + hr + echo -e "| You might consider disabling the OctoPrint service, |" + echo -e "| since an active OctoPrint service may lead to unex- |" + echo -e "| pected behavior of the Klipper Webinterfaces. |" + bottom_border + read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn + case "${yn}" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + status_msg "Stopping OctoPrint ..." + do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!" + status_msg "Disabling OctoPrint ..." + do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!" + break;; + N|n|No|no) + echo -e "###### > No" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + fi +} + +function fetch_webui_ports(){ + ### read listen ports from possible installed interfaces + ### and write them to ~/.kiauh.ini + WEBIFS=(mainsail fluidd octoprint) + for interface in "${WEBIFS[@]}"; do + if [ -f "/etc/nginx/sites-available/${interface}" ]; then + port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) + if [ ! -n "$(grep -E "${interface}_port" "${INI_FILE}")" ]; then + sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" + else + sed -i "/^${interface}_port/d" "${INI_FILE}" + sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" + fi + else + sed -i "/^${interface}_port/d" "${INI_FILE}" + fi + done +} + init_ini(){ ### copy an existing kiauh.ini to its new location to keep all possible saved values if [ -f "${SRCDIR}/kiauh/kiauh.ini" ] && [ ! -f "${INI_FILE}" ]; then From 588061a4c4c1850aeecf0950f895858f60f566e8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:36:20 +0200 Subject: [PATCH 049/183] refactor: octoprint Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 7d5913f..7807c29 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -371,3 +371,35 @@ octoprint_status(){ OCTOPRINT_STATUS="${yellow}Incomplete!${default} " fi } + +read_octoprint_service_status(){ + unset OPRINT_SERVICE_STATUS + if [ ! -f "/etc/systemd/system/octoprint.service" ]; then + return 0 + fi + if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then + OPRINT_SERVICE_STATUS="${red}[Disable]${white} OctoPrint Service " + else + OPRINT_SERVICE_STATUS="${green}[Enable]${white} OctoPrint Service " + fi +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +toggle_octoprint_service(){ + if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then + do_action_service "stop" "octoprint" + do_action_service "disable" "octoprint" + sleep 2 + CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !" + elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then + do_action_service "enable" "octoprint" + do_action_service "start" "octoprint" + sleep 2 + CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !" + else + ERROR_MSG=" You cannot activate a service that does not exist!" + fi +} From 36bef73d67e86787dc0b017cb13c6cd4c3782bea Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:36:39 +0200 Subject: [PATCH 050/183] style: add function keyword Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 2 +- scripts/klipperscreen.sh | 16 ++++++++-------- scripts/mjpg-streamer.sh | 28 ++++++++++++++++++++++++++-- scripts/moonraker-telegram-bot.sh | 14 +++++++------- scripts/network_functions.sh | 12 ++++++------ scripts/pretty_gcode.sh | 10 +++++----- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index 1f9409c..fa2e721 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -295,7 +295,7 @@ retrieve_id(){ fi 2>/dev/null } -check_usergroup_dialout(){ +function check_usergroup_dialout(){ if grep -q "dialout" Yes" + INSTALL_MJPG="true" + break;; + N|n|No|no) + echo -e "###### > No" + INSTALL_MJPG="false" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done +} + #=================================================# #============== REMOVE MJPG-STREAMER =============# #=================================================# -remove_mjpg-streamer(){ +function remove_mjpg-streamer(){ ### remove MJPG-Streamer service if [ -e "${SYSTEMD}/webcamd.service" ]; then status_msg "Removing MJPG-Streamer service ..." diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 220dacf..7888aed 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -22,12 +22,12 @@ KLIPPER_CONFIG="${HOME}/klipper_config" #=========== REMOVE MOONRAKERTELEGRAMBOT ===========# #===================================================# -install_MoonrakerTelegramBot(){ +function install_MoonrakerTelegramBot(){ MoonrakerTelegramBot_setup restart_MoonrakerTelegramBot } -MoonrakerTelegramBot_setup(){ +function MoonrakerTelegramBot_setup(){ source_kiauh_ini export klipper_cfg_loc dep=(virtualenv) @@ -48,7 +48,7 @@ MoonrakerTelegramBot_setup(){ #=========== REMOVE MOONRAKERTELEGRAMBOT ===========# #===================================================# -remove_MoonrakerTelegramBot(){ +function remove_MoonrakerTelegramBot(){ ### remove MoonrakerTelegramBot dir if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]; then status_msg "Removing MoonrakerTelegramBot directory ..." @@ -93,7 +93,7 @@ remove_MoonrakerTelegramBot(){ #=========== UPDATE MOONRAKERTELEGRAMBOT ===========# #===================================================# -update_MoonrakerTelegramBot(){ +function update_MoonrakerTelegramBot(){ export KLIPPER_CONFIG stop_MoonrakerTelegramBot cd "${MOONRAKER_TELEGRAM_BOT_DIR}" @@ -107,7 +107,7 @@ update_MoonrakerTelegramBot(){ #=========== MOONRAKERTELEGRAMBOT STATUS ===========# #===================================================# -MoonrakerTelegramBot_status(){ +function MoonrakerTelegramBot_status(){ mtbcount=0 MoonrakerTelegramBot_data=( SERVICE @@ -137,7 +137,7 @@ MoonrakerTelegramBot_status(){ fi } -read_MoonrakerTelegramBot_versions(){ +function read_MoonrakerTelegramBot_versions(){ if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]; then cd "${MOONRAKER_TELEGRAM_BOT_DIR}" git fetch origin master -q @@ -149,7 +149,7 @@ read_MoonrakerTelegramBot_versions(){ fi } -compare_MoonrakerTelegramBot_versions(){ +function compare_MoonrakerTelegramBot_versions(){ unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL read_MoonrakerTelegramBot_versions if [ "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}" != "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}" ]; then diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 4ba9a52..73f312e 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -1,4 +1,4 @@ -set_nginx_cfg(){ +function set_nginx_cfg(){ if [ "$SET_NGINX_CFG" = "true" ]; then #check for dependencies dep=(nginx) @@ -36,11 +36,11 @@ set_nginx_cfg(){ fi } -read_listen_port(){ +function read_listen_port(){ LISTEN_PORT=$(grep listen /etc/nginx/sites-enabled/$1 | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) } -detect_enabled_sites(){ +function detect_enabled_sites(){ #check if there is another UI config already installed #and reads the port they are listening on if [ -e /etc/nginx/sites-enabled/mainsail ]; then @@ -69,7 +69,7 @@ detect_enabled_sites(){ fi } -create_custom_hostname(){ +function create_custom_hostname(){ echo top_border echo -e "| You can change the hostname of this machine to use |" @@ -93,7 +93,7 @@ create_custom_hostname(){ done } -user_input_hostname(){ +function user_input_hostname(){ unset NEW_HOSTNAME unset HOSTNAME_VALID unset HOSTENAME_CONFIRM @@ -133,7 +133,7 @@ user_input_hostname(){ done } -set_hostname(){ +function set_hostname(){ if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then #check for dependencies dep=(avahi-daemon) diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh index 0cf342c..22cd4c0 100644 --- a/scripts/pretty_gcode.sh +++ b/scripts/pretty_gcode.sh @@ -19,7 +19,7 @@ PGC_DIR="${HOME}/pgcode" #================== INSTALL PGC ==================# #=================================================# -install_pgc_for_klipper(){ +function install_pgc_for_klipper(){ pgconfsrc="${PGC_DIR}/pgcode.local.conf" pgconf="/etc/nginx/sites-available/pgcode.local.conf" pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" @@ -57,7 +57,7 @@ install_pgc_for_klipper(){ #=================== REMOVE PGC ==================# #=================================================# -remove_prettygcode(){ +function remove_prettygcode(){ pgconf="/etc/nginx/sites-available/pgcode.local.conf" pgconfsl="/etc/nginx/sites-enabled/pgcode.local.conf" if [ -d "${HOME}/pgcode" ] || [ -f "${pgconf}" ] || [ -L "${pgconfsl}" ]; then @@ -76,7 +76,7 @@ remove_prettygcode(){ #=================== UPDATE PGC ==================# #=================================================# -update_pgc_for_klipper(){ +function update_pgc_for_klipper(){ PGC_DIR="${HOME}/pgcode" status_msg "Updating PrettyGCode for Klipper ..." cd "${PGC_DIR}" && git pull @@ -87,7 +87,7 @@ update_pgc_for_klipper(){ #=================== PGC STATUS ==================# #=================================================# -read_pgc_versions(){ +function read_pgc_versions(){ PGC_DIR="${HOME}/pgcode" if [ -d "${PGC_DIR}" ] && [ -d "${PGC_DIR}/.git" ]; then cd "${PGC_DIR}" @@ -100,7 +100,7 @@ read_pgc_versions(){ fi } -compare_pgc_versions(){ +function compare_pgc_versions(){ unset PGC_UPDATE_AVAIL read_pgc_versions if [ "${LOCAL_PGC_COMMIT}" != "${REMOTE_PGC_COMMIT}" ]; then From 046bf76e8e1929125550935080db5c2cf5fc9dae Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 11:09:30 +0200 Subject: [PATCH 051/183] refactor(utilities.sh): move code Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 64 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index dcfe364..46426ce 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -346,38 +346,6 @@ install_gcode_shell_command(){ do_action_service "restart" "klipper" } -function install_kiauh_macros(){ - ### copy kiauh_macros.cfg - if [ "${ADD_KIAUH_MACROS}" = "true" ]; then - ### create a backup of the config folder - backup_klipper_config_dir - ### handle multi printer.cfg - if ls "${KLIPPER_CONFIG}"/printer_* 2>/dev/null 1>&2; then - for config in $(find ${KLIPPER_CONFIG}/printer_*/printer.cfg); do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [ ! -f "${path}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" - ok_msg "${path}/kiauh_macros.cfg created!" - fi - done - ### handle single printer.cfg - elif [ -f "${KLIPPER_CONFIG}/printer.cfg" ] && [ ! -f "${KLIPPER_CONFIG}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${KLIPPER_CONFIG}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${KLIPPER_CONFIG}/printer.cfg" - ok_msg "${KLIPPER_CONFIG}/kiauh_macros.cfg created!" - fi - ### restart klipper service to parse the modified printer.cfg - do_action_service "restart" "klipper" - fi -} - function system_check_webui(){ ### check system for an installed and enabled octoprint service if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then @@ -437,6 +405,38 @@ function get_user_selection_kiauh_macros(){ done } +function install_kiauh_macros(){ + ### copy kiauh_macros.cfg + if [ "${ADD_KIAUH_MACROS}" = "true" ]; then + ### create a backup of the config folder + backup_klipper_config_dir + ### handle multi printer.cfg + if ls "${KLIPPER_CONFIG}"/printer_* 2>/dev/null 1>&2; then + for config in $(find ${KLIPPER_CONFIG}/printer_*/printer.cfg); do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/kiauh_macros.cfg" ]; then + ### copy kiauh_macros.cfg to config location + status_msg "Creating macro config file ..." + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" + ok_msg "${path}/kiauh_macros.cfg created!" + fi + done + ### handle single printer.cfg + elif [ -f "${KLIPPER_CONFIG}/printer.cfg" ] && [ ! -f "${KLIPPER_CONFIG}/kiauh_macros.cfg" ]; then + ### copy kiauh_macros.cfg to config location + status_msg "Creating macro config file ..." + cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${KLIPPER_CONFIG}" + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" "${KLIPPER_CONFIG}/printer.cfg" + ok_msg "${KLIPPER_CONFIG}/kiauh_macros.cfg created!" + fi + ### restart klipper service to parse the modified printer.cfg + do_action_service "restart" "klipper" + fi +} + function process_octoprint_dialog(){ #ask user to disable octoprint when its service was found if [ "${OCTOPRINT_ENABLED}" = "true" ]; then From 2d268006ac18eefdb688160a659d524363b9c6cb Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 11:10:26 +0200 Subject: [PATCH 052/183] refactor(advanced_menu.sh): update GUI Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index c09906b..2e9c5ae 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -13,22 +13,22 @@ set -e advanced_ui(){ top_border - echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " + echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} | " hr if [ ! "$OPRINT_SERVICE_STATUS" == "" ]; then echo -e "| 0) $OPRINT_SERVICE_STATUS| " hr echo -e "| | | " fi - echo -e "| Klipper: | Mainsail: | " - echo -e "| 1) [Switch Branch] | 7) [Theme installer] | " - echo -e "| 2) [Rollback] | | " - echo -e "| | System: | " - echo -e "| Firmware: | 8) [Change hostname] | " - echo -e "| 3) [Build only] | | " - echo -e "| 4) [Flash only] | Extensions: | " - echo -e "| 5) [Build + Flash] | 9) [Shell Command] | " - echo -e "| 6) [Get MCU ID] | | " + echo -e "| Klipper: | Mainsail: | " + echo -e "| 1) [Switch Branch] | 7) [Theme installer] | " + echo -e "| 2) [Rollback] | | " + echo -e "| | System: | " + echo -e "| Firmware: | 8) [Change hostname] | " + echo -e "| 3) [Build only] | | " + echo -e "| 4) [Flash only] | Extras: | " + echo -e "| 5) [Build + Flash] | 9) [G-Code Shell Command] | " + echo -e "| 6) [Get MCU ID] | | " back_footer } @@ -36,8 +36,8 @@ advanced_menu(){ read_octoprint_service_status do_action "" "advanced_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in + read -p "${cyan}Perform action:${white} " action; echo + case "${action}" in 0) clear print_header From e06b06c3ea42ebb61eb984b2c157dc455aa87ba5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 11:10:42 +0200 Subject: [PATCH 053/183] refactor(remove_menu.sh): update GUI Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/remove_menu.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 4ad2420..839c981 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -15,10 +15,8 @@ remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} | " hr - echo -e "| Directories which remain untouched: | " - echo -e "| --> Your printer configuration directory | " - echo -e "| --> ~/kiauh-backups | " - echo -e "| You need remove them manually if you wish so. | " + echo -e "| ${yellow}INFO:${white} | " + echo -e "| Printer configs or backups always remain untouched! | " hr echo -e "| Firmware: | Touchscreen GUI: | " echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " @@ -26,17 +24,16 @@ remove_ui(){ echo -e "| Klipper API: | Other: | " echo -e "| 2) [Moonraker] | 6) [OctoPrint] | " echo -e "| | 7) [PrettyGCode] | " - echo -e "| Klipper Webinterface: | 9) [Telegram Bot] | " - echo -e "| 3) [Mainsail] | | " - echo -e "| 4) [Fluidd] | 9) [MJPG-Streamer] | " - echo -e "| | 10) [NGINX] | " + echo -e "| Klipper Webinterface: | 8) [Telegram Bot] | " + echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] | " + echo -e "| 4) [Fluidd] | 10) [NGINX] | " back_footer } remove_menu(){ do_action "" "remove_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo + read -p "${cyan}Perform action:${white} " action; echo case "${action}" in 1) do_action "remove_klipper" "remove_ui";; From 52cb40ac898cbb0e85dfdaeb68614a494798d162 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 12:03:52 +0200 Subject: [PATCH 054/183] refactor(kiauh.sh): improve kiauh update routine Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 33 +++++++++++++++++++++++++++++- scripts/status.sh | 12 ----------- scripts/ui/general_ui.sh | 12 ----------- scripts/ui/main_menu.sh | 43 +++++++++++++++++++++------------------- scripts/update.sh | 11 ---------- 5 files changed, 55 insertions(+), 56 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index e82adfc..1ef8233 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -38,6 +38,37 @@ DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping +#===================================================# +#=================== UPDATE KIAUH ==================# +#===================================================# + +function update_kiauh(){ + status_msg "Updating KIAUH ..." + cd "${SRCDIR}/kiauh" + git reset --hard && git pull + ok_msg "Update complete! Please restart KIAUH." + exit 0 +} + +#===================================================# +#=================== KIAUH STATUS ==================# +#===================================================# + +function kiauh_update_avail(){ + [ ! -d "${SRCDIR}/kiauh/.git" ] && return + local origin head + cd "${SRCDIR}/kiauh" + ### abort if not on master branch + ! git branch -a | grep -q "\* master" && return + ### compare commit hash + git fetch -q + origin=$(git rev-parse --short=8 origin/master) + head=$(git rev-parse --short=8 HEAD) + if [ "${origin}" != "${head}" ]; then + echo "true" + fi +} + ### format some default message types select_msg() { echo -e "${white}>>>>>> $1" @@ -113,5 +144,5 @@ clear_msg(){ check_euid init_ini -kiauh_status +kiauh_update_avail main_menu diff --git a/scripts/status.sh b/scripts/status.sh index c3a1fad..c29c844 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -1,15 +1,3 @@ -kiauh_status(){ - if [ -d "${SRCDIR}/kiauh/.git" ]; then - cd ${SRCDIR}/kiauh - if git branch -a | grep "* master" -q; then - git fetch -q - if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then - KIAUH_UPDATE_AVAIL="true" - fi - fi - fi -} - check_system_updates(){ SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d") if [ ! -z "$SYS_UPDATE" ]; then diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index e46f859..e046bb7 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -54,18 +54,6 @@ print_header(){ bottom_border } -kiauh_update_msg(){ - top_border - echo -e "|${green} New KIAUH update available! ${default}| " - hr - echo -e "|${green} View Changelog: https://git.io/JnmlX ${default}| " - blank_line - echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${default}| " - echo -e "|${yellow} usually contain bugfixes, important changes or new ${default}| " - echo -e "|${yellow} features. Please consider updating! ${default}| " - bottom_border -} - ################################################################################ #******************************************************************************# ################################################################################ diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 117d8df..819c78d 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -12,13 +12,12 @@ set -e main_ui(){ - #[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr echo -e "| 0) [Upload Log] | Klipper: $(get_klipper_status)|" echo -e "| | |" - echo -e "| 1) [Install] |--------------------------------|" + echo -e "| 1) [Install] | |" echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" echo -e "| 3) [Remove] | |" echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" @@ -26,21 +25,31 @@ main_ui(){ echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" echo -e "| | |" - echo -e "| ${cyan}${KIAUH_VER}${white}| Octoprint: $OCTOPRINT_STATUS|" + echo -e "| $(get_kiauh_version)| Octoprint: $OCTOPRINT_STATUS|" quit_footer } -print_kiauh_version(){ - cd ${SRCDIR}/kiauh - KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")" +get_kiauh_version(){ + local version + cd "${SRCDIR}/kiauh" + version="$(printf "%-20s" "$(git describe HEAD --always --tags | cut -d "-" -f 1,2)")" + echo "${cyan}${version}${white}" } kiauh_update_dialog(){ - kiauh_update_msg - read -p "${cyan}Do you want to update now? (Y/n):${default} " yn + [ ! "$(kiauh_update_avail)" == "true" ] && return + top_border + echo -e "|${green} New KIAUH update available! ${white}| " + hr + echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}| " + blank_line + echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}| " + echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}| " + echo -e "|${yellow} features. Please consider updating! ${white}| " + bottom_border + read -p "${cyan}Do you want to update now? (Y/n):${white} " yn while true; do - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") do_action "update_kiauh" break;; @@ -53,24 +62,18 @@ kiauh_update_dialog(){ main_menu(){ print_header - #print KIAUH update msg if update available - if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then - kiauh_update_dialog - fi + #prompt for KIAUH update if update available + kiauh_update_dialog #check install status - print_kiauh_version -# klipper_status -# moonraker_status fluidd_status mainsail_status octoprint_status klipperscreen_status MoonrakerTelegramBot_status -# print_branch print_msg && clear_msg main_ui while true; do - read -p "${cyan}Perform action:${default} " action; echo + read -p "${cyan}Perform action:${white} " action; echo case "${action}" in "start klipper") do_action_service "start" "klipper"; main_ui;; "stop klipper") do_action_service "stop" "klipper"; main_ui;; @@ -90,7 +93,7 @@ main_menu(){ 5) clear && backup_menu && break;; 6) clear && settings_menu && break;; Q|q) - echo -e "${green}###### Happy printing! ######${default}"; echo + echo -e "${green}###### Happy printing! ######${white}"; echo exit 0;; *) deny_action "main_ui";; diff --git a/scripts/update.sh b/scripts/update.sh index b6828fe..d5d88ee 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -1,14 +1,3 @@ -update_kiauh(){ - if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then - status_msg "Updating KIAUH ..." - cd ${SRCDIR}/kiauh - ### force reset kiauh before updating - git reset --hard - git pull && ok_msg "Update complete! Please restart KIAUH." - exit -1 - fi -} - update_all(){ while true; do if [ "${#update_arr[@]}" = "0" ]; then From d1cb24d72531c1c37d7da06b09f5497fa8d21e18 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 23:25:07 +0200 Subject: [PATCH 055/183] refactor(kiauh.sh): clean up kiauh.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 113 ++++++++----------------------- scripts/nginx.sh | 5 ++ scripts/utilities.sh | 156 ++++++++++++++++++++++++++++++++----------- 3 files changed, 149 insertions(+), 125 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 1ef8233..119e7dd 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -12,32 +12,11 @@ set -e clear -### set color variables -green=$(echo -en "\e[92m") -yellow=$(echo -en "\e[93m") -red=$(echo -en "\e[91m") -cyan=$(echo -en "\e[96m") -default=$(echo -en "\e[39m") -white=$(echo -en "\e[39m") - ### sourcing all additional scripts SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . "${script}"; done for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . "${script}"; done -#nginx -NGINX_SA=/etc/nginx/sites-available -NGINX_SE=/etc/nginx/sites-enabled -NGINX_CONFD=/etc/nginx/conf.d -#misc -INI_FILE=${HOME}/.kiauh.ini - -### set github repos -DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git -#branches -BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing -BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping - #===================================================# #=================== UPDATE KIAUH ==================# #===================================================# @@ -70,77 +49,39 @@ function kiauh_update_avail(){ } ### format some default message types -select_msg() { - echo -e "${white}>>>>>> $1" -} -warn_msg(){ - echo -e "${red}>>>>>> $1${white}" -} -status_msg(){ - echo; echo -e "${yellow}###### $1${white}" -} -ok_msg(){ - echo -e "${green}>>>>>> $1${white}" -} -error_msg(){ - echo -e "${red}>>>>>> $1${white}" -} -abort_msg(){ - echo -e "${red}<<<<<< $1${white}" -} -title_msg(){ - echo -e "${cyan}$1${white}" -} get_date(){ current_date=$(date +"%y%m%d-%H%M") export current_date } -print_unkown_cmd(){ - ERROR_MSG="Invalid command!" -} -invalid_option(){ - ERROR_MSG="Invalid command!" -} -print_msg(){ - if [ -n "${ERROR_MSG}" ]; then - echo -e "${red}" - echo -e "#########################################################" - echo -e " ${ERROR_MSG} " - echo -e "#########################################################" - echo -e "${white}" - fi - if [ -n "${CONFIRM_MSG}" ]; then - echo -e "${green}" - echo -e "#########################################################" - echo -e " ${CONFIRM_MSG} " - echo -e "#########################################################" - echo -e "${white}" - fi -} +#print_unkown_cmd(){ +# ERROR_MSG="Invalid command!" +#} +#invalid_option(){ +# ERROR_MSG="Invalid command!" +#} -print_error(){ - [ -z "${1}" ] && return - echo -e "${red}" - echo -e "#########################################################" - echo -e " ${1} " - echo -e "#########################################################" - echo -e "${white}" -} - -print_confirm(){ - [ -z "${1}" ] && return - echo -e "${green}" - echo -e "#########################################################" - echo -e " ${1} " - echo -e "#########################################################" - echo -e "${white}" -} - -clear_msg(){ - unset CONFIRM_MSG - unset ERROR_MSG -} +#print_msg(){ +# if [ -n "${ERROR_MSG}" ]; then +# echo -e "${red}" +# echo -e "#########################################################" +# echo -e " ${ERROR_MSG} " +# echo -e "#########################################################" +# echo -e "${white}" +# fi +# if [ -n "${CONFIRM_MSG}" ]; then +# echo -e "${green}" +# echo -e "#########################################################" +# echo -e " ${CONFIRM_MSG} " +# echo -e "#########################################################" +# echo -e "${white}" +# fi +#} +# +#clear_msg(){ +# unset CONFIRM_MSG +# unset ERROR_MSG +#} check_euid init_ini diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 3d015e6..587c251 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -11,6 +11,11 @@ set -e +### global variables +NGINX_SA="/etc/nginx/sites-available" +NGINX_SE="/etc/nginx/sites-enabled" +NGINX_CONFD="/etc/nginx/conf.d" + #===================================================# #=================== REMOVE NGINX ==================# #===================================================# diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 46426ce..88d985b 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -11,12 +11,16 @@ set -e -### base variables +### global variables SYSTEMD="/etc/systemd/system" +INI_FILE="${HOME}/.kiauh.ini" LOGFILE="/tmp/kiauh.log" -# setting up some frequently used functions -check_euid(){ +#================================================# +#=================== STARTUP ====================# +#================================================# + +function check_euid(){ if [ "${EUID}" -eq 0 ] then echo -e "${red}" @@ -28,13 +32,121 @@ check_euid(){ fi } +#================================================# +#============= MESSAGE FORMATTING ===============# +#================================================# +green=$(echo -en "\e[92m") +yellow=$(echo -en "\e[93m") +red=$(echo -en "\e[91m") +cyan=$(echo -en "\e[96m") +white=$(echo -en "\e[39m") + +function select_msg() { + echo -e "${white}>>>>>> $1" +} +function warn_msg(){ + echo -e "${red}>>>>>> $1${white}" +} +function status_msg(){ + echo; echo -e "${yellow}###### $1${white}" +} +function ok_msg(){ + echo -e "${green}>>>>>> $1${white}" +} +function error_msg(){ + echo -e "${red}>>>>>> $1${white}" +} +function abort_msg(){ + echo -e "${red}<<<<<< $1${white}" +} +function title_msg(){ + echo -e "${cyan}$1${white}" +} + +function print_error(){ + [ -z "${1}" ] && return + echo -e "${red}" + echo -e "#########################################################" + echo -e " ${1} " + echo -e "#########################################################" + echo -e "${white}" +} + +function print_confirm(){ + [ -z "${1}" ] && return + echo -e "${green}" + echo -e "#########################################################" + echo -e " ${1} " + echo -e "#########################################################" + echo -e "${white}" +} + +#================================================# +#=================== LOGGING ====================# +#================================================# + function timestamp() { date +"[%F %T]" } -function log() { +function log_info() { local message="${1}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" +} + +function log_warning() { + local message="${1}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" +} + +function log_error() { + local message="${1}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" +} + +#================================================# +#=============== KIAUH SETTINGS =================# +#================================================# + +function read_kiauh_ini(){ + if [ ! -f "${INI_FILE}" ]; then + log_error "Reading from .kiauh.ini failed! File not found!" + return + fi + log_info "Reading from .kiauh.ini" + source "${INI_FILE}" +} + +function init_ini(){ + ### remove pre-version 4 ini files + if [ -f "${INI_FILE}" ] && ! grep -Eq "^KIAUH v4\.0\.0$" "${INI_FILE}"; then + rm "${INI_FILE}" + fi + ### initialize ini file + if [ ! -f "${INI_FILE}" ]; then + { + echo -e "File creation date: $(date)" + echo -e "#=================================================#" + echo -e "# KIAUH - Klipper Installation And Update Helper #" + echo -e "# https://github.com/th33xitus/kiauh #" + echo -e "# DO NOT edit this file! #" + echo -e "#=================================================#" + echo -e "KIAUH v4.0.0" + } >> "${INI_FILE}" + fi + if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then + echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}" + fi + if ! grep -Eq "^logupload_accepted=." "${INI_FILE}"; then + echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}" + fi + if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then + echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}" + fi + if ! grep -Eq "^mainsail_always_install_latest=" "${INI_FILE}"; then + echo -e "\nmainsail_always_install_latest=false\c" >> "${INI_FILE}" + fi + fetch_webui_ports } check_klipper_cfg_path(){ @@ -166,10 +278,6 @@ set_klipper_cfg_path(){ do_action_service "restart" "moonraker" } -source_kiauh_ini(){ - source $INI_FILE -} - do_action_service(){ shopt -s extglob # enable extended globbing SERVICES="${SYSTEMD}/$2?(-*([0-9])).service" @@ -487,33 +595,3 @@ function fetch_webui_ports(){ fi done } - -init_ini(){ - ### copy an existing kiauh.ini to its new location to keep all possible saved values - if [ -f "${SRCDIR}/kiauh/kiauh.ini" ] && [ ! -f "${INI_FILE}" ]; then - cp "${SRCDIR}/kiauh/kiauh.ini" "${INI_FILE}" - fi - if [ ! -f "${INI_FILE}" ]; then - echo -e "#don't edit this file if you don't know what you are doing...\c" > "${INI_FILE}" - fi - if [ ! $(grep -E "^backup_before_update=." "${INI_FILE}") ]; then - echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}" - fi - if [ ! $(grep -E "^previous_origin_state=[[:alnum:]]" "${INI_FILE}") ]; then - echo -e "\nprevious_origin_state=0\c" >> "${INI_FILE}" - fi - if [ ! $(grep -E "^previous_smoothing_state=[[:alnum:]]" "${INI_FILE}") ]; then - echo -e "\nprevious_smoothing_state=0\c" >> "${INI_FILE}" - fi - if [ ! $(grep -E "^previous_shaping_state=[[:alnum:]]" "${INI_FILE}") ]; then - echo -e "\nprevious_shaping_state=0\c" >> "${INI_FILE}" - fi - if [ ! $(grep -E "^logupload_accepted=." "${INI_FILE}") ]; then - echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}" - fi - ###add empty klipper config path if missing - if [ ! $(grep -E "^klipper_cfg_loc=" "${INI_FILE}") ]; then - echo -e "\nklipper_cfg_loc=\c" >> "${INI_FILE}" - fi - fetch_webui_ports -} From c9ef2d3d59b8a29c8d86f315badf06804aa72ad3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 23:34:31 +0200 Subject: [PATCH 056/183] refactor: replace ${default} with ${white} Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 6 +++--- scripts/klipperscreen.sh | 14 +++++++------- scripts/mjpg-streamer.sh | 2 +- scripts/moonraker-telegram-bot.sh | 14 +++++++------- scripts/moonraker.sh | 4 ++-- scripts/network_functions.sh | 14 +++++++------- scripts/nginx.sh | 6 +++--- scripts/octoprint.sh | 2 +- scripts/rollback.sh | 18 +++++++++--------- scripts/status.sh | 4 ++-- scripts/ui/advanced_menu.sh | 4 ++-- scripts/ui/backup_menu.sh | 4 ++-- scripts/ui/general_ui.sh | 6 +++--- scripts/ui/install_menu.sh | 2 +- scripts/ui/main_menu.sh | 1 - scripts/ui/settings_menu.sh | 10 +++++----- scripts/update.sh | 18 +++++++++--------- scripts/upload_log.sh | 16 ++++++++-------- scripts/utilities.sh | 16 ++++++++-------- 19 files changed, 80 insertions(+), 81 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 5096bb8..fb6e27c 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -168,11 +168,11 @@ function fluidd_status(){ fi done if [ "$fcount" == "${#fluidd_data[*]}" ]; then - FLUIDD_STATUS="${green}Installed!${default} " + FLUIDD_STATUS="${green}Installed!${white} " elif [ "$fcount" == 0 ]; then - FLUIDD_STATUS="${red}Not installed!${default} " + FLUIDD_STATUS="${red}Not installed!${white} " else - FLUIDD_STATUS="${yellow}Incomplete!${default} " + FLUIDD_STATUS="${yellow}Incomplete!${white} " fi } diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index b55c64b..8e9bcad 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -153,11 +153,11 @@ function klipperscreen_status(){ fi done if [ "${klsccount}" == "${#klipperscreen_data[*]}" ]; then - KLIPPERSCREEN_STATUS="${green}Installed!${default} " + KLIPPERSCREEN_STATUS="${green}Installed!${white} " elif [ "${klsccount}" == 0 ]; then - KLIPPERSCREEN_STATUS="${red}Not installed!${default} " + KLIPPERSCREEN_STATUS="${red}Not installed!${white} " else - KLIPPERSCREEN_STATUS="${yellow}Incomplete!${default} " + KLIPPERSCREEN_STATUS="${yellow}Incomplete!${white} " fi } @@ -177,13 +177,13 @@ function compare_klipperscreen_versions(){ unset KLIPPERSCREEN_UPDATE_AVAIL read_klipperscreen_versions if [ "${LOCAL_KLIPPERSCREEN_COMMIT}" != "${REMOTE_KLIPPERSCREEN_COMMIT}" ]; then - LOCAL_KLIPPERSCREEN_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${default}" - REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${default}" + LOCAL_KLIPPERSCREEN_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${white}" + REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${white}" KLIPPERSCREEN_UPDATE_AVAIL="true" update_arr+=(update_klipperscreen) else - LOCAL_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${default}" - REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${default}" + LOCAL_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${white}" + REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${white}" KLIPPERSCREEN_UPDATE_AVAIL="false" fi } diff --git a/scripts/mjpg-streamer.sh b/scripts/mjpg-streamer.sh index 27a1ecd..4081b6f 100644 --- a/scripts/mjpg-streamer.sh +++ b/scripts/mjpg-streamer.sh @@ -155,7 +155,7 @@ function get_user_selection_mjpg-streamer(){ top_border echo -e "| Install MJGP-Streamer for webcam support? |" bottom_border - read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn + read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 7888aed..1001f67 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -129,11 +129,11 @@ function MoonrakerTelegramBot_status(){ fi done if [ "${mtbcount}" == "${#MoonrakerTelegramBot_data[*]}" ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${default} " + MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${white} " elif [ "${mtbcount}" == 0 ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${default} " + MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${white} " else - MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${default} " + MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${white} " fi } @@ -153,13 +153,13 @@ function compare_MoonrakerTelegramBot_versions(){ unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL read_MoonrakerTelegramBot_versions if [ "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}" != "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}" ]; then - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" + LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" + REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" # add moonraker telegram bot to the update all array for the update all function in the updater MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_MoonrakerTelegramBot) else - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${default}" + LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" + REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false" fi } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 544ceb7..7aa9ebb 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -63,9 +63,9 @@ function moonraker_setup_dialog(){ top_border if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then - printf "|${green}%-55s${default}|\n" " 1 Klipper instance was found!" + printf "|${green}%-55s${white}|\n" " 1 Klipper instance was found!" elif [ "$(klipper_systemd | wc -w)" -gt 1 ]; then - printf "|${green}%-55s${default}|\n" " $(klipper_systemd | wc -w) Klipper instances were found!" + printf "|${green}%-55s${white}|\n" " $(klipper_systemd | wc -w) Klipper instances were found!" else echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" fi diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 73f312e..784bd3b 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -80,7 +80,7 @@ function create_custom_hostname(){ echo -e "| browsing to: http://my-printer.local |" bottom_border while true; do - read -p "${cyan}###### Do you want to change the hostname? (y/N):${default} " yn + read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn case "$yn" in Y|y|Yes|yes) user_input_hostname @@ -99,18 +99,18 @@ function user_input_hostname(){ unset HOSTENAME_CONFIRM echo top_border - echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |" - echo -e "| ${red}No special characters allowed!${default} |" - echo -e "| ${red}No leading or trailing '-' allowed!${default} |" + echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |" + echo -e "| ${red}No special characters allowed!${white} |" + echo -e "| ${red}No leading or trailing '-' allowed!${white} |" bottom_border while true; do - read -p "${cyan}###### Please set the new hostname:${default} " NEW_HOSTNAME + read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then ok_msg "'$NEW_HOSTNAME' is a valid hostname!" HOSTNAME_VALID="true" while true; do echo - read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${default} " yn + read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${white} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" @@ -118,7 +118,7 @@ function user_input_hostname(){ break;; N|n|No|no) echo -e "###### > No" - echo -e "${red}Skip hostname change ...${default}" + echo -e "${red}Skip hostname change ...${white}" HOSTENAME_CONFIRM="false" break;; *) diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 587c251..a66a473 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -196,7 +196,7 @@ function process_services_dialog(){ while true; do echo top_border - echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" + echo -e "| ${red}Possibly disruptive/incompatible services found!${white} |" hr if [ "${HAPROXY_FOUND}" = "true" ]; then echo -e "| ● haproxy |" @@ -213,9 +213,9 @@ function process_services_dialog(){ echo -e "| |" echo -e "| 1) Remove packages (recommend) |" echo -e "| 2) Disable only (may cause issues) |" - echo -e "| ${red}3) Skip this step (not recommended)${default} |" + echo -e "| ${red}3) Skip this step (not recommended)${white} |" bottom_border - read -p "${cyan}###### Please choose:${default} " action + read -p "${cyan}###### Please choose:${white} " action case "${action}" in 1) echo -e "###### > Remove packages" diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 7807c29..1b262ac 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -41,7 +41,7 @@ octoprint_setup_dialog(){ echo -e "| You need one OctoPrint instance per Klipper instance. | " bottom_border echo - read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${default} " yn + read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${white} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" diff --git a/scripts/rollback.sh b/scripts/rollback.sh index a1f74e5..aaa6d9d 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -35,15 +35,15 @@ load_klipper_state(){ PREVIOUS_COMMIT_DATE=$(git show -s --format=%cd --date=short $PREVIOUS_COMMIT) fi if [ "$PREVIOUS_COMMIT" = "0" ]; then - CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") - PREV_UI=$(echo -e "${red}None${default} ") + CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${white}") + PREV_UI=$(echo -e "${red}None${white} ") else if [ "$CURRENT_COMMIT" = "$PREVIOUS_COMMIT" ]; then - CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") - PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}") + CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${white}") + PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${white}") else - CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") - PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}") + CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${white}") + PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${white}") fi fi rollback_ui @@ -59,7 +59,7 @@ rollback_ui(){ echo -e "| used commit from which you have updated. | " bottom_border top_border - echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | " + echo -e "| Active branch: ${green}$PRINT_BRANCH${white} | " hr echo -e "| Currently on commit: | " echo -e "| $CURR_UI | " @@ -74,7 +74,7 @@ rollback_klipper(){ while true; do echo -e "${cyan}" read -p "###### Do you want to rollback to $PREVIOUS_COMMIT? (Y/n): " yn - echo -e "${default}" + echo -e "${white}" case "$yn" in Y|y|Yes|yes|"") clear @@ -95,7 +95,7 @@ rollback_klipper(){ while true; do echo -e "${cyan}" read -p "Perform action: " action; echo - echo -e "${default}" + echo -e "${white}" case "$action" in B|b) clear; advanced_menu; break;; diff --git a/scripts/status.sh b/scripts/status.sh index c29c844..8b453fc 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -3,10 +3,10 @@ check_system_updates(){ if [ ! -z "$SYS_UPDATE" ]; then # add system updates to the update all array for the update all function in the updater SYS_UPDATE_AVAIL="true" && update_arr+=(update_system) - DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${default}" + DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${white}" else SYS_UPDATE_AVAIL="false" - DISPLAY_SYS_UPDATE="${green}System up to date! ${default}" + DISPLAY_SYS_UPDATE="${green}System up to date! ${white}" fi } diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 2e9c5ae..a2f5bfb 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -91,7 +91,7 @@ switch_ui(){ echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" bottom_border echo - echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}" + echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${white}" echo top_border echo -e "| | " @@ -109,7 +109,7 @@ switch_menu(){ read_branch do_action "" "switch_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo + read -p "${cyan}Perform action:${white} " action; echo case "$action" in 1) clear diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index 6495333..1b6ee52 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -15,7 +15,7 @@ backup_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " hr - echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " + echo -e "| ${yellow}Backup location: ~/kiauh-backups${white} | " hr echo -e "| Configuration folder: | Klipper Webinterface: | " echo -e "| 0) [Klipper configs] | 4) [Mainsail] | " @@ -33,7 +33,7 @@ backup_ui(){ backup_menu(){ do_action "" "backup_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo + read -p "${cyan}Perform action:${white} " action; echo case "$action" in 0) do_action "backup_klipper_config_dir" "backup_ui";; diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index e046bb7..82ec0cf 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -30,19 +30,19 @@ hr(){ quit_footer(){ hr - echo -e "| ${red}Q) Quit${default} |" + echo -e "| ${red}Q) Quit${white} |" bottom_border } back_footer(){ hr - echo -e "| ${green}B) « Back${default} |" + echo -e "| ${green}B) « Back${white} |" bottom_border } back_help_footer(){ hr - echo -e "| ${green}B) « Back${default} | ${yellow}H) Help [?]${default} |" + echo -e "| ${green}B) « Back${white} | ${yellow}H) Help [?]${white} |" bottom_border } diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index a7d27c7..12703e7 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -35,7 +35,7 @@ install_ui(){ install_menu(){ do_action "" "install_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo + read -p "${cyan}Perform action:${white} " action; echo case "$action" in 1) do_action "klipper_setup_dialog" "install_ui";; diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 819c78d..f1dd53e 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -70,7 +70,6 @@ main_menu(){ octoprint_status klipperscreen_status MoonrakerTelegramBot_status - print_msg && clear_msg main_ui while true; do read -p "${cyan}Perform action:${white} " action; echo diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 7e9ddef..1a9cf86 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -16,20 +16,20 @@ settings_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | " hr - echo -e "| ${red}Caution:${default} | " + echo -e "| ${red}Caution:${white} | " echo -e "| When you change the config folder, be aware that ALL | " echo -e "| Klipper and Moonraker services will be STOPPED, | " echo -e "| reconfigured and then restarted again. | " blank_line - echo -e "| ${red}DO NOT change the folder during printing!${default} | " + echo -e "| ${red}DO NOT change the folder during printing!${white} | " hr blank_line - echo -e "| ${cyan}● Current Klipper config folder:${default} | " + echo -e "| ${cyan}● Current Klipper config folder:${white} | " printf "|%-55s|\n" " $klipper_cfg_loc" blank_line hr if [ -z $klipper_cfg_loc ]; then - echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${default} | " + echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${white} | " else echo -e "| 1) Change config folder | " fi @@ -39,7 +39,7 @@ settings_ui(){ settings_menu(){ do_action "" "settings_ui" while true; do - read -p "${cyan}Perform action:${default} " action; echo + read -p "${cyan}Perform action:${white} " action; echo case "$action" in 1) if [ ! -z $klipper_cfg_loc ]; then diff --git a/scripts/update.sh b/scripts/update.sh index d5d88ee..21111fd 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -8,32 +8,32 @@ update_all(){ top_border echo -e "| The following installations will be updated: |" if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Klipper${default} |" + echo -e "| ${cyan}● Klipper${white} |" fi if [ "$MOONRAKER_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Moonraker${default} |" + echo -e "| ${cyan}● Moonraker${white} |" fi if [ "$MAINSAIL_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Mainsail${default} |" + echo -e "| ${cyan}● Mainsail${white} |" fi if [ "$FLUIDD_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Fluidd${default} |" + echo -e "| ${cyan}● Fluidd${white} |" fi if [ "$KLIPPERSCREEN_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● KlipperScreen${default} |" + echo -e "| ${cyan}● KlipperScreen${white} |" fi if [ "$PGC_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● PrettyGCode for Klipper${default} |" + echo -e "| ${cyan}● PrettyGCode for Klipper${white} |" fi if [ "$MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● MoonrakerTelegramBot${default} |" + echo -e "| ${cyan}● MoonrakerTelegramBot${white} |" fi if [ "$SYS_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● System${default} |" + echo -e "| ${cyan}● System${white} |" fi bottom_border if [ "${#update_arr[@]}" != "0" ]; then - read -p "${cyan}###### Do you want to proceed? (Y/n):${default} " yn + read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn case "$yn" in Y|y|Yes|yes|"") for update in ${update_arr[@]} diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index eaa959b..5d27154 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -1,21 +1,21 @@ accept_upload_conditions(){ while true; do top_border - echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${default} |" + echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |" hr echo -e "| The following function will help to quickly upload |" echo -e "| logs for debugging purposes. With confirming this |" echo -e "| dialog, you agree that during that process your logs |" - echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${default} |" + echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |" hr - echo -e "| ${red}PLEASE NOTE:${default} |" + echo -e "| ${red}PLEASE NOTE:${white} |" echo -e "| Be aware that logs can contain network information, |" echo -e "| private data like usernames, filenames, or other |" echo -e "| information you may not want to make public. |" blank_line - echo -e "| Do ${red}NOT${default} use this function if you don't agree! |" + echo -e "| Do ${red}NOT${white} use this function if you don't agree! |" bottom_border - read -p "${cyan}Do you accept? (Y/n):${default} " yn + read -p "${cyan}Do you accept? (Y/n):${white} " yn case "$yn" in Y|y|Yes|yes|"") sed -i "/logupload_accepted=/s/false/true/" $INI_FILE @@ -59,7 +59,7 @@ upload_selection(){ ### draw interface i=0 top_border - echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |" + echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |" hr echo -e "| You can choose the following files for uploading: |" for log in ${logfiles[@]}; do @@ -68,7 +68,7 @@ upload_selection(){ done back_footer while true; do - read -p "${cyan}Please select:${default} " choice + read -p "${cyan}Please select:${white} " choice if [ $choice = "b" ] || [ $choice = "B" ]; then clear && main_menu && break elif [ $choice -le ${#logfiles[@]} ]; then @@ -88,7 +88,7 @@ upload_log(){ status_msg "Uploading $1 ..." LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') [ ! -z "$LINK" ] && ok_msg "$1 upload successfull!" - echo -e "\n${cyan}###### Here is your link:${default}" + echo -e "\n${cyan}###### Here is your link:${white}" echo -e ">>>>>> $LINK\n" unset LINK else diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 88d985b..6fea6d5 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -119,19 +119,19 @@ function read_kiauh_ini(){ function init_ini(){ ### remove pre-version 4 ini files - if [ -f "${INI_FILE}" ] && ! grep -Eq "^KIAUH v4\.0\.0$" "${INI_FILE}"; then + if [ -f "${INI_FILE}" ] && ! grep -Eq "^# KIAUH v4\.0\.0$" "${INI_FILE}"; then rm "${INI_FILE}" fi ### initialize ini file if [ ! -f "${INI_FILE}" ]; then { - echo -e "File creation date: $(date)" + echo -e "# File creation date: $(date)" echo -e "#=================================================#" echo -e "# KIAUH - Klipper Installation And Update Helper #" echo -e "# https://github.com/th33xitus/kiauh #" echo -e "# DO NOT edit this file! #" echo -e "#=================================================#" - echo -e "KIAUH v4.0.0" + echo -e "# KIAUH v4.0.0" } >> "${INI_FILE}" fi if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then @@ -487,16 +487,16 @@ function get_user_selection_kiauh_macros(){ echo -e "| fully functional and working. |" blank_line echo -e "| Those macros are: |" - echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |" - echo -e "| ${cyan}● [gcode_macro RESUME]${default} |" - echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |" + echo -e "| ${cyan}● [gcode_macro PAUSE]${white} |" + echo -e "| ${cyan}● [gcode_macro RESUME]${white} |" + echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${white} |" blank_line echo -e "| If you already have these macros in your config file |" echo -e "| you can skip this step and choose 'no'. |" echo -e "| Otherwise you should consider to answer with 'yes' to |" echo -e "| add the recommended example macros to your config. |" bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn + read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" @@ -551,7 +551,7 @@ function process_octoprint_dialog(){ while true; do echo top_border - echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" + echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${white} |" hr echo -e "| You might consider disabling the OctoPrint service, |" echo -e "| since an active OctoPrint service may lead to unex- |" From 1fb975df729dfef20516f124b7426130a2074170 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 23:39:18 +0200 Subject: [PATCH 057/183] refactor: replace ${default} with ${white} Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 1b262ac..157d112 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -366,9 +366,9 @@ octoprint_status(){ if [ "$ocount" == "${#octoprint_data[*]}" ]; then OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" elif [ "$ocount" == 0 ]; then - OCTOPRINT_STATUS="${red}Not installed!${default} " + OCTOPRINT_STATUS="${red}Not installed!${white} " else - OCTOPRINT_STATUS="${yellow}Incomplete!${default} " + OCTOPRINT_STATUS="${yellow}Incomplete!${white} " fi } From 94b63d2001c2c6bdc2e574bedd1ac633296af0fa Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 00:57:54 +0200 Subject: [PATCH 058/183] feat: allow mainsail and fluidd stable only installs/updates Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 90 +++++++++++++++++++++------------- scripts/ui/general_ui.sh | 5 +- scripts/ui/settings_menu.sh | 96 ++++++++++++++++++++++++++----------- scripts/utilities.sh | 3 ++ 4 files changed, 128 insertions(+), 66 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index b58757e..3d0d8cd 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -14,6 +14,7 @@ set -e ### global variables MAINSAIL_DIR="${HOME}/mainsail" MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" +MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags" KLIPPER_CONFIG="${HOME}/klipper_config" #===================================================# @@ -46,7 +47,7 @@ function install_mainsail(){ mainsail_port_check ### ask user to install mjpg-streamer - if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then + if [ ! -f "/etc/systemd/system/webcamd.service" ]; then get_user_selection_mjpg-streamer fi @@ -78,25 +79,24 @@ function install_mainsail(){ } function mainsail_setup(){ - ### get mainsail download url - MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) + local url + url=$(get_mainsail_download_url) + status_msg "Downloading Mainsail ..." + if [ -d "${MAINSAIL_DIR}" ]; then + rm -rf "${MAINSAIL_DIR}" + mkdir "${MAINSAIL_DIR}" + fi + cd "${MAINSAIL_DIR}" && wget "${url}" + ok_msg "Download complete!" - ### remove existing and create fresh mainsail folder, then download mainsail - [ -d "${MAINSAIL_DIR}" ] && rm -rf "${MAINSAIL_DIR}" - mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" - status_msg "Downloading Mainsail ${MAINSAIL_VERSION} ..." - wget "${MAINSAIL_DL_URL}" && ok_msg "Download complete!" - - ### extract archive status_msg "Extracting archive ..." unzip -q -o *.zip && ok_msg "Done!" - ### delete downloaded zip status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode - if [ $(ls /etc/systemd/system/moonraker* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then + if [ "$(moonraker_systemd | wc -w)" -gt 1 ]; then enable_mainsail_remotemode fi } @@ -173,11 +173,11 @@ function mainsail_status(){ fi done if [ "$mcount" == "${#mainsail_data[*]}" ]; then - MAINSAIL_STATUS="${green}Installed!${default} " + MAINSAIL_STATUS="${green}Installed!${white} " elif [ "$mcount" == 0 ]; then - MAINSAIL_STATUS="${red}Not installed!${default} " + MAINSAIL_STATUS="${red}Not installed!${white} " else - MAINSAIL_STATUS="${yellow}Incomplete!${default} " + MAINSAIL_STATUS="${yellow}Incomplete!${white} " fi } @@ -206,16 +206,16 @@ function compare_mainsail_versions(){ read_local_mainsail_version && read_remote_mainsail_version if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then #printf fits the string for displaying it in the ui to a total char length of 12 - MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${white}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}" elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then - MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${white}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}" # add mainsail to the update all array for the update all function in the updater MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) else MAINSAIL_LOCAL_VER=$NONE - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}" MAINSAIL_UPDATE_AVAIL="false" fi } @@ -246,12 +246,12 @@ function get_theme_list(){ function ms_theme_ui(){ top_border - echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " + echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} | " hr - echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " + echo -e "| ${green}A preview of each Mainsail theme can be found here:${white} | " echo -e "| https://docs.mainsail.xyz/theming/themes | " blank_line - echo -e "| ${yellow}Important note:${default} | " + echo -e "| ${yellow}Important note:${white} | " echo -e "| Installing a theme from this menu will overwrite an | " echo -e "| already installed theme or modified custom.css file! | " hr @@ -264,7 +264,7 @@ function ms_theme_ui(){ function ms_theme_menu(){ ms_theme_ui while true; do - read -p "${cyan}Install theme:${default} " a; echo + read -p "${cyan}Install theme:${white} " a; echo if [ "$a" = "b" ] || [ "$a" = "B" ]; then clear && advanced_menu && break elif [ "$a" = "r" ] || [ "$a" = "R" ]; then @@ -298,7 +298,7 @@ function check_select_printer(){ echo -e "| Please select the printer to which you want to | " echo -e "| apply the previously selected action. | " bottom_border - read -p "${cyan}Select printer:${default} " printer_num + read -p "${cyan}Select printer:${white} " printer_num ### rewrite the .theme path matching the selected printer THEME_PATH="$klipper_cfg_loc/printer_$printer_num" @@ -322,7 +322,7 @@ function ms_theme_install(){ cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" ok_msg "Theme installation complete!" - [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}" + [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${white}" ok_msg "Please remember to delete your browser cache!\n" } @@ -340,12 +340,34 @@ function ms_theme_delete(){ #=================== HELPERS ====================# #================================================# +function get_mainsail_download_url() { + local latest_tag latest_url stable_tag stable_url url + tags=$(curl -s "${MAINSAIL_TAGS}" | grep "name" | cut -d'"' -f4) + + ### latest download url including pre-releases (alpha, beta, rc) + latest_tag=$(echo "${tags}" | head -1) + latest_url="https://github.com/mainsail-crew/mainsail/releases/download/${latest_tag}/mainsail.zip" + + ### get stable mainsail download url + stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1) + stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip" + + read_kiauh_ini + if [ "${mainsail_always_install_latest}" == "true" ]; then + url="${latest_url}" + echo "${url}" + else + url="${stable_url}" + echo "${url}" + fi +} + function mainsail_port_check(){ if [ "${MAINSAIL_ENABLED}" = "false" ]; then if [ "${SITE_ENABLED}" = "true" ]; then status_msg "Detected other enabled interfaces:" - [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" - [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${default}" + [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${white}" + [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${white}" if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then PORT_80_BLOCKED="true" select_mainsail_port @@ -364,22 +386,22 @@ function select_mainsail_port(){ if [ "${PORT_80_BLOCKED}" = "true" ]; then echo top_border - echo -e "| ${red}!!!WARNING!!!${default} |" - echo -e "| ${red}You need to choose a different port for Mainsail!${default} |" - echo -e "| ${red}The following web interface is listening at port 80:${default} |" + echo -e "| ${red}!!!WARNING!!!${white} |" + echo -e "| ${red}You need to choose a different port for Mainsail!${white} |" + echo -e "| ${red}The following web interface is listening at port 80:${white} |" blank_line [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" [ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |" blank_line echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${white} |" echo -e "| use ports in the range of 4750 or above! |" blank_line - echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |" echo -e "| input. So make sure to choose a valid port! |" bottom_border while true; do - read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + read -p "${cyan}Please enter a new Port:${white} " NEW_PORT if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then echo "Setting port ${NEW_PORT} for Mainsail!" SET_LISTEN_PORT=${NEW_PORT} diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index 82ec0cf..88f95d7 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -63,14 +63,13 @@ do_action(){ clear && print_header ### $1 is the action the user wants to fire $1 - print_msg && clear_msg +# print_msg && clear_msg ### $2 is the menu the user usually gets directed back to after an action is completed $2 } deny_action(){ clear && print_header - print_unkown_cmd - print_msg && clear_msg + print_error "Invalid command!" $1 } diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 1a9cf86..53dc4ba 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -11,47 +11,85 @@ set -e -settings_ui(){ - source_kiauh_ini - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | " - hr - echo -e "| ${red}Caution:${white} | " - echo -e "| When you change the config folder, be aware that ALL | " - echo -e "| Klipper and Moonraker services will be STOPPED, | " - echo -e "| reconfigured and then restarted again. | " - blank_line - echo -e "| ${red}DO NOT change the folder during printing!${white} | " - hr - blank_line - echo -e "| ${cyan}● Current Klipper config folder:${white} | " - printf "|%-55s|\n" " $klipper_cfg_loc" - blank_line - hr - if [ -z $klipper_cfg_loc ]; then - echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${white} | " +### global variables +INI_FILE="${HOME}/.kiauh.ini" +KLIPPER_CONFIG="${HOME}/klipper_config" + +function settings_ui() { + read_kiauh_ini + local custom_cfg_loc="${custom_klipper_cfg_loc}" + local ms_pre_rls="${mainsail_always_install_latest}" + local fl_pre_rls="${fluidd_always_install_latest}" + + if [ -z "${custom_cfg_loc}" ]; then + custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}" else - echo -e "| 1) Change config folder | " + custom_cfg_loc="${cyan}${custom_cfg_loc}${white}" fi - back_footer + if [ "${ms_pre_rls}" == "false" ]; then + ms_pre_rls="${red}● ${ms_pre_rls}${white}" + else + ms_pre_rls="${green}● ${ms_pre_rls}${white}" + fi + if [ "${fl_pre_rls}" == "false" ]; then + fl_pre_rls="${red}● ${fl_pre_rls}${white}" + else + fl_pre_rls="${green}● ${fl_pre_rls}${white}" + fi + + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |" + hr + echo -e "| Klipper: |" + printf "| Config folder: %-49s|\n" "${custom_cfg_loc}" + blank_line + echo -e "| Klipper Webinterface: |" + printf "| 1) Install Mainsail latest: %-38s|\n" "${ms_pre_rls}" + printf "| 2) Install Fluidd latest: %-38s|\n" "${fl_pre_rls}" + hr + blank_line + back_help_footer } settings_menu(){ do_action "" "settings_ui" while true; do read -p "${cyan}Perform action:${white} " action; echo - case "$action" in + case "${action}" in 1) - if [ ! -z $klipper_cfg_loc ]; then - do_action "change_klipper_cfg_path" "settings_ui" - else - deny_action "settings_ui" - fi;; + switch_mainsail && settings_menu;; + 2) + switch_fluidd && settings_menu;; B|b) - clear; main_menu; break;; + clear + main_menu + break;; *) deny_action "settings_ui";; esac done - settings_ui +} + +function switch_mainsail() { + read_kiauh_ini + local state="${mainsail_always_install_latest}" + if [ "${state}" == "false" ]; then + sed -i '/mainsail_always_install_latest=/s/false/true/' "${INI_FILE}" + log_info "mainsail_always_install_latest changed (false -> true) " + else + sed -i '/mainsail_always_install_latest=/s/true/false/' "${INI_FILE}" + log_info "mainsail_always_install_latest changed (true -> false) " + fi +} + +function switch_fluidd() { + read_kiauh_ini + local state="${fluidd_always_install_latest}" + if [ "${state}" == "false" ]; then + sed -i '/fluidd_always_install_latest=/s/false/true/' "${INI_FILE}" + log_info "fluidd_always_install_latest changed (false -> true) " + else + sed -i '/fluidd_always_install_latest=/s/true/false/' "${INI_FILE}" + log_info "fluidd_always_install_latest changed (true -> false) " + fi } diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 6fea6d5..6336101 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -146,6 +146,9 @@ function init_ini(){ if ! grep -Eq "^mainsail_always_install_latest=" "${INI_FILE}"; then echo -e "\nmainsail_always_install_latest=false\c" >> "${INI_FILE}" fi + if ! grep -Eq "^fluidd_always_install_latest=" "${INI_FILE}"; then + echo -e "\nfluidd_always_install_latest=false\c" >> "${INI_FILE}" + fi fetch_webui_ports } From 8aae1f34ac5fdc7c0006fca862fd376c31cf501b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 01:03:45 +0200 Subject: [PATCH 059/183] style(mainsail.sh): fix some shellcheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 78 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 3d0d8cd..774ddde 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -161,20 +161,20 @@ function get_mainsail_ver(){ function mainsail_status(){ mcount=0 mainsail_data=( - $MAINSAIL_DIR - $NGINX_SA/mainsail - $NGINX_SE/mainsail + "${MAINSAIL_DIR}" + "${NGINX_SA}/mainsail" + "${NGINX_SE}/mainsail" ) #count+1 for each found data-item from array for md in "${mainsail_data[@]}" do - if [ -e $md ]; then - mcount=$(expr $mcount + 1) + if [ -e "${md}" ]; then + mcount=$((mcount + 1)) fi done - if [ "$mcount" == "${#mainsail_data[*]}" ]; then + if [ "${mcount}" == "${#mainsail_data[*]}" ]; then MAINSAIL_STATUS="${green}Installed!${white} " - elif [ "$mcount" == 0 ]; then + elif [ "${mcount}" == 0 ]; then MAINSAIL_STATUS="${red}Not installed!${white} " else MAINSAIL_STATUS="${yellow}Incomplete!${white} " @@ -194,28 +194,28 @@ function read_local_mainsail_version(){ function read_remote_mainsail_version(){ #remote checks don't work without curl installed! if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - MAINSAIL_REMOTE_VER=$NONE + MAINSAIL_REMOTE_VER=${NONE} else get_mainsail_ver - MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION + MAINSAIL_REMOTE_VER=${MAINSAIL_VERSION} fi } function compare_mainsail_versions(){ unset MAINSAIL_UPDATE_AVAIL read_local_mainsail_version && read_remote_mainsail_version - if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then + if [ "${MAINSAIL_VER_FOUND}" = "true" ] && [ "${MAINSAIL_LOCAL_VER}" == "${MAINSAIL_REMOTE_VER}" ]; then #printf fits the string for displaying it in the ui to a total char length of 12 - MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${white}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}" - elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then - MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${white}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}" + MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "${MAINSAIL_LOCAL_VER}")${white}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "${MAINSAIL_REMOTE_VER}")${white}" + elif [ "${MAINSAIL_VER_FOUND}" = "true" ] && [ "${MAINSAIL_LOCAL_VER}" != "${MAINSAIL_REMOTE_VER}" ]; then + MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "${MAINSAIL_LOCAL_VER}")${white}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "${MAINSAIL_REMOTE_VER}")${white}" # add mainsail to the update all array for the update all function in the updater MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) else - MAINSAIL_LOCAL_VER=$NONE - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}" + MAINSAIL_LOCAL_VER=${NONE} + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "${MAINSAIL_REMOTE_VER}")${white}" MAINSAIL_UPDATE_AVAIL="false" fi } @@ -226,22 +226,22 @@ function compare_mainsail_versions(){ function get_theme_list(){ theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" - theme_csv=$(curl -s -L $theme_csv_url) + theme_csv=$(curl -s -L "${theme_csv_url}") unset t_name unset t_note unset t_auth unset t_url i=0 while IFS="," read -r col1 col2 col3 col4; do - t_name+=("$col1") - t_note+=("$col2") - t_auth+=("$col3") - t_url+=("$col4") - if [ ! "$col1" == "name" ]; then - printf "| $i) %-50s|\n" "[$col1]" + t_name+=("${col1}") + t_note+=("${col2}") + t_auth+=("${col3}") + t_url+=("${col4}") + if [ ! "${col1}" == "name" ]; then + printf "| ${i}) %-50s|\n" "[${col1}]" fi i=$((i+1)) - done <<< "$theme_csv" + done <<< "${theme_csv}" } function ms_theme_ui(){ @@ -265,17 +265,17 @@ function ms_theme_menu(){ ms_theme_ui while true; do read -p "${cyan}Install theme:${white} " a; echo - if [ "$a" = "b" ] || [ "$a" = "B" ]; then + if [ "${a}" = "b" ] || [ "${a}" = "B" ]; then clear && advanced_menu && break - elif [ "$a" = "r" ] || [ "$a" = "R" ]; then + elif [ "${a}" = "r" ] || [ "${a}" = "R" ]; then ms_theme_delete ms_theme_menu - elif [ "$a" -le ${#t_url[@]} ]; then - ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" + elif [ "${a}" -le ${#t_url[@]} ]; then + ms_theme_install "${t_auth[${a}]}" "${t_url[${a}]}" "${t_name[${a}]}" "${t_note[${a}]}" ms_theme_menu else clear && print_header - ERROR_MSG="Invalid command!" && print_msg && clear_msg + print_error "Invalid command!" ms_theme_menu fi done @@ -287,12 +287,12 @@ function check_select_printer(){ ### get klipper cfg loc and set default .theme folder loc check_klipper_cfg_path - THEME_PATH="$klipper_cfg_loc" + THEME_PATH="${KLIPPER_CONFIG}" ### check if there is more than one moonraker instance and if yes ### ask the user to select the printer he wants to install/remove the theme - MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l) - if [[ $MR_SERVICE_COUNT -gt 1 ]]; then + MR_SERVICE_COUNT=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service" | wc -l) + if [[ ${MR_SERVICE_COUNT} -gt 1 ]]; then top_border echo -e "| More than one printer was found on this system! | " echo -e "| Please select the printer to which you want to | " @@ -301,11 +301,11 @@ function check_select_printer(){ read -p "${cyan}Select printer:${white} " printer_num ### rewrite the .theme path matching the selected printer - THEME_PATH="$klipper_cfg_loc/printer_$printer_num" + THEME_PATH="${KLIPPER_CONFIG}/printer_${printer_num}" fi ### create the cfg folder if there is none yet - [ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH" + [ ! -d "${THEME_PATH}" ] && mkdir -p "${THEME_PATH}" } function ms_theme_install(){ @@ -318,8 +318,8 @@ function ms_theme_install(){ status_msg "Installing $3 ..." status_msg "Please wait ..." - [ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme" - cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" + [ -d "${THEME_PATH}/.theme" ] && rm -rf "${THEME_PATH}/.theme" + cd "${THEME_PATH}" && git clone "${THEME_URL}" ".theme" ok_msg "Theme installation complete!" [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${white}" @@ -328,9 +328,9 @@ function ms_theme_install(){ function ms_theme_delete(){ check_select_printer - if [ -d "$THEME_PATH/.theme" ]; then + if [ -d "${THEME_PATH}/.theme" ]; then status_msg "Removing Theme ..." - rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n" + rm -rf "${THEME_PATH}/.theme" && ok_msg "Theme removed!\n" else status_msg "No Theme installed!\n" fi From c1358531abfa62e473b41e3372377faebcaa76ba Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 01:22:07 +0200 Subject: [PATCH 060/183] feat(settings_menu.sh): add help dialog Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/settings_menu.sh | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 53dc4ba..a9013e9 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -51,6 +51,40 @@ function settings_ui() { back_help_footer } +function show_settings_help(){ + top_border + echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |" + hr + echo -e "| ${cyan}Klipper config folder:${white} |" + echo -e "| The location of your printer.cfg and all other config |" + echo -e "| files that gets used during installation of Klipper |" + echo -e "| and all other components which need that location. |" + echo -e "| Default: /home//klipper_config |" + blank_line + echo -e "| ${cyan}Mainsail latest / Fluidd latest:${white} |" + echo -e "| If this setting is set to 'true', KIAUH will always |" + echo -e "| install or update Mainsail / Fluidd to the currently |" + echo -e "| latest available version. NOTE: This will include |" + echo -e "| alpha, beta, and rc (release-candidate) versions! |" + echo -e "| If this setting is set to 'false', KIAUH will only |" + echo -e "| install the latest STABLE Mainsail version. |" + echo -e "| Toggle between 'true' / 'false' by typing '1' / '2' |" + echo -e "| and hit enter. Default: 'false' |" + blank_line + back_footer + while true; do + read -p "${cyan}###### Please select:${white} " choice + case "${choice}" in + B|b) + clear && print_header + settings_menu + break;; + *) + deny_action "show_settings_help";; + esac + done +} + settings_menu(){ do_action "" "settings_ui" while true; do @@ -64,6 +98,10 @@ settings_menu(){ clear main_menu break;; + H|h) + clear && print_header + show_settings_help + break;; *) deny_action "settings_ui";; esac From 1cc0bb927f8b0d6fd35918f242843dd857175eef Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 11:33:29 +0200 Subject: [PATCH 061/183] refactor(mainsail.sh): reword setting Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 2 +- scripts/ui/settings_menu.sh | 55 ++++++++++++++++++------------------- scripts/utilities.sh | 8 +++--- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 774ddde..df1a309 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -353,7 +353,7 @@ function get_mainsail_download_url() { stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip" read_kiauh_ini - if [ "${mainsail_always_install_latest}" == "true" ]; then + if [ "${mainsail_install_unstable}" == "true" ]; then url="${latest_url}" echo "${url}" else diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index a9013e9..1f989d6 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -43,10 +43,9 @@ function settings_ui() { echo -e "| Klipper: |" printf "| Config folder: %-49s|\n" "${custom_cfg_loc}" blank_line - echo -e "| Klipper Webinterface: |" - printf "| 1) Install Mainsail latest: %-38s|\n" "${ms_pre_rls}" - printf "| 2) Install Fluidd latest: %-38s|\n" "${fl_pre_rls}" - hr + echo -e "| Install unstable releases: |" + printf "| 1) Mainsail: %-53s|\n" "${ms_pre_rls}" + printf "| 2) Fluidd: %-53s|\n" "${fl_pre_rls}" blank_line back_help_footer } @@ -59,17 +58,17 @@ function show_settings_help(){ echo -e "| The location of your printer.cfg and all other config |" echo -e "| files that gets used during installation of Klipper |" echo -e "| and all other components which need that location. |" - echo -e "| Default: /home//klipper_config |" + echo -e "| This location can not be changed from within KIAUH. |" + echo -e "| Default: ${cyan}/home//klipper_config${white} |" blank_line - echo -e "| ${cyan}Mainsail latest / Fluidd latest:${white} |" - echo -e "| If this setting is set to 'true', KIAUH will always |" - echo -e "| install or update Mainsail / Fluidd to the currently |" - echo -e "| latest available version. NOTE: This will include |" - echo -e "| alpha, beta, and rc (release-candidate) versions! |" - echo -e "| If this setting is set to 'false', KIAUH will only |" - echo -e "| install the latest STABLE Mainsail version. |" - echo -e "| Toggle between 'true' / 'false' by typing '1' / '2' |" - echo -e "| and hit enter. Default: 'false' |" + echo -e "| ${cyan}Install unstable releases:${white} |" + echo -e "| If set to ${green}true${white}, KIAUH installs/updates the software |" + echo -e "| with the latest, currently available release. |" + echo -e "| ${yellow}This will include alpha, beta and rc releases!${white} |" + echo -e "| If set to ${red}false${white}, KIAUH installs/updates the software |" + echo -e "| with the most recent stable release. |" + echo -e "| Change this setting by typing 1 or 2 and hit ENTER. |" + echo -e "| Default: ${red}false${white} |" blank_line back_footer while true; do @@ -91,9 +90,9 @@ settings_menu(){ read -p "${cyan}Perform action:${white} " action; echo case "${action}" in 1) - switch_mainsail && settings_menu;; + switch_mainsail_releasetype && settings_menu;; 2) - switch_fluidd && settings_menu;; + switch_fluidd_releasetype && settings_menu;; B|b) clear main_menu @@ -108,26 +107,26 @@ settings_menu(){ done } -function switch_mainsail() { +function switch_mainsail_releasetype() { read_kiauh_ini - local state="${mainsail_always_install_latest}" + local state="${mainsail_install_unstable}" if [ "${state}" == "false" ]; then - sed -i '/mainsail_always_install_latest=/s/false/true/' "${INI_FILE}" - log_info "mainsail_always_install_latest changed (false -> true) " + sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}" + log_info "mainsail_install_unstable changed (false -> true) " else - sed -i '/mainsail_always_install_latest=/s/true/false/' "${INI_FILE}" - log_info "mainsail_always_install_latest changed (true -> false) " + sed -i '/mainsail_install_unstable=/s/true/false/' "${INI_FILE}" + log_info "mainsail_install_unstable changed (true -> false) " fi } -function switch_fluidd() { +function switch_fluidd_releasetype() { read_kiauh_ini - local state="${fluidd_always_install_latest}" + local state="${fluidd_install_unstable}" if [ "${state}" == "false" ]; then - sed -i '/fluidd_always_install_latest=/s/false/true/' "${INI_FILE}" - log_info "fluidd_always_install_latest changed (false -> true) " + sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}" + log_info "fluidd_install_unstable changed (false -> true) " else - sed -i '/fluidd_always_install_latest=/s/true/false/' "${INI_FILE}" - log_info "fluidd_always_install_latest changed (true -> false) " + sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}" + log_info "fluidd_install_unstable changed (true -> false) " fi } diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 6336101..04e0622 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -143,11 +143,11 @@ function init_ini(){ if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}" fi - if ! grep -Eq "^mainsail_always_install_latest=" "${INI_FILE}"; then - echo -e "\nmainsail_always_install_latest=false\c" >> "${INI_FILE}" + if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then + echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}" fi - if ! grep -Eq "^fluidd_always_install_latest=" "${INI_FILE}"; then - echo -e "\nfluidd_always_install_latest=false\c" >> "${INI_FILE}" + if ! grep -Eq "^fluidd_install_unstable=" "${INI_FILE}"; then + echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}" fi fetch_webui_ports } From dd5e77520f8d94e68754bc4634526f628cd9484a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 12:44:44 +0200 Subject: [PATCH 062/183] fix(dependency_check): input was not taken as an array Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 73 ++------------------------------------------ 1 file changed, 2 insertions(+), 71 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 04e0622..e555793 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -339,10 +339,10 @@ restart_nginx(){ } dependency_check(){ - local dep="${1}" # dep: array + local dep=( "${@}" ) # dep: array status_msg "Checking for the following dependencies:" #check if package is installed, if not write name into array - for pkg in ${dep} + for pkg in "${dep[@]}" do echo -e "${cyan}● ${pkg} ${white}" if [[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]]; then @@ -479,75 +479,6 @@ function system_check_webui(){ fi } -function get_user_selection_kiauh_macros(){ - #ask user for webui default macros - while true; do - unset ADD_KIAUH_MACROS - echo - top_border - echo -e "| It is recommended to have some important macros set |" - echo -e "| up in your printer configuration to have $1|" - echo -e "| fully functional and working. |" - blank_line - echo -e "| Those macros are: |" - echo -e "| ${cyan}● [gcode_macro PAUSE]${white} |" - echo -e "| ${cyan}● [gcode_macro RESUME]${white} |" - echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${white} |" - blank_line - echo -e "| If you already have these macros in your config file |" - echo -e "| you can skip this step and choose 'no'. |" - echo -e "| Otherwise you should consider to answer with 'yes' to |" - echo -e "| add the recommended example macros to your config. |" - bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - ADD_KIAUH_MACROS="true" - break;; - N|n|No|no) - echo -e "###### > No" - ADD_KIAUH_MACROS="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -function install_kiauh_macros(){ - ### copy kiauh_macros.cfg - if [ "${ADD_KIAUH_MACROS}" = "true" ]; then - ### create a backup of the config folder - backup_klipper_config_dir - ### handle multi printer.cfg - if ls "${KLIPPER_CONFIG}"/printer_* 2>/dev/null 1>&2; then - for config in $(find ${KLIPPER_CONFIG}/printer_*/printer.cfg); do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [ ! -f "${path}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" - ok_msg "${path}/kiauh_macros.cfg created!" - fi - done - ### handle single printer.cfg - elif [ -f "${KLIPPER_CONFIG}/printer.cfg" ] && [ ! -f "${KLIPPER_CONFIG}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${KLIPPER_CONFIG}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${KLIPPER_CONFIG}/printer.cfg" - ok_msg "${KLIPPER_CONFIG}/kiauh_macros.cfg created!" - fi - ### restart klipper service to parse the modified printer.cfg - do_action_service "restart" "klipper" - fi -} - function process_octoprint_dialog(){ #ask user to disable octoprint when its service was found if [ "${OCTOPRINT_ENABLED}" = "true" ]; then From 95f473c4ca82ccc74679575c0664bbc5d6b941b0 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 12:54:08 +0200 Subject: [PATCH 063/183] feat(mainsail.sh): download official mainsail.cfg macro file Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 70 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index df1a309..8757115 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -28,7 +28,7 @@ function install_mainsail(){ print_error "${error}" && return fi ### checking dependencies - local dep=(nginx) + local dep=(wget nginx) dependency_check "${dep[@]}" ### check if moonraker is already installed system_check_webui @@ -52,9 +52,8 @@ function install_mainsail(){ fi ### ask user to install the recommended webinterface macros - if ! ls "${KLIPPER_CONFIG}/kiauh_macros.cfg" 2>/dev/null 1>&2 || ! ls "${KLIPPER_CONFIG}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then - get_user_selection_kiauh_macros "Mainsail " - fi + install_mainsail_macros + ### create /etc/nginx/conf.d/upstreams.conf set_upstream_nginx_cfg ### create /etc/nginx/sites-available/ @@ -78,6 +77,69 @@ function install_mainsail(){ print_confirm "Mainsail has been set up!" } +function install_mainsail_macros(){ + while true; do + echo + top_border + echo -e "| It is recommended to have some important macros in |" + echo -e "| your printer configuration to have Mainsail fully |" + echo -e "| functional and working. |" + blank_line + echo -e "| The recommended macros can be seen here: |" + echo -e "| https://docs.mainsail.xyz/configuration#macros |" + blank_line + echo -e "| If you already have these macros in your config file, |" + echo -e "| skip this step and answer with 'no'. |" + echo -e "| Otherwise you should consider to answer with 'yes' to |" + echo -e "| add the recommended example macros to your config. |" + bottom_border + read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + download_mainsail_macros + break;; + N|n|No|no) + select_msg "No" + break;; + *) + print_error "Invalid command!";; + esac + done + return +} + +function download_mainsail_macros(){ + log_info "executing: download_mainsail_macros" + local ms_cfg="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mainsail/filesystem/home/pi/klipper_config/mainsail.cfg" + local configs + configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg") + if [ -n "${configs}" ]; then + ### create a backup of the config folder + backup_klipper_config_dir + + for config in ${configs}; do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/mainsail.cfg" ]; then + status_msg "Downloading mainsail.cfg to ${path} ..." + log_info "downloading mainsail.cfg to: ${path}" + wget "${ms_cfg}" -O "${path}/mainsail.cfg" + ### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi' + log_info "modify mainsail.cfg" + sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg" + ### write the include to the very first line of the printer.cfg + log_info "modify printer.cfg" + sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg" + + ok_msg "Done!" + fi + done + else + log_error "execution stopped! reason: no printer.cfg found" + return + fi +} + function mainsail_setup(){ local url url=$(get_mainsail_download_url) From e8689cb8e7b25932859d084b76746c2247ecf74c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 12:55:41 +0200 Subject: [PATCH 064/183] fix(mainsail.sh): cd failed Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 8757115..cdf7cf6 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -146,16 +146,15 @@ function mainsail_setup(){ status_msg "Downloading Mainsail ..." if [ -d "${MAINSAIL_DIR}" ]; then rm -rf "${MAINSAIL_DIR}" - mkdir "${MAINSAIL_DIR}" fi - cd "${MAINSAIL_DIR}" && wget "${url}" - ok_msg "Download complete!" + mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" + wget "${url}" && ok_msg "Download complete!" status_msg "Extracting archive ..." - unzip -q -o *.zip && ok_msg "Done!" + unzip -q -o ./*.zip && ok_msg "Done!" status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" + rm -rf ./*.zip && ok_msg "Done!" ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode if [ "$(moonraker_systemd | wc -w)" -gt 1 ]; then From b5b20b89c6f5c890917d2160547dfc14a8f45776 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 12:57:11 +0200 Subject: [PATCH 065/183] fix(mainsail.sh): return if config.json doesn't exist Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index cdf7cf6..d74b944 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -475,6 +475,7 @@ function select_mainsail_port(){ } function enable_mainsail_remotemode(){ + [ ! -f "${MAINSAIL_DIR}/config.json" ] && return rm -f "${MAINSAIL_DIR}/config.json" echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" } \ No newline at end of file From 08f95cbb1bdd89f961fe167e67a2af33ca9ca5b7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 13:15:59 +0200 Subject: [PATCH 066/183] fix(mainsail.sh): prevent multiple includes Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index d74b944..2da3b97 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -128,8 +128,10 @@ function download_mainsail_macros(){ log_info "modify mainsail.cfg" sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg" ### write the include to the very first line of the printer.cfg - log_info "modify printer.cfg" - sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg" + if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then + log_info "modify printer.cfg" + sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg" + fi ok_msg "Done!" fi From 2e7717501777dee805cb1eeba4aa70498e78be17 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 13:47:26 +0200 Subject: [PATCH 067/183] fix(moonraker.sh): display of ip list after installation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 145 ++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 78 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 7aa9ebb..759e34b 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -88,7 +88,7 @@ function moonraker_setup_dialog(){ moonraker_setup "${count}" break;; N|n|No|no) - select_msg"No" + select_msg "No" error_msg "Exiting Moonraker setup ...\n" break;; *) @@ -129,9 +129,9 @@ function create_moonraker_virtualenv(){ } function moonraker_setup(){ - local instances=${1} + local confirm_msg instances=${1} ### checking dependencies - dep=(wget curl unzip dfu-util virtualenv) + dep=(git wget curl unzip dfu-util virtualenv) ### additional required dependencies on armbian dep+=(libjpeg-dev zlib1g-dev) dependency_check "${dep[@]}" @@ -161,15 +161,10 @@ function moonraker_setup(){ do_action_service "start" "moonraker" ### confirm message - if [[ ${instances} -eq 1 ]]; then - local confirm="Moonraker has been set up!" - elif [[ ${instances} -gt 1 ]]; then - local confirm="${instances} Moonraker instances have been set up!" - fi - print_confirm "${confirm}" - - print_mr_ip_list "${mr_ip_list}" - return + [ "${instances}" -eq 1 ] && confirm_msg="Moonraker has been set up!" + [ "${instances}" -gt 1 ] && confirm_msg="${instances} Moonraker instances have been set up!" + print_confirm "${confirm_msg}" + print_mr_ip_list "${instances}" } function write_moonraker_service(){ @@ -188,6 +183,59 @@ function write_moonraker_service(){ fi } +function create_moonraker_conf(){ + local lan instances=${1} log="${HOME}/klipper_logs" + lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" + + if [ "${instances}" -eq 1 ]; then + local cfg_dir="${KLIPPER_CONFIG}" + local cfg="${cfg_dir}/moonraker.conf" + local port=7125 + local db="${HOME}/.moonraker_database" + local uds="/tmp/klippy_uds" + ### write single instance config + write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" + elif [ "${instances}" -gt 1 ]; then + local i=1 + while [ "${i}" -le "${instances}" ]; do + local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" + local cfg="${cfg_dir}/moonraker.conf" + local port=7125 + local db="${HOME}/.moonraker_database_${i}" + local uds="/tmp/klippy_uds-${i}" + ### write multi instance config + write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" + port=$((port+1)) + i=$((i+1)) + done && unset port i + else + return 1 + fi +} + +function write_moonraker_conf(){ + local cfg_dir=${1} cfg=${2} port=${3} log=${4} db=${5} uds=${6} lan=${7} + local conf_template="${SRCDIR}/kiauh/resources/moonraker.conf" + [ ! -d "${cfg_dir}" ] && mkdir -p "${cfg_dir}" + + if [ ! -f "${cfg}" ]; then + status_msg "Creating moonraker.conf in ${cfg_dir} ..." + cp "${conf_template}" "${cfg}" + sed -i "s|%USER%|${USER}|g" "${cfg}" + sed -i "s|%CFG%|${cfg_dir}|; s|%PORT%|${port}|; s|%LOG%|${log}|; s|%DB%|${db}|; s|%UDS%|${uds}|" "${cfg}" + # if host ip is not in the default ip ranges replace placeholder, + # otherwise remove placeholder from config + if ! grep -q "${lan}" "${cfg}"; then + sed -i "s|%LAN%|${lan}|" "${cfg}" + else + sed -i "/%LAN%/d" "${cfg}" + fi + ok_msg "moonraker.conf created!" + else + status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..." + fi +} + function create_moonraker_service(){ local instances=${1} if [ "${instances}" -eq 1 ]; then @@ -223,73 +271,14 @@ function create_moonraker_service(){ fi } -function write_moonraker_conf(){ - local cfg_dir=${1} cfg=${2} port=${3} log=${4} db=${5} uds=${6} lan=${7} - local conf_template="${SRCDIR}/kiauh/resources/moonraker.conf" - [ ! -d "${cfg_dir}" ] && mkdir -p "${cfg_dir}" - - if [ ! -f "${cfg}" ]; then - status_msg "Creating moonraker.conf in ${cfg_dir} ..." - cp "${conf_template}" "${cfg}" - sed -i "s|%USER%|${USER}|g" "${cfg}" - sed -i "s|%CFG%|${cfg_dir}|; s|%PORT%|${port}|; s|%LOG%|${log}|; s|%DB%|${db}|; s|%UDS%|${uds}|" "${cfg}" - # if host ip is not in the default ip ranges replace placeholder, - # otherwise remove placeholder from config - if ! grep -q "${lan}" "${cfg}"; then - sed -i "s|%LAN%|${lan}|" "${cfg}" - else - sed -i "/%LAN%/d" "${cfg}" - fi - ok_msg "moonraker.conf created!" - else - status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..." - fi -} - -function create_moonraker_conf(){ - local instances=${1} - local log="${HOME}/klipper_logs" - local mr_ip_list=() - local ip lan - - ip=$(hostname -I | cut -d" " -f1) - lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" - - if [ "${instances}" -eq 1 ]; then - local cfg_dir="${KLIPPER_CONFIG}" - local cfg="${cfg_dir}/moonraker.conf" - local port=7125 - local db="${HOME}/.moonraker_database" - local uds="/tmp/klippy_uds" - ### write single instance config - write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" - mr_ip_list+=("${ip}:${port}") - elif [ "${instances}" -gt 1 ]; then - local i=1 - while [ "${i}" -le "${instances}" ]; do - local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" - local cfg="${cfg_dir}/moonraker.conf" - local port=7125 - local db="${HOME}/.moonraker_database_${i}" - local uds="/tmp/klippy_uds-${i}" - ### write multi instance config - write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" - mr_ip_list+=("${ip}:${port}") - port=$((port+1)) - i=$((i+1)) - done && unset port i - else - return 1 - fi - export mr_ip_list -} - function print_mr_ip_list(){ - local ips=${1} - local i=0 - for ip in "${ips[@]}"; do - echo -e " ${cyan}● Instance $((i + 1)):${white} ${ip}" - done + local ip instances="${1}" i=1 port=7125 + ip=$(hostname -I | cut -d" " -f1) + while [ "${i}" -le "${instances}" ] ; do + echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}" + port=$((port+1)) + i=$((i+1)) + done && echo } ### introduced due to From 439db3ce2cdfcfa718f568c6b701ea19211f12e3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 13:48:07 +0200 Subject: [PATCH 068/183] fix(moonraker.conf): typo in template Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/moonraker.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/moonraker.conf b/resources/moonraker.conf index 9b99cb7..c86c6d3 100644 --- a/resources/moonraker.conf +++ b/resources/moonraker.conf @@ -5,7 +5,7 @@ enable_debug_logging: False klippy_uds_address: %UDS% [database] -database_path: %MR_DB% +database_path: %DB% [authorization] trusted_clients: From eaaa0ce02b1b46aa670a3d10bb04eab2dcdab387 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 13:57:24 +0200 Subject: [PATCH 069/183] fix(backup.sh): fix backup of klipper_config dir Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index e7b6dfa..e13ba6c 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -13,6 +13,7 @@ set -e ### global variables BACKUP_DIR="${HOME}/kiauh-backups" +KLIPPER_CONFIG="${HOME}/klipper_config" function check_for_backup_dir(){ if [ ! -d "${BACKUP_DIR}" ]; then @@ -64,15 +65,14 @@ function backup_printer_cfg(){ } function backup_klipper_config_dir(){ - source_kiauh_ini check_for_backup_dir - if [ -d "${klipper_cfg_loc}" ]; then + if [ -d "${KLIPPER_CONFIG}" ]; then get_date status_msg "Timestamp: ${current_date}" status_msg "Create backup of the Klipper config directory ..." - config_folder_name="$(echo "${klipper_cfg_loc}" | rev | cut -d"/" -f1 | rev)" + config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)" mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" - cp -r "${klipper_cfg_loc}" "${_}" && ok_msg "Backup complete!" + cp -r "${KLIPPER_CONFIG}" "${_}" && ok_msg "Backup complete!" echo else ok_msg "No config directory found! Skipping backup ..." From b26c0faf67e01c5a5c4f5dd458b93a71c33130d8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 14:40:25 +0200 Subject: [PATCH 070/183] fix(utilities.sh): simplify do_action_service Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index e555793..e2ec222 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -282,23 +282,16 @@ set_klipper_cfg_path(){ } do_action_service(){ - shopt -s extglob # enable extended globbing - SERVICES="${SYSTEMD}/$2?(-*([0-9])).service" - ### set a variable for the ok and status messages - [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting" - [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping" - [ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting" - [ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling" - [ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling" - - if ls "${SERVICES}" 2>/dev/null 1>&2; then - for service in $(ls "${SERVICES}" | rev | cut -d"/" -f1 | rev); do - status_msg "${ACTION2} ${service} ..." - sudo systemctl "${1}" "${service}" - ok_msg "${service} ${ACTION1}!" + local action=${1} service=${2} + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[^0])?[0-9]*.service") + if [ -n "${services}" ]; then + for service in ${services}; do + service=$(echo "${service}" | rev | cut -d"/" -f1 | rev) + status_msg "${action^} ${service} ..." + sudo systemctl "${action}" "${service}" + ok_msg "OK!" done fi - shopt -u extglob # disable extended globbing } start_klipperscreen(){ From 1002ceb2a515e5ff1ec53a30fe13e1cf9a5f0a6d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 14:55:22 +0200 Subject: [PATCH 071/183] style(moonraker.sh): reformat Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 759e34b..f468d95 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -167,22 +167,6 @@ function moonraker_setup(){ print_mr_ip_list "${instances}" } -function write_moonraker_service(){ - local i=${1} cfg_dir=${2} cfg=${3} log=${4} service=${5} - local service_template="${SRCDIR}/kiauh/resources/moonraker.service" - - ### replace all placeholders - if [ ! -f "${service}" ]; then - status_msg "Creating Moonraker Service ${i} ..." - sudo cp "${service_template}" "${service}" - - [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" - [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" - sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}" - sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}" - fi - } - function create_moonraker_conf(){ local lan instances=${1} log="${HOME}/klipper_logs" lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" @@ -271,6 +255,22 @@ function create_moonraker_service(){ fi } +function write_moonraker_service(){ + local i=${1} cfg_dir=${2} cfg=${3} log=${4} service=${5} + local service_template="${SRCDIR}/kiauh/resources/moonraker.service" + + ### replace all placeholders + if [ ! -f "${service}" ]; then + status_msg "Creating Moonraker Service ${i} ..." + sudo cp "${service_template}" "${service}" + + [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" + [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" + sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}" + sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}" + fi +} + function print_mr_ip_list(){ local ip instances="${1}" i=1 port=7125 ip=$(hostname -I | cut -d" " -f1) From 63ea1542bafa604f822aff10aaf2d57a516a8f8f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 15:24:00 +0200 Subject: [PATCH 072/183] fix(moonraker.sh): bug in incrementing port Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index f468d95..b3cf73c 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -180,18 +180,17 @@ function create_moonraker_conf(){ ### write single instance config write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" elif [ "${instances}" -gt 1 ]; then - local i=1 + local i=1 port=7125 while [ "${i}" -le "${instances}" ]; do local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" local cfg="${cfg_dir}/moonraker.conf" - local port=7125 local db="${HOME}/.moonraker_database_${i}" local uds="/tmp/klippy_uds-${i}" ### write multi instance config write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" port=$((port+1)) i=$((i+1)) - done && unset port i + done else return 1 fi From ae2395f86bafb55d2c3d115aaae93452194f9179 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 15:39:42 +0200 Subject: [PATCH 073/183] fix(moonraker.sh): bug in instance confirmation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index b3cf73c..905f7a0 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -80,21 +80,23 @@ function moonraker_setup_dialog(){ error_msg "Invalid Input!\n" else echo - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - status_msg "Installing ${count} Moonraker instance(s) ... \n" - moonraker_setup "${count}" - break;; - N|n|No|no) - select_msg "No" - error_msg "Exiting Moonraker setup ...\n" - break;; - *) - print_error "Invalid command!" - ;; - esac + while true; do + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${default} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + status_msg "Installing ${count} Moonraker instance(s) ... \n" + moonraker_setup "${count}" + break;; + N|n|No|no) + select_msg "No" + error_msg "Exiting Moonraker setup ...\n" + break;; + *) + error_msg "Invalid Input!\n" + ;; + esac + done fi done } From 00876bd4bda39cd646f818e844e07c2a6616a2e4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 15:41:16 +0200 Subject: [PATCH 074/183] fix(moonraker.sh): remove polkit before deleting moonraker dir Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 905f7a0..d495323 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -395,9 +395,9 @@ function remove_moonraker(){ remove_moonraker_systemd remove_moonraker_logs remove_moonraker_api_key + remove_moonraker_polkit remove_moonraker_dir remove_moonraker_env - remove_moonraker_polkit remove_moonraker_nginx local confirm="Moonraker was successfully removed!" From 977bd2c144fa01851300cbb1052836c869cfd09d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 15:45:42 +0200 Subject: [PATCH 075/183] fix(moonraker.sh): remove polkit before deleting moonraker dir Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index d495323..3981546 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -375,8 +375,9 @@ function remove_moonraker_env() { } function remove_moonraker_polkit() { + [ ! -d "${MOONRAKER_DIR}" ] && return status_msg "Removing all Moonraker PolicyKit rules ..." - /bin/bash "${HOME}/moonraker/scripts/set-policykit-rules.sh" --clear + /bin/bash "${MOONRAKER_DIR}/scripts/set-policykit-rules.sh" --clear ok_msg "Done!" } From c6d7ba8f9c11fb077b0afe848af8dab2ca8645c4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 15:47:56 +0200 Subject: [PATCH 076/183] fix(klipper.sh): bug in instance confirmation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 31 ++++++++++++++++--------------- scripts/moonraker.sh | 3 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index f55adb9..34acdbc 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -77,21 +77,22 @@ function klipper_setup_dialog(){ error_msg "Invalid input!\n" else echo - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - status_msg "Installing ${count} Klipper instance(s) ... \n" - klipper_setup "${count}" - break;; - N|n|No|no) - select_msg "No" - abort_msg "Exiting Klipper setup ...\n" - break;; - *) - print_error "Invalid command!" - ;; - esac + while true; do + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + status_msg "Installing ${count} Klipper instance(s) ... \n" + klipper_setup "${count}" + break;; + N|n|No|no) + select_msg "No" + abort_msg "Exiting Klipper setup ...\n" + break;; + *) + error_msg "Invalid Input!\n";; + esac + done fi done } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 3981546..9e1685f 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -93,8 +93,7 @@ function moonraker_setup_dialog(){ error_msg "Exiting Moonraker setup ...\n" break;; *) - error_msg "Invalid Input!\n" - ;; + error_msg "Invalid Input!\n";; esac done fi From 81b69d455a1ba740e263877703bab8a965d7c230 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 18:27:11 +0200 Subject: [PATCH 077/183] refactor(moonraker.sh): reduce function calls Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 9e1685f..d35ac76 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -61,11 +61,13 @@ function moonraker_setup_dialog(){ print_error "${error}" && return fi + local klipper_count + klipper_count=$(klipper_systemd | wc -w) top_border if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then printf "|${green}%-55s${white}|\n" " 1 Klipper instance was found!" - elif [ "$(klipper_systemd | wc -w)" -gt 1 ]; then - printf "|${green}%-55s${white}|\n" " $(klipper_systemd | wc -w) Klipper instances were found!" + elif [ "${klipper_count}" -gt 1 ]; then + printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances were found!" else echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" fi From 898a6bbfd04b96422f4d5a30a206464e7c8b005d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 20:07:48 +0200 Subject: [PATCH 078/183] refactor(octoprint.sh): full refactor Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 368 +++++++++++++++++++------------------------ 1 file changed, 164 insertions(+), 204 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 157d112..53314aa 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -19,48 +19,53 @@ OCTOPRINT_ENV="${HOME}/OctoPrint" #=============== INSTALL OCTOPRINT ===============# #=================================================# -octoprint_setup_dialog(){ +function octoprint_setup_dialog(){ status_msg "Initializing OctoPrint installation ..." - ### count amount of klipper services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - INSTANCE_COUNT=1 + local klipper_count + klipper_count=$(klipper_systemd | wc -w) + top_border + if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then + printf "|${green}%-55s${white}|\n" " 1 Klipper instance was found!" + elif [ "${klipper_count}" -gt 1 ]; then + printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances were found!" else - INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) + echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" fi + echo -e "| Usually you need one OctoPrint instance per Klipper |" + echo -e "| instance. Though you can install as many as you wish. |" + bottom_border - ### instance confirmation dialog - while true; do + local count + while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do + read -p "${cyan}###### Number of OctoPrint instances to set up:${default} " count + if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then + error_msg "Invalid Input!\n" + else echo - top_border - if [ $INSTANCE_COUNT -gt 1 ]; then - printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" - else - echo -e "| 1 Klipper instance was found! | " - fi - echo -e "| You need one OctoPrint instance per Klipper instance. | " - bottom_border - echo - read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${white} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Creating $INSTANCE_COUNT OctoPrint instances ..." - octoprint_setup - break;; - N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting OctoPrint setup ..." - echo - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac + while true; do + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${default} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + status_msg "Installing ${count} OctoPrint instance(s) ... \n" + octoprint_setup "${count}" + break;; + N|n|No|no) + select_msg "No" + error_msg "Exiting OctoPrint setup ...\n" + break;; + *) + error_msg "Invalid Input!\n";; + esac + done + fi done } -octoprint_dependencies(){ +function octoprint_setup(){ + local instances="${1}" + ### check and install all dependencies dep=( git wget @@ -70,57 +75,86 @@ octoprint_dependencies(){ build-essential python-setuptools python-virtualenv - ) - dependency_check -} - -octoprint_setup(){ - ### check and install all dependencies - octoprint_dependencies + ) + dependency_check "${dep[@]}" ### add user to usergroups and add reboot permissions add_to_groups add_reboot_permission - ### create and activate the virtualenv - [ ! -d $OCTOPRINT_ENV ] && mkdir -p $OCTOPRINT_ENV - status_msg "Set up virtualenv ..." - cd $OCTOPRINT_ENV - virtualenv --python=python3 venv - source venv/bin/activate + ### install octoprint + install_octoprint - ### install octoprint with pip - status_msg "Download and install OctoPrint ..." + ### set up instances + if [ "${instances}" -eq 1 ]; then + create_single_octoprint_instance + else + create_multi_octoprint_instance "${instances}" + fi + + ### step 6: enable and start all instances + do_action_service "enable" "octoprint" + do_action_service "start" "octoprint" + + ### confirm message + [ "${instances}" -eq 1 ] && confirm_msg="OctoPrint has been set up!" + [ "${instances}" -gt 1 ] && confirm_msg="${instances} OctoPrint instances have been set up!" + print_confirm "${confirm_msg}" + print_op_ip_list "${instances}" +} + +function install_octoprint(){ + ### create and activate the virtualenv + [ ! -d "${OCTOPRINT_ENV}" ] && mkdir -p "${OCTOPRINT_ENV}" + status_msg "Installing python virtual environment..." + cd "${OCTOPRINT_ENV}" && virtualenv --python=python3 venv + ### activate virtualenv + source venv/bin/activate + status_msg "Installing OctoPrint ..." pip install pip --upgrade pip install --no-cache-dir octoprint ok_msg "Download complete!" - ### leave virtualenv deactivate - - ### set up instances - INSTANCE=1 - if [ $INSTANCE_COUNT -eq $INSTANCE ]; then - create_single_octoprint_instance - else - create_multi_octoprint_instance - fi } add_to_groups(){ if [ ! "$(groups | grep tty)" ]; then status_msg "Adding user '${USER}' to group 'tty' ..." - sudo usermod -a -G tty ${USER} && ok_msg "Done!" + sudo usermod -a -G tty "${USER}" && ok_msg "Done!" fi if [ ! "$(groups | grep dialout)" ]; then status_msg "Adding user '${USER}' to group 'dialout' ..." - sudo usermod -a -G dialout ${USER} && ok_msg "Done!" + sudo usermod -a -G dialout "${USER}" && ok_msg "Done!" fi } -create_single_octoprint_startscript(){ -### create single instance systemd service file -sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint.service" << OCTOPRINT +function create_config_yaml(){ + local base_dir=${1} tmp_printer=${2} restart_cmd=${3} + + /bin/sh -c "cat > ${base_dir}/config.yaml" << CONFIGYAML +serial: + additionalPorts: + - ${tmp_printer} + disconnectOnErrors: false + port: ${tmp_printer} +server: + commands: + serverRestartCommand: ${restart_cmd} + systemRestartCommand: sudo shutdown -r now + systemShutdownCommand: sudo shutdown -h now +CONFIGYAML +} + +function create_single_octoprint_instance(){ + local port=5000 + local base_dir="${HOME}/.octoprint" + local tmp_printer="/tmp/printer" + local config_yaml="${base_dir}/config.yaml" + local restart_cmd="sudo service octoprint restart" + + status_msg "Creating OctoPrint instance ..." + sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint.service" << OCTOPRINT [Unit] Description=Starts OctoPrint on startup After=network-online.target @@ -130,19 +164,36 @@ Wants=network-online.target Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple -User=$USER -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve +User=${USER} +ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${base_dir} --config ${config_yaml} --port=${port} serve [Install] WantedBy=multi-user.target OCTOPRINT + + ### create the config.yaml + if [ ! -f "${base_dir}/config.yaml" ]; then + status_msg "Creating config.yaml ..." + [ ! -d "${base_dir}" ] && mkdir "${base_dir}" + create_config_yaml "${base_dir}" "${tmp_printer}" "${restart_cmd}" + ok_msg "Config created!" + fi } -create_multi_octoprint_startscript(){ -### create multi instance systemd service file -sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint-$INSTANCE.service" << OCTOPRINT +function create_multi_octoprint_instance(){ + local i=1 port=5000 instance=${1} + while [ "${i}" -le "${instances}" ]; do + ### multi instance variables + local base_dir="${HOME}/.octoprint-${i}" + local tmp_printer="/tmp/printer-${i}" + local config_yaml="${base_dir}/config.yaml" + local restart_cmd="sudo service octoprint-${i} restart" + + ### create instance + status_msg "Creating instance #${i} ..." + sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint-${i}.service" << OCTOPRINT [Unit] -Description=Starts OctoPrint instance $INSTANCE on startup +Description=Starts OctoPrint instance ${instances} on startup After=network-online.target Wants=network-online.target @@ -150,162 +201,71 @@ Wants=network-online.target Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple -User=$USER -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve +User=${USER} +ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${base_dir} --config ${config_yaml} --port=${port} serve [Install] WantedBy=multi-user.target OCTOPRINT -} - -create_config_yaml(){ -### create multi instance config.yaml file -/bin/sh -c "cat > ${BASEDIR}/config.yaml" << CONFIGYAML -serial: - additionalPorts: - - ${TMP_PRINTER} - disconnectOnErrors: false - port: ${TMP_PRINTER} -server: - commands: - serverRestartCommand: ${RESTART_COMMAND} - systemRestartCommand: sudo shutdown -r now - systemShutdownCommand: sudo shutdown -h now -CONFIGYAML -} - -create_single_octoprint_instance(){ - status_msg "Setting up 1 OctoPrint instance ..." - - ### single instance variables - PORT=5000 - BASEDIR="${HOME}/.octoprint" - TMP_PRINTER="/tmp/printer" - CONFIG_YAML="$BASEDIR/config.yaml" - RESTART_COMMAND="sudo service octoprint restart" - - ### declare empty array for ips which get displayed to the user at the end of the setup - HOSTNAME=$(hostname -I | cut -d" " -f1) - op_ip_list=() - - ### create instance - status_msg "Creating single OctoPrint instance ..." - create_single_octoprint_startscript - op_ip_list+=("$HOSTNAME:$PORT") - - ### create the config.yaml - if [ ! -f $BASEDIR/config.yaml ]; then - status_msg "Creating config.yaml ..." - [ ! -d $BASEDIR ] && mkdir $BASEDIR - create_config_yaml - ok_msg "Config created!" - fi - - ### enable instance - sudo systemctl enable octoprint.service - ok_msg "Single OctoPrint instance created!" - - ### launching instance - status_msg "Launching OctoPrint instance ..." - sudo systemctl start octoprint - - ### confirm message - CONFIRM_MSG="Single OctoPrint instance has been set up!" - print_msg && clear_msg - - ### display all octoprint ips to the user - print_op_ip_list; echo -} - -create_multi_octoprint_instance(){ - status_msg "Setting up $INSTANCE_COUNT instances of OctoPrint ..." - - ### declare empty array for ips which get displayed to the user at the end of the setup - HOSTNAME=$(hostname -I | cut -d" " -f1) - op_ip_list=() - - ### default port - PORT=5000 - - while [ $INSTANCE -le $INSTANCE_COUNT ]; do - ### multi instance variables - BASEDIR="${HOME}/.octoprint-$INSTANCE" - TMP_PRINTER="/tmp/printer-$INSTANCE" - CONFIG_YAML="$BASEDIR/config.yaml" - RESTART_COMMAND="sudo service octoprint restart" - - ### create instance - status_msg "Creating instance #$INSTANCE ..." - create_multi_octoprint_startscript - op_ip_list+=("$HOSTNAME:$PORT") ### create the config.yaml - if [ ! -f $BASEDIR/config.yaml ]; then - status_msg "Creating config.yaml for instance #$INSTANCE..." - [ ! -d $BASEDIR ] && mkdir $BASEDIR + if [ ! -f "${base_dir}/config.yaml" ]; then + status_msg "Creating config.yaml for instance #${i}..." + [ ! -d "${base_dir}" ] && mkdir "${base_dir}" create_config_yaml - ok_msg "Config #$INSTANCE created!" + ok_msg "Config #${i} created!" fi ### enable instance - sudo systemctl enable octoprint-$INSTANCE.service - ok_msg "OctoPrint instance $INSTANCE created!" + sudo systemctl enable "octoprint-${i}.service" + ok_msg "OctoPrint instance ${i} created!" ### launching instance - status_msg "Launching OctoPrint instance $INSTANCE ..." - sudo systemctl start octoprint-$INSTANCE + status_msg "Launching OctoPrint instance ${i} ..." + sudo systemctl start "octoprint-${i}" - ### instance counter +1 - INSTANCE=$(expr $INSTANCE + 1) - - ### port +1 - PORT=$(expr $PORT + 1) + i=$((i+1)) + port=$((port+1)) done - - ### confirm message - CONFIRM_MSG="$INSTANCE_COUNT OctoPrint instances have been set up!" - print_msg && clear_msg - - ### display all moonraker ips to the user - print_op_ip_list; echo } -add_reboot_permission(){ - USER=${USER} - #create a backup when file already exists +function add_reboot_permission(){ + #create a backup if file already exists if [ -f /etc/sudoers.d/octoprint-shutdown ]; then sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old fi #create new permission file - status_msg "Add reboot permission to user '$USER' ..." - cd ${HOME} && echo "$USER ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown + status_msg "Add reboot permission to user '${USER}' ..." + cd "${HOME}" && echo "${USER} ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown sudo chown 0 octoprint-shutdown sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown ok_msg "Permission set!" } -print_op_ip_list(){ - i=1 - for ip in ${op_ip_list[@]}; do - echo -e " ${cyan}● Instance $i:${default} $ip" - i=$((i + 1)) - done +function print_op_ip_list(){ + local ip instances="${1}" i=1 port=5000 + ip=$(hostname -I | cut -d" " -f1) + while [ "${i}" -le "${instances}" ] ; do + echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}" + port=$((port+1)) + i=$((i+1)) + done && echo } #=================================================# #=============== REMOVE OCTOPRINT ================# #=================================================# -remove_octoprint(){ +function remove_octoprint(){ ###remove all octoprint services if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then status_msg "Removing OctoPrint Services ..." for service in $(ls /etc/systemd/system/octoprint*.service | cut -d"/" -f5) do - status_msg "Removing $service ..." - sudo systemctl stop $service - sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" ok_msg "OctoPrint Service removed!" done ### reloading units @@ -319,60 +279,60 @@ remove_octoprint(){ fi ### remove OctoPrint directory - if [ -d ${HOME}/OctoPrint ]; then + if [ -d "${HOME}/OctoPrint" ]; then status_msg "Removing OctoPrint directory ..." - rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!" + rm -rf "${HOME}/OctoPrint" && ok_msg "Directory removed!" fi ###remove .octoprint directories - if ls -d ${HOME}/.octoprint* 2>/dev/null 1>&2; then + if ls -d "${HOME}"/.octoprint* 2>/dev/null 1>&2; then for folder in $(ls -d ${HOME}/.octoprint*) do - status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!" + status_msg "Removing ${folder} ..." && rm -rf "${folder}" && ok_msg "Done!" done fi ### remove octoprint_port from ~/.kiauh.ini - sed -i "/^octoprint_port=/d" $INI_FILE + sed -i "/^octoprint_port=/d" "${INI_FILE}" - CONFIRM_MSG=" OctoPrint successfully removed!" + print_confirm "OctoPrint successfully removed!" } #=================================================# #=============== OCTOPRINT STATUS ================# #=================================================# -octoprint_status(){ +function octoprint_status(){ ocount=0 octoprint_data=( SERVICE - $OCTOPRINT_DIR + "${OCTOPRINT_DIR}" ) ### count amount of octoprint service files in /etc/systemd/system SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^octoprint(\-[[:digit:]]+)?\.service$" | wc -l) ### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed - [ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0] + [ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "octoprint_data[0]" #count+1 for each found data-item from array for op in "${octoprint_data[@]}" do - if [ -e $op ]; then - ocount=$(expr $ocount + 1) + if [ -e "${op}" ]; then + ocount=$((ocount+1)) fi done ### display status - if [ "$ocount" == "${#octoprint_data[*]}" ]; then - OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" - elif [ "$ocount" == 0 ]; then + if [ "${ocount}" == "${#octoprint_data[*]}" ]; then + OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" "${SERVICE_FILE_COUNT}")" + elif [ "${ocount}" == 0 ]; then OCTOPRINT_STATUS="${red}Not installed!${white} " else OCTOPRINT_STATUS="${yellow}Incomplete!${white} " fi } -read_octoprint_service_status(){ +function read_octoprint_service_status(){ unset OPRINT_SERVICE_STATUS if [ ! -f "/etc/systemd/system/octoprint.service" ]; then return 0 @@ -388,7 +348,7 @@ read_octoprint_service_status(){ #=================== HELPERS ====================# #================================================# -toggle_octoprint_service(){ +function toggle_octoprint_service(){ if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then do_action_service "stop" "octoprint" do_action_service "disable" "octoprint" From 00d63816ae4511d15af9c18c8941160b42f019b3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 23:12:09 +0200 Subject: [PATCH 079/183] refactor(octoprint.sh): rename base_dir to basedir Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 53314aa..9dcc6aa 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -132,7 +132,7 @@ add_to_groups(){ function create_config_yaml(){ local base_dir=${1} tmp_printer=${2} restart_cmd=${3} - /bin/sh -c "cat > ${base_dir}/config.yaml" << CONFIGYAML + /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML serial: additionalPorts: - ${tmp_printer} @@ -150,7 +150,7 @@ function create_single_octoprint_instance(){ local port=5000 local base_dir="${HOME}/.octoprint" local tmp_printer="/tmp/printer" - local config_yaml="${base_dir}/config.yaml" + local config_yaml="${basedir}/config.yaml" local restart_cmd="sudo service octoprint restart" status_msg "Creating OctoPrint instance ..." @@ -165,17 +165,17 @@ Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple User=${USER} -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${base_dir} --config ${config_yaml} --port=${port} serve +ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve [Install] WantedBy=multi-user.target OCTOPRINT ### create the config.yaml - if [ ! -f "${base_dir}/config.yaml" ]; then + if [ ! -f "${basedir}/config.yaml" ]; then status_msg "Creating config.yaml ..." - [ ! -d "${base_dir}" ] && mkdir "${base_dir}" - create_config_yaml "${base_dir}" "${tmp_printer}" "${restart_cmd}" + [ ! -d "${basedir}" ] && mkdir "${basedir}" + create_config_yaml "${basedir}" "${tmp_printer}" "${restart_cmd}" ok_msg "Config created!" fi } @@ -186,7 +186,7 @@ function create_multi_octoprint_instance(){ ### multi instance variables local base_dir="${HOME}/.octoprint-${i}" local tmp_printer="/tmp/printer-${i}" - local config_yaml="${base_dir}/config.yaml" + local config_yaml="${basedir}/config.yaml" local restart_cmd="sudo service octoprint-${i} restart" ### create instance @@ -202,16 +202,16 @@ Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple User=${USER} -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${base_dir} --config ${config_yaml} --port=${port} serve +ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve [Install] WantedBy=multi-user.target OCTOPRINT ### create the config.yaml - if [ ! -f "${base_dir}/config.yaml" ]; then + if [ ! -f "${basedir}/config.yaml" ]; then status_msg "Creating config.yaml for instance #${i}..." - [ ! -d "${base_dir}" ] && mkdir "${base_dir}" + [ ! -d "${basedir}" ] && mkdir "${basedir}" create_config_yaml ok_msg "Config #${i} created!" fi From 1dbbcf1eb2849a1cb79d7553d6d75ca990ebf249 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 23:29:44 +0200 Subject: [PATCH 080/183] refactor(flash_klipper.sh): fix some shellcheck warnings Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 76 ++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index fa2e721..c9102c1 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -11,7 +11,7 @@ set -e -show_flash_method_help(){ +function show_flash_method_help(){ top_border echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |" hr @@ -47,13 +47,12 @@ show_flash_method_help(){ select_flash_method break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done } -select_flash_method(){ +function select_flash_method(){ top_border echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |" hr @@ -89,13 +88,13 @@ select_flash_method(){ show_flash_method_help break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done } -select_mcu_id(){ +function select_mcu_id(){ + local id=0 sel_index=0 if [ ${#mcu_list[@]} -ge 1 ]; then top_border echo -e "| ${red}!!! ATTENTION !!!${white} |" @@ -105,47 +104,44 @@ select_mcu_id(){ bottom_border echo -e "${cyan}###### List of available MCU:${white}" ### list all mcus - id=0 for mcu in "${mcu_list[@]}"; do - let id++ + id=$((id+1)) echo -e " ${id}) ${mcu}" done ### verify user input - sel_index="" while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${id}" ]; do echo read -p "${cyan}###### Select MCU to flash:${white} " sel_index if [[ ! (${sel_index} =~ ^[1-9]+$) ]]; then - warn_msg "Invalid input!" + error_msg "Invalid input!" elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${id}" ]; then - warn_msg "Please select a number between 1 and ${id}!" + error_msg "Please select a number between 1 and ${id}!" fi - mcu_index=$(echo $((sel_index - 1))) + mcu_index=$((sel_index - 1)) selected_mcu_id="${mcu_list[${mcu_index}]}" done ### confirm selection while true; do echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n" read -p "${cyan}###### Continue? (Y/n):${white} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") - echo -e "###### > Yes" + select_msg "Yes" status_msg "Flashing ${selected_mcu_id} ..." CONFIRM_FLASH=true break;; N|n|No|no) - echo -e "###### > No" + select_msg "No" CONFIRM_FLASH=false break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done fi } -flash_mcu(){ +function flash_mcu(){ do_action_service "stop" "klipper" make flash FLASH_DEVICE="${mcu_list[${mcu_index}]}" ### evaluate exit code of make flash @@ -158,16 +154,15 @@ flash_mcu(){ do_action_service "start" "klipper" } -flash_mcu_sd(){ - flash_script="${HOME}/klipper/scripts/flash-sdcard.sh" +function flash_mcu_sd(){ + local i=0 board_list=() + local flash_script="${HOME}/klipper/scripts/flash-sdcard.sh" ### write each supported board to the array to make it selectable - board_list=() - for board in $("${flash_script}" -l | tail -n +2); do + for board in $(/bin/bash "${flash_script}" -l | tail -n +2); do board_list+=("${board}") done - i=0 top_border echo -e "| Please select the type of board that corresponds to |" echo -e "| the currently selected MCU ID you chose before. |" @@ -195,7 +190,7 @@ flash_mcu_sd(){ break else clear && print_header - ERROR_MSG="Invalid choice!" && print_msg && clear_msg + print_error "Invalid choice!" flash_mcu_sd fi done @@ -230,22 +225,22 @@ flash_mcu_sd(){ do_action_service "start" "klipper" } -build_fw(){ +function build_fw(){ if [ -d "${KLIPPER_DIR}" ]; then cd "${KLIPPER_DIR}" status_msg "Initializing firmware build ..." dep=(build-essential dpkg-dev make) - dependency_check + dependency_check "${dep[@]}" make clean && make menuconfig status_msg "Building firmware ..." make && ok_msg "Firmware built!" else - ERROR_MSG="Klipper was not found!\n Can not build firmware without Klipper!" - print_msg && clear_msg && return 1 + print_error "Klipper was not found!\n Can not build firmware without Klipper!" + return 1 fi } -select_mcu_connection(){ +function select_mcu_connection(){ echo top_border echo -e "| ${yellow}Make sure to have the controller board connected now!${white} |" @@ -277,25 +272,25 @@ select_mcu_connection(){ fi } -retrieve_id(){ +function retrieve_id(){ + local mcu_list=() mcu_count=1 status_msg "Identifying MCU ..." sleep 1 - mcu_list=() - mcu_count=1 - [ "$1" = "USB" ] && path="/dev/serial/by-id/*" - [ "$1" = "UART" ] && path="/dev/ttyAMA0" + [ "${1}" = "USB" ] && path="/dev/serial/by-id/*" + [ "${1}" = "UART" ] && path="/dev/ttyAMA0" if [[ "$(ls "${path}")" != "" ]] ; then for mcu in ${path}; do declare "mcu_id_${mcu_count}"="${mcu}" mcu_id="mcu_id_${mcu_count}" mcu_list+=("${!mcu_id}") echo -e " ● ($1) MCU #${mcu_count}: ${cyan}${mcu}${white}\n" - let mcu_count++ + mcu_count=$((mcu_count+1)) done fi 2>/dev/null } function check_usergroup_dialout(){ + local group_dialout if grep -q "dialout" Yes" + select_msg "Yes" status_msg "Adding user '${USER}' to group(s) ..." if [ "${group_tty}" == "false" ]; then sudo usermod -a -G tty "${USER}" && ok_msg "Group 'tty' assigned!" @@ -334,11 +329,10 @@ function check_usergroup_dialout(){ fi ok_msg "You need to relog/restart for the group(s) to be applied!" && exit 0;; N|n|No|no) - echo -e "###### > No" + select_msg "No" break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done fi From da2b5b777c7660538ffbde3ecf81dccd8029c01b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 3 Apr 2022 23:48:30 +0200 Subject: [PATCH 081/183] refactor(backup.sh): some refactor Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 6 ------ scripts/backup.sh | 13 +++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 119e7dd..93dbfe4 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -48,12 +48,6 @@ function kiauh_update_avail(){ fi } -### format some default message types -get_date(){ - current_date=$(date +"%y%m%d-%H%M") - export current_date -} - #print_unkown_cmd(){ # ERROR_MSG="Invalid command!" #} diff --git a/scripts/backup.sh b/scripts/backup.sh index e13ba6c..cde6557 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -15,6 +15,11 @@ set -e BACKUP_DIR="${HOME}/kiauh-backups" KLIPPER_CONFIG="${HOME}/klipper_config" +function get_date(){ + current_date=$(date +"%y%m%d-%H%M") + echo "${current_date}" +} + function check_for_backup_dir(){ if [ ! -d "${BACKUP_DIR}" ]; then status_msg "Create KIAUH backup directory ..." @@ -23,7 +28,7 @@ function check_for_backup_dir(){ } function toggle_backups(){ - source_kiauh_ini + read_kiauh_ini if [ "${backup_before_update}" = "true" ]; then sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}" BB4U_STATUS="${green}[Enable]${white} backups before updating " @@ -37,14 +42,14 @@ function toggle_backups(){ } function bb4u(){ - source_kiauh_ini + read_kiauh_ini if [ "${backup_before_update}" = "true" ]; then backup_"${1}" fi } function read_bb4u_stat(){ - source_kiauh_ini + read_kiauh_ini if [ ! "${backup_before_update}" = "true" ]; then BB4U_STATUS="${green}[Enable]${white} backups before updating " else @@ -82,7 +87,7 @@ function backup_klipper_config_dir(){ function backup_moonraker_database(){ check_for_backup_dir - if ls -d ${HOME}/.moonraker_database* 2>/dev/null 1>&2; then + if ls -d "${HOME}"/.moonraker_database* 2>/dev/null 1>&2; then get_date status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/mr_db_backup/${current_date}" From 2ad1ec55733d45bf1d02be0b6a37c9ac9c873d60 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 4 Apr 2022 00:02:20 +0200 Subject: [PATCH 082/183] refactor(network_functions.sh): some refactor Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/network_functions.sh | 72 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 784bd3b..006c24c 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -1,52 +1,53 @@ function set_nginx_cfg(){ - if [ "$SET_NGINX_CFG" = "true" ]; then + if [ "${SET_NGINX_CFG}" = "true" ]; then + local cfg="${SRCDIR}/kiauh/resources/${1}" #check for dependencies dep=(nginx) - dependency_check + dependency_check "${dep[@]}" #execute operations - status_msg "Creating Nginx configuration for $1 ..." + status_msg "Creating Nginx configuration for ${1} ..." #copy content from resources to the respective nginx config file - cat ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg > ${SRCDIR}/kiauh/resources/$1 + cat "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" > "${cfg}" ##edit the nginx config file before moving it - sed -i "s/<>/$1/g" ${SRCDIR}/kiauh/resources/$1 - if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then + sed -i "s/<>/${1}/g" "${cfg}" + if [ "${SET_LISTEN_PORT}" != "${DEFAULT_PORT}" ]; then status_msg "Configuring port for $1 ..." #set listen port ipv4 - sed -i "s/listen\s[0-9]*;/listen $SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1 + sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}" #set listen port ipv6 - sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1 + sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}" fi #set correct user - if [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then - sudo sed -i "/root/s/pi/${USER}/" ${SRCDIR}/kiauh/resources/$1 + if [ "${1}" = "mainsail" ] || [ "${1}" = "fluidd" ]; then + sudo sed -i "/root/s/pi/${USER}/" "${cfg}" fi #moving the config file into correct directory - sudo mv ${SRCDIR}/kiauh/resources/$1 /etc/nginx/sites-available/$1 + sudo mv "${cfg}" "/etc/nginx/sites-available/${1}" ok_msg "Nginx configuration for $1 was set!" - if [ "$SET_LISTEN_PORT" != "" ]; then - ok_msg "$1 listening on port $SET_LISTEN_PORT!" + if [ -n "${SET_LISTEN_PORT}" ]; then + ok_msg "${1} listening on port ${SET_LISTEN_PORT}!" else - ok_msg "$1 listening on default port $DEFAULT_PORT!" + ok_msg "${1} listening on default port ${DEFAULT_PORT}!" fi #remove nginx default config - [ -e /etc/nginx/sites-enabled/default ] && sudo rm /etc/nginx/sites-enabled/default + [ -e "/etc/nginx/sites-enabled/default" ] && sudo rm "/etc/nginx/sites-enabled/default" #create symlink for own sites - [ ! -e /etc/nginx/sites-enabled/$1 ] && sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ + [ ! -e "/etc/nginx/sites-enabled/${1}" ] && sudo ln -s "/etc/nginx/sites-available/${1}" "/etc/nginx/sites-enabled/" restart_nginx fi } function read_listen_port(){ - LISTEN_PORT=$(grep listen /etc/nginx/sites-enabled/$1 | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + LISTEN_PORT=$(grep listen "/etc/nginx/sites-enabled/${1}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) } function detect_enabled_sites(){ #check if there is another UI config already installed #and reads the port they are listening on - if [ -e /etc/nginx/sites-enabled/mainsail ]; then + if [ -e "/etc/nginx/sites-enabled/mainsail" ]; then SITE_ENABLED="true" && MAINSAIL_ENABLED="true" read_listen_port "mainsail" - MAINSAIL_PORT=$LISTEN_PORT + MAINSAIL_PORT=${LISTEN_PORT} #echo "debug: Mainsail listens on port: $MAINSAIL_PORT" else MAINSAIL_ENABLED="false" @@ -54,7 +55,7 @@ function detect_enabled_sites(){ if [ -e /etc/nginx/sites-enabled/fluidd ]; then SITE_ENABLED="true" && FLUIDD_ENABLED="true" read_listen_port "fluidd" - FLUIDD_PORT=$LISTEN_PORT + FLUIDD_PORT=${LISTEN_PORT} #echo "debug: Fluidd listens on port: $FLUIDD_PORT" else FLUIDD_ENABLED="false" @@ -62,7 +63,7 @@ function detect_enabled_sites(){ if [ -e /etc/nginx/sites-enabled/octoprint ]; then SITE_ENABLED="true" && OCTOPRINT_ENABLED="true" read_listen_port "octoprint" - OCTOPRINT_PORT=$LISTEN_PORT + OCTOPRINT_PORT=${LISTEN_PORT} #echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT" else OCTOPRINT_ENABLED="false" @@ -81,7 +82,7 @@ function create_custom_hostname(){ bottom_border while true; do read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes) user_input_hostname break;; @@ -105,13 +106,13 @@ function user_input_hostname(){ bottom_border while true; do read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME - if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then - ok_msg "'$NEW_HOSTNAME' is a valid hostname!" + if [[ ${NEW_HOSTNAME} =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then + ok_msg "'${NEW_HOSTNAME}' is a valid hostname!" HOSTNAME_VALID="true" while true; do echo - read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${white} " yn - case "$yn" in + read -p "${cyan}###### Do you want '${NEW_HOSTNAME}' to be the new hostname? (Y/n):${white} " yn + case "${yn}" in Y|y|Yes|yes|"") echo -e "###### > Yes" HOSTENAME_CONFIRM="true" @@ -122,22 +123,21 @@ function user_input_hostname(){ HOSTENAME_CONFIRM="false" break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done break else - warn_msg "'$NEW_HOSTNAME' is not a valid hostname!" + warn_msg "'${NEW_HOSTNAME}' is not a valid hostname!" fi done } function set_hostname(){ - if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then + if [ "${HOSTNAME_VALID}" = "true" ] && [ "${HOSTENAME_CONFIRM}" = "true" ]; then #check for dependencies dep=(avahi-daemon) - dependency_check + dependency_check "${dep[@]}" #execute operations #get current hostname and write to variable HOSTNAME=$(hostname) @@ -145,19 +145,19 @@ function set_hostname(){ if [ -f /etc/hosts ]; then status_msg "Creating backup of hosts file ..." get_date - sudo cp /etc/hosts /etc/hosts."$current_date".bak + sudo cp "/etc/hosts /etc/hosts.${current_date}.bak" ok_msg "Backup done!" - ok_msg "File:'/etc/hosts."$current_date".bak'" + ok_msg "File:'/etc/hosts.${current_date}.bak'" else sudo touch /etc/hosts fi #set hostname in /etc/hostname - status_msg "Setting hostname to '$NEW_HOSTNAME' ..." + status_msg "Setting hostname to '${NEW_HOSTNAME}' ..." status_msg "Please wait ..." - sudo hostnamectl set-hostname "$NEW_HOSTNAME" + sudo hostnamectl set-hostname "${NEW_HOSTNAME}" #write new hostname to /etc/hosts status_msg "Writing new hostname to /etc/hosts ..." - echo "127.0.0.1 $NEW_HOSTNAME" | sudo tee -a /etc/hosts &>/dev/null + echo "127.0.0.1 ${NEW_HOSTNAME}" | sudo tee -a /etc/hosts &>/dev/null ok_msg "New hostname successfully configured!" ok_msg "Remember to reboot for the changes to take effect!" fi From 114684030b65b95d20453a05437c4761c9b2508e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 5 Apr 2022 11:40:29 +0200 Subject: [PATCH 083/183] feat: read custom klipper config location from file Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 2 +- scripts/fluidd.sh | 2 +- scripts/klipper.sh | 17 ++++++++++++++++- scripts/klipperscreen.sh | 2 +- scripts/mainsail.sh | 2 +- scripts/moonraker-telegram-bot.sh | 2 +- scripts/ui/settings_menu.sh | 2 +- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index cde6557..ffa6158 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -13,7 +13,7 @@ set -e ### global variables BACKUP_DIR="${HOME}/kiauh-backups" -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" function get_date(){ current_date=$(date +"%y%m%d-%H%M") diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index fb6e27c..a15bd31 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -14,7 +14,7 @@ set -e ### global variables FLUIDD_DIR="${HOME}/fluidd" FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" #===================================================# #================== INSTALL FLUIDD =================# diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 34acdbc..7c4f642 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -18,7 +18,7 @@ ETCDEF="/etc/default" KLIPPY_ENV="${HOME}/klippy-env" KLIPPER_DIR="${HOME}/klipper" KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" #=================================================# #================ INSTALL KLIPPER ================# @@ -396,4 +396,19 @@ function compare_klipper_versions(){ KLIPPER_UPDATE_AVAIL="false" fi echo "${versions}" +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +function get_klipper_cfg_dir() { + local cfg_dir + read_kiauh_ini + if [ -z "${custom_klipper_cfg_loc}" ]; then + cfg_dir="${HOME}/klipper_config" + else + cfg_dir="${custom_klipper_cfg_loc}" + fi + echo "${cfg_dir}" } \ No newline at end of file diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index 8e9bcad..f05e40f 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -16,7 +16,7 @@ SYSTEMD="/etc/systemd/system" KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" #===================================================# #============== INSTALL KLIPPERSCREEN ==============# diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 2da3b97..f18e184 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -15,7 +15,7 @@ set -e MAINSAIL_DIR="${HOME}/mainsail" MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags" -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" #===================================================# #================= INSTALL MAINSAIL ================# diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 1001f67..080b5e0 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -16,7 +16,7 @@ SYSTEMD="/etc/systemd/system" MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" #===================================================# #=========== REMOVE MOONRAKERTELEGRAMBOT ===========# diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 1f989d6..27697f9 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -13,7 +13,7 @@ set -e ### global variables INI_FILE="${HOME}/.kiauh.ini" -KLIPPER_CONFIG="${HOME}/klipper_config" +KLIPPER_CONFIG="$(get_klipper_cfg_dir)" function settings_ui() { read_kiauh_ini From 8f3af54251ce43ba0adc0f396151ffacb62901f7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 5 Apr 2022 12:14:01 +0200 Subject: [PATCH 084/183] feat: outsource globals in own file Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 1 + scripts/backup.sh | 4 -- scripts/fluidd.sh | 5 --- scripts/globals.sh | 68 +++++++++++++++++++++++++++++++ scripts/klipper.sh | 9 ---- scripts/klipperscreen.sh | 7 ---- scripts/mainsail.sh | 6 --- scripts/mjpg-streamer.sh | 2 - scripts/moonraker-telegram-bot.sh | 7 ---- scripts/moonraker.sh | 8 ---- scripts/octoprint.sh | 4 -- scripts/pretty_gcode.sh | 4 -- scripts/utilities.sh | 10 ----- 13 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 scripts/globals.sh diff --git a/kiauh.sh b/kiauh.sh index 93dbfe4..d7e58a7 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -78,6 +78,7 @@ function kiauh_update_avail(){ #} check_euid +set_globals init_ini kiauh_update_avail main_menu diff --git a/scripts/backup.sh b/scripts/backup.sh index ffa6158..67bdade 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -11,10 +11,6 @@ set -e -### global variables -BACKUP_DIR="${HOME}/kiauh-backups" -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - function get_date(){ current_date=$(date +"%y%m%d-%H%M") echo "${current_date}" diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index a15bd31..4ae6232 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -11,11 +11,6 @@ set -e -### global variables -FLUIDD_DIR="${HOME}/fluidd" -FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - #===================================================# #================== INSTALL FLUIDD =================# #===================================================# diff --git a/scripts/globals.sh b/scripts/globals.sh new file mode 100644 index 0000000..455ce04 --- /dev/null +++ b/scripts/globals.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + + + +function set_globals(){ + #=================== SYSTEM ===================# + SYSTEMD="/etc/systemd/system" + INITD="/etc/init.d" + ETCDEF="/etc/default" + + #=================== KIAUH ====================# + green=$(echo -en "\e[92m") + yellow=$(echo -en "\e[93m") + red=$(echo -en "\e[91m") + cyan=$(echo -en "\e[96m") + white=$(echo -en "\e[39m") + INI_FILE="${HOME}/.kiauh.ini" + LOGFILE="/tmp/kiauh.log" + BACKUP_DIR="${HOME}/kiauh-backups" + + #================== KLIPPER ===================# + KLIPPY_ENV="${HOME}/klippy-env" + KLIPPER_DIR="${HOME}/klipper" + KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" + KLIPPER_CONFIG="$(get_klipper_cfg_dir)" + + #================= MOONRAKER ==================# + MOONRAKER_ENV="${HOME}/moonraker-env" + MOONRAKER_DIR="${HOME}/moonraker" + MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" + + #================= MAINSAIL ===================# + MAINSAIL_DIR="${HOME}/mainsail" + MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" + MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags" + + #================== FLUIDD ====================# + FLUIDD_DIR="${HOME}/fluidd" + FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" + + #=============== KLIPPERSCREEN ================# + KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" + KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" + KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git + + #================ OCTOPRINT ===================# + OCTOPRINT_ENV="${HOME}/OctoPrint" + + #========== MOONRAKER-TELEGRAM-BOT ============# + MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env + MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot + NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git + + #=============== PRETTY-GCODE =================# + PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" + PGC_DIR="${HOME}/pgcode" +} \ No newline at end of file diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 7c4f642..453dd05 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -11,15 +11,6 @@ set -e -### global variables -SYSTEMD="/etc/systemd/system" -INITD="/etc/init.d" -ETCDEF="/etc/default" -KLIPPY_ENV="${HOME}/klippy-env" -KLIPPER_DIR="${HOME}/klipper" -KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - #=================================================# #================ INSTALL KLIPPER ================# #=================================================# diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index f05e40f..9c3d9cf 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -11,13 +11,6 @@ set -e -### global variables -SYSTEMD="/etc/systemd/system" -KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" -KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" -KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - #===================================================# #============== INSTALL KLIPPERSCREEN ==============# #===================================================# diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index f18e184..eec7fd5 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -11,12 +11,6 @@ set -e -### global variables -MAINSAIL_DIR="${HOME}/mainsail" -MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" -MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags" -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - #===================================================# #================= INSTALL MAINSAIL ================# #===================================================# diff --git a/scripts/mjpg-streamer.sh b/scripts/mjpg-streamer.sh index 4081b6f..1cd2830 100644 --- a/scripts/mjpg-streamer.sh +++ b/scripts/mjpg-streamer.sh @@ -11,8 +11,6 @@ set -e -### base variables -SYSTEMD="/etc/systemd/system" WEBCAMD_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" WEBCAM_TXT_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 080b5e0..8ffca16 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -11,13 +11,6 @@ set -e -### global variables -SYSTEMD="/etc/systemd/system" -MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env -MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot -NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - #===================================================# #=========== REMOVE MOONRAKERTELEGRAMBOT ===========# #===================================================# diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index d35ac76..d7a6fcc 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -11,14 +11,6 @@ set -e -### global variables -SYSTEMD="/etc/systemd/system" -INITD="/etc/init.d" -ETCDEF="/etc/default" -MOONRAKER_ENV="${HOME}/moonraker-env" -MOONRAKER_DIR="${HOME}/moonraker" -MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" - #===================================================# #================ INSTALL MOONRAKER ================# #===================================================# diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 9dcc6aa..01552f7 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -11,10 +11,6 @@ set -e -### global variables -SYSTEMD="/etc/systemd/system" -OCTOPRINT_ENV="${HOME}/OctoPrint" - #=================================================# #=============== INSTALL OCTOPRINT ===============# #=================================================# diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh index 22cd4c0..8ca1b53 100644 --- a/scripts/pretty_gcode.sh +++ b/scripts/pretty_gcode.sh @@ -11,10 +11,6 @@ set -e -### base variables -PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" -PGC_DIR="${HOME}/pgcode" - #=================================================# #================== INSTALL PGC ==================# #=================================================# diff --git a/scripts/utilities.sh b/scripts/utilities.sh index e2ec222..479814d 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -11,11 +11,6 @@ set -e -### global variables -SYSTEMD="/etc/systemd/system" -INI_FILE="${HOME}/.kiauh.ini" -LOGFILE="/tmp/kiauh.log" - #================================================# #=================== STARTUP ====================# #================================================# @@ -35,11 +30,6 @@ function check_euid(){ #================================================# #============= MESSAGE FORMATTING ===============# #================================================# -green=$(echo -en "\e[92m") -yellow=$(echo -en "\e[93m") -red=$(echo -en "\e[91m") -cyan=$(echo -en "\e[96m") -white=$(echo -en "\e[39m") function select_msg() { echo -e "${white}>>>>>> $1" From ea8574949239887ad9f7d6ec687e435e296b8372 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 5 Apr 2022 12:29:22 +0200 Subject: [PATCH 085/183] style(globals.sh): add comment, remove empty lines Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index 455ce04..4284dc7 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -11,8 +11,6 @@ set -e - - function set_globals(){ #=================== SYSTEM ===================# SYSTEMD="/etc/systemd/system" @@ -33,7 +31,7 @@ function set_globals(){ KLIPPY_ENV="${HOME}/klippy-env" KLIPPER_DIR="${HOME}/klipper" KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" - KLIPPER_CONFIG="$(get_klipper_cfg_dir)" + KLIPPER_CONFIG="$(get_klipper_cfg_dir)" # default: ${HOME}/klipper_config #================= MOONRAKER ==================# MOONRAKER_ENV="${HOME}/moonraker-env" From e8dd0aed7dce66636bb79324e63a0d366b653d39 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 5 Apr 2022 12:30:06 +0200 Subject: [PATCH 086/183] fix(utilities.sh): fix no such file or directory Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 479814d..dd63aa8 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -80,18 +80,18 @@ function timestamp() { } function log_info() { - local message="${1}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" + local message="${1}" log="${LOGFILE}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" } function log_warning() { - local message="${1}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" + local message="${1}" log="${LOGFILE}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" } function log_error() { - local message="${1}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${LOGFILE}" + local message="${1}" log="${LOGFILE}" + echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" } #================================================# @@ -112,7 +112,7 @@ function init_ini(){ if [ -f "${INI_FILE}" ] && ! grep -Eq "^# KIAUH v4\.0\.0$" "${INI_FILE}"; then rm "${INI_FILE}" fi - ### initialize ini file + ### initialize v4.0.0 ini file if [ ! -f "${INI_FILE}" ]; then { echo -e "# File creation date: $(date)" From ecbb14f929aadc28a97ca5384b36ef8470769905 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 5 Apr 2022 13:44:37 +0200 Subject: [PATCH 087/183] fix(settings_menu.sh): fix menu Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/settings_menu.sh | 49 ++++++++++--------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 27697f9..ed082f3 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -11,15 +11,11 @@ set -e -### global variables -INI_FILE="${HOME}/.kiauh.ini" -KLIPPER_CONFIG="$(get_klipper_cfg_dir)" - function settings_ui() { read_kiauh_ini local custom_cfg_loc="${custom_klipper_cfg_loc}" - local ms_pre_rls="${mainsail_always_install_latest}" - local fl_pre_rls="${fluidd_always_install_latest}" + local ms_pre_rls="${mainsail_install_unstable}" + local fl_pre_rls="${fluidd_install_unstable}" if [ -z "${custom_cfg_loc}" ]; then custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}" @@ -44,9 +40,12 @@ function settings_ui() { printf "| Config folder: %-49s|\n" "${custom_cfg_loc}" blank_line echo -e "| Install unstable releases: |" - printf "| 1) Mainsail: %-53s|\n" "${ms_pre_rls}" - printf "| 2) Fluidd: %-53s|\n" "${fl_pre_rls}" - blank_line + printf "| Mainsail: %-56s|\n" "${ms_pre_rls}" + printf "| Fluidd: %-56s|\n" "${fl_pre_rls}" + hr + echo -e "| 1) Change Klipper config folder location |" + echo -e "| 2) Allow / Disallow unstable Mainsail releases |" + echo -e "| 3) Allow / Disallow unstable Fluidd releases |" back_help_footer } @@ -58,7 +57,8 @@ function show_settings_help(){ echo -e "| The location of your printer.cfg and all other config |" echo -e "| files that gets used during installation of Klipper |" echo -e "| and all other components which need that location. |" - echo -e "| This location can not be changed from within KIAUH. |" + echo -e "| It is not recommended to change this location. |" + echo -e "| Be advised, that negative side effects could occur. |" echo -e "| Default: ${cyan}/home//klipper_config${white} |" blank_line echo -e "| ${cyan}Install unstable releases:${white} |" @@ -67,7 +67,6 @@ function show_settings_help(){ echo -e "| ${yellow}This will include alpha, beta and rc releases!${white} |" echo -e "| If set to ${red}false${white}, KIAUH installs/updates the software |" echo -e "| with the most recent stable release. |" - echo -e "| Change this setting by typing 1 or 2 and hit ENTER. |" echo -e "| Default: ${red}false${white} |" blank_line back_footer @@ -90,8 +89,10 @@ settings_menu(){ read -p "${cyan}Perform action:${white} " action; echo case "${action}" in 1) - switch_mainsail_releasetype && settings_menu;; + change_klipper_cfg_folder && settings_menu;; 2) + switch_mainsail_releasetype && settings_menu;; + 3) switch_fluidd_releasetype && settings_menu;; B|b) clear @@ -106,27 +107,3 @@ settings_menu(){ esac done } - -function switch_mainsail_releasetype() { - read_kiauh_ini - local state="${mainsail_install_unstable}" - if [ "${state}" == "false" ]; then - sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}" - log_info "mainsail_install_unstable changed (false -> true) " - else - sed -i '/mainsail_install_unstable=/s/true/false/' "${INI_FILE}" - log_info "mainsail_install_unstable changed (true -> false) " - fi -} - -function switch_fluidd_releasetype() { - read_kiauh_ini - local state="${fluidd_install_unstable}" - if [ "${state}" == "false" ]; then - sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}" - log_info "fluidd_install_unstable changed (false -> true) " - else - sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}" - log_info "fluidd_install_unstable changed (true -> false) " - fi -} From e24b392605b19bf1f45a9101a8f610161f36ca0a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 12 Apr 2022 13:34:32 +0200 Subject: [PATCH 088/183] fix(main_menu.sh): fix menu Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/main_menu.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index f1dd53e..6db8aa5 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -84,13 +84,27 @@ main_menu(){ "stop octoprint") do_action_service "stop" "octoprint"; main_ui;; "restart octoprint") do_action_service "restart" "octoprint"; main_ui;; update) do_action "update_kiauh" "main_ui";; - 0) do_action "upload_selection" "main_ui";; - 1) clear && install_menu && break;; - 2) clear && update_menu && break;; - 3) clear && remove_menu && break;; - 4) clear && advanced_menu && break;; - 5) clear && backup_menu && break;; - 6) clear && settings_menu && break;; + 0)clear && print_header + upload_selection + break;; + 1)clear && print_header + install_menu + break;; + 2) clear && print_header + update_menu + break;; + 3) clear && print_header + remove_menu + break;; + 4)clear && print_header + advanced_menu + break;; + 5)clear && print_header + backup_menu + break;; + 6)clear && print_header + settings_menu + break;; Q|q) echo -e "${green}###### Happy printing! ######${white}"; echo exit 0;; From c655ca921275e2f7c017524f607a14d02cd74d1b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 12 Apr 2022 13:42:29 +0200 Subject: [PATCH 089/183] refactor: rewrite feature for changing config directory Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/settings_menu.sh | 17 ++- scripts/utilities.sh | 211 +++++++++++++++++++++--------------- 2 files changed, 137 insertions(+), 91 deletions(-) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index ed082f3..ba8c27a 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -50,6 +50,7 @@ function settings_ui() { } function show_settings_help(){ + local default_cfg="${cyan}${HOME}/klipper_config${white}" top_border echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |" hr @@ -58,15 +59,19 @@ function show_settings_help(){ echo -e "| files that gets used during installation of Klipper |" echo -e "| and all other components which need that location. |" echo -e "| It is not recommended to change this location. |" - echo -e "| Be advised, that negative side effects could occur. |" - echo -e "| Default: ${cyan}/home//klipper_config${white} |" + echo -e "| Be advised, that negative side effects could occur. |" blank_line + printf "| Default: %-55s|\n" "${default_cfg}" + blank_line + hr echo -e "| ${cyan}Install unstable releases:${white} |" echo -e "| If set to ${green}true${white}, KIAUH installs/updates the software |" echo -e "| with the latest, currently available release. |" echo -e "| ${yellow}This will include alpha, beta and rc releases!${white} |" + blank_line echo -e "| If set to ${red}false${white}, KIAUH installs/updates the software |" echo -e "| with the most recent stable release. |" + blank_line echo -e "| Default: ${red}false${white} |" blank_line back_footer @@ -84,16 +89,16 @@ function show_settings_help(){ } settings_menu(){ - do_action "" "settings_ui" + settings_ui while true; do read -p "${cyan}Perform action:${white} " action; echo case "${action}" in 1) - change_klipper_cfg_folder && settings_menu;; + change_klipper_cfg_folder && settings_ui;; 2) - switch_mainsail_releasetype && settings_menu;; + switch_mainsail_releasetype && settings_ui;; 3) - switch_fluidd_releasetype && settings_menu;; + switch_fluidd_releasetype && settings_ui;; B|b) clear main_menu diff --git a/scripts/utilities.sh b/scripts/utilities.sh index dd63aa8..1c3f262 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -100,8 +100,9 @@ function log_error() { function read_kiauh_ini(){ if [ ! -f "${INI_FILE}" ]; then + print_error "ERROR: File '~/.kiauh.ini' not found!" log_error "Reading from .kiauh.ini failed! File not found!" - return + return 1 fi log_info "Reading from .kiauh.ini" source "${INI_FILE}" @@ -142,123 +143,131 @@ function init_ini(){ fetch_webui_ports } -check_klipper_cfg_path(){ - source_kiauh_ini - if [ -z "${klipper_cfg_loc}" ]; then - echo - top_border - echo -e "| ${red}!!! WARNING !!!${white} |" - echo -e "| ${red}No Klipper configuration directory set!${white} |" - hr - echo -e "| Before we can continue, KIAUH needs to know where |" - echo -e "| you want your printer configuration to be. |" - blank_line - echo -e "| Please specify a folder where your Klipper configu- |" - echo -e "| ration is stored or, if you don't have one yet, in |" - echo -e "| which it should be saved after the installation. |" - bottom_border - change_klipper_cfg_path - fi -} - -change_klipper_cfg_path(){ - source_kiauh_ini - old_klipper_cfg_loc="${klipper_cfg_loc}" - EXAMPLE_FOLDER=$(printf "%s/your_config_folder" "${HOME}") +function change_klipper_cfg_folder(){ + local current_cfg_loc example_loc recommended_loc new_cfg_loc + current_cfg_loc="$(get_klipper_cfg_dir)" + example_loc=$(printf "%s/" "${HOME}") + recommended_loc=$(printf "%s/klipper_config" "${HOME}") while true; do top_border - echo -e "| ${red}IMPORTANT:${white} |" + echo -e "| ${yellow}IMPORTANT:${white} |" echo -e "| Please enter the new path in the following format: |" - printf "| ${yellow}%-51s${white} |\n" "${EXAMPLE_FOLDER}" + printf "| ${cyan}%-51s${white} |\n" "${example_loc}" blank_line - echo -e "| By default 'klipper_config' is recommended! |" + echo -e "| ${red}WARNING: ${white} |" + echo -e "| ${red}There will be no validation checks! Make sure to set${white} |" + echo -e "| ${red}a valid directory to prevent possible problems!${white} |" + blank_line + printf "| Recommended: ${cyan}%-38s${white} |\n" "${recommended_loc}" bottom_border echo - echo -e "${cyan}###### Please set the Klipper config directory:${white} " - if [ -z "${old_klipper_cfg_loc}" ]; then - read -e -i "/home/${USER}/klipper_config" -e new_klipper_cfg_loc - else - read -e -i "${old_klipper_cfg_loc}" -e new_klipper_cfg_loc - fi + echo -e "${cyan}###### Please set the new Klipper config directory:${white} " + read -e -i "${current_cfg_loc}" -e new_cfg_loc echo - read -p "${cyan}###### Set config directory to '${yellow}${new_klipper_cfg_loc}${cyan}' ? (Y/n):${white} " yn + read -p "${cyan}###### Set config directory to '${yellow}${new_cfg_loc}${cyan}' ? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") - echo -e "###### > Yes" - - ### backup the old config dir - backup_klipper_config_dir - - ### write new location to kiauh.ini - sed -i "s|klipper_cfg_loc=${old_klipper_cfg_loc}|klipper_cfg_loc=${new_klipper_cfg_loc}|" "${INI_FILE}" - status_msg "Directory set to '${new_klipper_cfg_loc}'!" - - ### write new location to klipper and moonraker service - set_klipper_cfg_path - echo; ok_msg "Config directory changed!" + select_msg "Yes" + set_klipper_cfg_path "${current_cfg_loc}" "${new_cfg_loc}" + print_confirm "New config directory set!" + settings_menu break;; N|n|No|no) - echo -e "###### > No" - change_klipper_cfg_path + select_msg "No" + settings_menu break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done } -set_klipper_cfg_path(){ +function set_klipper_cfg_path(){ + local current_cfg_loc="${1}" new_cfg_loc="${2}" + local instance klipper_services moonraker_services moonraker_configs + + log_info "Function set_klipper_cfg_path invoked\nCurrent location: ${1}\nNew location: ${2}" + ### backup the old config dir + backup_klipper_config_dir + ### write new location to .kiauh.ini + sed -i "/^custom_klipper_cfg_loc=/d" "${INI_FILE}" + sed -i '$a'"custom_klipper_cfg_loc=${new_cfg_loc}" "${INI_FILE}" + status_msg "New directory was set to '${new_cfg_loc}'!" + ### stop services do_action_service "stop" "klipper" do_action_service "stop" "moonraker" ### copy config files to new klipper config folder - if [ -n "${old_klipper_cfg_loc}" ] && [ -d "${old_klipper_cfg_loc}" ]; then - if [ ! -d "${new_klipper_cfg_loc}" ]; then - status_msg "Copy config files to '${new_klipper_cfg_loc}' ..." - mkdir -p "${new_klipper_cfg_loc}" - cd "${old_klipper_cfg_loc}" - cp -r -v ./* "${new_klipper_cfg_loc}" + if [ -n "${current_cfg_loc}" ] && [ -d "${current_cfg_loc}" ]; then + status_msg "Copy config files to '${new_cfg_loc}' ..." + if [ ! -d "${new_cfg_loc}" ]; then + log_info "Copy process started" + mkdir -p "${new_cfg_loc}" + cd "${current_cfg_loc}" + cp -r -v ./* "${new_cfg_loc}" ok_msg "Done!" + else + log_warning "Copy process skipped, new config directory already exists and may not be empty!" + warn_msg "New config directory already exists!\nCopy process skipped!" fi fi - SERVICE_FILES=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])+[0-9]*.service") - ### handle single klipper instance service file - if [ -f "${SYSTEMD}/klipper.service" ]; then - status_msg "Configuring Klipper for new path ..." - sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer.cfg|klippy.py ${new_klipper_cfg_loc}/printer.cfg|" "${SYSTEMD}/klipper.service" - ok_msg "OK!" - elif [ -n "${SERVICE_FILES}" ]; then - ### handle multi klipper instance service file - status_msg "Configuring Klipper for new path ..." - for service in ${SERVICE_FILES}; do - sudo sed -i -r "/ExecStart=/ s|klippy.py (.+)\/printer_|klippy.py ${new_klipper_cfg_loc}/printer_|" "${service}" + klipper_services=$(klipper_systemd) + if [ -n "${klipper_services}" ]; then + status_msg "Re-writing Klipper services to use new config file location ..." + for service in ${klipper_services}; do + if [ "${service}" = "/etc/systemd/system/klipper.service" ]; then + if grep "Environment=KLIPPER_CONFIG=" "${service}"; then + ### single instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0 + sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer\.cfg|CONFIG=${new_cfg_loc}/printer\.cfg|" "${service}" + else + ### single instance klipper service installed by kiauh v3 + sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer\.cfg|" "${service}" + fi + else + instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1) + if grep "Environment=KLIPPER_CONFIG=" "${service}"; then + ### multi instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0 + sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer_${instance}\/printer\.cfg|CONFIG=${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}" + else + ### multi instance klipper service installed by kiauh v3 + sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer_${instance}\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}" + fi + fi done ok_msg "OK!" fi - SERVICE_FILES=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])+[0-9]*.service") - ### handle single moonraker instance service and moonraker.conf file - if [ -f "${SYSTEMD}/moonraker.service" ]; then - status_msg "Configuring Moonraker for new path ..." - sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c ${new_klipper_cfg_loc}/moonraker.conf|" "${SYSTEMD}/moonraker.service" - - ### replace old file path with new one in moonraker.conf - sed -i -r "/config_path:/ s|config_path:.*|config_path: ${new_klipper_cfg_loc}|" "${new_klipper_cfg_loc}/moonraker.conf" - ok_msg "OK!" - elif [ -n "${SERVICE_FILES}" ]; then + moonraker_services=$(moonraker_systemd) + if [ -n "${moonraker_services}" ]; then ### handle multi moonraker instance service file - status_msg "Configuring Moonraker for new path ..." - for service in ${SERVICE_FILES}; do - sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c ${new_klipper_cfg_loc}/printer_|" "${service}" + status_msg "Re-writing Moonraker services to use new config file location ..." + for service in ${moonraker_services}; do + if [ "${service}" = "/etc/systemd/system/moonraker.service" ]; then + if grep "Environment=MOONRAKER_CONF=" "${service}"; then + ### single instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0 + sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/moonraker\.conf|_CONF=${new_cfg_loc}\/moonraker\.conf|" "${service}" + else + ### single instance moonraker service installed by kiauh v3 + sudo sed -i -r "/ExecStart=/ s| -c (.+)\/moonraker\.conf| -c ${new_cfg_loc}\/moonraker\.conf|" "${service}" + fi + else + instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1) + if grep "Environment=MOONRAKER_CONF=" "${service}"; then + ### multi instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0 + sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/printer_${instance}\/moonraker\.conf|_CONF=${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}" + else + ### multi instance moonraker service installed by kiauh v3 + sudo sed -i -r "/ExecStart=/ s| -c (.+)\/printer_${instance}\/moonraker\.conf| -c ${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}" + fi + fi done - MR_CONFS=$(find "${new_klipper_cfg_loc}" -regextype posix-extended -regex "${new_klipper_cfg_loc}/printer_[1-9]+/moonraker.conf") + moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf") ### replace old file path with new one in moonraker.conf - for moonraker_conf in ${MR_CONFS}; do - loc=$(echo "${moonraker_conf}" | rev | cut -d"/" -f2- | rev) - sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${moonraker_conf}" + for conf in ${moonraker_configs}; do + loc=$(echo "${conf}" | rev | cut -d"/" -f2- | rev) + sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${conf}" done ok_msg "OK!" fi @@ -271,6 +280,34 @@ set_klipper_cfg_path(){ do_action_service "restart" "moonraker" } +function switch_mainsail_releasetype() { + read_kiauh_ini + local state="${mainsail_install_unstable}" + if [ "${state}" == "false" ]; then + sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}" + log_info "mainsail_install_unstable changed (false -> true) " + else + sed -i '/mainsail_install_unstable=/s/true/false/' "${INI_FILE}" + log_info "mainsail_install_unstable changed (true -> false) " + fi +} + +function switch_fluidd_releasetype() { + read_kiauh_ini + local state="${fluidd_install_unstable}" + if [ "${state}" == "false" ]; then + sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}" + log_info "fluidd_install_unstable changed (false -> true) " + else + sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}" + log_info "fluidd_install_unstable changed (true -> false) " + fi +} + +#================================================# +#=============== HANDLE SERVICES ================# +#================================================# + do_action_service(){ local action=${1} service=${2} services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[^0])?[0-9]*.service") @@ -321,6 +358,10 @@ restart_nginx(){ fi } +#================================================# +#================ DEPENDENCIES ==================# +#================================================# + dependency_check(){ local dep=( "${@}" ) # dep: array status_msg "Checking for the following dependencies:" From 02e49edd08a10b9ac98922c3b078e553514dee87 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 12 Apr 2022 13:44:29 +0200 Subject: [PATCH 090/183] refactor: update backup.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 67bdade..28b7a37 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -55,8 +55,9 @@ function read_bb4u_stat(){ function backup_printer_cfg(){ check_for_backup_dir + local current_date if [ -f "${PRINTER_CFG}" ]; then - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" status_msg "Create backup of printer.cfg ..." cp "${PRINTER_CFG}" "${BACKUP_DIR}/printer.cfg.${current_date}.backup" && ok_msg "Backup complete!" @@ -67,8 +68,9 @@ function backup_printer_cfg(){ function backup_klipper_config_dir(){ check_for_backup_dir + local current_date if [ -d "${KLIPPER_CONFIG}" ]; then - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" status_msg "Create backup of the Klipper config directory ..." config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)" @@ -83,8 +85,9 @@ function backup_klipper_config_dir(){ function backup_moonraker_database(){ check_for_backup_dir + local current_date if ls -d "${HOME}"/.moonraker_database* 2>/dev/null 1>&2; then - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/mr_db_backup/${current_date}" for database in $(ls -d ${HOME}/.moonraker_database*) @@ -100,10 +103,11 @@ function backup_moonraker_database(){ } function backup_klipper(){ + local current_date if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPY_ENV}" ]; then status_msg "Creating Klipper backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}" cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" && ok_msg "Backup complete!" @@ -113,10 +117,11 @@ function backup_klipper(){ } function backup_mainsail(){ + local current_date if [ -d "${MAINSAIL_DIR}" ]; then status_msg "Creating Mainsail backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}" cp -r "${MAINSAIL_DIR}" "${_}" && ok_msg "Backup complete!" @@ -126,10 +131,11 @@ function backup_mainsail(){ } function backup_fluidd(){ + local current_date if [ -d "${FLUIDD_DIR}" ]; then status_msg "Creating Fluidd backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}" cp -r "${FLUIDD_DIR}" "${_}" && ok_msg "Backup complete!" @@ -139,10 +145,11 @@ function backup_fluidd(){ } function backup_moonraker(){ + local current_date if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_ENV}" ]; then status_msg "Creating Moonraker backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}" cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" && ok_msg "Backup complete!" @@ -152,10 +159,11 @@ function backup_moonraker(){ } function backup_octoprint(){ + local current_date if [ -d "${OCTOPRINT_DIR}" ] && [ -d "${OCTOPRINT_CFG_DIR}" ]; then status_msg "Creating OctoPrint backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}" cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}" @@ -166,10 +174,11 @@ function backup_octoprint(){ } function backup_klipperscreen(){ + local current_date if [ -d "${KLIPPERSCREEN_DIR}" ] ; then status_msg "Creating KlipperScreen backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}" cp -r "${KLIPPERSCREEN_DIR}" "${_}" @@ -180,10 +189,11 @@ function backup_klipperscreen(){ } function backup_MoonrakerTelegramBot(){ + local current_date if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] ; then status_msg "Creating MoonrakerTelegramBot backup ..." check_for_backup_dir - get_date + current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}" cp -r "${MOONRAKER_TELEGRAM_BOT_DIR}" "${_}" From 077cb1654a38c81d4c861b7e9a6271c6218df408 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 12 Apr 2022 16:02:48 +0200 Subject: [PATCH 091/183] refactor: update update_menu.sh and update functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 67 +++++++++++++++++++------------ scripts/globals.sh | 3 +- scripts/klipper.sh | 2 + scripts/klipperscreen.sh | 43 +++++++++++--------- scripts/mainsail.sh | 45 +++++++++------------ scripts/moonraker-telegram-bot.sh | 43 +++++++++++--------- scripts/moonraker.sh | 23 +++++------ scripts/pretty_gcode.sh | 44 +++++++++++--------- scripts/ui/update_menu.sh | 65 +++++++++++++++++++++++++++--- scripts/update.sh | 53 ------------------------ 10 files changed, 207 insertions(+), 181 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 4ae6232..8573641 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -171,49 +171,64 @@ function fluidd_status(){ fi } -function read_local_fluidd_version(){ - unset FLUIDD_VER_FOUND - if [ -e "${FLUIDD_DIR}/.version" ]; then - FLUIDD_VER_FOUND="true" - FLUIDD_LOCAL_VER=$(head -n 1 "${FLUIDD_DIR}/.version") - else - FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER - fi +function get_local_fluidd_version(){ + local version + [ ! -f "${FLUIDD_DIR}/.version" ] && return + version=$(head -n 1 "${FLUIDD_DIR}/.version") + echo "${version}" } -function read_remote_fluidd_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - FLUIDD_REMOTE_VER=${NONE} - else - get_fluidd_ver - FLUIDD_REMOTE_VER=${FLUIDD_VERSION} - fi +function get_remote_fluidd_version(){ + local version + [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return + version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev) + echo "${version}" } function compare_fluidd_versions(){ unset FLUIDD_UPDATE_AVAIL - read_local_fluidd_version && read_remote_fluidd_version - if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - FLUIDD_LOCAL_VER="${green}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then - FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" + local versions local_ver remote_ver + local_ver="$(get_local_fluidd_version)" + remote_ver="$(get_remote_fluidd_version)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" # add fluidd to the update all array for the update all function in the updater FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) else - FLUIDD_LOCAL_VER=$NONE - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" FLUIDD_UPDATE_AVAIL="false" fi + echo "${versions}" } #================================================# #=================== HELPERS ====================# #================================================# +function get_fluidd_download_url() { + local latest_tag latest_url stable_tag stable_url url + tags=$(curl -s "${FLUIDD_TAGS}" | grep "name" | cut -d'"' -f4) + + ### latest download url including pre-releases (alpha, beta, rc) + latest_tag=$(echo "${tags}" | head -1) + latest_url="https://github.com/fluidd-core/fluidd/releases/download/${latest_tag}/fluidd.zip" + + ### get stable fluidd download url + stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1) + stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip" + + read_kiauh_ini + if [ "${fluidd_install_unstable}" == "true" ]; then + url="${latest_url}" + echo "${url}" + else + url="${stable_url}" + echo "${url}" + fi +} + function fluidd_port_check(){ if [ "${FLUIDD_ENABLED}" = "false" ]; then if [ "${SITE_ENABLED}" = "true" ]; then diff --git a/scripts/globals.sh b/scripts/globals.sh index 4284dc7..c551812 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -46,6 +46,7 @@ function set_globals(){ #================== FLUIDD ====================# FLUIDD_DIR="${HOME}/fluidd" FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" + FLUIDD_TAGS="https://api.github.com/repos/fluidd-core/fluidd/tags" #=============== KLIPPERSCREEN ================# KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" @@ -61,6 +62,6 @@ function set_globals(){ NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git #=============== PRETTY-GCODE =================# - PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" PGC_DIR="${HOME}/pgcode" + PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" } \ No newline at end of file diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 453dd05..3e7253f 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -358,6 +358,7 @@ function get_klipper_status(){ } function get_local_klipper_commit(){ + local commit [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPER_DIR}"/.git ] && return cd "${KLIPPER_DIR}" commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" @@ -365,6 +366,7 @@ function get_local_klipper_commit(){ } function get_remote_klipper_commit(){ + local commit [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPER_DIR}"/.git ] && return cd "${KLIPPER_DIR}" && git fetch origin -q commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index 9c3d9cf..5f24b94 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -154,29 +154,36 @@ function klipperscreen_status(){ fi } -function read_klipperscreen_versions(){ - if [ -d "${KLIPPERSCREEN_DIR}" ] && [ -d "${KLIPPERSCREEN_DIR}/.git" ]; then - cd "${KLIPPERSCREEN_DIR}" - git fetch origin master -q - LOCAL_KLIPPERSCREEN_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_KLIPPERSCREEN_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_KLIPPERSCREEN_COMMIT="${NONE}" - REMOTE_KLIPPERSCREEN_COMMIT="${NONE}" - fi +function get_local_klipperscreen_commit(){ + local commit + [ ! -d "${KLIPPERSCREEN_DIR}" ] || [ ! -d "${KLIPPERSCREEN_DIR}"/.git ] && return + cd "${KLIPPERSCREEN_DIR}" + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" + echo "${commit}" +} + +function get_remote_klipperscreen_commit(){ + local commit + [ ! -d "${KLIPPERSCREEN_DIR}" ] || [ ! -d "${KLIPPERSCREEN_DIR}"/.git ] && return + cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + echo "${commit}" } function compare_klipperscreen_versions(){ unset KLIPPERSCREEN_UPDATE_AVAIL - read_klipperscreen_versions - if [ "${LOCAL_KLIPPERSCREEN_COMMIT}" != "${REMOTE_KLIPPERSCREEN_COMMIT}" ]; then - LOCAL_KLIPPERSCREEN_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${white}" - REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${white}" - KLIPPERSCREEN_UPDATE_AVAIL="true" - update_arr+=(update_klipperscreen) + local versions local_ver remote_ver + local_ver="$(get_local_klipperscreen_commit)" + remote_ver="$(get_remote_klipperscreen_commit)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" + # add klipperscreen to the update all array for the update all function in the updater + KLIPPERSCREEN_UPDATE_AVAIL="true" && update_arr+=(update_klipperscreen) else - LOCAL_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${LOCAL_KLIPPERSCREEN_COMMIT}")${white}" - REMOTE_KLIPPERSCREEN_COMMIT="${green}$(printf "%-12s" "${REMOTE_KLIPPERSCREEN_COMMIT}")${white}" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" KLIPPERSCREEN_UPDATE_AVAIL="false" fi + echo "${versions}" } diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index eec7fd5..8dd2130 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -238,43 +238,36 @@ function mainsail_status(){ fi } -function read_local_mainsail_version(){ - unset MAINSAIL_VER_FOUND - if [ -e "${MAINSAIL_DIR}/.version" ]; then - MAINSAIL_VER_FOUND="true" - MAINSAIL_LOCAL_VER=$(head -n 1 "${MAINSAIL_DIR}/.version") - else - MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER - fi +function get_local_mainsail_version(){ + local version + [ ! -f "${MAINSAIL_DIR}/.version" ] && return + version=$(head -n 1 "${MAINSAIL_DIR}/.version") + echo "${version}" } -function read_remote_mainsail_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - MAINSAIL_REMOTE_VER=${NONE} - else - get_mainsail_ver - MAINSAIL_REMOTE_VER=${MAINSAIL_VERSION} - fi +function get_remote_mainsail_version(){ + local version + [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return + version=$(get_mainsail_download_url | rev | cut -d"/" -f2 | rev) + echo "${version}" } function compare_mainsail_versions(){ unset MAINSAIL_UPDATE_AVAIL - read_local_mainsail_version && read_remote_mainsail_version - if [ "${MAINSAIL_VER_FOUND}" = "true" ] && [ "${MAINSAIL_LOCAL_VER}" == "${MAINSAIL_REMOTE_VER}" ]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "${MAINSAIL_LOCAL_VER}")${white}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "${MAINSAIL_REMOTE_VER}")${white}" - elif [ "${MAINSAIL_VER_FOUND}" = "true" ] && [ "${MAINSAIL_LOCAL_VER}" != "${MAINSAIL_REMOTE_VER}" ]; then - MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "${MAINSAIL_LOCAL_VER}")${white}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "${MAINSAIL_REMOTE_VER}")${white}" + local versions local_ver remote_ver + local_ver="$(get_local_mainsail_version)" + remote_ver="$(get_remote_mainsail_version)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" # add mainsail to the update all array for the update all function in the updater MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) else - MAINSAIL_LOCAL_VER=${NONE} - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "${MAINSAIL_REMOTE_VER}")${white}" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" MAINSAIL_UPDATE_AVAIL="false" fi + echo "${versions}" } #================================================# diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 8ffca16..20d02e3 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -130,29 +130,36 @@ function MoonrakerTelegramBot_status(){ fi } -function read_MoonrakerTelegramBot_versions(){ - if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}/.git" ]; then - cd "${MOONRAKER_TELEGRAM_BOT_DIR}" - git fetch origin master -q - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${NONE}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${NONE}" - fi +function get_local_telegram_bot_commit(){ + local commit + [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] || [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ] && return + cd "${MOONRAKER_TELEGRAM_BOT_DIR}" + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" + echo "${commit}" } -function compare_MoonrakerTelegramBot_versions(){ +function get_remote_telegram_bot_commit(){ + local commit + [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] || [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ] && return + cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + echo "${commit}" +} + +function compare_prettygcode_versions(){ unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL - read_MoonrakerTelegramBot_versions - if [ "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}" != "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}" ]; then - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" - # add moonraker telegram bot to the update all array for the update all function in the updater + local versions local_ver remote_ver + local_ver="$(get_local_telegram_bot_commit)" + remote_ver="$(get_remote_telegram_bot_commit)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" + # add moonraker-telegram-bot to the update all array for the update all function in the updater MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_MoonrakerTelegramBot) else - LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" - REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT="${green}$(printf "%-12s" "${REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT}")${white}" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false" fi + echo "${versions}" } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index d7a6fcc..27c6362 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -452,23 +452,18 @@ function get_moonraker_status(){ } function get_local_moonraker_commit(){ - if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_DIR}"/.git ]; then - cd "${MOONRAKER_DIR}" - commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" - else - commit="${NONE}" - fi + local commit + [ ! -d "${MOONRAKER_DIR}" ] || [ ! -d "${MOONRAKER_DIR}"/.git ] && return + cd "${MOONRAKER_DIR}" + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" echo "${commit}" } function get_remote_moonraker_commit(){ - if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_DIR}"/.git ]; then - cd "${MOONRAKER_DIR}" - git fetch origin -q - commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) - else - commit="${NONE}" - fi + local commit + [ ! -d "${MOONRAKER_DIR}" ] || [ ! -d "${MOONRAKER_DIR}"/.git ] && return + cd "${MOONRAKER_DIR}" && git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) echo "${commit}" } @@ -480,7 +475,7 @@ function compare_moonraker_versions(){ if [ "${local_ver}" != "${remote_ver}" ]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add klipper to the update all array for the update all function in the updater + # add moonraker to the update all array for the update all function in the updater MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker) else versions="${green}$(printf " %-14s" "${local_ver}")${white}" diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh index 8ca1b53..341fb55 100644 --- a/scripts/pretty_gcode.sh +++ b/scripts/pretty_gcode.sh @@ -83,30 +83,36 @@ function update_pgc_for_klipper(){ #=================== PGC STATUS ==================# #=================================================# -function read_pgc_versions(){ - PGC_DIR="${HOME}/pgcode" - if [ -d "${PGC_DIR}" ] && [ -d "${PGC_DIR}/.git" ]; then - cd "${PGC_DIR}" - git fetch origin main -q - LOCAL_PGC_COMMIT=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) - REMOTE_PGC_COMMIT=$(git describe origin/main --always --tags | cut -d "-" -f 1,2) - else - LOCAL_PGC_COMMIT=${NONE} - REMOTE_PGC_COMMIT=${NONE} - fi +function get_local_prettygcode_commit(){ + local commit + [ ! -d "${PGC_DIR}" ] || [ ! -d "${PGC_DIR}"/.git ] && return + cd "${PGC_DIR}" + commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" + echo "${commit}" } -function compare_pgc_versions(){ +function get_remote_prettygcode_commit(){ + local commit + [ ! -d "${PGC_DIR}" ] || [ ! -d "${PGC_DIR}"/.git ] && return + cd "${PGC_DIR}" && git fetch origin -q + commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) + echo "${commit}" +} + +function compare_prettygcode_versions(){ unset PGC_UPDATE_AVAIL - read_pgc_versions - if [ "${LOCAL_PGC_COMMIT}" != "${REMOTE_PGC_COMMIT}" ]; then - LOCAL_PGC_COMMIT="${yellow}$(printf "%-12s" "${LOCAL_PGC_COMMIT}")${white}" - REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "${REMOTE_PGC_COMMIT}")${white}" - # add PGC to the update all array for the update all function in the updater + local versions local_ver remote_ver + local_ver="$(get_local_prettygcode_commit)" + remote_ver="$(get_remote_prettygcode_commit)" + if [ "${local_ver}" != "${remote_ver}" ]; then + versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" + # add prettygcode to the update all array for the update all function in the updater PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper) else - LOCAL_PGC_COMMIT="${green}$(printf "%-12s" "${LOCAL_PGC_COMMIT}")${white}" - REMOTE_PGC_COMMIT="${green}$(printf "%-12s" "${REMOTE_PGC_COMMIT}")${white}" + versions="${green}$(printf " %-14s" "${local_ver}")${white}" + versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" PGC_UPDATE_AVAIL="false" fi + echo "${versions}" } \ No newline at end of file diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index c18ec4e..48cc8b2 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -20,20 +20,20 @@ update_ui(){ hr echo -e "| a) [Update all] | | | " echo -e "| | Installed: | Latest: | " - echo -e "| Klipper & API : |---------------|--------------| " + echo -e "| Klipper & API: |---------------|--------------| " echo -e "| 1) [Klipper] |$(compare_klipper_versions)| " echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)| " echo -e "| | | | " echo -e "| Webinterface: |---------------|--------------| " - echo -e "| 3) [Mainsail] | $MAINSAIL_LOCAL_VER | $MAINSAIL_REMOTE_VER | " - echo -e "| 4) [Fluidd] | $FLUIDD_LOCAL_VER | $FLUIDD_REMOTE_VER | " + echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)| " + echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)| " echo -e "| | | | " echo -e "| Touchscreen GUI: |---------------|--------------| " - echo -e "| 5) [KlipperScreen] | $LOCAL_KLIPPERSCREEN_COMMIT | $REMOTE_KLIPPERSCREEN_COMMIT | " + echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)| " echo -e "| | | | " echo -e "| Other: |---------------|--------------| " - echo -e "| 6) [PrettyGCode] | $LOCAL_PGC_COMMIT | $REMOTE_PGC_COMMIT | " - echo -e "| 7) [Telegram Bot] | $LOCAL_MOONRAKER_TELEGRAM_BOT_COMMIT | $REMOTE_MOONRAKER_TELEGRAM_BOT_COMMIT | " + echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)| " + echo -e "| 7) [Telegram Bot] |$(compare_prettygcode_versions)| " echo -e "| |------------------------------| " echo -e "| 8) [System] | $DISPLAY_SYS_UPDATE | " back_footer @@ -73,3 +73,56 @@ update_menu(){ done update_menu } + +function update_all(){ + while true; do + if [ "${#update_arr[@]}" = "0" ]; then + CONFIRM_MSG="Everything is already up to date!" + echo; break + fi + echo + top_border + echo -e "| The following installations will be updated: |" + if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then + echo -e "| ${cyan}● Klipper${white} |" + fi + if [ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● Moonraker${white} |" + fi + if [ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● Mainsail${white} |" + fi + if [ "${FLUIDD_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● Fluidd${white} |" + fi + if [ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● KlipperScreen${white} |" + fi + if [ "${PGC_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● PrettyGCode for Klipper${white} |" + fi + if [ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● MoonrakerTelegramBot${white} |" + fi + if [ "${SYS_UPDATE_AVAIL}" = "true" ]; then + echo -e "| ${cyan}● System${white} |" + fi + bottom_border + if [ "${#update_arr[@]}" != "0" ]; then + read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn + case "$yn" in + Y|y|Yes|yes|"") + for update in "${update_arr[@]}" + do + $update + done + break;; + N|n|No|no) + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + fi + done +} diff --git a/scripts/update.sh b/scripts/update.sh index 21111fd..a522cba 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -1,56 +1,3 @@ -update_all(){ - while true; do - if [ "${#update_arr[@]}" = "0" ]; then - CONFIRM_MSG="Everything is already up to date!" - echo; break - fi - echo - top_border - echo -e "| The following installations will be updated: |" - if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Klipper${white} |" - fi - if [ "$MOONRAKER_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Moonraker${white} |" - fi - if [ "$MAINSAIL_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Mainsail${white} |" - fi - if [ "$FLUIDD_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● Fluidd${white} |" - fi - if [ "$KLIPPERSCREEN_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● KlipperScreen${white} |" - fi - if [ "$PGC_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● PrettyGCode for Klipper${white} |" - fi - if [ "$MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● MoonrakerTelegramBot${white} |" - fi - if [ "$SYS_UPDATE_AVAIL" = "true" ]; then - echo -e "| ${cyan}● System${white} |" - fi - bottom_border - if [ "${#update_arr[@]}" != "0" ]; then - read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn - case "$yn" in - Y|y|Yes|yes|"") - for update in ${update_arr[@]} - do - $update - done - break;; - N|n|No|no) - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - fi - done -} - update_log_paths(){ ### update services to make use of moonrakers new log_path option ### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a From 5001681ee2de4dabdd5ed22a29e46aba1ec1113c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 12 Apr 2022 19:11:15 +0200 Subject: [PATCH 092/183] fix: group `dialout` is required for klippers USB communication Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 14 ++++++-------- scripts/klipper.sh | 3 +++ scripts/ui/advanced_menu.sh | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index c9102c1..d2a29c6 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -289,17 +289,13 @@ function retrieve_id(){ fi 2>/dev/null } -function check_usergroup_dialout(){ - local group_dialout +function check_usergroups(){ + local group_dialout group_tty if grep -q "dialout" Date: Tue, 12 Apr 2022 20:35:41 +0200 Subject: [PATCH 093/183] feat: allow klipper installation with python3 Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 16 +++++++++----- scripts/klipper.sh | 39 +++++++++++++++++++++++---------- scripts/ui/install_menu.sh | 45 +++++++++++++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index d2a29c6..437fc8a 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -226,17 +226,23 @@ function flash_mcu_sd(){ } function build_fw(){ - if [ -d "${KLIPPER_DIR}" ]; then + local python_version + if [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPY_ENV}" ]; then + print_error "Klipper not found!\n Cannot build firmware without Klipper!" + return 1 + else cd "${KLIPPER_DIR}" status_msg "Initializing firmware build ..." dep=(build-essential dpkg-dev make) dependency_check "${dep[@]}" + make clean && make menuconfig + status_msg "Building firmware ..." - make && ok_msg "Firmware built!" - else - print_error "Klipper was not found!\n Can not build firmware without Klipper!" - return 1 + python_version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1) + [ "${python_version}" == "3" ] && make PYTHON=python3 + [ "${python_version}" == "2" ] && make + ok_msg "Firmware built!" fi } diff --git a/scripts/klipper.sh b/scripts/klipper.sh index d2e7cfc..917eb0e 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -36,6 +36,7 @@ function klipper_exists() { } function klipper_setup_dialog(){ + local python_version="${1}" status_msg "Initializing Klipper installation ..." ### return early if klipper already exists @@ -44,7 +45,7 @@ function klipper_setup_dialog(){ if [ -n "${klipper_services}" ]; then local error="At least one Klipper service is already installed:" for s in ${klipper_services}; do - log "Found Klipper service: ${s}" + log_info "Found Klipper service: ${s}" error="${error}\n ➔ ${s}" done print_error "${error}" && return @@ -74,7 +75,7 @@ function klipper_setup_dialog(){ Y|y|Yes|yes|"") select_msg "Yes" status_msg "Installing ${count} Klipper instance(s) ... \n" - klipper_setup "${count}" + klipper_setup "${count}" "${python_version}" break;; N|n|No|no) select_msg "No" @@ -89,12 +90,14 @@ function klipper_setup_dialog(){ } function install_klipper_packages(){ - local packages + local packages python_version="${1}" local install_script="${HOME}/klipper/scripts/install-octopi.sh" status_msg "Reading dependencies..." # shellcheck disable=SC2016 - packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')" + packages=$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n') + ### replace python-dev with python3-dev if python3 was selected + [ "${python_version}" == "python3" ] && packages="${packages//python-dev/python3-dev}" ### add dbus requirement for DietPi distro [ -e "/boot/dietpi/.version" ] && packages+=" dbus" @@ -111,15 +114,27 @@ function install_klipper_packages(){ } function create_klipper_virtualenv(){ - status_msg "Installing python virtual environment..." - ### always create a clean virtualenv - [ -d "${KLIPPY_ENV}" ] && rm -rf "${KLIPPY_ENV}" - virtualenv -p python2 "${KLIPPY_ENV}" - "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt + local python_version="${1}" py2_ver py3_ver + if [ "${python_version}" == "python2" ]; then + py2_ver=$(python2 -V) + status_msg "Installing ${py2_ver} virtual environment..." + [ -d "${KLIPPY_ENV}" ] && rm -rf "${KLIPPY_ENV}" + virtualenv -p python2 "${KLIPPY_ENV}" + "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt + fi + if [ "${python_version}" == "python3" ]; then + py3_ver=$(python3 -V) + status_msg "Installing ${py3_ver} virtual environment..." + virtualenv -p python3 "${KLIPPY_ENV}" + ### upgrade pip + "${KLIPPY_ENV}"/bin/pip install -U pip + "${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt + fi + return } function klipper_setup(){ - local instances=${1} + local instances=${1} python_version=${2} ### checking dependencies local dep=(git) dependency_check "${dep[@]}" @@ -131,8 +146,8 @@ function klipper_setup(){ cd "${HOME}" && git clone "${KLIPPER_REPO}" ### step 2: install klipper dependencies and create python virtualenv - install_klipper_packages - create_klipper_virtualenv + install_klipper_packages "${python_version}" + create_klipper_virtualenv "${python_version}" ### step 3: create gcode_files and logs folder [ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files" diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 12703e7..3773cdd 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -11,7 +11,7 @@ set -e -install_ui(){ +function install_ui(){ top_border echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | " hr @@ -32,13 +32,16 @@ install_ui(){ back_footer } -install_menu(){ - do_action "" "install_ui" +function install_menu(){ + clear && print_header + install_ui + while true; do read -p "${cyan}Perform action:${white} " action; echo - case "$action" in - 1) - do_action "klipper_setup_dialog" "install_ui";; + case "${action}" in + 1)clear && print_header + select_klipper_python_version + install_ui;; 2) do_action "moonraker_setup_dialog" "install_ui";; 3) @@ -63,3 +66,33 @@ install_menu(){ done install_menu } + +function select_klipper_python_version(){ + top_border + echo -e "| Please select the preferred Python version. | " + echo -e "| The recommended version is Python 2.7. | " + blank_line + echo -e "| Installing Klipper with Python 3 is officially not | " + echo -e "| recommended and should be considered as experimental. | " + hr + echo -e "| 1) [Python 2.7] (recommended) | " + echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | " + back_footer + while true; do + read -p "${cyan}###### Select Python version:${white} " action; echo + case "${action}" in + 1) + select_msg "Python 2.7" + klipper_setup_dialog "python2" + break;; + 2) + select_msg "Python 3.x" + klipper_setup_dialog "python3" + break;; + B|b) + clear; install_menu; break;; + *) + error_msg "Invalid Input!\n";; + esac + done +} From f91b2aa230ff1a624fc6c3e16d44a699582dfa96 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 14 Apr 2022 19:45:49 +0200 Subject: [PATCH 094/183] refactor: flash_klipper.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 303 +++++++++++++++++------------------- scripts/ui/advanced_menu.sh | 9 +- scripts/utilities.sh | 73 +++++++-- 3 files changed, 208 insertions(+), 177 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index 437fc8a..de363fc 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -11,48 +11,12 @@ set -e -function show_flash_method_help(){ - top_border - echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |" - hr - echo -e "| ${cyan}Regular flashing method:${white} |" - echo -e "| The default method to flash controller boards which |" - echo -e "| are connected and updated over USB and not by placing |" - echo -e "| a compiled firmware file onto an internal SD-Card. |" - blank_line - echo -e "| Common controllers that get flashed that way are: |" - echo -e "| - Arduino Mega 2560 |" - echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |" - blank_line - echo -e "| ${cyan}Updating via SD-Card Update:${white} |" - echo -e "| Many popular controller boards ship with a bootloader |" - echo -e "| capable of updating the firmware via SD-Card. |" - echo -e "| Choose this method if your controller board supports |" - echo -e "| this way of updating. This method ONLY works for up- |" - echo -e "| grading firmware. The initial flashing procedure must |" - echo -e "| be done manually per the instructions that apply to |" - echo -e "| your controller board. |" - blank_line - echo -e "| Common controllers that can be flashed that way are: |" - echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |" - echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |" - echo -e "| - Fysetc Spider |" - blank_line - back_footer - while true; do - read -p "${cyan}###### Please select:${white} " choice - case "${choice}" in - B|b) - clear && print_header - select_flash_method - break;; - *) - print_error "Invalid command!";; - esac - done -} +function init_flash_process(){ + local method + + ### step 1: check for required userhgroups (tty & dialout) + check_usergroups -function select_flash_method(){ top_border echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |" hr @@ -69,16 +33,12 @@ function select_flash_method(){ read -p "${cyan}###### Please select:${white} " choice case "${choice}" in 1) - echo -e "###### > Regular flashing method" - select_mcu_connection - select_mcu_id - [[ "${CONFIRM_FLASH}" == true ]] && flash_mcu + select_msg "Regular flashing method" + method="regular" break;; 2) - echo -e "###### > SD-Card Update" - select_mcu_connection - select_mcu_id - [[ "${CONFIRM_FLASH}" == true ]] && flash_mcu_sd + select_msg "SD-Card Update" + method="sdcard" break;; B|b) advanced_menu @@ -91,11 +51,61 @@ function select_flash_method(){ print_error "Invalid command!";; esac done + + ### step 2: select how the mcu is connected to the host + select_mcu_connection + ### step 3: select which detected mcu should be flashed + select_mcu_id "${method}" } +#================================================# +#=================== STEP 2 =====================# +#================================================# +function select_mcu_connection(){ + echo + top_border + echo -e "| ${yellow}Make sure to have the controller board connected now!${white} |" + blank_line + echo -e "| How is the controller board connected to the host? |" + echo -e "| 1) USB |" + echo -e "| 2) UART |" + bottom_border + while true; do + read -p "${cyan}###### Connection method:${white} " choice + case "${choice}" in + 1) + status_msg "Identifying MCU connected via USB ...\n" + get_usb_id + break;; + 2) + status_msg "Identifying MCU possibly connected via UART ...\n" + get_uart_id + break;; + *) + error_msg "Invalid input!\n";; + esac + done + + if [[ "${#mcu_list[@]}" -lt 1 ]]; then + warn_msg "No MCU found!" + warn_msg "MCU not plugged in or not detectable!" + echo + else + local i=1 + for mcu in "${mcu_list[@]}"; do + mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) + echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" + i=$((i+1)) + done + echo + fi +} + +#================================================# +#=================== STEP 3 =====================# +#================================================# function select_mcu_id(){ - local id=0 sel_index=0 - if [ ${#mcu_list[@]} -ge 1 ]; then + local i=1 sel_index=0 method=${1} top_border echo -e "| ${red}!!! ATTENTION !!!${white} |" hr @@ -105,17 +115,18 @@ function select_mcu_id(){ echo -e "${cyan}###### List of available MCU:${white}" ### list all mcus for mcu in "${mcu_list[@]}"; do - id=$((id+1)) - echo -e " ${id}) ${mcu}" + mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) + echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" + i=$((i+1)) done ### verify user input - while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${id}" ]; do + while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${i}" ]; do echo read -p "${cyan}###### Select MCU to flash:${white} " sel_index if [[ ! (${sel_index} =~ ^[1-9]+$) ]]; then error_msg "Invalid input!" - elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${id}" ]; then - error_msg "Please select a number between 1 and ${id}!" + elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${i}" ]; then + error_msg "Please select a number between 1 and ${i}!" fi mcu_index=$((sel_index - 1)) selected_mcu_id="${mcu_list[${mcu_index}]}" @@ -128,38 +139,45 @@ function select_mcu_id(){ Y|y|Yes|yes|"") select_msg "Yes" status_msg "Flashing ${selected_mcu_id} ..." - CONFIRM_FLASH=true + if [ "${method}" == "regular" ]; then + log_info "Flashing device '${selected_mcu_id}' with method '${method}'" + start_flash_mcu "${selected_mcu_id}" + elif [ "${method}" == "sdcard" ]; then + log_info "Flashing device '${selected_mcu_id}' with method '${method}'" + start_flash_mcu_sd "${selected_mcu_id}" + else + error_msg "No flash method set! Aborting..." + log_error "No flash method set!" + return 1 + fi break;; N|n|No|no) select_msg "No" - CONFIRM_FLASH=false break;; *) print_error "Invalid command!";; esac done - fi } -function flash_mcu(){ +function start_flash_mcu(){ + local device=${1} do_action_service "stop" "klipper" - make flash FLASH_DEVICE="${mcu_list[${mcu_index}]}" - ### evaluate exit code of make flash - if [ ! $? -eq 0 ]; then + if make flash FLASH_DEVICE="${device}"; then + ok_msg "Flashing successfull!" + else warn_msg "Flashing failed!" warn_msg "Please read the console output above!" - else - ok_msg "Flashing successfull!" fi do_action_service "start" "klipper" } -function flash_mcu_sd(){ - local i=0 board_list=() +function start_flash_mcu_sd(){ + local i=0 board_list=() device=${1} local flash_script="${HOME}/klipper/scripts/flash-sdcard.sh" ### write each supported board to the array to make it selectable - for board in $(/bin/bash "${flash_script}" -l | tail -n +2); do + for board in $("${flash_script}" -l | tail -n +2); do board_list+=("${board}") done @@ -214,13 +232,13 @@ function flash_mcu_sd(){ ###flash process do_action_service "stop" "klipper" - /bin/bash "${flash_script}" -b "${selected_baud_rate}" "${selected_mcu_id}" "${selected_board}" - ### evaluate exit code of flash-sdcard.sh execution - if [ ! $? -eq 0 ]; then + if "${flash_script}" -b "${selected_baud_rate}" "${device}" "${selected_board}"; then + ok_msg "Flashing successfull!" + log_info "Flash successfull!" + else warn_msg "Flashing failed!" warn_msg "Please read the console output above!" - else - ok_msg "Flashing successfull!" + log_error "Flash failed!" fi do_action_service "start" "klipper" } @@ -246,98 +264,65 @@ function build_fw(){ fi } -function select_mcu_connection(){ - echo +#================================================# +#=================== HELPERS ====================# +#================================================# + +function get_usb_id(){ + unset mcu_list + sleep 1 + mcus=$(find /dev/serial/by-id/*) + for mcu in ${mcus}; do + mcu_list+=("${mcu}") + done +} + +function get_uart_id() { + unset mcu_list + sleep 1 + mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty[^0-9]+([0-9]+)?$") + for mcu in ${mcus}; do + mcu_list+=("${mcu}") + done +} + +function show_flash_method_help(){ top_border - echo -e "| ${yellow}Make sure to have the controller board connected now!${white} |" + echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |" + hr + echo -e "| ${cyan}Regular flashing method:${white} |" + echo -e "| The default method to flash controller boards which |" + echo -e "| are connected and updated over USB and not by placing |" + echo -e "| a compiled firmware file onto an internal SD-Card. |" blank_line - echo -e "| How is the controller board connected to the host? |" - echo -e "| 1) USB |" - echo -e "| 2) UART |" - bottom_border + echo -e "| Common controllers that get flashed that way are: |" + echo -e "| - Arduino Mega 2560 |" + echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |" + blank_line + echo -e "| ${cyan}Updating via SD-Card Update:${white} |" + echo -e "| Many popular controller boards ship with a bootloader |" + echo -e "| capable of updating the firmware via SD-Card. |" + echo -e "| Choose this method if your controller board supports |" + echo -e "| this way of updating. This method ONLY works for up- |" + echo -e "| grading firmware. The initial flashing procedure must |" + echo -e "| be done manually per the instructions that apply to |" + echo -e "| your controller board. |" + blank_line + echo -e "| Common controllers that can be flashed that way are: |" + echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |" + echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |" + echo -e "| - Fysetc Spider |" + blank_line + back_footer while true; do - read -p "${cyan}###### Connection method:${white} " choice + read -p "${cyan}###### Please select:${white} " choice case "${choice}" in - 1) - retrieve_id "USB" - break;; - 2) - retrieve_id "UART" + B|b) + clear && print_header + init_flash_process break;; *) - print_unkown_cmd - print_msg && clear_msg;; + print_error "Invalid command!";; esac done - unset mcu_count - - if [[ "${#mcu_list[@]}" -lt 1 ]]; then - warn_msg "No MCU found!" - warn_msg "MCU not plugged in or not detectable!" - echo - fi -} - -function retrieve_id(){ - local mcu_list=() mcu_count=1 - status_msg "Identifying MCU ..." - sleep 1 - [ "${1}" = "USB" ] && path="/dev/serial/by-id/*" - [ "${1}" = "UART" ] && path="/dev/ttyAMA0" - if [[ "$(ls "${path}")" != "" ]] ; then - for mcu in ${path}; do - declare "mcu_id_${mcu_count}"="${mcu}" - mcu_id="mcu_id_${mcu_count}" - mcu_list+=("${!mcu_id}") - echo -e " ● ($1) MCU #${mcu_count}: ${cyan}${mcu}${white}\n" - mcu_count=$((mcu_count+1)) - done - fi 2>/dev/null -} - -function check_usergroups(){ - local group_dialout group_tty - if grep -q "dialout" /dev/null 1>&2; then status_msg "Restarting NGINX Service ..." sudo systemctl restart nginx && ok_msg "NGINX Service restarted!" @@ -362,7 +362,7 @@ restart_nginx(){ #================ DEPENDENCIES ==================# #================================================# -dependency_check(){ +function dependency_check(){ local dep=( "${@}" ) # dep: array status_msg "Checking for the following dependencies:" #check if package is installed, if not write name into array @@ -390,7 +390,7 @@ dependency_check(){ fi } -setup_gcode_shell_command(){ +function setup_gcode_shell_command(){ echo top_border echo -e "| You are about to install the G-Code Shell Command |" @@ -435,7 +435,7 @@ setup_gcode_shell_command(){ done } -install_gcode_shell_command(){ +function install_gcode_shell_command(){ do_action_service "stop" "klipper" status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..." cp "${SRCDIR}/kiauh/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras" @@ -553,3 +553,54 @@ function fetch_webui_ports(){ fi done } + +#================================================# +#================= USERGROUPS ===================# +#================================================# + +function check_usergroups(){ + local group_dialout group_tty + if grep -q "dialout" Date: Thu, 14 Apr 2022 19:49:37 +0200 Subject: [PATCH 095/183] style: add copyright and shellcheck ignores Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 1 + scripts/network_functions.sh | 13 +++++++++++++ scripts/rollback.sh | 13 +++++++++++++ scripts/switch_branch.sh | 13 +++++++++++++ 4 files changed, 40 insertions(+) diff --git a/scripts/globals.sh b/scripts/globals.sh index c551812..85f23ea 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -9,6 +9,7 @@ # This file may be distributed under the terms of the GNU GPLv3 license # #=======================================================================# +# shellcheck disable=SC2034 set -e function set_globals(){ diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 006c24c..8511673 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + function set_nginx_cfg(){ if [ "${SET_NGINX_CFG}" = "true" ]; then local cfg="${SRCDIR}/kiauh/resources/${1}" diff --git a/scripts/rollback.sh b/scripts/rollback.sh index aaa6d9d..9f236b7 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + save_klipper_state(){ source_kiauh_ini #read current klipper state diff --git a/scripts/switch_branch.sh b/scripts/switch_branch.sh index 212c436..1773ef5 100755 --- a/scripts/switch_branch.sh +++ b/scripts/switch_branch.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + switch_to_master(){ cd $KLIPPER_DIR status_msg "Switching...Please wait ..."; echo From c21827f3ee9d2d1a8100bef7a1ea51b2f83df5e1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 14 Apr 2022 19:51:06 +0200 Subject: [PATCH 096/183] style: remove unused commented code Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index d7e58a7..868547b 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -48,35 +48,6 @@ function kiauh_update_avail(){ fi } -#print_unkown_cmd(){ -# ERROR_MSG="Invalid command!" -#} -#invalid_option(){ -# ERROR_MSG="Invalid command!" -#} - -#print_msg(){ -# if [ -n "${ERROR_MSG}" ]; then -# echo -e "${red}" -# echo -e "#########################################################" -# echo -e " ${ERROR_MSG} " -# echo -e "#########################################################" -# echo -e "${white}" -# fi -# if [ -n "${CONFIRM_MSG}" ]; then -# echo -e "${green}" -# echo -e "#########################################################" -# echo -e " ${CONFIRM_MSG} " -# echo -e "#########################################################" -# echo -e "${white}" -# fi -#} -# -#clear_msg(){ -# unset CONFIRM_MSG -# unset ERROR_MSG -#} - check_euid set_globals init_ini From 3ea0623d95ff73eab9a55018c66d9ed24b537e7c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 11:46:14 +0200 Subject: [PATCH 097/183] fix: bug in mcu index selection Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index de363fc..00295df 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -105,7 +105,7 @@ function select_mcu_connection(){ #=================== STEP 3 =====================# #================================================# function select_mcu_id(){ - local i=1 sel_index=0 method=${1} + local i=0 sel_index=0 method=${1} top_border echo -e "| ${red}!!! ATTENTION !!!${white} |" hr @@ -115,9 +115,9 @@ function select_mcu_id(){ echo -e "${cyan}###### List of available MCU:${white}" ### list all mcus for mcu in "${mcu_list[@]}"; do + i=$((i+1)) mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" - i=$((i+1)) done ### verify user input while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${i}" ]; do From 8aab598b8bf1f1fbaf09508451f3ec2d376ff38c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 11:49:54 +0200 Subject: [PATCH 098/183] refactor: remove octoprint service toggle option the octoprint process does not interfere with any moonraker/mainsail/fluidd instance. that option is therefore not really required anymore as haproxy is the real 'troublemaker' Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 0d2aaeb..ca4dfae 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -14,12 +14,6 @@ set -e advanced_ui(){ top_border echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} | " - hr - if [ ! "$OPRINT_SERVICE_STATUS" == "" ]; then - echo -e "| 0) $OPRINT_SERVICE_STATUS| " - hr - echo -e "| | | " - fi echo -e "| Klipper: | Mainsail: | " echo -e "| 1) [Switch Branch] | 7) [Theme installer] | " echo -e "| 2) [Rollback] | | " @@ -33,17 +27,10 @@ back_footer } advanced_menu(){ - read_octoprint_service_status do_action "" "advanced_ui" while true; do read -p "${cyan}Perform action:${white} " action; echo case "${action}" in - 0) - clear - print_header - toggle_octoprint_service - read_octoprint_service_status - advanced_ui;; 1) do_action "switch_menu";; 2) @@ -86,7 +73,7 @@ switch_ui(){ echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" bottom_border echo - echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${white}" + echo -e " $(title_msg "Active Branch: ")${green}${GET_BRANCH}${white}" echo top_border echo -e "| | " @@ -100,12 +87,12 @@ switch_ui(){ } switch_menu(){ - if [ -d $KLIPPER_DIR ]; then + if [ -d "${KLIPPER_DIR}" ]; then read_branch do_action "" "switch_ui" while true; do read -p "${cyan}Perform action:${white} " action; echo - case "$action" in + case "${action}" in 1) clear print_header From 011d90e4fa466099a653e7c23ceed7f2eee9af8c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 11:54:07 +0200 Subject: [PATCH 099/183] refactor: rename `start_flash_mcu_sd` to `start_flash_sd` Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index 00295df..f701e56 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -144,7 +144,7 @@ function select_mcu_id(){ start_flash_mcu "${selected_mcu_id}" elif [ "${method}" == "sdcard" ]; then log_info "Flashing device '${selected_mcu_id}' with method '${method}'" - start_flash_mcu_sd "${selected_mcu_id}" + start_flash_sd "${selected_mcu_id}" else error_msg "No flash method set! Aborting..." log_error "No flash method set!" @@ -172,7 +172,7 @@ function start_flash_mcu(){ do_action_service "start" "klipper" } -function start_flash_mcu_sd(){ +function start_flash_sd(){ local i=0 board_list=() device=${1} local flash_script="${HOME}/klipper/scripts/flash-sdcard.sh" From c735d0327b92312ebb54950b656c3da78ec1804d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 13:47:30 +0200 Subject: [PATCH 100/183] refactor: improve flash methods Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 216 ++++++++++++++++++++++-------------- scripts/ui/advanced_menu.sh | 6 +- 2 files changed, 139 insertions(+), 83 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index f701e56..bcb88d7 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -48,7 +48,7 @@ function init_flash_process(){ show_flash_method_help break;; *) - print_error "Invalid command!";; + error_msg "Invalid command!";; esac done @@ -62,43 +62,56 @@ function init_flash_process(){ #=================== STEP 2 =====================# #================================================# function select_mcu_connection(){ - echo top_border - echo -e "| ${yellow}Make sure to have the controller board connected now!${white} |" + echo -e "| ${yellow}Make sure that the controller board is connected now!${white} |" + hr blank_line echo -e "| How is the controller board connected to the host? |" echo -e "| 1) USB |" echo -e "| 2) UART |" - bottom_border + blank_line + back_help_footer while true; do read -p "${cyan}###### Connection method:${white} " choice case "${choice}" in + ### continue to execute script even if get_usb_id or get_uart_id returns with exit code 1 + ### this is not critical, as the mcu_list array will be empty and that specific + ### case is handled later during execution of the script 1) status_msg "Identifying MCU connected via USB ...\n" - get_usb_id + get_usb_id || true # continue even after exit code 1 break;; 2) status_msg "Identifying MCU possibly connected via UART ...\n" - get_uart_id + get_uart_id || true # continue even after exit code 1 + break;; + B|b) + advanced_menu + break;; + H|h) + clear && print_header + show_mcu_connection_help break;; *) - error_msg "Invalid input!\n";; + error_msg "Invalid command!";; esac done +} - if [[ "${#mcu_list[@]}" -lt 1 ]]; then - warn_msg "No MCU found!" - warn_msg "MCU not plugged in or not detectable!" - echo - else - local i=1 - for mcu in "${mcu_list[@]}"; do - mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) - echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" - i=$((i+1)) - done - echo +function print_detected_mcu_to_screen(){ + local i=1 + + if [ "${#mcu_list[@]}" -lt 1 ]; then + print_error "No MCU found!\n MCU eihter not connected or not detected!" + return fi + + for mcu in "${mcu_list[@]}"; do + mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) + echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" + i=$((i+1)) + done + echo } #================================================# @@ -106,58 +119,64 @@ function select_mcu_connection(){ #================================================# function select_mcu_id(){ local i=0 sel_index=0 method=${1} - top_border - echo -e "| ${red}!!! ATTENTION !!!${white} |" - hr - echo -e "| Make sure, to select the correct MCU! |" - echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |" - bottom_border - echo -e "${cyan}###### List of available MCU:${white}" - ### list all mcus - for mcu in "${mcu_list[@]}"; do - i=$((i+1)) - mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) - echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" - done - ### verify user input - while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${i}" ]; do - echo - read -p "${cyan}###### Select MCU to flash:${white} " sel_index - if [[ ! (${sel_index} =~ ^[1-9]+$) ]]; then - error_msg "Invalid input!" - elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${i}" ]; then - error_msg "Please select a number between 1 and ${i}!" - fi - mcu_index=$((sel_index - 1)) - selected_mcu_id="${mcu_list[${mcu_index}]}" - done - ### confirm selection - while true; do - echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n" - read -p "${cyan}###### Continue? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - status_msg "Flashing ${selected_mcu_id} ..." - if [ "${method}" == "regular" ]; then - log_info "Flashing device '${selected_mcu_id}' with method '${method}'" - start_flash_mcu "${selected_mcu_id}" - elif [ "${method}" == "sdcard" ]; then - log_info "Flashing device '${selected_mcu_id}' with method '${method}'" - start_flash_sd "${selected_mcu_id}" - else - error_msg "No flash method set! Aborting..." - log_error "No flash method set!" - return 1 - fi - break;; - N|n|No|no) - select_msg "No" - break;; - *) - print_error "Invalid command!";; - esac - done + + if [ "${#mcu_list[@]}" -lt 1 ]; then + print_error "No MCU found!\n MCU eihter not connected or not detected!" + return + fi + + top_border + echo -e "| ${red}!!! ATTENTION !!!${white} |" + hr + echo -e "| Make sure, to select the correct MCU! |" + echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |" + bottom_border + echo -e "${cyan}###### List of available MCU:${white}" + ### list all mcus + for mcu in "${mcu_list[@]}"; do + i=$((i+1)) + mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev) + echo -e " ● MCU #${i}: ${cyan}${mcu}${white}" + done + ### verify user input + while [[ ! (${sel_index} =~ ^[1-9]+$) ]] || [ "${sel_index}" -gt "${i}" ]; do + echo + read -p "${cyan}###### Select MCU to flash:${white} " sel_index + if [[ ! (${sel_index} =~ ^[1-9]+$) ]]; then + error_msg "Invalid input!" + elif [ "${sel_index}" -lt 1 ] || [ "${sel_index}" -gt "${i}" ]; then + error_msg "Please select a number between 1 and ${i}!" + fi + mcu_index=$((sel_index - 1)) + selected_mcu_id="${mcu_list[${mcu_index}]}" + done + ### confirm selection + while true; do + echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n" + read -p "${cyan}###### Continue? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + status_msg "Flashing ${selected_mcu_id} ..." + if [ "${method}" == "regular" ]; then + log_info "Flashing device '${selected_mcu_id}' with method '${method}'" + start_flash_mcu "${selected_mcu_id}" + elif [ "${method}" == "sdcard" ]; then + log_info "Flashing device '${selected_mcu_id}' with method '${method}'" + start_flash_sd "${selected_mcu_id}" + else + print_error "No flash method set! Aborting..." + log_error "No flash method set!" + return + fi + break;; + N|n|No|no) + select_msg "No" + break;; + *) + error_msg "Invalid command!";; + esac + done } function start_flash_mcu(){ @@ -204,16 +223,17 @@ function start_flash_sd(){ if [ "${choice}" = "q" ] || [ "${choice}" = "Q" ]; then clear && advanced_menu && break elif [ "${choice}" -le ${#board_list[@]} ]; then - selected_board="${board_list[${choice}]}" + local selected_board="${board_list[${choice}]}" break else clear && print_header - print_error "Invalid choice!" + error_msg "Invalid choice!" flash_mcu_sd fi done while true; do + echo top_border echo -e "| If your board is flashed with firmware that connects |" echo -e "| at a custom baud rate, please change it now. |" @@ -221,10 +241,9 @@ function start_flash_sd(){ echo -e "| If you are unsure, stick to the default 250000! |" bottom_border echo -e "${cyan}###### Please set the baud rate:${white} " - unset baud_rate while [[ ! ${baud_rate} =~ ^[0-9]+$ ]]; do read -e -i "250000" -e baud_rate - selected_baud_rate=${baud_rate} + local selected_baud_rate=${baud_rate} break done break @@ -233,11 +252,10 @@ function start_flash_sd(){ ###flash process do_action_service "stop" "klipper" if "${flash_script}" -b "${selected_baud_rate}" "${device}" "${selected_board}"; then - ok_msg "Flashing successfull!" + print_confirm "Flashing successfull!" log_info "Flash successfull!" else - warn_msg "Flashing failed!" - warn_msg "Please read the console output above!" + print_error "Flashing failed!\n Please read the console output above!" log_error "Flash failed!" fi do_action_service "start" "klipper" @@ -247,7 +265,7 @@ function build_fw(){ local python_version if [ ! -d "${KLIPPER_DIR}" ] || [ ! -d "${KLIPPY_ENV}" ]; then print_error "Klipper not found!\n Cannot build firmware without Klipper!" - return 1 + return else cd "${KLIPPER_DIR}" status_msg "Initializing firmware build ..." @@ -271,7 +289,7 @@ function build_fw(){ function get_usb_id(){ unset mcu_list sleep 1 - mcus=$(find /dev/serial/by-id/*) + mcus=$(find /dev/serial/by-id/* 2>/dev/null) for mcu in ${mcus}; do mcu_list+=("${mcu}") done @@ -280,7 +298,7 @@ function get_usb_id(){ function get_uart_id() { unset mcu_list sleep 1 - mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty[^0-9]+([0-9]+)?$") + mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty[^0-9]+([0-9]+)?$" 2>/dev/null) for mcu in ${mcus}; do mcu_list+=("${mcu}") done @@ -322,7 +340,41 @@ function show_flash_method_help(){ init_flash_process break;; *) - print_error "Invalid command!";; + error_msg "Invalid command!";; + esac + done +} + +function show_mcu_connection_help(){ + top_border + echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |" + hr + echo -e "| ${cyan}USB:${white} |" + echo -e "| Selecting USB as the connection method will scan the |" + echo -e "| USB ports for connected controller boards. This will |" + echo -e "| be similar to the 'ls /dev/serial/by-id/*' command |" + echo -e "| suggested by the official Klipper documentation for |" + echo -e "| determining successfull USB connections! |" + blank_line + echo -e "| ${cyan}UART:${white} |" + echo -e "| Selecting UART as the connection method will list all |" + echo -e "| possible UART serial ports. Note: This method ALWAYS |" + echo -e "| returns something as it seems impossible to determine |" + echo -e "| if a valid Klipper controller board is connected or |" + echo -e "| not. Because of that, you ${red}MUST${white} know which UART serial |" + echo -e "| port your controller board is connected to when using |" + echo -e "| this connection method. |" + blank_line + back_footer + while true; do + read -p "${cyan}###### Please select:${white} " choice + case "${choice}" in + B|b) + clear && print_header + select_mcu_connection + break;; + *) + error_msg "Invalid command!";; esac done } \ No newline at end of file diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index ca4dfae..dd7b50b 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -14,6 +14,7 @@ set -e advanced_ui(){ top_border echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} | " + hr echo -e "| Klipper: | Mainsail: | " echo -e "| 1) [Switch Branch] | 7) [Theme installer] | " echo -e "| 2) [Rollback] | | " @@ -46,7 +47,10 @@ advanced_menu(){ build_fw && init_flash_process advanced_ui;; 6) - do_action "select_mcu_connection" "advanced_ui";; + clear && print_header + select_mcu_connection + print_detected_mcu_to_screen + advanced_ui;; 7) do_action "ms_theme_menu";; 8) From c1523a0ea102c3a945296f1013ff437e6f37c9b2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 17:45:10 +0200 Subject: [PATCH 101/183] feat: custom klipper repos Signed-off-by: Dominik Willner th33xitus@gmail.com --- .gitignore | 3 +- klipper_repos.txt | 12 +++ scripts/switch_branch.sh | 36 --------- scripts/switch_klipper_repo.sh | 131 +++++++++++++++++++++++++++++++++ scripts/ui/settings_menu.sh | 50 +++++++++++-- scripts/utilities.sh | 27 +++++++ 6 files changed, 214 insertions(+), 45 deletions(-) create mode 100644 klipper_repos.txt delete mode 100755 scripts/switch_branch.sh create mode 100644 scripts/switch_klipper_repo.sh diff --git a/.gitignore b/.gitignore index cfac3d9..42a230f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -.shellcheckrc \ No newline at end of file +.shellcheckrc +klipper_repos.txt \ No newline at end of file diff --git a/klipper_repos.txt b/klipper_repos.txt new file mode 100644 index 0000000..be83f45 --- /dev/null +++ b/klipper_repos.txt @@ -0,0 +1,12 @@ +############################################################## +## DO NOT REMOVE OR EDIT THIS COMMENT BLOCK! ## +## ## +## Always add the URL and branch in this form: ## +## , ## +## Example: ## +## https://github.com/Klipper3d/klipper,master ## +## ## +## A wrong format will cause issues! You have been warned! ## +############################################################## +##~~~~~ Add the custom repositories below this line ~~~~~~~~## +https://github.com/Klipper3d/klipper,master diff --git a/scripts/switch_branch.sh b/scripts/switch_branch.sh deleted file mode 100755 index 1773ef5..0000000 --- a/scripts/switch_branch.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -#=======================================================================# -# Copyright (C) 2020 - 2022 Dominik Willner # -# # -# This file is part of KIAUH - Klipper Installation And Update Helper # -# https://github.com/th33xitus/kiauh # -# # -# This file may be distributed under the terms of the GNU GPLv3 license # -#=======================================================================# - -set -e - -switch_to_master(){ - cd $KLIPPER_DIR - status_msg "Switching...Please wait ..."; echo - git fetch origin -q && git checkout master; echo -} - -switch_to_scurve_shaping(){ - cd $KLIPPER_DIR - status_msg "Switching...Please wait ..."; echo - if ! git remote | grep dmbutyugin -q; then - git remote add dmbutyugin $DMBUTYUGIN_REPO - fi - git fetch dmbutyugin -q && git checkout scurve-shaping; echo -} - -switch_to_scurve_smoothing(){ - cd $KLIPPER_DIR - status_msg "Switching...Please wait ..."; echo - if ! git remote | grep dmbutyugin -q; then - git remote add dmbutyugin $DMBUTYUGIN_REPO - fi - git fetch dmbutyugin -q && git checkout scurve-smoothing; echo -} \ No newline at end of file diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh new file mode 100644 index 0000000..e4a7f2a --- /dev/null +++ b/scripts/switch_klipper_repo.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +function change_klipper_repo_menu(){ + local repo_file="${SRCDIR}/kiauh/klipper_repos.txt" + local url branch i=0 + + top_border + echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | " + hr + blank_line + ### dynamically generate the repolist from the klipper_repos.txt textfile + get_klipper_repo_list "${repo_file}" + blank_line + back_help_footer + + while IFS="," read -r col1 col2; do + url+=("${col1}") + branch+=("${col2}") + i=$((i+1)) + done < <(grep "" "${repo_file}" | tail -n "+12") + + while true; do + read -p "${cyan}Select Klipper repo:${white} " option + if [ "${option}" = "b" ] || [ "${option}" = "B" ]; then + clear && print_header + settings_menu + break + elif [ "${option}" = "h" ] || [ "${option}" = "H" ]; then + clear && print_header + show_custom_klipper_repo_help + elif [ "${option}" -le ${#url[@]} ]; then + if [ -d "${KLIPPER_DIR}" ]; then + top_border + echo -e "| ${red}!!! ATTENTION !!!${white} |" + echo -e "| Existing Klipper folder found! Proceeding will remove | " + echo -e "| the existing Klipper folder and replace it with a | " + echo -e "| clean copy of the previously selected source repo! | " + bottom_border + while true; do + read -p "${cyan}###### Proceed? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + switch_klipper_repo "${url[${option}]}" "${branch[${option}]}" + set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" + break;; + N|n|No|no) + select_msg "No" + break;; + *) + error_msg "Invalid command!";; + esac + done + else + status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}" + set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" + ok_msg "This repo will now be used for new Klipper installations!\n" + fi + break + else + clear && print_header + print_error "Invalid command!" + change_klipper_repo_menu + fi + done +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +function get_klipper_repo_list(){ + local repo_file=${1} i=0 + while IFS="," read -r col1 col2; do + col1=$(echo "${col1}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" ) + col1=${yellow}${col1}${white} + printf "| ${i}) %s → %-31s|\n" "${col1}" "${col2}" + i=$((i+1)) + done < <(grep "" "${repo_file}" | tail -n "+12") +} + +function switch_klipper_repo(){ + local url branch + url=${1} branch=${2} + status_msg "Switching Klipper repository..." + do_action_service "stop" "klipper" + cd ~ && rm -rf "${KLIPPER_DIR}" + git clone "${url}" && cd "${KLIPPER_DIR}" + git checkout "${branch}" && cd ~ + do_action_service "start" "klipper" +} + +function show_custom_klipper_repo_help(){ + top_border + echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |" + hr + echo -e "| With this setting, it is possible to install Klipper | " + echo -e "| from a custom repository. It will also switch an | " + echo -e "| existing Klipper installation to the newly selected | " + echo -e "| source repository. | " + echo -e "| A list of selectable repositories is automatically | " + echo -e "| generated by a 'klipper_repos.txt' textfile in KIAUHs | " + echo -e "| root folder. You can add as many additional repos as | " + echo -e "| you wish. Make sure to always add URL ${red}and${white} branch! | " + blank_line + echo -e "| Default: ${red}none${white} |" + blank_line + back_footer + while true; do + read -p "${cyan}###### Please select:${white} " choice + case "${choice}" in + B|b) + clear && print_header + change_klipper_repo_menu + break;; + *) + deny_action "show_settings_help";; + esac + done +} \ No newline at end of file diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index ba8c27a..4fb91f1 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -14,14 +14,31 @@ set -e function settings_ui() { read_kiauh_ini local custom_cfg_loc="${custom_klipper_cfg_loc}" + local custom_repo="${custom_klipper_repo}" + local custom_branch="${custom_klipper_repo_branch}" local ms_pre_rls="${mainsail_install_unstable}" local fl_pre_rls="${fluidd_install_unstable}" + ### config location if [ -z "${custom_cfg_loc}" ]; then custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}" else custom_cfg_loc="${cyan}${custom_cfg_loc}${white}" fi + ### custom repository + custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" ) + if [ -z "${custom_repo}" ]; then + custom_repo="${cyan}Klipper3D/klipper${white}" + else + custom_repo="${cyan}${custom_repo}${white}" + fi + ### custom repository branch + if [ -z "${custom_branch}" ]; then + custom_branch="${cyan}master${white}" + else + custom_branch="${cyan}${custom_branch}${white}" + fi + ### webinterface stable toggle if [ "${ms_pre_rls}" == "false" ]; then ms_pre_rls="${red}● ${ms_pre_rls}${white}" else @@ -37,15 +54,27 @@ function settings_ui() { echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |" hr echo -e "| Klipper: |" - printf "| Config folder: %-49s|\n" "${custom_cfg_loc}" - blank_line + echo -e "| ● Config folder: |" + printf "| %-60s|\n" "${custom_cfg_loc}" + echo -e "| ● Repository: |" + printf "| %-70s|\n" "${custom_repo} (${custom_branch})" + hr echo -e "| Install unstable releases: |" - printf "| Mainsail: %-56s|\n" "${ms_pre_rls}" - printf "| Fluidd: %-56s|\n" "${fl_pre_rls}" + printf "| Mainsail: %-55s|\n" "${ms_pre_rls}" + printf "| Fluidd: %-55s|\n" "${fl_pre_rls}" hr echo -e "| 1) Change Klipper config folder location |" - echo -e "| 2) Allow / Disallow unstable Mainsail releases |" - echo -e "| 3) Allow / Disallow unstable Fluidd releases |" + echo -e "| 2) Set custom Klipper repository |" + if [ "${mainsail_install_unstable}" == "false" ]; then + echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |" + else + echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |" + fi + if [ "${fluidd_install_unstable}" == "false" ]; then + echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |" + else + echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |" + fi back_help_footer } @@ -89,6 +118,7 @@ function show_settings_help(){ } settings_menu(){ + clear && print_header settings_ui while true; do read -p "${cyan}Perform action:${white} " action; echo @@ -96,9 +126,13 @@ settings_menu(){ 1) change_klipper_cfg_folder && settings_ui;; 2) - switch_mainsail_releasetype && settings_ui;; + clear && print_header + change_klipper_repo_menu + settings_ui;; 3) - switch_fluidd_releasetype && settings_ui;; + switch_mainsail_releasetype && settings_menu;; + 4) + switch_fluidd_releasetype && settings_menu;; B|b) clear main_menu diff --git a/scripts/utilities.sh b/scripts/utilities.sh index e5e9266..32e8aa6 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -134,6 +134,12 @@ function init_ini(){ if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}" fi + if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then + echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}" + fi + if ! grep -Eq "^custom_klipper_repo_branch=" "${INI_FILE}"; then + echo -e "\ncustom_klipper_repo_branch=\c" >> "${INI_FILE}" + fi if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}" fi @@ -304,6 +310,27 @@ function switch_fluidd_releasetype() { fi } +function switch_fluidd_releasetype() { + read_kiauh_ini + local state="${fluidd_install_unstable}" + if [ "${state}" == "false" ]; then + sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}" + log_info "fluidd_install_unstable changed (false -> true) " + else + sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}" + log_info "fluidd_install_unstable changed (true -> false) " + fi +} + +function set_custom_klipper_repo() { + read_kiauh_ini + local repo_url=${1} branch=${2} + sed -i "/^custom_klipper_repo=/d" "${INI_FILE}" + sed -i '$a'"custom_klipper_repo=${repo_url}" "${INI_FILE}" + sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}" + sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}" +} + #================================================# #=============== HANDLE SERVICES ================# #================================================# From 3d198ab15352d6721b33041db534b41a7e2793a1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 17:58:33 +0200 Subject: [PATCH 102/183] refactor: tweak repo file and settings Signed-off-by: Dominik Willner th33xitus@gmail.com --- klipper_repos.txt | 11 +++++------ scripts/switch_klipper_repo.sh | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/klipper_repos.txt b/klipper_repos.txt index be83f45..3a6ac38 100644 --- a/klipper_repos.txt +++ b/klipper_repos.txt @@ -1,12 +1,11 @@ ############################################################## ## DO NOT REMOVE OR EDIT THIS COMMENT BLOCK! ## -## ## -## Always add the URL and branch in this form: ## +## Always add the URL and branch in a pattern like this: ## ## , ## -## Example: ## -## https://github.com/Klipper3d/klipper,master ## +## E.g.: https://github.com/Klipper3d/klipper,master ## ## ## -## A wrong format will cause issues! You have been warned! ## +## A wrong format will cause problems! ## +## Do NOT insert blank lines. Only add one entry per line! ## ############################################################## -##~~~~~ Add the custom repositories below this line ~~~~~~~~## +##~~~~~ Add the custom repositories below THIS line ~~~~~~~~## https://github.com/Klipper3d/klipper,master diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh index e4a7f2a..27eeb11 100644 --- a/scripts/switch_klipper_repo.sh +++ b/scripts/switch_klipper_repo.sh @@ -87,7 +87,7 @@ function get_klipper_repo_list(){ col1=${yellow}${col1}${white} printf "| ${i}) %s → %-31s|\n" "${col1}" "${col2}" i=$((i+1)) - done < <(grep "" "${repo_file}" | tail -n "+12") + done < <(grep "" "${repo_file}" | tail -n "+11") } function switch_klipper_repo(){ @@ -114,8 +114,6 @@ function show_custom_klipper_repo_help(){ echo -e "| root folder. You can add as many additional repos as | " echo -e "| you wish. Make sure to always add URL ${red}and${white} branch! | " blank_line - echo -e "| Default: ${red}none${white} |" - blank_line back_footer while true; do read -p "${cyan}###### Please select:${white} " choice From ac163589e80209d653a975088cadd655ccdb530c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 18:03:25 +0200 Subject: [PATCH 103/183] refactor: remove switch menu from advanced menu this function got replaced by the custom klipper repo function Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 100 ++++++------------------------------ 1 file changed, 15 insertions(+), 85 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index dd7b50b..e45aaa5 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -16,14 +16,13 @@ advanced_ui(){ echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} | " hr echo -e "| Klipper: | Mainsail: | " - echo -e "| 1) [Switch Branch] | 7) [Theme installer] | " - echo -e "| 2) [Rollback] | | " - echo -e "| | System: | " - echo -e "| Firmware: | 8) [Change hostname] | " - echo -e "| 3) [Build only] | | " - echo -e "| 4) [Flash only] | Extras: | " - echo -e "| 5) [Build + Flash] | 9) [G-Code Shell Command] | " - echo -e "| 6) [Get MCU ID] | | " + echo -e "| 1) [Rollback] | 6) [Theme installer] | " + echo -e "| | | " + echo -e "| Firmware: | System: | " + echo -e "| 2) [Build only] | 7) [Change hostname] | " + echo -e "| 3) [Flash only] | | " + echo -e "| 4) [Build + Flash] | Extras: | " + echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] | " back_footer } @@ -33,32 +32,30 @@ advanced_menu(){ read -p "${cyan}Perform action:${white} " action; echo case "${action}" in 1) - do_action "switch_menu";; - 2) do_action "load_klipper_state" "advanced_ui";; - 3) + 2) do_action "build_fw" "advanced_ui";; - 4) + 3) clear && print_header do_action "init_flash_process" "advanced_ui";; - 5) + 4) clear && print_header status_msg "Please wait..." build_fw && init_flash_process advanced_ui;; - 6) + 5) clear && print_header select_mcu_connection print_detected_mcu_to_screen advanced_ui;; - 7) + 6) do_action "ms_theme_menu";; - 8) + 7) clear print_header create_custom_hostname && set_hostname advanced_ui;; - 9) + 8) do_action "setup_gcode_shell_command" "advanced_ui";; B|b) clear; main_menu; break;; @@ -67,71 +64,4 @@ advanced_menu(){ esac done advanced_menu -} - -############################################################# -############################################################# - -switch_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" - bottom_border - echo - echo -e " $(title_msg "Active Branch: ")${green}${GET_BRANCH}${white}" - echo - top_border - echo -e "| | " - echo -e "| KevinOConnor: | " - echo -e "| 1) [--> master] | " - echo -e "| | " - echo -e "| dmbutyugin: | " - echo -e "| 2) [--> scurve-shaping] | " - echo -e "| 3) [--> scurve-smoothing] | " - back_footer -} - -switch_menu(){ - if [ -d "${KLIPPER_DIR}" ]; then - read_branch - do_action "" "switch_ui" - while true; do - read -p "${cyan}Perform action:${white} " action; echo - case "${action}" in - 1) - clear - print_header - switch_to_master - read_branch - print_msg && clear_msg - switch_ui;; - 2) - clear - print_header - switch_to_scurve_shaping - read_branch - print_msg && clear_msg - switch_ui;; - 3) - clear - print_header - switch_to_scurve_smoothing - read_branch - print_msg && clear_msg - switch_ui;; - 4) - clear - print_header - switch_to_moonraker - read_branch - print_msg && clear_msg - switch_ui;; - B|b) - clear; advanced_menu; break;; - *) - deny_action "switch_ui";; - esac - done - else - ERROR_MSG="No Klipper directory found! Download Klipper first!" - fi -} +} \ No newline at end of file From 239f759c61118c4c9a1300151add9d40cf78d006 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 18:59:11 +0200 Subject: [PATCH 104/183] fix: dialog allowed a higher option than actually possible Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/switch_klipper_repo.sh | 96 +++++++++++++++++----------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh index 27eeb11..cf89b5a 100644 --- a/scripts/switch_klipper_repo.sh +++ b/scripts/switch_klipper_repo.sh @@ -13,7 +13,7 @@ set -e function change_klipper_repo_menu(){ local repo_file="${SRCDIR}/kiauh/klipper_repos.txt" - local url branch i=0 + local url branch top_border echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | " @@ -27,52 +27,51 @@ function change_klipper_repo_menu(){ while IFS="," read -r col1 col2; do url+=("${col1}") branch+=("${col2}") - i=$((i+1)) - done < <(grep "" "${repo_file}" | tail -n "+12") + done < <(grep "" "${repo_file}" | tail -n "+11") while true; do - read -p "${cyan}Select Klipper repo:${white} " option - if [ "${option}" = "b" ] || [ "${option}" = "B" ]; then - clear && print_header - settings_menu - break - elif [ "${option}" = "h" ] || [ "${option}" = "H" ]; then - clear && print_header - show_custom_klipper_repo_help - elif [ "${option}" -le ${#url[@]} ]; then - if [ -d "${KLIPPER_DIR}" ]; then - top_border - echo -e "| ${red}!!! ATTENTION !!!${white} |" - echo -e "| Existing Klipper folder found! Proceeding will remove | " - echo -e "| the existing Klipper folder and replace it with a | " - echo -e "| clean copy of the previously selected source repo! | " - bottom_border - while true; do - read -p "${cyan}###### Proceed? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - switch_klipper_repo "${url[${option}]}" "${branch[${option}]}" - set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" - break;; - N|n|No|no) - select_msg "No" - break;; - *) - error_msg "Invalid command!";; - esac - done - else - status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}" - set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" - ok_msg "This repo will now be used for new Klipper installations!\n" - fi - break - else - clear && print_header - print_error "Invalid command!" - change_klipper_repo_menu - fi + read -p "${cyan}Perform action:${white} " option + case "${option}" in + 0 | "$((option < ${#url[@]}))") + if [ -d "${KLIPPER_DIR}" ]; then + top_border + echo -e "| ${red}!!! ATTENTION !!!${white} |" + echo -e "| Existing Klipper folder found! Proceeding will remove | " + echo -e "| the existing Klipper folder and replace it with a | " + echo -e "| clean copy of the previously selected source repo! | " + bottom_border + while true; do + read -p "${cyan}###### Proceed? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + switch_klipper_repo "${url[${option}]}" "${branch[${option}]}" + set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" + break;; + N|n|No|no) + select_msg "No" + break;; + *) + error_msg "Invalid command!";; + esac + done + else + status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}" + set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" + ok_msg "This repo will now be used for new Klipper installations!\n" + fi + break;; + B|b) + clear && print_header + settings_menu + break;; + H|h) + clear && print_header + show_custom_klipper_repo_help + break;; + *) + error_msg "Invalid command!";; + esac done } @@ -95,9 +94,10 @@ function switch_klipper_repo(){ url=${1} branch=${2} status_msg "Switching Klipper repository..." do_action_service "stop" "klipper" - cd ~ && rm -rf "${KLIPPER_DIR}" - git clone "${url}" && cd "${KLIPPER_DIR}" - git checkout "${branch}" && cd ~ + cd "${HOME}" + [ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}" + git clone "${url}" "klipper" && cd "${KLIPPER_DIR}" + git checkout "${branch}" && cd "${HOME}" do_action_service "start" "klipper" } From e968ed1d6db104f402d131af011fa882909e3b7d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 19:03:51 +0200 Subject: [PATCH 105/183] fix: make klipper install account for custom klipper repo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 917eb0e..54dc677 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -134,16 +134,28 @@ function create_klipper_virtualenv(){ } function klipper_setup(){ + read_kiauh_ini + local custom_repo="${custom_klipper_repo}" + local custom_branch="${custom_klipper_repo_branch}" local instances=${1} python_version=${2} ### checking dependencies local dep=(git) dependency_check "${dep[@]}" ### step 1: clone klipper - status_msg "Downloading Klipper ..." ### force remove existing klipper dir and clone into fresh klipper dir [ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}" - cd "${HOME}" && git clone "${KLIPPER_REPO}" + if [ -z "${custom_repo}" ]; then + status_msg "Downloading Klipper ..." + cd "${HOME}" && git clone "${KLIPPER_REPO}" + else + local repo_name + repo_name=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" ) + status_msg "Downloading Klipper from ${repo_name} ..." + cd "${HOME}" && git clone "${custom_repo}" "klipper" + cd "${KLIPPER_DIR}" && git checkout "${custom_branch}" + cd "${HOME}" + fi ### step 2: install klipper dependencies and create python virtualenv install_klipper_packages "${python_version}" From 6463f5007d8626c53bf48fe0813348da6419024c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 19:44:02 +0200 Subject: [PATCH 106/183] refactor: rework moonraker telegram bot functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 2 +- scripts/moonraker-telegram-bot.sh | 82 +++++++++++++++---------------- scripts/ui/main_menu.sh | 3 +- scripts/ui/update_menu.sh | 4 +- 4 files changed, 45 insertions(+), 46 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index 85f23ea..b140a5b 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -60,7 +60,7 @@ function set_globals(){ #========== MOONRAKER-TELEGRAM-BOT ============# MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot - NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git + MOONRAKER_TELEGRAM_BOT_REPO=https://github.com/nlef/moonraker-telegram-bot.git #=============== PRETTY-GCODE =================# PGC_DIR="${HOME}/pgcode" diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 20d02e3..c949f80 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -12,24 +12,31 @@ set -e #===================================================# -#=========== REMOVE MOONRAKERTELEGRAMBOT ===========# +#========== INSTALL MOONRAKERTELEGRAMBOT ===========# #===================================================# +function telegram_bot_systemd() { + local services + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[^0])?[0-9]*.service") + echo "${services}" +} + function install_MoonrakerTelegramBot(){ MoonrakerTelegramBot_setup - restart_MoonrakerTelegramBot + do_action_service "restart" "moonraker-telegram-bot" } function MoonrakerTelegramBot_setup(){ - source_kiauh_ini + local klipper_cfg_loc + klipper_cfg_loc="$(get_klipper_cfg_dir)" export klipper_cfg_loc - dep=(virtualenv) - dependency_check + local dep=(virtualenv) + dependency_check "${dep[@]}" status_msg "Downloading MoonrakerTelegramBot ..." #force remove existing MoonrakerTelegramBot dir [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" #clone into fresh MoonrakerTelegramBot dir - cd "${HOME}" && git clone "${NLEF_REPO}" + cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}" ok_msg "Download complete!" status_msg "Installing MoonrakerTelegramBot ..." /bin/bash "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/install.sh" @@ -57,8 +64,8 @@ function remove_MoonrakerTelegramBot(){ ### remove MoonrakerTelegramBot service if [ -e "${SYSTEMD}/moonraker-telegram-bot.service" ]; then status_msg "Removing MoonrakerTelegramBot service ..." - sudo systemctl stop moonraker-telegram-bot - sudo systemctl disable moonraker-telegram-bot + do_action_service "stop" "moonraker-telegram-bot" + do_action_service "disable" "moonraker-telegram-bot" sudo rm -f "${SYSTEMD}/moonraker-telegram-bot.service" ###reloading units sudo systemctl daemon-reload @@ -73,61 +80,54 @@ function remove_MoonrakerTelegramBot(){ fi ### remove MoonrakerTelegramBot log symlink in config dir - if [ -e "${KLIPPER_CONFIG}/telegram.log" ]; then status_msg "Removing MoonrakerTelegramBot log symlink ..." rm -f "${KLIPPER_CONFIG}/telegram.log" && ok_msg "File removed!" fi - CONFIRM_MSG="MoonrakerTelegramBot successfully removed!" + print_confirm "MoonrakerTelegramBot successfully removed!" } #===================================================# #=========== UPDATE MOONRAKERTELEGRAMBOT ===========# #===================================================# -function update_MoonrakerTelegramBot(){ - export KLIPPER_CONFIG - stop_MoonrakerTelegramBot - cd "${MOONRAKER_TELEGRAM_BOT_DIR}" - git pull +function update_telegram_bot(){ + local klipper_cfg_loc + klipper_cfg_loc="$(get_klipper_cfg_dir)" + do_action_service "stop" "moonraker-telegram-bot" + cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git pull /bin/bash "./scripts/install.sh" + do_action_service "start" "moonraker-telegram-bot" ok_msg "Update complete!" - start_MoonrakerTelegramBot } #===================================================# #=========== MOONRAKERTELEGRAMBOT STATUS ===========# #===================================================# -function MoonrakerTelegramBot_status(){ - mtbcount=0 - MoonrakerTelegramBot_data=( - SERVICE - "${MOONRAKER_TELEGRAM_BOT_DIR}" - "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" - ) +function get_telegram_bot_status(){ + local sf_count status + sf_count="$(telegram_bot_systemd | wc -w)" - ### count amount of MoonrakerTelegramBot_data service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker-telegram-bot" | wc -l) + ### remove the "SERVICE" entry from the data array if a moonraker service is installed + local data_arr=(SERVICE "${MOONRAKER_TELEGRAM_BOT_DIR}" "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}") + [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" - ### remove the "SERVICE" entry from the MoonrakerTelegramBot_data array if a MoonrakerTelegramBot service is installed - [ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "MoonrakerTelegramBot_data[0]" - - #count+1 for each found data-item from array - for mtbd in "${MoonrakerTelegramBot_data[@]}" - do - if [ -e "${mtbd}" ]; then - mtbcount=$((mtbcount + 1)) - fi + ### count+1 for each found data-item from array + local filecount=0 + for data in "${data_arr[@]}"; do + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${mtbcount}" == "${#MoonrakerTelegramBot_data[*]}" ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${white} " - elif [ "${mtbcount}" == 0 ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${white} " + + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " else - MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${white} " + status="${yellow}Incomplete!${white} " fi + echo "${status}" } function get_local_telegram_bot_commit(){ @@ -146,7 +146,7 @@ function get_remote_telegram_bot_commit(){ echo "${commit}" } -function compare_prettygcode_versions(){ +function compare_telegram_bot_versions(){ unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_telegram_bot_commit)" @@ -155,7 +155,7 @@ function compare_prettygcode_versions(){ versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" # add moonraker-telegram-bot to the update all array for the update all function in the updater - MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_MoonrakerTelegramBot) + MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_telegram_bot) else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 6db8aa5..da06501 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -23,7 +23,7 @@ main_ui(){ echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" - echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" + echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" echo -e "| | |" echo -e "| $(get_kiauh_version)| Octoprint: $OCTOPRINT_STATUS|" quit_footer @@ -69,7 +69,6 @@ main_menu(){ mainsail_status octoprint_status klipperscreen_status - MoonrakerTelegramBot_status main_ui while true; do read -p "${cyan}Perform action:${white} " action; echo diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 48cc8b2..2b3f9e9 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -33,7 +33,7 @@ update_ui(){ echo -e "| | | | " echo -e "| Other: |---------------|--------------| " echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)| " - echo -e "| 7) [Telegram Bot] |$(compare_prettygcode_versions)| " + echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)| " echo -e "| |------------------------------| " echo -e "| 8) [System] | $DISPLAY_SYS_UPDATE | " back_footer @@ -60,7 +60,7 @@ update_menu(){ 6) do_action "update_pgc_for_klipper" "update_ui";; 7) - do_action "update_MoonrakerTelegramBot" "update_ui";; + do_action "update_telegram_bot" "update_ui";; 8) do_action "update_system" "update_ui";; a) From 3664cf0e2f1996b1411614ac79bac53454554bad Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 19:45:00 +0200 Subject: [PATCH 107/183] refactor: move python check to utilities.sh also remove several unused service start and restart functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipperscreen.sh | 40 +++++++++++++------------------------ scripts/moonraker.sh | 15 +------------- scripts/utilities.sh | 43 ++++++++++++---------------------------- 3 files changed, 28 insertions(+), 70 deletions(-) diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index 5f24b94..e7f6b0f 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -16,31 +16,19 @@ set -e #===================================================# function install_klipperscreen(){ - python3_check - if [ "${py_chk_ok}" = "true" ]; then - klipperscreen_setup - restart_klipperscreen - else - ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." - print_msg && clear_msg - fi -} - -function python3_check(){ - status_msg "Your Python 3 version is: $(python3 --version)" - major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) - minor=$(python3 --version | cut -d"." -f2) - if [ "${major}" -ge 3 ] && [ "${minor}" -ge 7 ]; then - ok_msg "Python version ok!" - py_chk_ok="true" - else - py_chk_ok="false" + ### return early if python version check fails + if [ "$(python3_check)" == "false" ]; then + local error="Versioncheck failed! Python 3.7 or newer required!\n" + error="${error} Please upgrade Python." + print_error "${error}" && return fi + klipperscreen_setup + do_action_service "restart" "KlipperScreen" } function klipperscreen_setup(){ - dep=(wget curl unzip dfu-util) - dependency_check + local dep=(wget curl unzip dfu-util) + dependency_check "${dep[@]}" status_msg "Downloading KlipperScreen ..." # force remove existing KlipperScreen dir [ -d "${KLIPPERSCREEN_DIR}" ] && rm -rf "${KLIPPERSCREEN_DIR}" @@ -74,8 +62,8 @@ function remove_klipperscreen(){ ### remove KlipperScreen service if [ -e "${SYSTEMD}/KlipperScreen.service" ]; then status_msg "Removing KlipperScreen service ..." - sudo systemctl stop KlipperScreen - sudo systemctl disable KlipperScreen + do_action_service "stop" "KlipperScreen" + do_action_service "disable" "KlipperScreen" sudo rm -f "${SYSTEMD}/KlipperScreen.service" ###reloading units sudo systemctl daemon-reload @@ -96,7 +84,7 @@ function remove_klipperscreen(){ rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!" fi - CONFIRM_MSG="KlipperScreen successfully removed!" + print_confirm "KlipperScreen successfully removed!" } #===================================================# @@ -104,7 +92,7 @@ function remove_klipperscreen(){ #===================================================# function update_klipperscreen(){ - stop_klipperscreen + do_action_service "stop" "KlipperScreen" cd "${KLIPPERSCREEN_DIR}" KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) git pull origin master -q && ok_msg "Fetch successfull!" @@ -117,7 +105,7 @@ function update_klipperscreen(){ ok_msg "Dependencies have been installed!" fi ok_msg "Update complete!" - start_klipperscreen + do_action_service "start" "KlipperScreen" } #===================================================# diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 27c6362..a315965 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -15,19 +15,6 @@ set -e #================ INSTALL MOONRAKER ================# #===================================================# -function system_check_moonraker(){ - local major minor - ### python 3 check - status_msg "Your Python 3 version is: $(python3 --version)" - major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) - minor=$(python3 --version | cut -d"." -f2) - if [ "${major}" -ge 3 ] && [ "${minor}" -ge 7 ]; then - echo "true" - else - echo "false" - fi -} - function moonraker_systemd() { local services services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service") @@ -47,7 +34,7 @@ function moonraker_setup_dialog(){ fi ### return early if python version check fails - if [ "$(system_check_moonraker)" == "false" ]; then + if [ "$(python3_check)" == "false" ]; then local error="Versioncheck failed! Python 3.7 or newer required!\n" error="${error} Please upgrade Python." print_error "${error}" && return diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 32e8aa6..96214ab 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -348,36 +348,6 @@ function do_action_service(){ fi } -function start_klipperscreen(){ - status_msg "Starting KlipperScreen Service ..." - sudo systemctl start KlipperScreen && ok_msg "KlipperScreen Service started!" -} - -function stop_klipperscreen(){ - status_msg "Stopping KlipperScreen Service ..." - sudo systemctl stop KlipperScreen && ok_msg "KlipperScreen Service stopped!" -} - -function restart_klipperscreen(){ - status_msg "Restarting KlipperScreen Service ..." - sudo systemctl restart KlipperScreen && ok_msg "KlipperScreen Service restarted!" -} - -function start_MoonrakerTelegramBot(){ - status_msg "Starting MoonrakerTelegramBot Service ..." - sudo systemctl start moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service started!" -} - -function stop_MoonrakerTelegramBot(){ - status_msg "Stopping MoonrakerTelegramBot Service ..." - sudo systemctl stop moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service stopped!" -} - -function restart_MoonrakerTelegramBot(){ - status_msg "Restarting MoonrakerTelegramBot Service ..." - sudo systemctl restart moonraker-telegram-bot && ok_msg "MoonrakerTelegramBot Service restarted!" -} - function restart_nginx(){ if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then status_msg "Restarting NGINX Service ..." @@ -389,6 +359,19 @@ function restart_nginx(){ #================ DEPENDENCIES ==================# #================================================# +function python3_check(){ + local major minor + ### python 3 check + status_msg "Your Python 3 version is: $(python3 --version)" + major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) + minor=$(python3 --version | cut -d"." -f2) + if [ "${major}" -ge 3 ] && [ "${minor}" -ge 7 ]; then + echo "true" + else + echo "false" + fi +} + function dependency_check(){ local dep=( "${@}" ) # dep: array status_msg "Checking for the following dependencies:" From 26c812e1d3bb7be35d4fbf5c1c44a333150c8bde Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 19:50:05 +0200 Subject: [PATCH 108/183] refactor: rework some klipperscreen functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipperscreen.sh | 53 ++++++++++++++++++++-------------------- scripts/ui/main_menu.sh | 3 +-- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index e7f6b0f..f1ca32d 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -15,6 +15,12 @@ set -e #============== INSTALL KLIPPERSCREEN ==============# #===================================================# +function klipperscreen_systemd() { + local services + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/KlipperScreen.service") + echo "${services}" +} + function install_klipperscreen(){ ### return early if python version check fails if [ "$(python3_check)" == "false" ]; then @@ -45,8 +51,6 @@ function klipperscreen_setup(){ #===================================================# function remove_klipperscreen(){ - source_kiauh_ini - ### remove KlipperScreen dir if [ -d "${KLIPPERSCREEN_DIR}" ]; then status_msg "Removing KlipperScreen directory ..." @@ -92,13 +96,14 @@ function remove_klipperscreen(){ #===================================================# function update_klipperscreen(){ + local old_md5 + old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) + do_action_service "stop" "KlipperScreen" cd "${KLIPPERSCREEN_DIR}" - KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) git pull origin master -q && ok_msg "Fetch successfull!" git checkout -f master && ok_msg "Checkout successfull" - #KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt) - if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${KLIPPERSCREEN_OLDREQ_MD5SUM}" ]]; then + if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then status_msg "New dependecies detected..." PYTHONDIR="${HOME}/.KlipperScreen-env" "${PYTHONDIR}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" @@ -113,33 +118,27 @@ function update_klipperscreen(){ #===================================================# function klipperscreen_status(){ - klsccount=0 - klipperscreen_data=( - SERVICE - "${KLIPPERSCREEN_DIR}" - "${KLIPPERSCREEN_ENV_DIR}" - ) + local sf_count status + sf_count="$(klipperscreen_systemd | wc -w)" - ### count amount of klipperscreen_data service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l) + ### remove the "SERVICE" entry from the data array if a moonraker service is installed + local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV_DIR}") + [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" - ### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed - [ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "klipperscreen_data[0]" - - #count+1 for each found data-item from array - for klscd in "${klipperscreen_data[@]}" - do - if [ -e "${klscd}" ]; then - klsccount=$((klsccount + 1)) - fi + ### count+1 for each found data-item from array + local filecount=0 + for data in "${data_arr[@]}"; do + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${klsccount}" == "${#klipperscreen_data[*]}" ]; then - KLIPPERSCREEN_STATUS="${green}Installed!${white} " - elif [ "${klsccount}" == 0 ]; then - KLIPPERSCREEN_STATUS="${red}Not installed!${white} " + + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " else - KLIPPERSCREEN_STATUS="${yellow}Incomplete!${white} " + status="${yellow}Incomplete!${white} " fi + echo "${status}" } function get_local_klipperscreen_commit(){ diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index da06501..ff95122 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -22,7 +22,7 @@ main_ui(){ echo -e "| 3) [Remove] | |" echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" - echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" + echo -e "| | KlipperScreen: $(klipperscreen_status)|" echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" echo -e "| | |" echo -e "| $(get_kiauh_version)| Octoprint: $OCTOPRINT_STATUS|" @@ -68,7 +68,6 @@ main_menu(){ fluidd_status mainsail_status octoprint_status - klipperscreen_status main_ui while true; do read -p "${cyan}Perform action:${white} " action; echo From 4487b9593c55a693a6b6601dcc79e343256ca20a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 19:55:46 +0200 Subject: [PATCH 109/183] refactor: mainsail status Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 33 ++++++++++++++++----------------- scripts/ui/main_menu.sh | 3 +-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 8dd2130..2cfb5c3 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -216,26 +216,25 @@ function get_mainsail_ver(){ } function mainsail_status(){ - mcount=0 - mainsail_data=( - "${MAINSAIL_DIR}" - "${NGINX_SA}/mainsail" - "${NGINX_SE}/mainsail" - ) - #count+1 for each found data-item from array - for md in "${mainsail_data[@]}" - do - if [ -e "${md}" ]; then - mcount=$((mcount + 1)) - fi + local status + + ### remove the "SERVICE" entry from the data array if a moonraker service is installed + local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail") + + ### count+1 for each found data-item from array + local filecount=0 + for data in "${data_arr[@]}"; do + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${mcount}" == "${#mainsail_data[*]}" ]; then - MAINSAIL_STATUS="${green}Installed!${white} " - elif [ "${mcount}" == 0 ]; then - MAINSAIL_STATUS="${red}Not installed!${white} " + + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="${green}Installed!${white} " + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " else - MAINSAIL_STATUS="${yellow}Incomplete!${white} " + status="${yellow}Incomplete!${white} " fi + echo "${status}" } function get_local_mainsail_version(){ diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index ff95122..83da7d6 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -20,7 +20,7 @@ main_ui(){ echo -e "| 1) [Install] | |" echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" echo -e "| 3) [Remove] | |" - echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| 4) [Advanced] | Mainsail: $(mainsail_status)|" echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" echo -e "| | KlipperScreen: $(klipperscreen_status)|" echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" @@ -66,7 +66,6 @@ main_menu(){ kiauh_update_dialog #check install status fluidd_status - mainsail_status octoprint_status main_ui while true; do From bc2ce383ee34673ea0781a90f2252031b832db68 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 19:57:03 +0200 Subject: [PATCH 110/183] refactor: fluidd status Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 33 ++++++++++++++++----------------- scripts/ui/main_menu.sh | 3 +-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 8573641..1fbf2c2 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -149,26 +149,25 @@ function get_fluidd_ver(){ } function fluidd_status(){ - fcount=0 - fluidd_data=( - $FLUIDD_DIR - $NGINX_SA/fluidd - $NGINX_SE/fluidd - ) - #count+1 for each found data-item from array - for fd in "${fluidd_data[@]}" - do - if [ -e $fd ]; then - fcount=$(expr $fcount + 1) - fi + local status + + ### remove the "SERVICE" entry from the data array if a moonraker service is installed + local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd") + + ### count+1 for each found data-item from array + local filecount=0 + for data in "${data_arr[@]}"; do + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "$fcount" == "${#fluidd_data[*]}" ]; then - FLUIDD_STATUS="${green}Installed!${white} " - elif [ "$fcount" == 0 ]; then - FLUIDD_STATUS="${red}Not installed!${white} " + + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="${green}Installed!${white} " + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " else - FLUIDD_STATUS="${yellow}Incomplete!${white} " + status="${yellow}Incomplete!${white} " fi + echo "${status}" } function get_local_fluidd_version(){ diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 83da7d6..6e65349 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -21,7 +21,7 @@ main_ui(){ echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" echo -e "| 3) [Remove] | |" echo -e "| 4) [Advanced] | Mainsail: $(mainsail_status)|" - echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" + echo -e "| 5) [Backup] | Fluidd: $(fluidd_status)|" echo -e "| | KlipperScreen: $(klipperscreen_status)|" echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" echo -e "| | |" @@ -65,7 +65,6 @@ main_menu(){ #prompt for KIAUH update if update available kiauh_update_dialog #check install status - fluidd_status octoprint_status main_ui while true; do From 539653d9cf954f2d33992891063b19bbd5e0e3b7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 20:03:34 +0200 Subject: [PATCH 111/183] refactor: octoprint status also remove unused functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 103 ++++++++++++++-------------------------- scripts/ui/main_menu.sh | 4 +- 2 files changed, 36 insertions(+), 71 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 01552f7..bcb1838 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -15,6 +15,12 @@ set -e #=============== INSTALL OCTOPRINT ===============# #=================================================# +function octoprint_systemd() { + local services + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[^0])?[0-9]*.service") + echo "${services}" +} + function octoprint_setup_dialog(){ status_msg "Initializing OctoPrint installation ..." @@ -254,20 +260,19 @@ function print_op_ip_list(){ function remove_octoprint(){ ###remove all octoprint services - if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then - status_msg "Removing OctoPrint Services ..." - for service in $(ls /etc/systemd/system/octoprint*.service | cut -d"/" -f5) - do - status_msg "Removing ${service} ..." - sudo systemctl stop "${service}" - sudo systemctl disable "${service}" - sudo rm -f "${SYSTEMD}/${service}" - ok_msg "OctoPrint Service removed!" - done - ### reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - fi + [ -z "$(octoprint_systemd)" ] && return + status_msg "Removing Moonraker Systemd Services ..." + for service in $(octoprint_systemd | cut -d"/" -f5) + do + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" + ok_msg "Done!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed ### remove sudoers file if [ -f /etc/sudoers.d/octoprint-shutdown ]; then @@ -299,63 +304,25 @@ function remove_octoprint(){ #=================================================# function octoprint_status(){ - ocount=0 - octoprint_data=( - SERVICE - "${OCTOPRINT_DIR}" - ) - ### count amount of octoprint service files in /etc/systemd/system - SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^octoprint(\-[[:digit:]]+)?\.service$" | wc -l) + local sf_count status + sf_count="$(octoprint_systemd | wc -w)" - ### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed - [ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "octoprint_data[0]" + ### remove the "SERVICE" entry from the data array if a moonraker service is installed + local data_arr=(SERVICE "${OCTOPRINT_DIR}") + [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" - #count+1 for each found data-item from array - for op in "${octoprint_data[@]}" - do - if [ -e "${op}" ]; then - ocount=$((ocount+1)) - fi + ### count+1 for each found data-item from array + local filecount=0 + for data in "${data_arr[@]}"; do + [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - ### display status - if [ "${ocount}" == "${#octoprint_data[*]}" ]; then - OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" "${SERVICE_FILE_COUNT}")" - elif [ "${ocount}" == 0 ]; then - OCTOPRINT_STATUS="${red}Not installed!${white} " + if [ "${filecount}" == "${#data_arr[*]}" ]; then + status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" + elif [ "${filecount}" == 0 ]; then + status="${red}Not installed!${white} " else - OCTOPRINT_STATUS="${yellow}Incomplete!${white} " + status="${yellow}Incomplete!${white} " fi -} - -function read_octoprint_service_status(){ - unset OPRINT_SERVICE_STATUS - if [ ! -f "/etc/systemd/system/octoprint.service" ]; then - return 0 - fi - if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then - OPRINT_SERVICE_STATUS="${red}[Disable]${white} OctoPrint Service " - else - OPRINT_SERVICE_STATUS="${green}[Enable]${white} OctoPrint Service " - fi -} - -#================================================# -#=================== HELPERS ====================# -#================================================# - -function toggle_octoprint_service(){ - if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then - do_action_service "stop" "octoprint" - do_action_service "disable" "octoprint" - sleep 2 - CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !" - elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then - do_action_service "enable" "octoprint" - do_action_service "start" "octoprint" - sleep 2 - CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !" - else - ERROR_MSG=" You cannot activate a service that does not exist!" - fi -} + echo "${status}" +} \ No newline at end of file diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 6e65349..273a909 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -25,7 +25,7 @@ main_ui(){ echo -e "| | KlipperScreen: $(klipperscreen_status)|" echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" echo -e "| | |" - echo -e "| $(get_kiauh_version)| Octoprint: $OCTOPRINT_STATUS|" + echo -e "| $(get_kiauh_version)| Octoprint: $(octoprint_status)|" quit_footer } @@ -64,8 +64,6 @@ main_menu(){ print_header #prompt for KIAUH update if update available kiauh_update_dialog - #check install status - octoprint_status main_ui while true; do read -p "${cyan}Perform action:${white} " action; echo From c7ad0613322f7816dfefbed842677b6cf6cb1d2a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 20:11:09 +0200 Subject: [PATCH 112/183] refactor(octoprint.sh): use utility function for checking tty and dialout usergroup Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index bcb1838..dac5b2a 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -80,8 +80,8 @@ function octoprint_setup(){ ) dependency_check "${dep[@]}" - ### add user to usergroups and add reboot permissions - add_to_groups + ### check for tty and dialout usergroups and add reboot permissions + check_usergroups add_reboot_permission ### install octoprint @@ -120,17 +120,6 @@ function install_octoprint(){ deactivate } -add_to_groups(){ - if [ ! "$(groups | grep tty)" ]; then - status_msg "Adding user '${USER}' to group 'tty' ..." - sudo usermod -a -G tty "${USER}" && ok_msg "Done!" - fi - if [ ! "$(groups | grep dialout)" ]; then - status_msg "Adding user '${USER}' to group 'dialout' ..." - sudo usermod -a -G dialout "${USER}" && ok_msg "Done!" - fi -} - function create_config_yaml(){ local base_dir=${1} tmp_printer=${2} restart_cmd=${3} From 21a7d59ff5a25fc831e402f512a2f90dfbbc00eb Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 20:21:24 +0200 Subject: [PATCH 113/183] fix(octoprint.sh): typos Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index dac5b2a..4f8a427 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -121,7 +121,7 @@ function install_octoprint(){ } function create_config_yaml(){ - local base_dir=${1} tmp_printer=${2} restart_cmd=${3} + local basedir=${1} tmp_printer=${2} restart_cmd=${3} /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML serial: @@ -139,7 +139,7 @@ CONFIGYAML function create_single_octoprint_instance(){ local port=5000 - local base_dir="${HOME}/.octoprint" + local basedir="${HOME}/.octoprint" local tmp_printer="/tmp/printer" local config_yaml="${basedir}/config.yaml" local restart_cmd="sudo service octoprint restart" @@ -175,7 +175,7 @@ function create_multi_octoprint_instance(){ local i=1 port=5000 instance=${1} while [ "${i}" -le "${instances}" ]; do ### multi instance variables - local base_dir="${HOME}/.octoprint-${i}" + local basedir="${HOME}/.octoprint-${i}" local tmp_printer="/tmp/printer-${i}" local config_yaml="${basedir}/config.yaml" local restart_cmd="sudo service octoprint-${i} restart" @@ -203,7 +203,7 @@ OCTOPRINT if [ ! -f "${basedir}/config.yaml" ]; then status_msg "Creating config.yaml for instance #${i}..." [ ! -d "${basedir}" ] && mkdir "${basedir}" - create_config_yaml + create_config_yaml "${basedir}" "${tmp_printer}" "${restart_cmd}" ok_msg "Config #${i} created!" fi From 856fa8dfa50a5cfecbf95138edf94d58250f70f5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Apr 2022 23:28:35 +0200 Subject: [PATCH 114/183] fix(octoprint.sh): typo in argument Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 4f8a427..6bed598 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -172,7 +172,7 @@ OCTOPRINT } function create_multi_octoprint_instance(){ - local i=1 port=5000 instance=${1} + local i=1 port=5000 instances=${1} while [ "${i}" -le "${instances}" ]; do ### multi instance variables local basedir="${HOME}/.octoprint-${i}" From 28782e910e70f6fd6e557d2be2b75acbd20d01d2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 18 Apr 2022 01:29:08 +0200 Subject: [PATCH 115/183] refactor(octoprint.sh): octoprint instance setup one dedicated env for each instance. allows independent installation of plugins. previously, all instances shared the same env and therefore all plugins. Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 3 - scripts/octoprint.sh | 254 ++++++++++++++++++++----------------------- 2 files changed, 116 insertions(+), 141 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index b140a5b..5238b06 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -54,9 +54,6 @@ function set_globals(){ KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git - #================ OCTOPRINT ===================# - OCTOPRINT_ENV="${HOME}/OctoPrint" - #========== MOONRAKER-TELEGRAM-BOT ============# MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 6bed598..81489aa 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -22,10 +22,10 @@ function octoprint_systemd() { } function octoprint_setup_dialog(){ - status_msg "Initializing OctoPrint installation ..." - local klipper_count klipper_count=$(klipper_systemd | wc -w) + + status_msg "Initializing OctoPrint installation ..." top_border if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then printf "|${green}%-55s${white}|\n" " 1 Klipper instance was found!" @@ -71,12 +71,12 @@ function octoprint_setup(){ dep=( git wget - python-pip - python-dev + python3-pip + python3-dev libyaml-dev build-essential - python-setuptools - python-virtualenv + python3-setuptools + python3-virtualenv ) dependency_check "${dep[@]}" @@ -85,14 +85,10 @@ function octoprint_setup(){ add_reboot_permission ### install octoprint - install_octoprint + install_octoprint "${instances}" - ### set up instances - if [ "${instances}" -eq 1 ]; then - create_single_octoprint_instance - else - create_multi_octoprint_instance "${instances}" - fi + ### set up service + create_octoprint_service "${instances}" ### step 6: enable and start all instances do_action_service "enable" "octoprint" @@ -106,24 +102,72 @@ function octoprint_setup(){ } function install_octoprint(){ - ### create and activate the virtualenv - [ ! -d "${OCTOPRINT_ENV}" ] && mkdir -p "${OCTOPRINT_ENV}" - status_msg "Installing python virtual environment..." - cd "${OCTOPRINT_ENV}" && virtualenv --python=python3 venv - ### activate virtualenv - source venv/bin/activate - status_msg "Installing OctoPrint ..." - pip install pip --upgrade - pip install --no-cache-dir octoprint - ok_msg "Download complete!" - ### leave virtualenv - deactivate + local i=1 instances=${1} octo_env + while (( i <= instances )); do + (( instances == 1 )) && octo_env="${HOME}/OctoPrint" + (( instances > 1 )) && octo_env="${HOME}/OctoPrint_${i}" + ### create and activate the virtualenv + status_msg "Installing python virtual environment..." + [ ! -d "${octo_env}" ] && mkdir -p "${octo_env}" + cd "${octo_env}" && virtualenv --python=python3 venv + ### activate virtualenv + source venv/bin/activate + (( instances == 1 )) && status_msg "Installing OctoPrint ..." + (( instances > 1 )) && status_msg "Installing OctoPrint instance ${i} ..." + pip install pip --upgrade + pip install --no-cache-dir octoprint + ok_msg "Ok!" + ### leave virtualenv + deactivate + i=$((i+1)) + done } -function create_config_yaml(){ - local basedir=${1} tmp_printer=${2} restart_cmd=${3} +function create_octoprint_service(){ + local i=1 instances=${1} port=5000 + local octo_env service basedir tmp_printer config_yaml restart_cmd - /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML + while (( i <= instances )); do + if (( instances == 1 )); then + octo_env="${HOME}/OctoPrint" + service="${SYSTEMD}/octoprint.service" + basedir="${HOME}/.octoprint" + tmp_printer="/tmp/printer" + config_yaml="${basedir}/config.yaml" + restart_cmd="sudo service octoprint restart" + elif (( instances > 1 )); then + octo_env="${HOME}/OctoPrint_${i}" + service="${SYSTEMD}/octoprint-${i}.service" + basedir="${HOME}/.octoprint_${i}" + tmp_printer="/tmp/printer-${i}" + config_yaml="${basedir}/config.yaml" + restart_cmd="sudo service octoprint-${i} restart" + fi + (( instances == 1 )) && status_msg "Creating OctoPrint service ..." + (( instances > 1 )) && status_msg "Creating OctoPrint service ${i} ..." + sudo /bin/sh -c "cat > ${service}" << OCTOPRINT +[Unit] +Description=Starts OctoPrint on startup +After=network-online.target +Wants=network-online.target + +[Service] +Environment="LC_ALL=C.UTF-8" +Environment="LANG=C.UTF-8" +Type=simple +User=${USER} +ExecStart=${octo_env}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve + +[Install] +WantedBy=multi-user.target +OCTOPRINT + ok_msg "Ok!" + + ### create config.yaml + if [ ! -f "${basedir}/config.yaml" ]; then + [ ! -d "${basedir}" ] && mkdir "${basedir}" + status_msg "Creating config.yaml ..." + /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML serial: additionalPorts: - ${tmp_printer} @@ -135,88 +179,11 @@ server: systemRestartCommand: sudo shutdown -r now systemShutdownCommand: sudo shutdown -h now CONFIGYAML -} - -function create_single_octoprint_instance(){ - local port=5000 - local basedir="${HOME}/.octoprint" - local tmp_printer="/tmp/printer" - local config_yaml="${basedir}/config.yaml" - local restart_cmd="sudo service octoprint restart" - - status_msg "Creating OctoPrint instance ..." - sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint.service" << OCTOPRINT -[Unit] -Description=Starts OctoPrint on startup -After=network-online.target -Wants=network-online.target - -[Service] -Environment="LC_ALL=C.UTF-8" -Environment="LANG=C.UTF-8" -Type=simple -User=${USER} -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve - -[Install] -WantedBy=multi-user.target -OCTOPRINT - - ### create the config.yaml - if [ ! -f "${basedir}/config.yaml" ]; then - status_msg "Creating config.yaml ..." - [ ! -d "${basedir}" ] && mkdir "${basedir}" - create_config_yaml "${basedir}" "${tmp_printer}" "${restart_cmd}" - ok_msg "Config created!" + ok_msg "Ok!" fi -} -function create_multi_octoprint_instance(){ - local i=1 port=5000 instances=${1} - while [ "${i}" -le "${instances}" ]; do - ### multi instance variables - local basedir="${HOME}/.octoprint-${i}" - local tmp_printer="/tmp/printer-${i}" - local config_yaml="${basedir}/config.yaml" - local restart_cmd="sudo service octoprint-${i} restart" - - ### create instance - status_msg "Creating instance #${i} ..." - sudo /bin/sh -c "cat > ${SYSTEMD}/octoprint-${i}.service" << OCTOPRINT -[Unit] -Description=Starts OctoPrint instance ${instances} on startup -After=network-online.target -Wants=network-online.target - -[Service] -Environment="LC_ALL=C.UTF-8" -Environment="LANG=C.UTF-8" -Type=simple -User=${USER} -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${basedir} --config ${config_yaml} --port=${port} serve - -[Install] -WantedBy=multi-user.target -OCTOPRINT - - ### create the config.yaml - if [ ! -f "${basedir}/config.yaml" ]; then - status_msg "Creating config.yaml for instance #${i}..." - [ ! -d "${basedir}" ] && mkdir "${basedir}" - create_config_yaml "${basedir}" "${tmp_printer}" "${restart_cmd}" - ok_msg "Config #${i} created!" - fi - - ### enable instance - sudo systemctl enable "octoprint-${i}.service" - ok_msg "OctoPrint instance ${i} created!" - - ### launching instance - status_msg "Launching OctoPrint instance ${i} ..." - sudo systemctl start "octoprint-${i}" - - i=$((i+1)) - port=$((port+1)) + port=$((port+1)) + i=$((i+1)) done } @@ -247,10 +214,10 @@ function print_op_ip_list(){ #=============== REMOVE OCTOPRINT ================# #=================================================# -function remove_octoprint(){ +function remove_octoprint_service(){ ###remove all octoprint services [ -z "$(octoprint_systemd)" ] && return - status_msg "Removing Moonraker Systemd Services ..." + status_msg "Removing OctoPrint Systemd Services ..." for service in $(octoprint_systemd | cut -d"/" -f5) do status_msg "Removing ${service} ..." @@ -262,30 +229,49 @@ function remove_octoprint(){ ### reloading units sudo systemctl daemon-reload sudo systemctl reset-failed +} +function remove_octoprint_sudoers(){ + [ ! -f /etc/sudoers.d/octoprint-shutdown ] && return ### remove sudoers file - if [ -f /etc/sudoers.d/octoprint-shutdown ]; then - sudo rm -rf /etc/sudoers.d/octoprint-shutdown - fi + sudo rm -f /etc/sudoers.d/octoprint-shutdown +} - ### remove OctoPrint directory - if [ -d "${HOME}/OctoPrint" ]; then - status_msg "Removing OctoPrint directory ..." - rm -rf "${HOME}/OctoPrint" && ok_msg "Directory removed!" - fi - - ###remove .octoprint directories - if ls -d "${HOME}"/.octoprint* 2>/dev/null 1>&2; then - for folder in $(ls -d ${HOME}/.octoprint*) - do - status_msg "Removing ${folder} ..." && rm -rf "${folder}" && ok_msg "Done!" +function remove_octoprint_env(){ + local files + files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -rf "${file}" + ok_msg "${file} removed!" done fi +} + +function remove_octoprint_dir(){ + local files + files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -rf "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_octoprint(){ + remove_octoprint_service + remove_octoprint_sudoers + remove_octoprint_env + remove_octoprint_dir ### remove octoprint_port from ~/.kiauh.ini sed -i "/^octoprint_port=/d" "${INI_FILE}" - print_confirm "OctoPrint successfully removed!" + local confirm="OctoPrint was successfully removed!" + print_confirm "${confirm}" && return } #=================================================# @@ -293,22 +279,14 @@ function remove_octoprint(){ #=================================================# function octoprint_status(){ - local sf_count status + local sf_count env_count dir_count status sf_count="$(octoprint_systemd | wc -w)" + env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*" | wc -w) + dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*" | wc -w) - ### remove the "SERVICE" entry from the data array if a moonraker service is installed - local data_arr=(SERVICE "${OCTOPRINT_DIR}") - [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" - - ### count+1 for each found data-item from array - local filecount=0 - for data in "${data_arr[@]}"; do - [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) - done - - if [ "${filecount}" == "${#data_arr[*]}" ]; then + if (( sf_count == env_count)) && (( sf_count == dir_count)); then status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" - elif [ "${filecount}" == 0 ]; then + elif (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then status="${red}Not installed!${white} " else status="${yellow}Incomplete!${white} " From 9722a1fcfe50c0fdd59338ad4e7424ba1c8e9892 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 18 Apr 2022 09:51:07 +0200 Subject: [PATCH 116/183] style(globals.sh): add quotes Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index 5238b06..43665aa 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -52,12 +52,12 @@ function set_globals(){ #=============== KLIPPERSCREEN ================# KLIPPERSCREEN_ENV_DIR="${HOME}/.KlipperScreen-env" KLIPPERSCREEN_DIR="${HOME}/KlipperScreen" - KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git + KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git" #========== MOONRAKER-TELEGRAM-BOT ============# - MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env - MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot - MOONRAKER_TELEGRAM_BOT_REPO=https://github.com/nlef/moonraker-telegram-bot.git + MOONRAKER_TELEGRAM_BOT_ENV_DIR="${HOME}/moonraker-telegram-bot-env" + MOONRAKER_TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot" + MOONRAKER_TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git" #=============== PRETTY-GCODE =================# PGC_DIR="${HOME}/pgcode" From 2406df702b1eafbf640433a6924728f9eb6f7de5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 18 Apr 2022 10:32:33 +0200 Subject: [PATCH 117/183] changelog: update changelog correct date needs to be added once released Signed-off-by: Dominik Willner th33xitus@gmail.com --- docs/changelog.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index e0f63bd..326baaa 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,21 @@ This document covers possible important changes to KIAUH. +### 2022-04-XX +KIAUH is now at Version 4!\ +The majority of things that have been rewritten are mainly for internal reasons and not affecting the user at all. +* feat: Klipper can be installed under Python3 (consideres experimental) +* feat: Klipper can be installed from custom repositories +* feat: Option to only allow installation of stable builds of Mainsail and Fluidd +* feat: Multi-Instance OctoPrint installations now each have their own Virtualenv, allowing independent installation of Plugins +* feat: Implementing the use of shellcheck during development +* feat: Implementing a simple logging mechanic +* fix: During Klipper installation checks for group membership of `tty` and `dialout` are made +* refactor: Support for DWC and DWC-for-Klipper has been removed +* refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature) +* refactor: Rewriting a lot of functions to pass shellcheck checks + + ### 2022-01-29 * Starting from the 28th of January, Moonraker can make use of PackageKit and PolicyKit.\ More details on that can be found [here]( From e6df33c5180e2d36891fe9c04dd5b0db7fa8c2dc Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 18 Apr 2022 10:53:11 +0200 Subject: [PATCH 118/183] refactor: multiple Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 2 +- scripts/moonraker.sh | 52 ++++++++++ scripts/network_functions.sh | 177 ----------------------------------- scripts/nginx.sh | 74 ++++++++++++++- scripts/rollback.sh | 8 +- scripts/status.sh | 29 ------ scripts/ui/advanced_menu.sh | 6 +- scripts/ui/backup_menu.sh | 6 +- scripts/ui/general_ui.sh | 25 ++--- scripts/ui/main_menu.sh | 8 +- scripts/ui/remove_menu.sh | 4 +- scripts/ui/settings_menu.sh | 4 +- scripts/ui/update_menu.sh | 6 +- scripts/update.sh | 54 ----------- scripts/utilities.sh | 114 +++++++++++++++++++++- 15 files changed, 270 insertions(+), 299 deletions(-) delete mode 100755 scripts/network_functions.sh delete mode 100755 scripts/status.sh delete mode 100755 scripts/update.sh diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 1fbf2c2..4221a1a 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -132,7 +132,7 @@ function remove_fluidd(){ #================== UPDATE FLUIDD ==================# #===================================================# -update_fluidd(){ +function update_fluidd(){ bb4u "fluidd" status_msg "Updating Fluidd ..." fluidd_setup diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index a315965..abbb177 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -471,3 +471,55 @@ function compare_moonraker_versions(){ fi echo "${versions}" } + +#==================================================# +#==================== HELPERS =====================# +#==================================================# + +function update_log_paths(){ + ### update services to make use of moonrakers new log_path option + ### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a + shopt -s extglob # enable extended globbing + source_kiauh_ini + LPATH="${HOME}/klipper_logs" + [ ! -d "$LPATH" ] && mkdir -p "$LPATH" + FILE="$SYSTEMDDIR/$1?(-*([0-9])).service" + for file in $(ls $FILE); do + [ "$1" == "klipper" ] && LOG="klippy" + [ "$1" == "moonraker" ] && LOG="moonraker" + if [ ! "$(grep "\-l" $file)" ]; then + status_msg "Updating $file ..." + sudo sed -i -r "/ExecStart=/ s|$| -l $LPATH/$LOG.log|" $file + ok_msg "$file updated!" + elif [ "$(grep "\-l \/tmp\/$LOG" $file)" ]; then + status_msg "Updating $file ..." + sudo sed -i -r "/ExecStart=/ s|-l \/tmp\/$LOG|-l $LPATH/$LOG|" $file + ok_msg "$file updated!" + fi + done + sudo systemctl daemon-reload + + # patch log_path entry if not found + dir1="$klipper_cfg_loc" + dir2="$klipper_cfg_loc/printer_*" + for conf in $(find $dir1 $dir2 -name "moonraker.conf" 2> /dev/null); do + if ! grep -q "log_path" $conf; then + status_msg "Patching $conf" + sed -i "/^config_path/a log_path: $LPATH" $conf + ok_msg "OK!" + fi + done + + # create symlink for mainsail and fluidd nginx logs + symlink_webui_nginx_log "mainsail" + symlink_webui_nginx_log "fluidd" + + # create symlink for webcamd log + if [ -f "/var/log/webcamd.log" ] && [ ! -L "$LPATH/webcamd.log" ]; then + status_msg "Creating symlink for '/var/log/webcamd.log' ..." + ln -s "/var/log/webcamd.log" "$LPATH" + ok_msg "OK!" + fi + + shopt -u extglob # disable extended globbing +} \ No newline at end of file diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh deleted file mode 100755 index 8511673..0000000 --- a/scripts/network_functions.sh +++ /dev/null @@ -1,177 +0,0 @@ -#!/bin/bash - -#=======================================================================# -# Copyright (C) 2020 - 2022 Dominik Willner # -# # -# This file is part of KIAUH - Klipper Installation And Update Helper # -# https://github.com/th33xitus/kiauh # -# # -# This file may be distributed under the terms of the GNU GPLv3 license # -#=======================================================================# - -set -e - -function set_nginx_cfg(){ - if [ "${SET_NGINX_CFG}" = "true" ]; then - local cfg="${SRCDIR}/kiauh/resources/${1}" - #check for dependencies - dep=(nginx) - dependency_check "${dep[@]}" - #execute operations - status_msg "Creating Nginx configuration for ${1} ..." - #copy content from resources to the respective nginx config file - cat "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" > "${cfg}" - ##edit the nginx config file before moving it - sed -i "s/<>/${1}/g" "${cfg}" - if [ "${SET_LISTEN_PORT}" != "${DEFAULT_PORT}" ]; then - status_msg "Configuring port for $1 ..." - #set listen port ipv4 - sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}" - #set listen port ipv6 - sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}" - fi - #set correct user - if [ "${1}" = "mainsail" ] || [ "${1}" = "fluidd" ]; then - sudo sed -i "/root/s/pi/${USER}/" "${cfg}" - fi - #moving the config file into correct directory - sudo mv "${cfg}" "/etc/nginx/sites-available/${1}" - ok_msg "Nginx configuration for $1 was set!" - if [ -n "${SET_LISTEN_PORT}" ]; then - ok_msg "${1} listening on port ${SET_LISTEN_PORT}!" - else - ok_msg "${1} listening on default port ${DEFAULT_PORT}!" - fi - #remove nginx default config - [ -e "/etc/nginx/sites-enabled/default" ] && sudo rm "/etc/nginx/sites-enabled/default" - #create symlink for own sites - [ ! -e "/etc/nginx/sites-enabled/${1}" ] && sudo ln -s "/etc/nginx/sites-available/${1}" "/etc/nginx/sites-enabled/" - restart_nginx - fi -} - -function read_listen_port(){ - LISTEN_PORT=$(grep listen "/etc/nginx/sites-enabled/${1}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) -} - -function detect_enabled_sites(){ - #check if there is another UI config already installed - #and reads the port they are listening on - if [ -e "/etc/nginx/sites-enabled/mainsail" ]; then - SITE_ENABLED="true" && MAINSAIL_ENABLED="true" - read_listen_port "mainsail" - MAINSAIL_PORT=${LISTEN_PORT} - #echo "debug: Mainsail listens on port: $MAINSAIL_PORT" - else - MAINSAIL_ENABLED="false" - fi - if [ -e /etc/nginx/sites-enabled/fluidd ]; then - SITE_ENABLED="true" && FLUIDD_ENABLED="true" - read_listen_port "fluidd" - FLUIDD_PORT=${LISTEN_PORT} - #echo "debug: Fluidd listens on port: $FLUIDD_PORT" - else - FLUIDD_ENABLED="false" - fi - if [ -e /etc/nginx/sites-enabled/octoprint ]; then - SITE_ENABLED="true" && OCTOPRINT_ENABLED="true" - read_listen_port "octoprint" - OCTOPRINT_PORT=${LISTEN_PORT} - #echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT" - else - OCTOPRINT_ENABLED="false" - fi -} - -function create_custom_hostname(){ - echo - top_border - echo -e "| You can change the hostname of this machine to use |" - echo -e "| that name to open the Interface in your browser. |" - echo -e "| |" - echo -e "| E.g.: If you set the hostname to 'my-printer' you |" - echo -e "| can open Mainsail / Fluidd / Octoprint by |" - echo -e "| browsing to: http://my-printer.local |" - bottom_border - while true; do - read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn - case "${yn}" in - Y|y|Yes|yes) - user_input_hostname - break;; - N|n|No|no|"") break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -function user_input_hostname(){ - unset NEW_HOSTNAME - unset HOSTNAME_VALID - unset HOSTENAME_CONFIRM - echo - top_border - echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |" - echo -e "| ${red}No special characters allowed!${white} |" - echo -e "| ${red}No leading or trailing '-' allowed!${white} |" - bottom_border - while true; do - read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME - if [[ ${NEW_HOSTNAME} =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then - ok_msg "'${NEW_HOSTNAME}' is a valid hostname!" - HOSTNAME_VALID="true" - while true; do - echo - read -p "${cyan}###### Do you want '${NEW_HOSTNAME}' to be the new hostname? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - HOSTENAME_CONFIRM="true" - break;; - N|n|No|no) - echo -e "###### > No" - echo -e "${red}Skip hostname change ...${white}" - HOSTENAME_CONFIRM="false" - break;; - *) - print_error "Invalid command!";; - esac - done - break - else - warn_msg "'${NEW_HOSTNAME}' is not a valid hostname!" - fi - done -} - -function set_hostname(){ - if [ "${HOSTNAME_VALID}" = "true" ] && [ "${HOSTENAME_CONFIRM}" = "true" ]; then - #check for dependencies - dep=(avahi-daemon) - dependency_check "${dep[@]}" - #execute operations - #get current hostname and write to variable - HOSTNAME=$(hostname) - #create host file if missing or create backup of existing one with current date&time - if [ -f /etc/hosts ]; then - status_msg "Creating backup of hosts file ..." - get_date - sudo cp "/etc/hosts /etc/hosts.${current_date}.bak" - ok_msg "Backup done!" - ok_msg "File:'/etc/hosts.${current_date}.bak'" - else - sudo touch /etc/hosts - fi - #set hostname in /etc/hostname - status_msg "Setting hostname to '${NEW_HOSTNAME}' ..." - status_msg "Please wait ..." - sudo hostnamectl set-hostname "${NEW_HOSTNAME}" - #write new hostname to /etc/hosts - status_msg "Writing new hostname to /etc/hosts ..." - echo "127.0.0.1 ${NEW_HOSTNAME}" | sudo tee -a /etc/hosts &>/dev/null - ok_msg "New hostname successfully configured!" - ok_msg "Remember to reboot for the changes to take effect!" - fi -} diff --git a/scripts/nginx.sh b/scripts/nginx.sh index a66a473..7375db9 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -20,7 +20,7 @@ NGINX_CONFD="/etc/nginx/conf.d" #=================== REMOVE NGINX ==================# #===================================================# -remove_nginx(){ +function remove_nginx(){ if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then status_msg "Stopping Nginx service ..." sudo systemctl stop nginx && sudo systemctl disable nginx @@ -238,4 +238,76 @@ function process_services_dialog(){ esac done fi +} + +function set_nginx_cfg(){ + if [ "${SET_NGINX_CFG}" = "true" ]; then + local cfg="${SRCDIR}/kiauh/resources/${1}" + #check for dependencies + dep=(nginx) + dependency_check "${dep[@]}" + #execute operations + status_msg "Creating Nginx configuration for ${1} ..." + #copy content from resources to the respective nginx config file + cat "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" > "${cfg}" + ##edit the nginx config file before moving it + sed -i "s/<>/${1}/g" "${cfg}" + if [ "${SET_LISTEN_PORT}" != "${DEFAULT_PORT}" ]; then + status_msg "Configuring port for $1 ..." + #set listen port ipv4 + sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}" + #set listen port ipv6 + sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}" + fi + #set correct user + if [ "${1}" = "mainsail" ] || [ "${1}" = "fluidd" ]; then + sudo sed -i "/root/s/pi/${USER}/" "${cfg}" + fi + #moving the config file into correct directory + sudo mv "${cfg}" "/etc/nginx/sites-available/${1}" + ok_msg "Nginx configuration for $1 was set!" + if [ -n "${SET_LISTEN_PORT}" ]; then + ok_msg "${1} listening on port ${SET_LISTEN_PORT}!" + else + ok_msg "${1} listening on default port ${DEFAULT_PORT}!" + fi + #remove nginx default config + [ -e "/etc/nginx/sites-enabled/default" ] && sudo rm "/etc/nginx/sites-enabled/default" + #create symlink for own sites + [ ! -e "/etc/nginx/sites-enabled/${1}" ] && sudo ln -s "/etc/nginx/sites-available/${1}" "/etc/nginx/sites-enabled/" + restart_nginx + fi +} + +function read_listen_port(){ + LISTEN_PORT=$(grep listen "/etc/nginx/sites-enabled/${1}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) +} + +function detect_enabled_sites(){ + #check if there is another UI config already installed + #and reads the port they are listening on + if [ -e "/etc/nginx/sites-enabled/mainsail" ]; then + SITE_ENABLED="true" && MAINSAIL_ENABLED="true" + read_listen_port "mainsail" + MAINSAIL_PORT=${LISTEN_PORT} + #echo "debug: Mainsail listens on port: $MAINSAIL_PORT" + else + MAINSAIL_ENABLED="false" + fi + if [ -e /etc/nginx/sites-enabled/fluidd ]; then + SITE_ENABLED="true" && FLUIDD_ENABLED="true" + read_listen_port "fluidd" + FLUIDD_PORT=${LISTEN_PORT} + #echo "debug: Fluidd listens on port: $FLUIDD_PORT" + else + FLUIDD_ENABLED="false" + fi + if [ -e /etc/nginx/sites-enabled/octoprint ]; then + SITE_ENABLED="true" && OCTOPRINT_ENABLED="true" + read_listen_port "octoprint" + OCTOPRINT_PORT=${LISTEN_PORT} + #echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT" + else + OCTOPRINT_ENABLED="false" + fi } \ No newline at end of file diff --git a/scripts/rollback.sh b/scripts/rollback.sh index 9f236b7..93b964b 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -11,7 +11,7 @@ set -e -save_klipper_state(){ +function save_klipper_state(){ source_kiauh_ini #read current klipper state cd $KLIPPER_DIR @@ -31,7 +31,7 @@ save_klipper_state(){ fi } -load_klipper_state(){ +function load_klipper_state(){ source_kiauh_ini print_branch cd $KLIPPER_DIR @@ -63,7 +63,7 @@ load_klipper_state(){ rollback_klipper } -rollback_ui(){ +function rollback_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | " hr @@ -82,7 +82,7 @@ rollback_ui(){ back_footer } -rollback_klipper(){ +function rollback_klipper(){ if [ "$PREVIOUS_COMMIT" != "0" ] && [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then while true; do echo -e "${cyan}" diff --git a/scripts/status.sh b/scripts/status.sh deleted file mode 100755 index 8b453fc..0000000 --- a/scripts/status.sh +++ /dev/null @@ -1,29 +0,0 @@ -check_system_updates(){ - SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d") - if [ ! -z "$SYS_UPDATE" ]; then - # add system updates to the update all array for the update all function in the updater - SYS_UPDATE_AVAIL="true" && update_arr+=(update_system) - DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${white}" - else - SYS_UPDATE_AVAIL="false" - DISPLAY_SYS_UPDATE="${green}System up to date! ${white}" - fi -} - -############################################################# -############################################################# - -#display this as placeholder if no version/commit could be fetched -NONE="${red}$(printf "%-12s" "--------")${default}" - -ui_print_versions(){ - unset update_arr - check_system_updates -# compare_klipper_versions -# compare_moonraker_versions -# compare_mainsail_versions -# compare_fluidd_versions -# compare_klipperscreen_versions -# compare_MoonrakerTelegramBot_versions -# compare_pgc_versions -} diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index e45aaa5..1ef2ec3 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -11,7 +11,7 @@ set -e -advanced_ui(){ +function advanced_ui(){ top_border echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} | " hr @@ -23,10 +23,10 @@ advanced_ui(){ echo -e "| 3) [Flash only] | | " echo -e "| 4) [Build + Flash] | Extras: | " echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] | " -back_footer + back_footer } -advanced_menu(){ +function advanced_menu(){ do_action "" "advanced_ui" while true; do read -p "${cyan}Perform action:${white} " action; echo diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index 1b6ee52..f70abd3 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -11,7 +11,7 @@ set -e -backup_ui(){ +function backup_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " hr @@ -30,11 +30,11 @@ backup_ui(){ back_footer } -backup_menu(){ +function backup_menu(){ do_action "" "backup_ui" while true; do read -p "${cyan}Perform action:${white} " action; echo - case "$action" in + case "${action}" in 0) do_action "backup_klipper_config_dir" "backup_ui";; 1) diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index 88f95d7..5312c09 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -12,41 +12,41 @@ set -e #ui total width = 57 chars -top_border(){ +function top_border(){ echo -e "/=======================================================\\" } -bottom_border(){ +function bottom_border(){ echo -e "\=======================================================/" } -blank_line(){ +function blank_line(){ echo -e "| |" } -hr(){ +function hr(){ echo -e "|-------------------------------------------------------|" } -quit_footer(){ +function quit_footer(){ hr echo -e "| ${red}Q) Quit${white} |" bottom_border } -back_footer(){ +function back_footer(){ hr echo -e "| ${green}B) « Back${white} |" bottom_border } -back_help_footer(){ +function back_help_footer(){ hr echo -e "| ${green}B) « Back${white} | ${yellow}H) Help [?]${white} |" bottom_border } -print_header(){ +function print_header(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |" echo -e "| $(title_msg " Klipper Installation And Update Helper ") |" @@ -54,12 +54,7 @@ print_header(){ bottom_border } -################################################################################ -#******************************************************************************# -################################################################################ -### TODO: rework other menus to make use of the following functions too and make them more readable - -do_action(){ +function do_action(){ clear && print_header ### $1 is the action the user wants to fire $1 @@ -68,7 +63,7 @@ do_action(){ $2 } -deny_action(){ +function deny_action(){ clear && print_header print_error "Invalid command!" $1 diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 273a909..55b2aba 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -11,7 +11,7 @@ set -e -main_ui(){ +function main_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr @@ -29,14 +29,14 @@ main_ui(){ quit_footer } -get_kiauh_version(){ +function get_kiauh_version(){ local version cd "${SRCDIR}/kiauh" version="$(printf "%-20s" "$(git describe HEAD --always --tags | cut -d "-" -f 1,2)")" echo "${cyan}${version}${white}" } -kiauh_update_dialog(){ +function kiauh_update_dialog(){ [ ! "$(kiauh_update_avail)" == "true" ] && return top_border echo -e "|${green} New KIAUH update available! ${white}| " @@ -60,7 +60,7 @@ kiauh_update_dialog(){ done } -main_menu(){ +function main_menu(){ print_header #prompt for KIAUH update if update available kiauh_update_dialog diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 839c981..a89ab8f 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -11,7 +11,7 @@ set -e -remove_ui(){ +function remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} | " hr @@ -30,7 +30,7 @@ remove_ui(){ back_footer } -remove_menu(){ +function remove_menu(){ do_action "" "remove_ui" while true; do read -p "${cyan}Perform action:${white} " action; echo diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 4fb91f1..da370ba 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -117,7 +117,7 @@ function show_settings_help(){ done } -settings_menu(){ +function settings_menu(){ clear && print_header settings_ui while true; do @@ -127,7 +127,7 @@ settings_menu(){ change_klipper_cfg_folder && settings_ui;; 2) clear && print_header - change_klipper_repo_menu + change_klippefunction r_repo_menu settings_ui;; 3) switch_mainsail_releasetype && settings_menu;; diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 2b3f9e9..e126a27 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -11,8 +11,7 @@ set -e -update_ui(){ - ui_print_versions +function update_ui(){ top_border echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} | " hr @@ -39,7 +38,8 @@ update_ui(){ back_footer } -update_menu(){ +function update_menu(){ + unset update_arr read_bb4u_stat do_action "" "update_ui" while true; do diff --git a/scripts/update.sh b/scripts/update.sh deleted file mode 100755 index a522cba..0000000 --- a/scripts/update.sh +++ /dev/null @@ -1,54 +0,0 @@ -update_log_paths(){ - ### update services to make use of moonrakers new log_path option - ### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a - shopt -s extglob # enable extended globbing - source_kiauh_ini - LPATH="${HOME}/klipper_logs" - [ ! -d "$LPATH" ] && mkdir -p "$LPATH" - FILE="$SYSTEMDDIR/$1?(-*([0-9])).service" - for file in $(ls $FILE); do - [ "$1" == "klipper" ] && LOG="klippy" - [ "$1" == "moonraker" ] && LOG="moonraker" - if [ ! "$(grep "\-l" $file)" ]; then - status_msg "Updating $file ..." - sudo sed -i -r "/ExecStart=/ s|$| -l $LPATH/$LOG.log|" $file - ok_msg "$file updated!" - elif [ "$(grep "\-l \/tmp\/$LOG" $file)" ]; then - status_msg "Updating $file ..." - sudo sed -i -r "/ExecStart=/ s|-l \/tmp\/$LOG|-l $LPATH/$LOG|" $file - ok_msg "$file updated!" - fi - done - sudo systemctl daemon-reload - - # patch log_path entry if not found - dir1="$klipper_cfg_loc" - dir2="$klipper_cfg_loc/printer_*" - for conf in $(find $dir1 $dir2 -name "moonraker.conf" 2> /dev/null); do - if ! grep -q "log_path" $conf; then - status_msg "Patching $conf" - sed -i "/^config_path/a log_path: $LPATH" $conf - ok_msg "OK!" - fi - done - - # create symlink for mainsail and fluidd nginx logs - symlink_webui_nginx_log "mainsail" - symlink_webui_nginx_log "fluidd" - - # create symlink for webcamd log - if [ -f "/var/log/webcamd.log" ] && [ ! -L "$LPATH/webcamd.log" ]; then - status_msg "Creating symlink for '/var/log/webcamd.log' ..." - ln -s "/var/log/webcamd.log" "$LPATH" - ok_msg "OK!" - fi - - shopt -u extglob # disable extended globbing -} - -update_system(){ - status_msg "Updating System ..." - sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y - CONFIRM_MSG="Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}" - print_msg && clear_msg -} \ No newline at end of file diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 96214ab..f1980d5 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -565,9 +565,28 @@ function fetch_webui_ports(){ } #================================================# -#================= USERGROUPS ===================# +#=================== SYSTEM =====================# #================================================# +function check_system_updates(){ + SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d") + if [ ! -z "$SYS_UPDATE" ]; then + # add system updates to the update all array for the update all function in the updater + SYS_UPDATE_AVAIL="true" && update_arr+=(update_system) + DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${white}" + else + SYS_UPDATE_AVAIL="false" + DISPLAY_SYS_UPDATE="${green}System up to date! ${white}" + fi +} + +function update_system(){ + status_msg "Updating System ..." + sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y + CONFIRM_MSG="Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}" + print_msg && clear_msg +} + function check_usergroups(){ local group_dialout group_tty if grep -q "dialout" Yes" + HOSTENAME_CONFIRM="true" + break;; + N|n|No|no) + echo -e "###### > No" + echo -e "${red}Skip hostname change ...${white}" + HOSTENAME_CONFIRM="false" + break;; + *) + print_error "Invalid command!";; + esac + done + break + else + warn_msg "'${NEW_HOSTNAME}' is not a valid hostname!" + fi + done +} + +function set_hostname(){ + if [ "${HOSTNAME_VALID}" = "true" ] && [ "${HOSTENAME_CONFIRM}" = "true" ]; then + #check for dependencies + dep=(avahi-daemon) + dependency_check "${dep[@]}" + #execute operations + #get current hostname and write to variable + HOSTNAME=$(hostname) + #create host file if missing or create backup of existing one with current date&time + if [ -f /etc/hosts ]; then + status_msg "Creating backup of hosts file ..." + get_date + sudo cp "/etc/hosts /etc/hosts.${current_date}.bak" + ok_msg "Backup done!" + ok_msg "File:'/etc/hosts.${current_date}.bak'" + else + sudo touch /etc/hosts + fi + #set hostname in /etc/hostname + status_msg "Setting hostname to '${NEW_HOSTNAME}' ..." + status_msg "Please wait ..." + sudo hostnamectl set-hostname "${NEW_HOSTNAME}" + #write new hostname to /etc/hosts + status_msg "Writing new hostname to /etc/hosts ..." + echo "127.0.0.1 ${NEW_HOSTNAME}" | sudo tee -a /etc/hosts &>/dev/null + ok_msg "New hostname successfully configured!" + ok_msg "Remember to reboot for the changes to take effect!" + fi } \ No newline at end of file From c20fd1a79a127afc963fe29e481bded9cdcc1d43 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 18 Apr 2022 17:30:18 +0200 Subject: [PATCH 119/183] fix: wrong status display Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 81489aa..042b8fd 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -32,7 +32,7 @@ function octoprint_setup_dialog(){ elif [ "${klipper_count}" -gt 1 ]; then printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances were found!" else - echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" + echo -e "| ${yellow}INFO: No existing Klipper installation found!${white} |" fi echo -e "| Usually you need one OctoPrint instance per Klipper |" echo -e "| instance. Though you can install as many as you wish. |" @@ -40,13 +40,13 @@ function octoprint_setup_dialog(){ local count while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of OctoPrint instances to set up:${default} " count + read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " count if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then error_msg "Invalid Input!\n" else echo while true; do - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${default} " yn + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" @@ -284,10 +284,10 @@ function octoprint_status(){ env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*" | wc -w) dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*" | wc -w) - if (( sf_count == env_count)) && (( sf_count == dir_count)); then - status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" - elif (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then + if (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then status="${red}Not installed!${white} " + elif (( sf_count == env_count)) && (( sf_count == dir_count)); then + status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" else status="${yellow}Incomplete!${white} " fi From b84a04be1496d236737e734bd436daebf52eabb6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 18 Apr 2022 17:31:19 +0200 Subject: [PATCH 120/183] fix: typo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index abbb177..825ad2c 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -48,7 +48,7 @@ function moonraker_setup_dialog(){ elif [ "${klipper_count}" -gt 1 ]; then printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances were found!" else - echo -e "| ${yellow}INFO: No existing Klipper installation found!${default} |" + echo -e "| ${yellow}INFO: No existing Klipper installation found!${white} |" fi echo -e "| Usually you need one Moonraker instance per Klipper |" echo -e "| instance. Though you can install as many as you wish. |" @@ -56,13 +56,13 @@ function moonraker_setup_dialog(){ local count while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of Moonraker instances to set up:${default} " count + read -p "${cyan}###### Number of Moonraker instances to set up:${white} " count if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then error_msg "Invalid Input!\n" else echo while true; do - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${default} " yn + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" From 1475ea57860db446a2ab57f648d77e6d9058155b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 19 Apr 2022 21:27:27 +0200 Subject: [PATCH 121/183] style: fix indentation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/switch_klipper_repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh index cf89b5a..0ecac90 100644 --- a/scripts/switch_klipper_repo.sh +++ b/scripts/switch_klipper_repo.sh @@ -52,7 +52,7 @@ function change_klipper_repo_menu(){ select_msg "No" break;; *) - error_msg "Invalid command!";; + error_msg "Invalid command!";; esac done else From 48309fae240b7f0b3fdc3d0f5b909d28fb4544a6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 19 Apr 2022 21:37:17 +0200 Subject: [PATCH 122/183] refactor: mjgp-streamer installer Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mjpg-streamer.sh | 113 +++++++++++++++------------------------ 1 file changed, 44 insertions(+), 69 deletions(-) diff --git a/scripts/mjpg-streamer.sh b/scripts/mjpg-streamer.sh index 1cd2830..de13a83 100644 --- a/scripts/mjpg-streamer.sh +++ b/scripts/mjpg-streamer.sh @@ -11,50 +11,47 @@ set -e -WEBCAMD_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" -WEBCAM_TXT_SRC="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" - #=================================================# #============= INSTALL MJPG-STREAMER =============# #=================================================# function install_mjpg-streamer(){ - check_klipper_cfg_path - source_kiauh_ini + local webcamd="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" + local webcam_txt="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" + local repo="https://github.com/jacksonliam/mjpg-streamer.git" + local service="${SRCDIR}/kiauh/resources/webcamd.service" - ### set default values - MJPG_SERV_SRC="${SRCDIR}/kiauh/resources/webcamd.service" - MJPG_SERV_TARGET="${SYSTEMD}/webcamd.service" - WEBCAM_TXT="${KLIPPER_CONFIG}/webcam.txt" - - ### if there is a webcamd.service -> exit - if [ -f "${MJPG_SERV_TARGET}" ]; then - ERROR_MSG="Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!" - print_msg && clear_msg && return + ### return early if webcamd.service already exists + if [ -f "${SYSTEMD}/webcamd.service" ]; then + print_error "Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!" + return fi + status_msg "Initializing MJPG-Streamer installation ..." + ### check and install dependencies if missing - dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg) + local dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg) if apt-cache search libjpeg62-turbo-dev | grep -Eq "^libjpeg62-turbo-dev "; then dep+=(libjpeg62-turbo-dev) elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then dep+=(libjpeg8-dev) fi - dependency_check + dependency_check "${dep[@]}" - ### step 1: clone moonraker + ### step 1: clone mjpg-streamer status_msg "Downloading MJPG-Streamer ..." - cd "${HOME}" && git clone https://github.com/jacksonliam/mjpg-streamer.git + [ -d "${HOME}/mjpg-streamer" ] && rm -rf "${HOME}/mjpg-streamer" + cd "${HOME}" && git clone "${repo}" ok_msg "Download complete!" ### step 2: compiling mjpg-streamer status_msg "Compiling MJPG-Streamer ..." - cd "${HOME}"/mjpg-streamer/mjpg-streamer-experimental && make + cd "${HOME}/mjpg-streamer/mjpg-streamer-experimental" && make ok_msg "Compiling complete!" #step 3: install mjpg-streamer status_msg "Installing MJPG-Streamer ..." - cd "${HOME}"/mjpg-streamer && mv mjpg-streamer-experimental/* . + cd "${HOME}/mjpg-streamer" && mv mjpg-streamer-experimental/* . mkdir www-mjpgstreamer cat <> ./www-mjpgstreamer/index.html @@ -68,30 +65,33 @@ function install_mjpg-streamer(){ EOT - sudo wget "${WEBCAMD_SRC}" -O "/usr/local/bin/webcamd" + sudo wget "${webcamd}" -O "/usr/local/bin/webcamd" sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /usr/local/bin/webcamd sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd sudo chmod +x /usr/local/bin/webcamd ### step 4: create webcam.txt config file [ ! -d "${KLIPPER_CONFIG}" ] && mkdir -p "${KLIPPER_CONFIG}" - if [ ! -f "${WEBCAM_TXT}" ]; then + if [ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]; then status_msg "Creating webcam.txt config file ..." - wget "${WEBCAM_TXT_SRC}" -O "${WEBCAM_TXT}" + wget "${webcam_txt}" -O "${KLIPPER_CONFIG}/webcam.txt" ok_msg "Done!" fi ### step 5: create systemd service status_msg "Creating MJPG-Streamer service ..." - sudo cp "${MJPG_SERV_SRC}" "${MJPG_SERV_TARGET}" - sudo sed -i "s|%USER%|${USER}|" "${MJPG_SERV_TARGET}" + sudo cp "${service}" "${SYSTEMD}/webcamd.service" + sudo sed -i "s|%USER%|${USER}|" "${SYSTEMD}/webcamd.service" ok_msg "MJPG-Streamer service created!" ### step 6: enabling and starting mjpg-streamer service - status_msg "Starting MJPG-Streamer service ..." + status_msg "Starting MJPG-Streamer service, please wait ..." sudo systemctl enable webcamd.service - sudo systemctl start webcamd.service - ok_msg "MJPG-Streamer service started!" + if sudo systemctl start webcamd.service; then + ok_msg "MJPG-Streamer service started!" + else + status_msg "MJPG-Streamer service couldn't be started! No webcam connected?\n###### You need to manually restart the service once your webcam is set up correctly." + fi ### step 6.1: create webcamd.log symlink [ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs" @@ -119,57 +119,32 @@ EOF fi ### step 7: check if user is in group "video" - usergroup_changed=false - USER_IN_VIDEO_GROUP=$(groups "${USER}" | grep "video") - if [ -z "${USER_IN_VIDEO_GROUP}" ]; then + local usergroup_changed="false" usergroup_video + usergroup_video=$(groups "${USER}" | grep "video") + if [ -z "${usergroup_video}" ]; then status_msg "Adding user ${USER} to group 'video' ..." sudo usermod -a -G video "${USER}" && ok_msg "Done!" - usergroup_changed=true - else - ok_msg "User ${USER} already in group 'video'!" + usergroup_changed="true" fi ### confirm message - CONFIRM_MSG="MJPG-Streamer has been set up!" - if [ "${usergroup_changed}" == true ]; then - CONFIRM_MSG="${CONFIRM_MSG}\n ${yellow}INFO: Your User was added to a new group!${green}" - CONFIRM_MSG="${CONFIRM_MSG}\n ${yellow}You need to relog/restart for the group to be applied!${green}" + local confirm_msg="MJPG-Streamer has been set up!" + if [ "${usergroup_changed}" == "true" ]; then + confirm_msg="${confirm_msg}\n ${yellow}INFO: Your User was added to a new group!${green}" + confirm_msg="${confirm_msg}\n ${yellow}You need to relog/restart for the group to be applied!${green}" fi - print_msg && clear_msg + print_confirm "${confirm_msg}" ### print webcam ip adress/url - IP=$(hostname -I | cut -d" " -f1) - WEBCAM_IP="http://${IP}:8080/?action=stream" - WEBCAM_URL="http://${IP}/webcam/?action=stream" - echo -e " ${cyan}● Webcam URL:${white} ${WEBCAM_IP}" - echo -e " ${cyan}● Webcam URL:${white} ${WEBCAM_URL}" + local ip + ip=$(hostname -I | cut -d" " -f1) + local cam_url="http://${ip}:8080/?action=stream" + local cam_url_alt="http://${ip}/webcam/?action=stream" + echo -e " ${cyan}● Webcam URL:${white} ${cam_url}" + echo -e " ${cyan}● Webcam URL:${white} ${cam_url_alt}" echo } -function get_user_selection_mjpg-streamer(){ - while true; do - unset INSTALL_MJPG - echo - top_border - echo -e "| Install MJGP-Streamer for webcam support? |" - bottom_border - read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - INSTALL_MJPG="true" - break;; - N|n|No|no) - echo -e "###### > No" - INSTALL_MJPG="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - #=================================================# #============== REMOVE MJPG-STREAMER =============# #=================================================# @@ -202,5 +177,5 @@ function remove_mjpg-streamer(){ [ -f "/var/log/webcamd.log" ] && sudo rm -f "/var/log/webcamd.log" [ -L "${HOME}/klipper_logs/webcamd.log" ] && rm -f "${HOME}/klipper_logs/webcamd.log" - CONFIRM_MSG="MJPG-Streamer successfully removed!" + print_confirm "MJPG-Streamer successfully removed!" } \ No newline at end of file From 140a287249d751435cd784a9b6fcb4395ea3a399 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 19 Apr 2022 23:58:19 +0200 Subject: [PATCH 123/183] refactor: mainsail installer & mainsail theme installer Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/mainsail.sh | 219 ++++++++++++++++++++---------------- scripts/nginx.sh | 5 +- scripts/ui/advanced_menu.sh | 2 +- 3 files changed, 126 insertions(+), 100 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 2cfb5c3..8cbf41c 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -41,8 +41,27 @@ function install_mainsail(){ mainsail_port_check ### ask user to install mjpg-streamer - if [ ! -f "/etc/systemd/system/webcamd.service" ]; then - get_user_selection_mjpg-streamer + local install_mjpg_streamer + if [ ! -f "${SYSTEMD}/webcamd.service" ]; then + while true; do + echo + top_border + echo -e "| Install MJGP-Streamer for webcam support? |" + bottom_border + read -p "${cyan}###### Please select (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + install_mjpg_streamer="true" + break;; + N|n|No|no) + select_msg "No" + install_mjpg_streamer="false" + break;; + *) + error_msg "Invalid command!";; + esac + done fi ### ask user to install the recommended webinterface macros @@ -56,14 +75,11 @@ function install_mainsail(){ ### symlink nginx log symlink_webui_nginx_log "mainsail" - ### copy the kiauh_macros.cfg to the config location - install_kiauh_macros - ### install mainsail/fluidd mainsail_setup ### install mjpg-streamer - [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer + [ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer fetch_webui_ports #WIP @@ -79,7 +95,7 @@ function install_mainsail_macros(){ echo -e "| your printer configuration to have Mainsail fully |" echo -e "| functional and working. |" blank_line - echo -e "| The recommended macros can be seen here: |" + echo -e "| The recommended macros for Mainsail can be seen here: |" echo -e "| https://docs.mainsail.xyz/configuration#macros |" blank_line echo -e "| If you already have these macros in your config file, |" @@ -162,32 +178,52 @@ function mainsail_setup(){ #================= REMOVE MAINSAIL =================# #===================================================# -function remove_mainsail(){ - ### remove mainsail dir - if [ -d "${MAINSAIL_DIR}" ]; then - status_msg "Removing Mainsail directory ..." - rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!" - fi +function remove_mainsail_dir(){ + [ ! -d "${MAINSAIL_DIR}" ] && return + status_msg "Removing Mainsail directory ..." + rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!" +} - ### remove mainsail config for nginx +function remove_mainsail_config(){ if [ -e "/etc/nginx/sites-available/mainsail" ]; then status_msg "Removing Mainsail configuration for Nginx ..." sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!" fi - - ### remove mainsail symlink for nginx if [ -L "/etc/nginx/sites-enabled/mainsail" ]; then status_msg "Removing Mainsail Symlink for Nginx ..." sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!" fi +} - ### remove mainsail nginx logs and log symlinks - for log in $(find /var/log/nginx -name "mainsail*"); do - sudo rm -f "${log}" - done - for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do - rm -f "${log}" - done +function remove_mainsail_logs(){ + local files + files=$(find /var/log/nginx -name "mainsail*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + sudo rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_mainsail_log_symlinks(){ + local files + files=$(find "${HOME}/klipper_logs" -name "mainsail*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_mainsail(){ + remove_mainsail_dir + remove_mainsail_config + remove_mainsail_logs + remove_mainsail_log_symlinks ### remove mainsail_port from ~/.kiauh.ini sed -i "/^mainsail_port=/d" "${INI_FILE}" @@ -211,14 +247,8 @@ function update_mainsail(){ #================= MAINSAIL STATUS =================# #===================================================# -function get_mainsail_ver(){ - MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) -} - function mainsail_status(){ local status - - ### remove the "SERVICE" entry from the data array if a moonraker service is installed local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail") ### count+1 for each found data-item from array @@ -273,27 +303,21 @@ function compare_mainsail_versions(){ #=========== MAINSAIL THEME INSTALLER ===========# #================================================# -function get_theme_list(){ - theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" - theme_csv=$(curl -s -L "${theme_csv_url}") - unset t_name - unset t_note - unset t_auth - unset t_url - i=0 +function print_theme_list(){ + local i=0 theme_list=${1} while IFS="," read -r col1 col2 col3 col4; do - t_name+=("${col1}") - t_note+=("${col2}") - t_auth+=("${col3}") - t_url+=("${col4}") - if [ ! "${col1}" == "name" ]; then + if [ "${col1}" != "name" ]; then printf "| ${i}) %-50s|\n" "[${col1}]" fi i=$((i+1)) - done <<< "${theme_csv}" + done <<< "${theme_list}" } -function ms_theme_ui(){ +function ms_theme_installer_menu(){ + local theme_author theme_repo theme_name theme_note theme_url + local theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" + theme_list=$(curl -s -L "${theme_csv_url}") + top_border echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} | " hr @@ -304,82 +328,83 @@ function ms_theme_ui(){ echo -e "| Installing a theme from this menu will overwrite an | " echo -e "| already installed theme or modified custom.css file! | " hr - get_theme_list # dynamically generate the themelist from a csv file + print_theme_list "${theme_list}" echo -e "| | " echo -e "| R) [Remove Theme] | " back_footer -} -function ms_theme_menu(){ - ms_theme_ui + while IFS="," read -r col1 col2 col3 col4; do + theme_name+=("${col1}") + theme_note+=("${col2}") + theme_author+=("${col3}") + theme_repo+=("${col4}") + done <<< "${theme_list}" + while true; do - read -p "${cyan}Install theme:${white} " a; echo - if [ "${a}" = "b" ] || [ "${a}" = "B" ]; then - clear && advanced_menu && break - elif [ "${a}" = "r" ] || [ "${a}" = "R" ]; then + read -p "${cyan}Install theme:${white} " option + if ((option > 0 && option < ${#theme_name[@]})); then + theme_url="https://github.com/${theme_author[${option}]}/${theme_repo[${option}]}" + ms_theme_install "${theme_url}" "${theme_name[${option}]}" "${theme_note[${option}]}" + break + elif [[ "${option}" == "R" || "${option}" == "r" ]]; then ms_theme_delete - ms_theme_menu - elif [ "${a}" -le ${#t_url[@]} ]; then - ms_theme_install "${t_auth[${a}]}" "${t_url[${a}]}" "${t_name[${a}]}" "${t_note[${a}]}" - ms_theme_menu + break + elif [[ "${option}" == "B" || "${option}" == "b" ]]; then + advanced_menu + break else - clear && print_header - print_error "Invalid command!" - ms_theme_menu + error_msg "Invalid command!" fi done - ms_theme_menu + ms_theme_installer_menu } -function check_select_printer(){ - unset printer_num +function ms_theme_install(){ + local path moonraker_count theme_url=${1} theme_name theme_note + theme_name=${2} theme_note=${3} - ### get klipper cfg loc and set default .theme folder loc - check_klipper_cfg_path - THEME_PATH="${KLIPPER_CONFIG}" - - ### check if there is more than one moonraker instance and if yes - ### ask the user to select the printer he wants to install/remove the theme - MR_SERVICE_COUNT=$(find "${SYSTEMD}" -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service" | wc -l) - if [[ ${MR_SERVICE_COUNT} -gt 1 ]]; then + ### check and select printer if there is more than 1 + path="$(get_klipper_cfg_dir)" + moonraker_count=$(moonraker_systemd | wc -w) + if ((moonraker_count > 1)); then top_border echo -e "| More than one printer was found on this system! | " echo -e "| Please select the printer to which you want to | " echo -e "| apply the previously selected action. | " bottom_border - read -p "${cyan}Select printer:${white} " printer_num - - ### rewrite the .theme path matching the selected printer - THEME_PATH="${KLIPPER_CONFIG}/printer_${printer_num}" + read -p "${cyan}Select printer:${white} " printer + path="${path}/printer_${printer}" fi - ### create the cfg folder if there is none yet - [ ! -d "${THEME_PATH}" ] && mkdir -p "${THEME_PATH}" -} - -function ms_theme_install(){ - THEME_URL="https://github.com/$1/$2" - - ### check and select printer if there is more than 1 - check_select_printer - - ### download all files - status_msg "Installing $3 ..." - status_msg "Please wait ..." - - [ -d "${THEME_PATH}/.theme" ] && rm -rf "${THEME_PATH}/.theme" - cd "${THEME_PATH}" && git clone "${THEME_URL}" ".theme" - - ok_msg "Theme installation complete!" - [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${white}" - ok_msg "Please remember to delete your browser cache!\n" + [ ! -d "${path}" ] && mkdir -p "${path}" + [ -d "${path}/.theme" ] && rm -rf "${path}/.theme" + status_msg "Installing ${theme_name[${option}]} ..." + cd "${path}" && + if git clone "${theme_url}" ".theme"; then + ok_msg "Theme installation complete!" + [ -n "${theme_note}" ] && echo "${yellow}###### Theme Info: ${theme_note}${white}" + ok_msg "Please remember to delete your browser cache!\n" + else + error_msg "Theme installation failed!\n" + fi } function ms_theme_delete(){ - check_select_printer - if [ -d "${THEME_PATH}/.theme" ]; then + local path + path="$(get_klipper_cfg_dir)" + moonraker_count=$(moonraker_systemd | wc -w) + if ((moonraker_count > 1)); then + top_border + echo -e "| More than one printer was found on this system! | " + echo -e "| Please select the printer to which you want to | " + echo -e "| apply the previously selected action. | " + bottom_border + read -p "${cyan}Select printer:${white} " printer + path="${path}/printer_${printer}" + fi + if [ -d "${path}/.theme" ]; then status_msg "Removing Theme ..." - rm -rf "${THEME_PATH}/.theme" && ok_msg "Theme removed!\n" + rm -rf "${path}/.theme" && ok_msg "Theme removed!\n" else status_msg "No Theme installed!\n" fi diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 7375db9..e01918b 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -39,14 +39,15 @@ function remove_nginx(){ #===================================================# function set_upstream_nginx_cfg(){ - get_date + local current_date + current_date=$(get_date) ### backup existing nginx configs [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" ### transfer ownership of backed up files from root to ${USER} for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/$log" + sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/${log}" done ### copy nginx configs to target destination if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 1ef2ec3..31a82bd 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -49,7 +49,7 @@ function advanced_menu(){ print_detected_mcu_to_screen advanced_ui;; 6) - do_action "ms_theme_menu";; + do_action "ms_theme_installer_menu";; 7) clear print_header From b73274053ef2ad7745e61e2a4582c03a6b70c815 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Apr 2022 00:11:53 +0200 Subject: [PATCH 124/183] refactor: fluidd installer Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 180 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 136 insertions(+), 44 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 4221a1a..c866cdb 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -41,14 +41,32 @@ function install_fluidd(){ fluidd_port_check ### ask user to install mjpg-streamer - if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then - get_user_selection_mjpg-streamer + local install_mjpg_streamer + if [ ! -f "${SYSTEMD}/webcamd.service" ]; then + while true; do + echo + top_border + echo -e "| Install MJGP-Streamer for webcam support? |" + bottom_border + read -p "${cyan}###### Please select (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + install_mjpg_streamer="true" + break;; + N|n|No|no) + select_msg "No" + install_mjpg_streamer="false" + break;; + *) + error_msg "Invalid command!";; + esac + done fi ### ask user to install the recommended webinterface macros - if ! ls "${KLIPPER_CONFIG}/kiauh_macros.cfg" 2>/dev/null 1>&2 || ! ls "${KLIPPER_CONFIG}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then - get_user_selection_kiauh_macros "Fluidd " - fi + install_fluidd_macros + ### create /etc/nginx/conf.d/upstreams.conf set_upstream_nginx_cfg ### create /etc/nginx/sites-available/ @@ -57,14 +75,11 @@ function install_fluidd(){ ### symlink nginx log symlink_webui_nginx_log "fluidd" - ### copy the kiauh_macros.cfg to the config location - install_kiauh_macros - ### install mainsail/fluidd fluidd_setup ### install mjpg-streamer - [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer + [ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer fetch_webui_ports #WIP @@ -72,55 +87,138 @@ function install_fluidd(){ print_confirm "Fluidd has been set up!" } +function install_fluidd_macros(){ + while true; do + echo + top_border + echo -e "| It is recommended to have some important macros in |" + echo -e "| your printer configuration to have Mainsail fully |" + echo -e "| functional and working. |" + blank_line + echo -e "| The recommended macros for Fluidd can be found here: |" + echo -e "| https://docs.fluidd.xyz/configuration/initial_setup |" + blank_line + echo -e "| If you already have these macros in your config file, |" + echo -e "| skip this step and answer with 'no'. |" + echo -e "| Otherwise you should consider to answer with 'yes' to |" + echo -e "| add the recommended example macros to your config. |" + bottom_border + read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + download_fluidd_macros + break;; + N|n|No|no) + select_msg "No" + break;; + *) + print_error "Invalid command!";; + esac + done + return +} + +function download_fluidd_macros(){ + log_info "executing: download_fluidd_macros" + local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg" + local configs + configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg") + if [ -n "${configs}" ]; then + ### create a backup of the config folder + backup_klipper_config_dir + + for config in ${configs}; do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/fluidd.cfg" ]; then + status_msg "Downloading fluidd.cfg to ${path} ..." + log_info "downloading fluidd.cfg to: ${path}" + wget "${fluidd_cfg}" -O "${path}/fluidd.cfg" + ### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi' + log_info "modify fluidd.cfg" + sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg" + ### write the include to the very first line of the printer.cfg + if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then + log_info "modify printer.cfg" + sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg" + fi + + ok_msg "Done!" + fi + done + else + log_error "execution stopped! reason: no printer.cfg found" + return + fi +} + function fluidd_setup(){ - ### get fluidd download url - FLUIDD_DL_URL=$(curl -s "${FLUIDD_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) - - ### remove existing and create fresh fluidd folder, then download fluidd - [ -d "${FLUIDD_DIR}" ] && rm -rf "${FLUIDD_DIR}" + local url + url=$(get_fluidd_download_url) + status_msg "Downloading Fluidd ..." + if [ -d "${FLUIDD_DIR}" ]; then + rm -rf "${FLUIDD_DIR}" + fi mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}" - status_msg "Downloading Fluidd ${FLUIDD_VERSION} ..." - wget "${FLUIDD_DL_URL}" && ok_msg "Download complete!" + wget "${url}" && ok_msg "Download complete!" - ### extract archive status_msg "Extracting archive ..." - unzip -q -o *.zip && ok_msg "Done!" + unzip -q -o ./*.zip && ok_msg "Done!" - ### delete downloaded zip status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" + rm -rf ./*.zip && ok_msg "Done!" } #===================================================# #================== REMOVE FLUIDD ==================# #===================================================# -function remove_fluidd(){ - ### remove fluidd dir - if [ -d "${FLUIDD_DIR}" ]; then - status_msg "Removing Fluidd directory ..." - rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!" - fi +function remove_fluidd_dir(){ + [ ! -d "${FLUIDD_DIR}" ] && return + status_msg "Removing Fluidd directory ..." + rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!" +} - ### remove fluidd config for nginx +function remove_fluidd_config(){ if [ -e "/etc/nginx/sites-available/fluidd" ]; then status_msg "Removing Fluidd configuration for Nginx ..." sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!" fi - - ### remove fluidd symlink for nginx - if [ -L /etc/nginx/sites-enabled/fluidd ]; then + if [ -L "/etc/nginx/sites-enabled/fluidd" ]; then status_msg "Removing Fluidd Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" + sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!" fi +} - ### remove mainsail nginx logs and log symlinks - for log in $(find /var/log/nginx -name "fluidd*"); do - sudo rm -f "${log}" - done - for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do - rm -f "${log}" - done +function remove_fluidd_logs(){ + local files + files=$(find /var/log/nginx -name "fluidd*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + sudo rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_fluidd_log_symlinks(){ + local files + files=$(find "${HOME}/klipper_logs" -name "fluidd*") + if [ -n "${files}" ]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_fluidd(){ + remove_fluidd_dir + remove_fluidd_config + remove_fluidd_logs + remove_fluidd_log_symlinks ### remove fluidd_port from ~/.kiauh.ini sed -i "/^fluidd_port=/d" "${INI_FILE}" @@ -144,14 +242,8 @@ function update_fluidd(){ #================== FLUIDD STATUS ==================# #===================================================# -function get_fluidd_ver(){ - FLUIDD_VERSION=$(curl -s "${FLUIDD_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) -} - function fluidd_status(){ local status - - ### remove the "SERVICE" entry from the data array if a moonraker service is installed local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd") ### count+1 for each found data-item from array From 156fec37f2886b0083b526449145f22d06dce0de Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Apr 2022 00:18:43 +0200 Subject: [PATCH 125/183] refactor: remove octoprint disable prompt the octoprint service itself does not cause any issues. so it is safe to have it still running besides mainsail or fluidd. only programs like haproxy, lighttps or apache2 cause issues in combination with nginx Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 19 +++++++++---------- scripts/mainsail.sh | 3 +-- scripts/utilities.sh | 32 -------------------------------- 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index c866cdb..f8cba00 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -26,8 +26,7 @@ function install_fluidd(){ dependency_check "${dep[@]}" ### check if moonraker is already installed system_check_webui - ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found - process_octoprint_dialog + ### ask user how to handle Haproxy, Lighttpd, Apache2 if found process_services_dialog ### process possible disruptive services process_disruptive_services @@ -324,8 +323,8 @@ function fluidd_port_check(){ if [ "${FLUIDD_ENABLED}" = "false" ]; then if [ "${SITE_ENABLED}" = "true" ]; then status_msg "Detected other enabled interfaces:" - [ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" - [ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${default}" + [ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${white}" + [ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}" if [ "${MAINSAIL_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then PORT_80_BLOCKED="true" select_fluidd_port @@ -344,22 +343,22 @@ function select_fluidd_port(){ if [ "${PORT_80_BLOCKED}" = "true" ]; then echo top_border - echo -e "| ${red}!!!WARNING!!!${default} |" - echo -e "| ${red}You need to choose a different port for Fluidd!${default} |" - echo -e "| ${red}The following web interface is listening at port 80:${default} |" + echo -e "| ${red}!!!WARNING!!!${white} |" + echo -e "| ${red}You need to choose a different port for Fluidd!${white} |" + echo -e "| ${red}The following web interface is listening at port 80:${white} |" blank_line [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" [ "${MAINSAIL_PORT}" = "80" ] && echo "| ● Mainsail |" blank_line echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${white} |" echo -e "| use ports in the range of 4750 or above! |" blank_line - echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |" echo -e "| input. So make sure to choose a valid port! |" bottom_border while true; do - read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + read -p "${cyan}Please enter a new Port:${white} " NEW_PORT if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then echo "Setting port ${NEW_PORT} for Fluidd!" SET_LISTEN_PORT=${NEW_PORT} diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 8cbf41c..a920a62 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -26,8 +26,7 @@ function install_mainsail(){ dependency_check "${dep[@]}" ### check if moonraker is already installed system_check_webui - ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found - process_octoprint_dialog + ### ask user how to handle Haproxy, Lighttpd, Apache2 if found process_services_dialog ### process possible disruptive services process_disruptive_services diff --git a/scripts/utilities.sh b/scripts/utilities.sh index f1980d5..d270718 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -513,38 +513,6 @@ function system_check_webui(){ fi } -function process_octoprint_dialog(){ - #ask user to disable octoprint when its service was found - if [ "${OCTOPRINT_ENABLED}" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${white} |" - hr - echo -e "| You might consider disabling the OctoPrint service, |" - echo -e "| since an active OctoPrint service may lead to unex- |" - echo -e "| pected behavior of the Klipper Webinterfaces. |" - bottom_border - read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Stopping OctoPrint ..." - do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!" - status_msg "Disabling OctoPrint ..." - do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!" - break;; - N|n|No|no) - echo -e "###### > No" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -} - function fetch_webui_ports(){ ### read listen ports from possible installed interfaces ### and write them to ~/.kiauh.ini From ebca847123f65477a01a1d62e32c2d20dbc2cc89 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Apr 2022 11:32:07 +0200 Subject: [PATCH 126/183] refactor(nginx.sh): reword local scope variables - fix typo for reading kiauh ini - use different method for restarting nginx Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/nginx.sh | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/scripts/nginx.sh b/scripts/nginx.sh index e01918b..f637acf 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -21,7 +21,7 @@ NGINX_CONFD="/etc/nginx/conf.d" #===================================================# function remove_nginx(){ - if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then + if [ -f "${SYSTEMD}/nginx.service" ]; then status_msg "Stopping Nginx service ..." sudo systemctl stop nginx && sudo systemctl disable nginx ok_msg "Service stopped and disabled!" @@ -46,8 +46,10 @@ function set_upstream_nginx_cfg(){ [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" ### transfer ownership of backed up files from root to ${USER} - for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/${log}" + local files + files=$(find "${BACKUP_DIR}/nginx_cfg") + for file in ${files}; do + sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/${file}" done ### copy nginx configs to target destination if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then @@ -59,26 +61,26 @@ function set_upstream_nginx_cfg(){ } function symlink_webui_nginx_log(){ - local LPATH="${HOME}/klipper_logs" - local UI_ACCESS_LOG="/var/log/nginx/${1}-access.log" - local UI_ERROR_LOG="/var/log/nginx/${1}-error.log" - [ ! -d "${LPATH}" ] && mkdir -p "${LPATH}" - if [ -f "${UI_ACCESS_LOG}" ] && [ ! -L "${LPATH}/${1}-access.log" ]; then - status_msg "Creating symlink for ${UI_ACCESS_LOG} ..." - ln -s "${UI_ACCESS_LOG}" "${LPATH}" + local path="${HOME}/klipper_logs" + local access_log="/var/log/nginx/${1}-access.log" + local error_log="/var/log/nginx/${1}-error.log" + [ ! -d "${path}" ] && mkdir -p "${path}" + if [ -f "${access_log}" ] && [ ! -L "${path}/${1}-access.log" ]; then + status_msg "Creating symlink for ${access_log} ..." + ln -s "${access_log}" "${path}" ok_msg "OK!" fi - if [ -f "${UI_ERROR_LOG}" ] && [ ! -L "${LPATH}/${1}-error.log" ]; then - status_msg "Creating symlink for ${UI_ERROR_LOG} ..." - ln -s "${UI_ERROR_LOG}" "${LPATH}" + if [ -f "${error_log}" ] && [ ! -L "${path}/${1}-error.log" ]; then + status_msg "Creating symlink for ${error_log} ..." + ln -s "${error_log}" "${path}" ok_msg "OK!" fi } function match_nginx_configs(){ + local cfg_updated="false" ### reinstall nginx configs if the amount of upstreams don't match anymore - source_kiauh_ini - cfg_updated="false" + read_kiauh_ini mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) @@ -124,9 +126,7 @@ function match_nginx_configs(){ fi fi ### only restart nginx if configs were updated - if [ "${cfg_updated}" == "true" ]; then - restart_nginx && unset cfg_updated - fi + [ "${cfg_updated}" == "true" ] && do_action_service "restart" "nginx" } function process_disruptive_services(){ @@ -276,7 +276,8 @@ function set_nginx_cfg(){ [ -e "/etc/nginx/sites-enabled/default" ] && sudo rm "/etc/nginx/sites-enabled/default" #create symlink for own sites [ ! -e "/etc/nginx/sites-enabled/${1}" ] && sudo ln -s "/etc/nginx/sites-available/${1}" "/etc/nginx/sites-enabled/" - restart_nginx + + do_action_service "restart" "nginx" fi } From 680f4e16e50ab25b49c61fd8ee6617d9347a018f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Apr 2022 11:32:50 +0200 Subject: [PATCH 127/183] refactor(utilities.sh): add logging to do_action_service function - remove unused restart_nginx function Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index d270718..ee71ed9 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -32,25 +32,25 @@ function check_euid(){ #================================================# function select_msg() { - echo -e "${white}>>>>>> $1" -} -function warn_msg(){ - echo -e "${red}>>>>>> $1${white}" + echo -e "${white}>>>>>> ${1}" } function status_msg(){ - echo; echo -e "${yellow}###### $1${white}" + echo -e "${yellow}###### ${1}${white}" } function ok_msg(){ - echo -e "${green}>>>>>> $1${white}" + echo -e "${green}>>>>>> ${1}${white}" +} +function warn_msg(){ + echo -e "${yellow}>>>>>> ${1}${white}" } function error_msg(){ - echo -e "${red}>>>>>> $1${white}" + echo -e "${red}>>>>>> ${1}${white}" } function abort_msg(){ - echo -e "${red}<<<<<< $1${white}" + echo -e "${red}<<<<<< ${1}${white}" } function title_msg(){ - echo -e "${cyan}$1${white}" + echo -e "${cyan}${1}${white}" } function print_error(){ @@ -342,19 +342,17 @@ function do_action_service(){ for service in ${services}; do service=$(echo "${service}" | rev | cut -d"/" -f1 | rev) status_msg "${action^} ${service} ..." - sudo systemctl "${action}" "${service}" - ok_msg "OK!" + if sudo systemctl "${action}" "${service}"; then + log_info "${service}: ${action} > success" + ok_msg "${action^} ${service} successfull!" + else + log_warning "${service}: ${action} > failed" + warn_msg "${action^} ${service} failed!" + fi done fi } -function restart_nginx(){ - if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then - status_msg "Restarting NGINX Service ..." - sudo systemctl restart nginx && ok_msg "NGINX Service restarted!" - fi -} - #================================================# #================ DEPENDENCIES ==================# #================================================# From 08f9ef84a65735f9893cc6816753129a5869951e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Apr 2022 11:59:17 +0200 Subject: [PATCH 128/183] refactor(utilities.sh): refactor system updates - remove unused restart_nginx function Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/update_menu.sh | 2 +- scripts/utilities.sh | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index e126a27..893a339 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -34,7 +34,7 @@ function update_ui(){ echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)| " echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)| " echo -e "| |------------------------------| " - echo -e "| 8) [System] | $DISPLAY_SYS_UPDATE | " + echo -e "| 8) [System] | $(check_system_updates) | " back_footer } diff --git a/scripts/utilities.sh b/scripts/utilities.sh index ee71ed9..6c93b54 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -535,22 +535,26 @@ function fetch_webui_ports(){ #================================================# function check_system_updates(){ - SYS_UPDATE=$(apt list --upgradeable 2>/dev/null | sed "1d") - if [ ! -z "$SYS_UPDATE" ]; then + local updates_avail info_msg + updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d") + if [ -n "${updates_avail}" ]; then # add system updates to the update all array for the update all function in the updater SYS_UPDATE_AVAIL="true" && update_arr+=(update_system) - DISPLAY_SYS_UPDATE="${yellow}System upgrade available!${white}" + info_msg="${yellow}System upgrade available!${white}" else SYS_UPDATE_AVAIL="false" - DISPLAY_SYS_UPDATE="${green}System up to date! ${white}" + info_msg="${green}System up to date! ${white}" fi + echo "${info_msg}" } function update_system(){ status_msg "Updating System ..." - sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y - CONFIRM_MSG="Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}" - print_msg && clear_msg + if sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y; then + print_confirm "Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}" + else + print_error "System update failed! Please watch for any errors printed above!" + fi } function check_usergroups(){ From 659c6bd14039fd1d3b0ca2fa3e280960a71de893 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Apr 2022 12:34:44 +0200 Subject: [PATCH 129/183] refactor(utilities.sh): refactor change hostname functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 2 +- scripts/utilities.sh | 95 ++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 50 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 31a82bd..2caa6c8 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -53,7 +53,7 @@ function advanced_menu(){ 7) clear print_header - create_custom_hostname && set_hostname + set_custom_hostname advanced_ui;; 8) do_action "setup_gcode_shell_command" "advanced_ui";; diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 6c93b54..46469f5 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -604,11 +604,12 @@ function check_usergroups(){ fi } -function create_custom_hostname(){ +function set_custom_hostname(){ echo top_border - echo -e "| You can change the hostname of this machine to use |" - echo -e "| that name to open the Interface in your browser. |" + echo -e "| Changing the hostname of this machine allows you to |" + echo -e "| access a webinterface that is configured for port 80 |" + echo -e "| by simply typing '.local' in the browser. |" echo -e "| |" echo -e "| E.g.: If you set the hostname to 'my-printer' you |" echo -e "| can open Mainsail / Fluidd / Octoprint by |" @@ -618,20 +619,20 @@ function create_custom_hostname(){ read -p "${cyan}###### Do you want to change the hostname? (y/N):${white} " yn case "${yn}" in Y|y|Yes|yes) - user_input_hostname + select_msg "Yes" + change_hostname + break;; + N|n|No|no|"") + select_msg "No" break;; - N|n|No|no|"") break;; *) - print_unkown_cmd - print_msg && clear_msg;; + error_msg "Invalid command!";; esac done } -function user_input_hostname(){ - unset NEW_HOSTNAME - unset HOSTNAME_VALID - unset HOSTENAME_CONFIRM +function change_hostname(){ + local new_hostname echo top_border echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${white} |" @@ -639,60 +640,56 @@ function user_input_hostname(){ echo -e "| ${red}No leading or trailing '-' allowed!${white} |" bottom_border while true; do - read -p "${cyan}###### Please set the new hostname:${white} " NEW_HOSTNAME - if [[ ${NEW_HOSTNAME} =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then - ok_msg "'${NEW_HOSTNAME}' is a valid hostname!" - HOSTNAME_VALID="true" + read -p "${cyan}###### Please set the new hostname:${white} " new_hostname + if [[ ${new_hostname} =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then while true; do echo - read -p "${cyan}###### Do you want '${NEW_HOSTNAME}' to be the new hostname? (Y/n):${white} " yn + read -p "${cyan}###### Do you want '${new_hostname}' to be the new hostname? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") - echo -e "###### > Yes" - HOSTENAME_CONFIRM="true" + select_msg "Yes" + set_hostname "${new_hostname}" break;; N|n|No|no) - echo -e "###### > No" - echo -e "${red}Skip hostname change ...${white}" - HOSTENAME_CONFIRM="false" + select_msg "No" + abort_msg "Skip hostname change ..." break;; *) print_error "Invalid command!";; esac done - break else - warn_msg "'${NEW_HOSTNAME}' is not a valid hostname!" + warn_msg "'${new_hostname}' is not a valid hostname!" fi + break done } function set_hostname(){ - if [ "${HOSTNAME_VALID}" = "true" ] && [ "${HOSTENAME_CONFIRM}" = "true" ]; then - #check for dependencies - dep=(avahi-daemon) - dependency_check "${dep[@]}" - #execute operations - #get current hostname and write to variable - HOSTNAME=$(hostname) - #create host file if missing or create backup of existing one with current date&time - if [ -f /etc/hosts ]; then - status_msg "Creating backup of hosts file ..." - get_date - sudo cp "/etc/hosts /etc/hosts.${current_date}.bak" - ok_msg "Backup done!" - ok_msg "File:'/etc/hosts.${current_date}.bak'" - else - sudo touch /etc/hosts - fi - #set hostname in /etc/hostname - status_msg "Setting hostname to '${NEW_HOSTNAME}' ..." - status_msg "Please wait ..." - sudo hostnamectl set-hostname "${NEW_HOSTNAME}" - #write new hostname to /etc/hosts - status_msg "Writing new hostname to /etc/hosts ..." - echo "127.0.0.1 ${NEW_HOSTNAME}" | sudo tee -a /etc/hosts &>/dev/null - ok_msg "New hostname successfully configured!" - ok_msg "Remember to reboot for the changes to take effect!" + local new_hostname=${1} current_date + #check for dependencies + dep=(avahi-daemon) + dependency_check "${dep[@]}" + + #create host file if missing or create backup of existing one with current date&time + if [ -f /etc/hosts ]; then + current_date=$(get_date) + status_msg "Creating backup of hosts file ..." + sudo cp "/etc/hosts /etc/hosts.${current_date}.bak" + ok_msg "Backup done!" + ok_msg "File:'/etc/hosts.${current_date}.bak'" + else + sudo touch /etc/hosts fi + + #set new hostname in /etc/hostname + status_msg "Setting hostname to '${new_hostname}' ..." + status_msg "Please wait ..." + sudo hostnamectl set-hostname "${new_hostname}" + + #write new hostname to /etc/hosts + status_msg "Writing new hostname to /etc/hosts ..." + echo "127.0.0.1 ${new_hostname}" | sudo tee -a /etc/hosts &>/dev/null + ok_msg "New hostname successfully configured!" + ok_msg "Remember to reboot for the changes to take effect!" } \ No newline at end of file From c231c1ec9525c48c03bb2f6db02ee283570f574f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 10:01:16 +0200 Subject: [PATCH 130/183] refactor: rename telegram bot functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker-telegram-bot.sh | 42 +++++++++++++++---------------- scripts/ui/install_menu.sh | 2 +- scripts/ui/remove_menu.sh | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index c949f80..395625c 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -21,26 +21,26 @@ function telegram_bot_systemd() { echo "${services}" } -function install_MoonrakerTelegramBot(){ - MoonrakerTelegramBot_setup +function install_telegram_bot(){ + telegram_bot_setup do_action_service "restart" "moonraker-telegram-bot" } -function MoonrakerTelegramBot_setup(){ +function telegram_bot_setup(){ local klipper_cfg_loc klipper_cfg_loc="$(get_klipper_cfg_dir)" export klipper_cfg_loc local dep=(virtualenv) dependency_check "${dep[@]}" - status_msg "Downloading MoonrakerTelegramBot ..." - #force remove existing MoonrakerTelegramBot dir + status_msg "Downloading Moonraker-Telegram-Bot ..." + #force remove existing Moonraker-Telegram-Bot dir [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" - #clone into fresh MoonrakerTelegramBot dir + #clone into fresh Moonraker-Telegram-Bot dir cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}" ok_msg "Download complete!" - status_msg "Installing MoonrakerTelegramBot ..." + status_msg "Installing Moonraker-Telegram-Bot ..." /bin/bash "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/install.sh" - echo; ok_msg "MoonrakerTelegramBot successfully installed!" + echo; ok_msg "Moonraker-Telegram-Bot successfully installed!" } @@ -48,44 +48,44 @@ function MoonrakerTelegramBot_setup(){ #=========== REMOVE MOONRAKERTELEGRAMBOT ===========# #===================================================# -function remove_MoonrakerTelegramBot(){ - ### remove MoonrakerTelegramBot dir +function remove_telegram_bot(){ + ### remove Moonraker-Telegram-Bot dir if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]; then - status_msg "Removing MoonrakerTelegramBot directory ..." + status_msg "Removing Moonraker-Telegram-Bot directory ..." rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" && ok_msg "Directory removed!" fi - ### remove MoonrakerTelegramBot VENV dir + ### remove Moonraker-Telegram-Bot VENV dir if [ -d "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" ]; then - status_msg "Removing MoonrakerTelegramBot VENV directory ..." + status_msg "Removing Moonraker-Telegram-Bot VENV directory ..." rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" && ok_msg "Directory removed!" fi - ### remove MoonrakerTelegramBot service + ### remove Moonraker-Telegram-Bot service if [ -e "${SYSTEMD}/moonraker-telegram-bot.service" ]; then - status_msg "Removing MoonrakerTelegramBot service ..." + status_msg "Removing Moonraker-Telegram-Bot service ..." do_action_service "stop" "moonraker-telegram-bot" do_action_service "disable" "moonraker-telegram-bot" sudo rm -f "${SYSTEMD}/moonraker-telegram-bot.service" ###reloading units sudo systemctl daemon-reload sudo systemctl reset-failed - ok_msg "MoonrakerTelegramBot Service removed!" + ok_msg "Moonraker-Telegram-Bot Service removed!" fi - ### remove MoonrakerTelegramBot log + ### remove Moonraker-Telegram-Bot log if [ -e "/tmp/telegram.log" ] || [ -e "${HOME}/klipper_logs/telegram.log" ]; then - status_msg "Removing MoonrakerTelegramBot log file ..." + status_msg "Removing Moonraker-Telegram-Bot log file ..." rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" && ok_msg "File removed!" fi - ### remove MoonrakerTelegramBot log symlink in config dir + ### remove Moonraker-Telegram-Bot log symlink in config dir if [ -e "${KLIPPER_CONFIG}/telegram.log" ]; then - status_msg "Removing MoonrakerTelegramBot log symlink ..." + status_msg "Removing Moonraker-Telegram-Bot log symlink ..." rm -f "${KLIPPER_CONFIG}/telegram.log" && ok_msg "File removed!" fi - print_confirm "MoonrakerTelegramBot successfully removed!" + print_confirm "Moonraker-Telegram-Bot successfully removed!" } #===================================================# diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 3773cdd..6109590 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -55,7 +55,7 @@ function install_menu(){ 7) do_action "install_pgc_for_klipper" "install_ui";; 8) - do_action "install_MoonrakerTelegramBot" "install_ui";; + do_action "install_telegram_bot" "install_ui";; 9) do_action "install_mjpg-streamer" "install_ui";; B|b) diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index a89ab8f..0ab0de6 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -50,7 +50,7 @@ function remove_menu(){ 7) do_action "remove_prettygcode" "remove_ui";; 8) - do_action "remove_MoonrakerTelegramBot" "remove_ui";; + do_action "remove_telegram_bot" "remove_ui";; 9) do_action "remove_mjpg-streamer" "remove_ui";; 10) From 4ae0df16232325944f66c89d26670d6ebeb7e069 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 12:58:55 +0200 Subject: [PATCH 131/183] fix: small bug in chown command Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/nginx.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/nginx.sh b/scripts/nginx.sh index f637acf..2a474a8 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -49,7 +49,7 @@ function set_upstream_nginx_cfg(){ local files files=$(find "${BACKUP_DIR}/nginx_cfg") for file in ${files}; do - sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/${file}" + sudo chown "${USER}" "${file}" done ### copy nginx configs to target destination if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then From 26eb380addd92fdfb634c77318fa5038a21411d3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 13:07:52 +0200 Subject: [PATCH 132/183] refactor: only execute chown on files that the user do not already own Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/nginx.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 2a474a8..5998680 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -49,7 +49,10 @@ function set_upstream_nginx_cfg(){ local files files=$(find "${BACKUP_DIR}/nginx_cfg") for file in ${files}; do - sudo chown "${USER}" "${file}" + if [ "$(stat -c "%U" "${file}" )" != "${USER}" ]; then + log_info "chown for user: ${USER} on file: ${file}" + sudo chown "${USER}" "${file}" + fi done ### copy nginx configs to target destination if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then From f1415c54a27324d57e2af654925733d0cf78e121 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 13:09:21 +0200 Subject: [PATCH 133/183] fix: typos Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index f8cba00..fc7fc3a 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -74,7 +74,7 @@ function install_fluidd(){ ### symlink nginx log symlink_webui_nginx_log "fluidd" - ### install mainsail/fluidd + ### install fluidd fluidd_setup ### install mjpg-streamer @@ -91,7 +91,7 @@ function install_fluidd_macros(){ echo top_border echo -e "| It is recommended to have some important macros in |" - echo -e "| your printer configuration to have Mainsail fully |" + echo -e "| your printer configuration to have Fluidd fully |" echo -e "| functional and working. |" blank_line echo -e "| The recommended macros for Fluidd can be found here: |" From 551b0400216d621658aef86b70edc7d96ddadbd5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 15:30:43 +0200 Subject: [PATCH 134/183] refactor: log-upload functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- docs/changelog.md | 1 + scripts/ui/main_menu.sh | 2 +- scripts/upload_log.sh | 125 ++++++++++++++++++++-------------------- 3 files changed, 65 insertions(+), 63 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 326baaa..4c96933 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -11,6 +11,7 @@ The majority of things that have been rewritten are mainly for internal reasons * feat: Multi-Instance OctoPrint installations now each have their own Virtualenv, allowing independent installation of Plugins * feat: Implementing the use of shellcheck during development * feat: Implementing a simple logging mechanic +* feat: Log-upload function allows uploading for several, other logfiles (kiauh.log, webcamd.log etc.) * fix: During Klipper installation checks for group membership of `tty` and `dialout` are made * refactor: Support for DWC and DWC-for-Klipper has been removed * refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 55b2aba..b5c786b 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -15,7 +15,7 @@ function main_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr - echo -e "| 0) [Upload Log] | Klipper: $(get_klipper_status)|" + echo -e "| 0) [Log-Upload] | Klipper: $(get_klipper_status)|" echo -e "| | |" echo -e "| 1) [Install] | |" echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 5d27154..05185d4 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -1,24 +1,24 @@ -accept_upload_conditions(){ +function accept_upload_conditions(){ + top_border + echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |" + hr + echo -e "| The following function will help to quickly upload |" + echo -e "| logs for debugging purposes. With confirming this |" + echo -e "| dialog, you agree that during that process your logs |" + echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |" + hr + echo -e "| ${red}PLEASE NOTE:${white} |" + echo -e "| Be aware that logs can contain network information, |" + echo -e "| private data like usernames, filenames, or other |" + echo -e "| information you may not want to make public. |" + blank_line + echo -e "| Do ${red}NOT${white} use this function if you don't agree! |" + bottom_border while true; do - top_border - echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |" - hr - echo -e "| The following function will help to quickly upload |" - echo -e "| logs for debugging purposes. With confirming this |" - echo -e "| dialog, you agree that during that process your logs |" - echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |" - hr - echo -e "| ${red}PLEASE NOTE:${white} |" - echo -e "| Be aware that logs can contain network information, |" - echo -e "| private data like usernames, filenames, or other |" - echo -e "| information you may not want to make public. |" - blank_line - echo -e "| Do ${red}NOT${white} use this function if you don't agree! |" - bottom_border read -p "${cyan}Do you accept? (Y/n):${white} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") - sed -i "/logupload_accepted=/s/false/true/" $INI_FILE + sed -i "/logupload_accepted=/s/false/true/" "${INI_FILE}" clear && print_header && upload_selection ;; N|n|No|no) @@ -27,73 +27,74 @@ accept_upload_conditions(){ break ;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - accept_upload_conditions;; + error_msg "Invalid command!";; esac done } -upload_selection(){ - source_kiauh_ini - [ "$logupload_accepted" = "false" ] && accept_upload_conditions +function upload_selection(){ + read_kiauh_ini + local upload_agreed="${logupload_accepted}" + [ "${upload_agreed}" = "false" ] && accept_upload_conditions - ### find all suitable logfiles for klipper - logfiles=() - klipper_logs="${HOME}/klipper_logs/klippy*.log" - moonraker_logs="${HOME}/klipper_logs/moonraker*.log" + local logfiles + local klipper_logs="${HOME}/klipper_logs" + local webif_logs="/var/log/nginx" - if ls $klipper_logs 2>/dev/null 1>&2; then - for kl_log in $(find $klipper_logs); do - logfiles+=($kl_log) + function find_logfile(){ + local name=${1} location=${2} + for log in $(find "${location}" -maxdepth 1 -type f -name "${name}" | sort -g); do + logfiles+=("${log}") done - fi - if ls $moonraker_logs 2>/dev/null 1>&2; then - for mr_log in $(find $moonraker_logs); do - logfiles+=($mr_log) - done - fi + } + + find_logfile "kiauh.log" "/tmp" + find_logfile "klippy*.log" "${klipper_logs}" + find_logfile "moonraker*.log" "${klipper_logs}" + find_logfile "telegram*.log" "${klipper_logs}" + find_logfile "mainsail*" "${webif_logs}" + find_logfile "fluidd*" "${webif_logs}" + find_logfile "KlipperScreen.log" "/tmp" + find_logfile "webcamd*" "/var/log" ### draw interface - i=0 + local i=0 top_border echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |" hr - echo -e "| You can choose the following files for uploading: |" - for log in ${logfiles[@]}; do - printf "| $i) %-50s|\n" "${logfiles[$i]}" + echo -e "| You can choose the following files for uploading: |" + blank_line + for log in "${logfiles[@]}"; do + log=${log//${HOME}/"~"} + ((i < 10)) && printf "| ${i}) %-50s|\n" "${log}" + ((i >= 10)) && printf "| ${i}) %-50s|\n" "${log}" i=$((i + 1)) done + blank_line back_footer while true; do - read -p "${cyan}Please select:${white} " choice - if [ $choice = "b" ] || [ $choice = "B" ]; then - clear && main_menu && break - elif [ $choice -le ${#logfiles[@]} ]; then - upload_log "${logfiles[$choice]}" + read -p "${cyan}Please select:${white} " option + if [ -n "${option}" ] && ((option < ${#logfiles[@]})); then + upload_log "${logfiles[${option}]}" upload_selection + elif [[ "${option}" == "B" || "${option}" == "b" ]]; then + return else - clear && print_header - ERROR_MSG="File not found!" && print_msg && clear_msg - upload_selection + error_msg "Invalid command!" fi done } -upload_log(){ - if [ -f "$1" ]; then - clear && print_header - status_msg "Uploading $1 ..." - LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') - [ ! -z "$LINK" ] && ok_msg "$1 upload successfull!" +function upload_log(){ + local link + clear && print_header + status_msg "Uploading ${1} ..." + link=$(curl -s --upload-file "${1}" 'http://paste.c-net.org/') + if [ -n "${link}" ]; then + ok_msg "${1} upload successfull!" echo -e "\n${cyan}###### Here is your link:${white}" - echo -e ">>>>>> $LINK\n" - unset LINK + echo -e ">>>>>> ${link}\n" else - clear && print_header - ERROR_MSG="File not found!" && print_msg && clear_msg - upload_selection + error_msg "Uploading failed!" fi } From a0ca25a99acdacb28cc83725fe1906c12aa034d8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 19:44:25 +0200 Subject: [PATCH 135/183] refactor: visual tweaks Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 1 + scripts/klipper.sh | 12 +++++----- scripts/ui/advanced_menu.sh | 2 +- scripts/ui/backup_menu.sh | 2 +- scripts/ui/install_menu.sh | 4 ++-- scripts/ui/main_menu.sh | 2 +- scripts/ui/remove_menu.sh | 5 ++-- scripts/ui/settings_menu.sh | 2 +- scripts/ui/update_menu.sh | 2 +- scripts/utilities.sh | 46 +++++++++++++++++++------------------ 10 files changed, 40 insertions(+), 38 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index 43665aa..7b3a1b1 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -21,6 +21,7 @@ function set_globals(){ #=================== KIAUH ====================# green=$(echo -en "\e[92m") yellow=$(echo -en "\e[93m") + magenta=$(echo -en "\e[95m") red=$(echo -en "\e[91m") cyan=$(echo -en "\e[96m") white=$(echo -en "\e[39m") diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 54dc677..499a427 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -55,11 +55,10 @@ function klipper_setup_dialog(){ top_border echo -e "| Please select the number of Klipper instances to set |" echo -e "| up. The number of Klipper instances will determine |" - echo -e "| the amount of printers you can run from this machine. |" + echo -e "| the amount of printers you can run from this host. |" blank_line - echo -e "| ${yellow}WARNING: There is no limit on the number of instances${white} |" - echo -e "| ${yellow}you can set up with this script. Setting up too many${white} |" - echo -e "| ${yellow}Klipper instances can potentially crash your system.${white} |" + echo -e "| ${yellow}WARNING:${white} |" + echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |" bottom_border local count @@ -74,7 +73,8 @@ function klipper_setup_dialog(){ case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" - status_msg "Installing ${count} Klipper instance(s) ... \n" + ((count == 1)) && status_msg "Installing single Klipper instance ..." + ((count > 1)) && status_msg "Installing ${count} Klipper instances ..." klipper_setup "${count}" "${python_version}" break;; N|n|No|no) @@ -82,7 +82,7 @@ function klipper_setup_dialog(){ abort_msg "Exiting Klipper setup ...\n" break;; *) - error_msg "Invalid Input!\n";; + error_msg "Invalid Input!";; esac done fi diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 2caa6c8..62da3fa 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -29,7 +29,7 @@ function advanced_ui(){ function advanced_menu(){ do_action "" "advanced_ui" while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in 1) do_action "load_klipper_state" "advanced_ui";; diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index f70abd3..fef8bae 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -33,7 +33,7 @@ function backup_ui(){ function backup_menu(){ do_action "" "backup_ui" while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in 0) do_action "backup_klipper_config_dir" "backup_ui";; diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 6109590..a43d5cf 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -37,7 +37,7 @@ function install_menu(){ install_ui while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in 1)clear && print_header select_klipper_python_version @@ -79,7 +79,7 @@ function select_klipper_python_version(){ echo -e "| 2) [Python 3.x] ${yellow}(experimental)${white} | " back_footer while true; do - read -p "${cyan}###### Select Python version:${white} " action; echo + read -p "${cyan}###### Select Python version:${white} " action case "${action}" in 1) select_msg "Python 2.7" diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index b5c786b..6d69ae0 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -66,7 +66,7 @@ function main_menu(){ kiauh_update_dialog main_ui while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in "start klipper") do_action_service "start" "klipper"; main_ui;; "stop klipper") do_action_service "stop" "klipper"; main_ui;; diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 0ab0de6..3c89096 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -15,8 +15,7 @@ function remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} | " hr - echo -e "| ${yellow}INFO:${white} | " - echo -e "| Printer configs or backups always remain untouched! | " + echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} | " hr echo -e "| Firmware: | Touchscreen GUI: | " echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " @@ -33,7 +32,7 @@ function remove_ui(){ function remove_menu(){ do_action "" "remove_ui" while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in 1) do_action "remove_klipper" "remove_ui";; diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index da370ba..40370f7 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -121,7 +121,7 @@ function settings_menu(){ clear && print_header settings_ui while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in 1) change_klipper_cfg_folder && settings_ui;; diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 893a339..94d885f 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -43,7 +43,7 @@ function update_menu(){ read_bb4u_stat do_action "" "update_ui" while true; do - read -p "${cyan}Perform action:${white} " action; echo + read -p "${cyan}####### Perform action:${white} " action case "${action}" in 0) do_action "toggle_backups" "update_ui";; diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 46469f5..22e41f7 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -32,13 +32,13 @@ function check_euid(){ #================================================# function select_msg() { - echo -e "${white}>>>>>> ${1}" + echo -e "${white} [➔] ${1}" } function status_msg(){ - echo -e "${yellow}###### ${1}${white}" + echo -e "\n${magenta}###### ${1}${white}" } function ok_msg(){ - echo -e "${green}>>>>>> ${1}${white}" + echo -e "${green}[✓ OK] ${1}${white}" } function warn_msg(){ echo -e "${yellow}>>>>>> ${1}${white}" @@ -56,18 +56,18 @@ function title_msg(){ function print_error(){ [ -z "${1}" ] && return echo -e "${red}" - echo -e "#########################################################" + echo -e "#=======================================================#" echo -e " ${1} " - echo -e "#########################################################" + echo -e "#=======================================================#" echo -e "${white}" } function print_confirm(){ [ -z "${1}" ] && return echo -e "${green}" - echo -e "#########################################################" + echo -e "#=======================================================#" echo -e " ${1} " - echo -e "#########################################################" + echo -e "#=======================================================#" echo -e "${white}" } @@ -371,30 +371,32 @@ function python3_check(){ } function dependency_check(){ - local dep=( "${@}" ) # dep: array + local dep=( "${@}" ) + local packages status_msg "Checking for the following dependencies:" - #check if package is installed, if not write name into array - for pkg in "${dep[@]}" - do + #check if package is installed, if not write its name into array + for pkg in "${dep[@]}"; do echo -e "${cyan}● ${pkg} ${white}" if [[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]]; then - inst+=("${pkg}") + packages+=("${pkg}") fi done - #if array is not empty, install packages from array elements - if [ "${#inst[@]}" -ne 0 ]; then + #if array is not empty, install packages from array + if (( ${#packages[@]} > 0 )); then status_msg "Installing the following dependencies:" - for element in "${inst[@]}" - do - echo -e "${cyan}● ${element} ${white}" + for package in "${packages[@]}"; do + echo -e "${cyan}● ${package} ${white}" done echo - sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${inst[@]}" -y - ok_msg "Dependencies installed!" - #clearing the array - unset inst + if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then + ok_msg "Dependencies installed!" + else + error_msg "Installing dependencies failed!" + return 1 # exit kiauh + fi else - ok_msg "Dependencies already met! Continue..." + ok_msg "Dependencies already met!" + return fi } From aa446e1db77164ec112bac6da3694c5d050a80dd Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 22:12:32 +0200 Subject: [PATCH 136/183] refactor: patch only necessary update manager sections upon webif install Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/moonraker.conf | 24 +++--------------------- scripts/fluidd.sh | 24 ++++++++++++++++++++++++ scripts/klipperscreen.sh | 33 +++++++++++++++++++++++++++++++++ scripts/mainsail.sh | 26 +++++++++++++++++++++++++- scripts/moonraker.sh | 3 ++- 5 files changed, 87 insertions(+), 23 deletions(-) diff --git a/resources/moonraker.conf b/resources/moonraker.conf index c86c6d3..2d1d3c2 100644 --- a/resources/moonraker.conf +++ b/resources/moonraker.conf @@ -4,9 +4,6 @@ port: %PORT% enable_debug_logging: False klippy_uds_address: %UDS% -[database] -database_path: %DB% - [authorization] trusted_clients: %LAN% @@ -23,6 +20,9 @@ cors_domains: http://*://my.mainsail.xyz http://*://app.fluidd.xyz +[database] +database_path: %DB% + [file_manager] config_path: %CFG% log_path: %LOG% @@ -34,21 +34,3 @@ log_path: %LOG% [update_manager] channel: dev refresh_interval: 168 - -[update_manager mainsail] -type: web -repo: mainsail-crew/mainsail -path: ~/mainsail - -[update_manager fluidd] -type: web -repo: fluidd-core/fluidd -path: ~/fluidd - -#[update_manager KlipperScreen] -#type: git_repo -#path: /home/%USER%/KlipperScreen -#origin: https://github.com/jordanruthe/KlipperScreen.git -#env: /home/%USER%/.KlipperScreen-env/bin/python -#requirements: scripts/KlipperScreen-requirements.txt -#install_script: scripts/KlipperScreen-install.sh \ No newline at end of file diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index fc7fc3a..c59339c 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -77,6 +77,9 @@ function install_fluidd(){ ### install fluidd fluidd_setup + ### add fluidd to the update manager in moonraker.conf + patch_fluidd_update_manager + ### install mjpg-streamer [ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer @@ -368,4 +371,25 @@ function select_fluidd_port(){ fi done fi +} + +function patch_fluidd_update_manager(){ + local moonraker_configs + moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") + for conf in ${moonraker_configs}; do + status_msg "Adding Fluidd to update manager in file:\n ${conf}" + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + ### add Fluidds update manager section to moonraker.conf + if grep -Eq "[update_manager fluidd]" "${conf}"; then + /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF + +[update_manager fluidd] +type: web +channel: stable +repo: fluidd-core/fluidd +path: ~/fluidd +MOONRAKER_CONF + fi + done } \ No newline at end of file diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index f1ca32d..50209bd 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -28,7 +28,13 @@ function install_klipperscreen(){ error="${error} Please upgrade Python." print_error "${error}" && return fi + + ### install KlipperScreen klipperscreen_setup + + ### add klipperscreen to the update manager in moonraker.conf + patch_klipperscreen_update_manager + do_action_service "restart" "KlipperScreen" } @@ -174,3 +180,30 @@ function compare_klipperscreen_versions(){ fi echo "${versions}" } + +#================================================# +#=================== HELPERS ====================# +#================================================# + +function patch_klipperscreen_update_manager(){ + local moonraker_configs + moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") + for conf in ${moonraker_configs}; do + status_msg "Adding KlipperScreen to update manager in file:\n ${conf}" + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + ### add KlipperScreens update manager section to moonraker.conf + if grep -Eq "[update_manager KlipperScreen]" "${conf}"; then + /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF + +[update_manager KlipperScreen] +type: git_repo +path: ${HOME}/KlipperScreen +origin: https://github.com/jordanruthe/KlipperScreen.git +env: ${HOME}/.KlipperScreen-env/bin/python +requirements: scripts/KlipperScreen-requirements.txt +install_script: scripts/KlipperScreen-install.sh +MOONRAKER_CONF + fi + done +} diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index a920a62..c441651 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -74,9 +74,12 @@ function install_mainsail(){ ### symlink nginx log symlink_webui_nginx_log "mainsail" - ### install mainsail/fluidd + ### install mainsail mainsail_setup + ### add mainsail to the update manager in moonraker.conf + patch_mainsail_update_manager + ### install mjpg-streamer [ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer @@ -490,4 +493,25 @@ function enable_mainsail_remotemode(){ [ ! -f "${MAINSAIL_DIR}/config.json" ] && return rm -f "${MAINSAIL_DIR}/config.json" echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" +} + +function patch_mainsail_update_manager(){ + local moonraker_configs + moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") + for conf in ${moonraker_configs}; do + status_msg "Adding Mainsail to update manager in file:\n ${conf}" + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + ### add Mainsails update manager section to moonraker.conf + if grep -Eq "[update_manager mainsail]" "${conf}"; then + /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF + +[update_manager mainsail] +type: web +channel: stable +repo: mainsail-crew/mainsail +path: ~/mainsail +MOONRAKER_CONF + fi + done } \ No newline at end of file diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 825ad2c..2ccaf09 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -66,7 +66,8 @@ function moonraker_setup_dialog(){ case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" - status_msg "Installing ${count} Moonraker instance(s) ... \n" + ((count == 1)) && status_msg "Installing single Moonraker instance ..." + ((count > 1)) && status_msg "Installing ${count} Moonraker instances ..." moonraker_setup "${count}" break;; N|n|No|no) From 1ab119212368ceda6089aafbddd9030030859a77 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 23:12:12 +0200 Subject: [PATCH 137/183] fix: bug in order of operations Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 10 +++++----- scripts/klipperscreen.sh | 10 +++++----- scripts/mainsail.sh | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index c59339c..bff2219 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -377,11 +377,11 @@ function patch_fluidd_update_manager(){ local moonraker_configs moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") for conf in ${moonraker_configs}; do - status_msg "Adding Fluidd to update manager in file:\n ${conf}" - ### add new line to conf if it doesn't end with one - [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" - ### add Fluidds update manager section to moonraker.conf - if grep -Eq "[update_manager fluidd]" "${conf}"; then + if ! grep -Eq "[update_manager fluidd]" "${conf}"; then + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + ### add Fluidds update manager section to moonraker.conf + status_msg "Adding Fluidd to update manager in file:\n ${conf}" /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF [update_manager fluidd] diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index 50209bd..451efe9 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -189,11 +189,11 @@ function patch_klipperscreen_update_manager(){ local moonraker_configs moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") for conf in ${moonraker_configs}; do - status_msg "Adding KlipperScreen to update manager in file:\n ${conf}" - ### add new line to conf if it doesn't end with one - [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" - ### add KlipperScreens update manager section to moonraker.conf - if grep -Eq "[update_manager KlipperScreen]" "${conf}"; then + if ! grep -Eq "[update_manager KlipperScreen]" "${conf}"; then + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + ### add KlipperScreens update manager section to moonraker.conf + status_msg "Adding KlipperScreen to update manager in file:\n ${conf}" /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF [update_manager KlipperScreen] diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index c441651..323311b 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -499,11 +499,11 @@ function patch_mainsail_update_manager(){ local moonraker_configs moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") for conf in ${moonraker_configs}; do - status_msg "Adding Mainsail to update manager in file:\n ${conf}" - ### add new line to conf if it doesn't end with one - [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" - ### add Mainsails update manager section to moonraker.conf - if grep -Eq "[update_manager mainsail]" "${conf}"; then + if ! grep -Eq "[update_manager mainsail]" "${conf}"; then + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + ### add Mainsails update manager section to moonraker.conf + status_msg "Adding Mainsail to update manager in file:\n ${conf}" /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF [update_manager mainsail] From 8497604d2c5c1bbb9b36ef4d7aed68bc8bd253ed Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Apr 2022 23:15:52 +0200 Subject: [PATCH 138/183] style: use darker magenta Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index 7b3a1b1..964b3e1 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -21,7 +21,7 @@ function set_globals(){ #=================== KIAUH ====================# green=$(echo -en "\e[92m") yellow=$(echo -en "\e[93m") - magenta=$(echo -en "\e[95m") + magenta=$(echo -en "\e[35m") red=$(echo -en "\e[91m") cyan=$(echo -en "\e[96m") white=$(echo -en "\e[39m") From 01d20056c8de09baf0e2f8acb32f4cdcf533351f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 11:30:10 +0200 Subject: [PATCH 139/183] style: restructure install menu Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/install_menu.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index a43d5cf..dd99cb4 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -19,15 +19,15 @@ function install_ui(){ echo -e "| all necessary dependencies for the various | " echo -e "| functions on a completely fresh system. | " hr - echo -e "| Firmware & API: | Other: | " + echo -e "| Firmware & API: | 3rd Party Webinterface: | " echo -e "| 1) [Klipper] | 6) [OctoPrint] | " - echo -e "| 2) [Moonraker] | 7) [PrettyGCode] | " - echo -e "| | 8) [Telegram Bot] | " - echo -e "| Klipper Webinterface: | | " - echo -e "| 3) [Mainsail] | Webcam: | " - echo -e "| 4) [Fluidd] | 9) [MJPG-Streamer] | " - echo -e "| | | " - echo -e "| Touchscreen GUI: | | " + echo -e "| 2) [Moonraker] | | " + echo -e "| | Other: | " + echo -e "| Klipper Webinterface: | 7) [PrettyGCode] | " + echo -e "| 3) [Mainsail] | 8) [Telegram Bot] | " + echo -e "| 4) [Fluidd] | | " + echo -e "| | Webcam Streamer: | " + echo -e "| Touchscreen GUI: | 9) [MJPG-Streamer] | " echo -e "| 5) [KlipperScreen] | | " back_footer } @@ -39,9 +39,8 @@ function install_menu(){ while true; do read -p "${cyan}####### Perform action:${white} " action case "${action}" in - 1)clear && print_header - select_klipper_python_version - install_ui;; + 1) + do_action "select_klipper_python_version" "install_ui";; 2) do_action "moonraker_setup_dialog" "install_ui";; 3) From c98535c9946a915471369c91422574310f755f93 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 12:14:21 +0200 Subject: [PATCH 140/183] style(backup.sh): remove unwanted echos Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 28b7a37..98cb05d 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -76,10 +76,8 @@ function backup_klipper_config_dir(){ config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)" mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" cp -r "${KLIPPER_CONFIG}" "${_}" && ok_msg "Backup complete!" - echo else ok_msg "No config directory found! Skipping backup ..." - echo fi } From 2b9eb367f808f451b58806bb9e2cbafec0af6c59 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 12:16:19 +0200 Subject: [PATCH 141/183] fix(moonraker.sh): script exits on multi instance setup during polkit installation Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 2ccaf09..2da795d 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -137,7 +137,7 @@ function moonraker_setup(){ create_moonraker_service "${instances}" ### step 5: create polkit rules for moonraker - moonraker_polkit + moonraker_polkit || true ### step 6: enable and start all instances do_action_service "enable" "moonraker" From b8ffbb0edb473ae130c72dd87a6c511f681f63d6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 12:24:02 +0200 Subject: [PATCH 142/183] refactor: refactor gcode_shell_command Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/gcode_shell_command.sh | 111 +++++++++++++++++++++++++++++++++ scripts/utilities.sh | 91 --------------------------- 2 files changed, 111 insertions(+), 91 deletions(-) create mode 100644 scripts/gcode_shell_command.sh diff --git a/scripts/gcode_shell_command.sh b/scripts/gcode_shell_command.sh new file mode 100644 index 0000000..f8d88b2 --- /dev/null +++ b/scripts/gcode_shell_command.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +#=================================================# +#======== INSTALL GCODE_SHELL_COMMAND.PY =========# +#=================================================# + +function setup_gcode_shell_command(){ + top_border + echo -e "| You are about to install the G-Code Shell Command |" + echo -e "| extension. Please make sure to read the instructions |" + echo -e "| before you continue and remember that potential risks |" + echo -e "| can be involved after installing this extension! |" + blank_line + echo -e "| ${red}You accept that you are doing this on your own risk!${white} |" + bottom_border + while true; do + read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + if [ ! -d "${KLIPPER_DIR}/klippy/extras" ]; then + print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?" + return + fi + + status_msg "Installing gcode shell command extension ..." + if [ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]; then + install_gcode_shell_command + else + echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!" + while true; do + read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" + install_gcode_shell_command + break;; + N|n|No|no) + select_msg "No" + break;; + *) + error_msg "Invalid Input!";; + esac + done + fi + return;; + N|n|No|no) + select_msg "No" + return;; + *) + error_msg "Invalid Input!";; + esac + done +} + +function install_gcode_shell_command(){ + do_action_service "stop" "klipper" + status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..." + if cp "${SRCDIR}/kiauh/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then + ok_msg "Done!" + else + error_msg "Cannot copy file to target destination...Exiting!" + return 1 + fi + while true; do + echo + read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + create_example_shell_command + break;; + N|n|No|no) + select_msg "No" + break;; + esac + done + do_action_service "restart" "klipper" + print_confirm "Shell command extension installed!" + return +} + +function create_example_shell_command() { + ### create a backup of the config folder + backup_klipper_config_dir + + local printer_cfgs + printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg") + for cfg in ${printer_cfgs}; do + path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev) + if [ ! -f "${path}/shell_command.cfg" ]; then + status_msg "Copy shell_command.cfg to ${path} ..." + cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${path}" + ok_msg "${path}/shell_command.cfg created!" + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include shell_command.cfg]" "${cfg}" + fi + done +} \ No newline at end of file diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 22e41f7..8e28231 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -400,97 +400,6 @@ function dependency_check(){ fi } -function setup_gcode_shell_command(){ - echo - top_border - echo -e "| You are about to install the G-Code Shell Command |" - echo -e "| extension. Please make sure to read the instructions |" - echo -e "| before you continue and remember that potential risks |" - echo -e "| can be involved after installing this extension! |" - blank_line - echo -e "| ${red}You accept that you are doing this on your own risk!${white} |" - bottom_border - while true; do - read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - if [ -d "${KLIPPER_DIR}/klippy/extras" ]; then - status_msg "Installing gcode shell command extension ..." - if [ -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]; then - warn_msg "There is already a file named 'gcode_shell_command.py'\nin the destination location!" - while true; do - read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" - install_gcode_shell_command - break;; - N|n|No|no) - break;; - esac - done - else - install_gcode_shell_command - fi - else - ERROR_MSG="Folder ~/klipper/klippy/extras not found!" - fi - break;; - N|n|No|no) - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -function install_gcode_shell_command(){ - do_action_service "stop" "klipper" - status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..." - cp "${SRCDIR}/kiauh/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras" - while true; do - echo - read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - status_msg "Copy shell_command.cfg ..." - ### create a backup of the config folder - backup_klipper_config_dir - - ### handle single printer.cfg - if [ -f "${klipper_cfg_loc}/printer.cfg" ] && [ ! -f "${klipper_cfg_loc}/shell_command.cfg" ]; then - ### copy shell_command.cfg to config location - cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${klipper_cfg_loc}" - ok_msg "${klipper_cfg_loc}/shell_command.cfg created!" - - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include shell_command.cfg]" "${klipper_cfg_loc}/printer.cfg" - fi - - ### handle multi printer.cfg - if ls "${klipper_cfg_loc}"/printer_* 2>/dev/null 1>&2; then - for config in $(find ${klipper_cfg_loc}/printer_*/printer.cfg); do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [ ! -f "${path}/shell_command.cfg" ]; then - ### copy shell_command.cfg to config location - cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${path}" - ok_msg "${path}/shell_command.cfg created!" - - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include shell_command.cfg]" "${path}/printer.cfg" - fi - done - fi - break;; - N|n|No|no) - break;; - esac - done - ok_msg "Shell command extension installed!" - do_action_service "restart" "klipper" -} - function system_check_webui(){ ### check system for an installed and enabled octoprint service if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then From 1915453b7e9ce099562c71993915334057566444 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 12:41:46 +0200 Subject: [PATCH 143/183] refactor: remove double declaration of function Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 8e28231..f6ebc94 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -310,18 +310,6 @@ function switch_fluidd_releasetype() { fi } -function switch_fluidd_releasetype() { - read_kiauh_ini - local state="${fluidd_install_unstable}" - if [ "${state}" == "false" ]; then - sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}" - log_info "fluidd_install_unstable changed (false -> true) " - else - sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}" - log_info "fluidd_install_unstable changed (true -> false) " - fi -} - function set_custom_klipper_repo() { read_kiauh_ini local repo_url=${1} branch=${2} From 7da500a945c42927b7cde3118e4254068aa444f5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 12:51:51 +0200 Subject: [PATCH 144/183] refactor: backup_before_updates functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 31 ++++--------------------------- scripts/fluidd.sh | 2 +- scripts/klipper.sh | 2 +- scripts/mainsail.sh | 2 +- scripts/moonraker.sh | 2 +- scripts/ui/settings_menu.sh | 16 ++++++++++++++++ scripts/ui/update_menu.sh | 3 --- scripts/utilities.sh | 10 ++++++++++ 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 98cb05d..4288a54 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -23,34 +23,11 @@ function check_for_backup_dir(){ fi } -function toggle_backups(){ +function backup_before_update(){ read_kiauh_ini - if [ "${backup_before_update}" = "true" ]; then - sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}" - BB4U_STATUS="${green}[Enable]${white} backups before updating " - CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !" - fi - if [ "${backup_before_update}" = "false" ]; then - sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}" - BB4U_STATUS="${red}[Disable]${white} backups before updating " - CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !" - fi -} - -function bb4u(){ - read_kiauh_ini - if [ "${backup_before_update}" = "true" ]; then - backup_"${1}" - fi -} - -function read_bb4u_stat(){ - read_kiauh_ini - if [ ! "${backup_before_update}" = "true" ]; then - BB4U_STATUS="${green}[Enable]${white} backups before updating " - else - BB4U_STATUS="${red}[Disable]${white} backups before updating " - fi + local state="${backup_before_update}" + [ "${state}" = "false" ] && return + backup_"${1}" } function backup_printer_cfg(){ diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index bff2219..00025db 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -233,7 +233,7 @@ function remove_fluidd(){ #===================================================# function update_fluidd(){ - bb4u "fluidd" + backup_before_update "fluidd" status_msg "Updating Fluidd ..." fluidd_setup match_nginx_configs diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 499a427..34bfdb7 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -341,7 +341,7 @@ function update_klipper(){ if [ ! -d "${KLIPPER_DIR}" ]; then cd "${HOME}" && git clone "${KLIPPER_REPO}" else - bb4u "klipper" + backup_before_update "klipper" status_msg "Updating Klipper ..." cd "${KLIPPER_DIR}" && git pull ### read PKGLIST and install possible new dependencies diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 323311b..1b3f60b 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -238,7 +238,7 @@ function remove_mainsail(){ #===================================================# function update_mainsail(){ - bb4u "mainsail" + backup_before_update "mainsail" status_msg "Updating Mainsail ..." mainsail_setup match_nginx_configs diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 2da795d..75fb5ea 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -395,7 +395,7 @@ function update_moonraker(){ if [ ! -d "${MOONRAKER_DIR}" ]; then cd "${HOME}" && git clone "${MOONRAKER_REPO}" else - bb4u "moonraker" + backup_before_update "moonraker" status_msg "Updating Moonraker ..." cd "${MOONRAKER_DIR}" && git pull ### read PKGLIST and install possible new dependencies diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 40370f7..d58fdca 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -18,6 +18,7 @@ function settings_ui() { local custom_branch="${custom_klipper_repo_branch}" local ms_pre_rls="${mainsail_install_unstable}" local fl_pre_rls="${fluidd_install_unstable}" + local bbu="${backup_before_update}" ### config location if [ -z "${custom_cfg_loc}" ]; then @@ -49,6 +50,12 @@ function settings_ui() { else fl_pre_rls="${green}● ${fl_pre_rls}${white}" fi + ### backup before update toggle + if [ "${bbu}" == "false" ]; then + bbu="${red}● ${bbu}${white}" + else + bbu="${green}● ${bbu}${white}" + fi top_border echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |" @@ -63,6 +70,8 @@ function settings_ui() { printf "| Mainsail: %-55s|\n" "${ms_pre_rls}" printf "| Fluidd: %-55s|\n" "${fl_pre_rls}" hr + printf "| Backup before updating: %-42s|\n" "${bbu}" + hr echo -e "| 1) Change Klipper config folder location |" echo -e "| 2) Set custom Klipper repository |" if [ "${mainsail_install_unstable}" == "false" ]; then @@ -75,6 +84,11 @@ function settings_ui() { else echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |" fi + if [ "${backup_before_update}" == "false" ]; then + echo -e "| 5) ${green}Enable${white} automatic backups before updates |" + else + echo -e "| 5) ${red}Disable${white} automatic backups before updates |" + fi back_help_footer } @@ -133,6 +147,8 @@ function settings_menu(){ switch_mainsail_releasetype && settings_menu;; 4) switch_fluidd_releasetype && settings_menu;; + 5) + toggle_backup_before_update && settings_menu;; B|b) clear main_menu diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 94d885f..31ccd99 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -15,8 +15,6 @@ function update_ui(){ top_border echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} | " hr - echo -e "| 0) ${BB4U_STATUS}| " - hr echo -e "| a) [Update all] | | | " echo -e "| | Installed: | Latest: | " echo -e "| Klipper & API: |---------------|--------------| " @@ -40,7 +38,6 @@ function update_ui(){ function update_menu(){ unset update_arr - read_bb4u_stat do_action "" "update_ui" while true; do read -p "${cyan}####### Perform action:${white} " action diff --git a/scripts/utilities.sh b/scripts/utilities.sh index f6ebc94..0a1bb5b 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -310,6 +310,16 @@ function switch_fluidd_releasetype() { fi } +function toggle_backup_before_update(){ + read_kiauh_ini + local state="${backup_before_update}" + if [ "${state}" = "false" ]; then + sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}" + else + sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}" + fi +} + function set_custom_klipper_repo() { read_kiauh_ini local repo_url=${1} branch=${2} From 40cc53807ad9289789f19fb9cf65a4d75118a4ef Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 13:43:46 +0200 Subject: [PATCH 145/183] changelog.md: update changelog.md Signed-off-by: Dominik Willner th33xitus@gmail.com --- docs/changelog.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4c96933..65d31f1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -3,19 +3,22 @@ This document covers possible important changes to KIAUH. ### 2022-04-XX -KIAUH is now at Version 4!\ -The majority of things that have been rewritten are mainly for internal reasons and not affecting the user at all. +KIAUH has now reached major version 4 ! * feat: Klipper can be installed under Python3 (consideres experimental) * feat: Klipper can be installed from custom repositories * feat: Option to only allow installation of stable builds of Mainsail and Fluidd -* feat: Multi-Instance OctoPrint installations now each have their own Virtualenv, allowing independent installation of Plugins +* feat: Multi-Instance OctoPrint installations now each have their own virtual python environment + * allows independent installation of Plugins for each instance * feat: Implementing the use of shellcheck during development * feat: Implementing a simple logging mechanic * feat: Log-upload function allows uploading for several, other logfiles (kiauh.log, webcamd.log etc.) * fix: During Klipper installation checks for group membership of `tty` and `dialout` are made * refactor: Support for DWC and DWC-for-Klipper has been removed +* refactor: The backup before update settings were moved to the KIAUH settings menu * refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature) * refactor: Rewriting a lot of functions to pass shellcheck checks +* refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen were removed from the moonraker.conf template + * They will now be individually added during installation of the corresponding interface ### 2022-01-29 From 73753ff44bf7bf0644e1a99b82226b91624511c1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 13:45:24 +0200 Subject: [PATCH 146/183] fix: previously introduced bug Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/settings_menu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index d58fdca..6a33505 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -141,7 +141,7 @@ function settings_menu(){ change_klipper_cfg_folder && settings_ui;; 2) clear && print_header - change_klippefunction r_repo_menu + change_klipper_repo_menu settings_ui;; 3) switch_mainsail_releasetype && settings_menu;; From 62f3d3e3c9e6c550cc92888cdb760a66b05107b2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 14:45:38 +0200 Subject: [PATCH 147/183] refactor: backup functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 50 +++++++++++++++++++++++---------------- scripts/ui/backup_menu.sh | 39 +++++++++++++++--------------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 4288a54..bc1ea26 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -17,14 +17,14 @@ function get_date(){ } function check_for_backup_dir(){ - if [ ! -d "${BACKUP_DIR}" ]; then - status_msg "Create KIAUH backup directory ..." - mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!" - fi + [ -d "${BACKUP_DIR}" ] && return + status_msg "Create KIAUH backup directory ..." + mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!" } function backup_before_update(){ read_kiauh_ini + # shellcheck disable=SC2154 local state="${backup_before_update}" [ "${state}" = "false" ] && return backup_"${1}" @@ -52,7 +52,8 @@ function backup_klipper_config_dir(){ status_msg "Create backup of the Klipper config directory ..." config_folder_name="$(echo "${KLIPPER_CONFIG}" | rev | cut -d"/" -f1 | rev)" mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}" - cp -r "${KLIPPER_CONFIG}" "${_}" && ok_msg "Backup complete!" + cp -r "${KLIPPER_CONFIG}" "${_}" + print_confirm "Configuration directory backup complete!" else ok_msg "No config directory found! Skipping backup ..." fi @@ -60,21 +61,24 @@ function backup_klipper_config_dir(){ function backup_moonraker_database(){ check_for_backup_dir - local current_date - if ls -d "${HOME}"/.moonraker_database* 2>/dev/null 1>&2; then + local current_date databases target_dir + + databases=$(find "${HOME}" -maxdepth 1 -type d -regextype posix-extended -regex "${HOME}/.moonraker_database(_[^0])?[0-9]*" | sort) + if [ -n "${databases}" ]; then current_date=$(get_date) + target_dir="${BACKUP_DIR}/moonraker_database_backup/${current_date}" status_msg "Timestamp: ${current_date}" - mkdir -p "${BACKUP_DIR}/mr_db_backup/${current_date}" - for database in $(ls -d ${HOME}/.moonraker_database*) - do + mkdir -p "${target_dir}" + for database in ${databases}; do status_msg "Create backup of ${database} ..." - cp -r "${database}" "${BACKUP_DIR}/mr_db_backup/${current_date}" + cp -r "${database}" "${target_dir}" ok_msg "Done!" done - ok_msg "Backup complete!\n" + print_confirm "Moonraker database backup complete!" else - ok_msg "No Moonraker database found! Skipping backup ..." + print_error "No Moonraker database found! Skipping backup ..." fi + return } function backup_klipper(){ @@ -85,7 +89,8 @@ function backup_klipper(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}" - cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" && ok_msg "Backup complete!" + cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" + print_confirm "Klipper backup complete!" else print_error "Can't backup klipper and/or klipper-env directory! Not found!" fi @@ -99,7 +104,8 @@ function backup_mainsail(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}" - cp -r "${MAINSAIL_DIR}" "${_}" && ok_msg "Backup complete!" + cp -r "${MAINSAIL_DIR}" "${_}" + print_confirm "Mainsail backup complete!" else print_error "Can't backup mainsail directory! Not found!" fi @@ -113,7 +119,8 @@ function backup_fluidd(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}" - cp -r "${FLUIDD_DIR}" "${_}" && ok_msg "Backup complete!" + cp -r "${FLUIDD_DIR}" "${_}" + print_confirm "Fluidd backup complete!" else print_error "Can't backup fluidd directory! Not found!" fi @@ -127,7 +134,8 @@ function backup_moonraker(){ current_date=$(get_date) status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}" - cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" && ok_msg "Backup complete!" + cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" + print_confirm "Moonraker backup complete!" else print_error "Can't backup moonraker and/or moonraker-env directory! Not found!" fi @@ -142,7 +150,7 @@ function backup_octoprint(){ status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}" cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}" - ok_msg "Backup complete!" + print_confirm " OctoPrint backup complete!" else print_error "Can't backup OctoPrint and/or .octoprint directory!\n Not found!" fi @@ -157,13 +165,13 @@ function backup_klipperscreen(){ status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}" cp -r "${KLIPPERSCREEN_DIR}" "${_}" - ok_msg "Backup complete!" + print_confirm "KlipperScreen backup complete!" else print_error "Can't backup KlipperScreen directory!\n Not found!" fi } -function backup_MoonrakerTelegramBot(){ +function backup_telegram_bot(){ local current_date if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] ; then status_msg "Creating MoonrakerTelegramBot backup ..." @@ -172,7 +180,7 @@ function backup_MoonrakerTelegramBot(){ status_msg "Timestamp: ${current_date}" mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}" cp -r "${MOONRAKER_TELEGRAM_BOT_DIR}" "${_}" - ok_msg "Backup complete!" + print_confirm "MoonrakerTelegramBot backup complete!" else print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!" fi diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index fef8bae..6e681c6 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -13,20 +13,19 @@ set -e function backup_ui(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " + echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") |" hr - echo -e "| ${yellow}Backup location: ~/kiauh-backups${white} | " + echo -e "| ${yellow}INFO: Backups are located in '~/kiauh-backups'${white} |" hr - echo -e "| Configuration folder: | Klipper Webinterface: | " - echo -e "| 0) [Klipper configs] | 4) [Mainsail] | " - echo -e "| | 5) [Fluidd] | " - echo -e "| Firmware: | | " - echo -e "| 1) [Klipper] | HDMI Screen: | " - echo -e "| | 6) [KlipperScreen] | " - echo -e "| Klipper API: | | " - echo -e "| 2) [Moonraker] | Other: | " - echo -e "| 3) [Moonraker DB] | 7) [OctoPrint] | " - echo -e "| | 8) [MoonrakerTelegramBot] | " + echo -e "| Klipper & API: | Touchscreen GUI: |" + echo -e "| 1) [Klipper] | 7) [KlipperScreen] |" + echo -e "| 2) [Moonraker] | |" + echo -e "| 3) [Configuration Folder] | 3rd Party Webinterface: |" + echo -e "| 4) [Moonraker Database] | 8) [OctoPrint] |" + echo -e "| | |" + echo -e "| Klipper Webinterface: | Other: |" + echo -e "| 5) [Mainsail] | 9) [Telegram Bot] |" + echo -e "| 6) [Fluidd] | |" back_footer } @@ -35,24 +34,24 @@ function backup_menu(){ while true; do read -p "${cyan}####### Perform action:${white} " action case "${action}" in - 0) - do_action "backup_klipper_config_dir" "backup_ui";; 1) do_action "backup_klipper" "backup_ui";; 2) do_action "backup_moonraker" "backup_ui";; 3) - do_action "backup_moonraker_database" "backup_ui";; + do_action "backup_klipper_config_dir" "backup_ui";; 4) - do_action "backup_mainsail" "backup_ui";; + do_action "backup_moonraker_database" "backup_ui";; 5) - do_action "backup_fluidd" "backup_ui";; + do_action "backup_mainsail" "backup_ui";; 6) - do_action "backup_klipperscreen" "backup_ui";; + do_action "backup_fluidd" "backup_ui";; 7) - do_action "backup_octoprint" "backup_ui";; + do_action "backup_klipperscreen" "backup_ui";; 8) - do_action "backup_MoonrakerTelegramBot" "backup_ui";; + do_action "backup_octoprint" "backup_ui";; + 9) + do_action "backup_telegram_bot" "backup_ui";; B|b) clear; main_menu; break;; *) From bacc611b301c6b49365d1356645e553db4739072 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 14:46:25 +0200 Subject: [PATCH 148/183] refactor: tweak other menus visual appearance Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/advanced_menu.sh | 18 +++++++++--------- scripts/ui/install_menu.sh | 28 +++++++++++++-------------- scripts/ui/main_menu.sh | 10 +++++----- scripts/ui/remove_menu.sh | 31 +++++++++++++++--------------- scripts/ui/settings_menu.sh | 12 ++++++++++++ scripts/ui/update_menu.sh | 38 ++++++++++++++++++------------------- 6 files changed, 75 insertions(+), 62 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 62da3fa..d3e89b9 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -13,16 +13,16 @@ set -e function advanced_ui(){ top_border - echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} | " + echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} |" hr - echo -e "| Klipper: | Mainsail: | " - echo -e "| 1) [Rollback] | 6) [Theme installer] | " - echo -e "| | | " - echo -e "| Firmware: | System: | " - echo -e "| 2) [Build only] | 7) [Change hostname] | " - echo -e "| 3) [Flash only] | | " - echo -e "| 4) [Build + Flash] | Extras: | " - echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] | " + echo -e "| Klipper: | Mainsail: |" + echo -e "| 1) [Rollback] | 6) [Theme installer] |" + echo -e "| | |" + echo -e "| Firmware: | System: |" + echo -e "| 2) [Build only] | 7) [Change hostname] |" + echo -e "| 3) [Flash only] | |" + echo -e "| 4) [Build + Flash] | Extras: |" + echo -e "| 5) [Get MCU ID] | 8) [G-Code Shell Command] |" back_footer } diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index dd99cb4..0cdb4de 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -13,22 +13,22 @@ set -e function install_ui(){ top_border - echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} | " + echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${white} |" hr - echo -e "| You need this menu usually only for installing | " - echo -e "| all necessary dependencies for the various | " - echo -e "| functions on a completely fresh system. | " + echo -e "| You need this menu usually only for installing |" + echo -e "| all necessary dependencies for the various |" + echo -e "| functions on a completely fresh system. |" hr - echo -e "| Firmware & API: | 3rd Party Webinterface: | " - echo -e "| 1) [Klipper] | 6) [OctoPrint] | " - echo -e "| 2) [Moonraker] | | " - echo -e "| | Other: | " - echo -e "| Klipper Webinterface: | 7) [PrettyGCode] | " - echo -e "| 3) [Mainsail] | 8) [Telegram Bot] | " - echo -e "| 4) [Fluidd] | | " - echo -e "| | Webcam Streamer: | " - echo -e "| Touchscreen GUI: | 9) [MJPG-Streamer] | " - echo -e "| 5) [KlipperScreen] | | " + echo -e "| Firmware & API: | 3rd Party Webinterface: |" + echo -e "| 1) [Klipper] | 6) [OctoPrint] |" + echo -e "| 2) [Moonraker] | |" + echo -e "| | Other: |" + echo -e "| Klipper Webinterface : | 7) [PrettyGCode] |" + echo -e "| 3) [Mainsail] | 8) [Telegram Bot] |" + echo -e "| 4) [Fluidd] | |" + echo -e "| | Webcam Streamer: |" + echo -e "| Touchscreen GUI: | 9) [MJPG-Streamer] |" + echo -e "| 5) [KlipperScreen] | |" back_footer } diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 6d69ae0..3f43eea 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -39,13 +39,13 @@ function get_kiauh_version(){ function kiauh_update_dialog(){ [ ! "$(kiauh_update_avail)" == "true" ] && return top_border - echo -e "|${green} New KIAUH update available! ${white}| " + echo -e "|${green} New KIAUH update available! ${white}|" hr - echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}| " + echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}|" blank_line - echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}| " - echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}| " - echo -e "|${yellow} features. Please consider updating! ${white}| " + echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}|" + echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|" + echo -e "|${yellow} features. Please consider updating! ${white}|" bottom_border read -p "${cyan}Do you want to update now? (Y/n):${white} " yn while true; do diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 3c89096..0da186c 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -13,19 +13,20 @@ set -e function remove_ui(){ top_border - echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} | " + echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${white} |" hr - echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} | " + echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |" hr - echo -e "| Firmware: | Touchscreen GUI: | " - echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " - echo -e "| | | " - echo -e "| Klipper API: | Other: | " - echo -e "| 2) [Moonraker] | 6) [OctoPrint] | " - echo -e "| | 7) [PrettyGCode] | " - echo -e "| Klipper Webinterface: | 8) [Telegram Bot] | " - echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] | " - echo -e "| 4) [Fluidd] | 10) [NGINX] | " + echo -e "| Firmware & API: | 3rd Party Webinterface: |" + echo -e "| 1) [Klipper] | 6) [OctoPrint] |" + echo -e "| 2) [Moonraker] | |" + echo -e "| | Webcam Streamer: |" + echo -e "| Klipper Webinterface: | 7) [MJPG-Streamer] |" + echo -e "| 3) [Mainsail] | |" + echo -e "| 4) [Fluidd] | Other: |" + echo -e "| | 8) [PrettyGCode] |" + echo -e "| Touchscreen GUI: | 9) [Telegram Bot] |" + echo -e "| 5) [KlipperScreen] | 10) [NGINX] |" back_footer } @@ -47,11 +48,11 @@ function remove_menu(){ 6) do_action "remove_octoprint" "remove_ui";; 7) - do_action "remove_prettygcode" "remove_ui";; - 8) - do_action "remove_telegram_bot" "remove_ui";; - 9) do_action "remove_mjpg-streamer" "remove_ui";; + 8) + do_action "remove_prettygcode" "remove_ui";; + 9) + do_action "remove_telegram_bot" "remove_ui";; 10) do_action "remove_nginx" "remove_ui";; B|b) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 6a33505..1a050a5 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -74,6 +74,7 @@ function settings_ui() { hr echo -e "| 1) Change Klipper config folder location |" echo -e "| 2) Set custom Klipper repository |" + blank_line if [ "${mainsail_install_unstable}" == "false" ]; then echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |" else @@ -84,6 +85,7 @@ function settings_ui() { else echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |" fi + blank_line if [ "${backup_before_update}" == "false" ]; then echo -e "| 5) ${green}Enable${white} automatic backups before updates |" else @@ -117,6 +119,16 @@ function show_settings_help(){ blank_line echo -e "| Default: ${red}false${white} |" blank_line + hr + echo -e "| ${cyan}Backup before updating:${white} |" + echo -e "| If set to true, KIAUH will automatically create a |" + echo -e "| backup from the corresponding component you are about |" + echo -e "| to update before actually updating it, preserving the |" + echo -e "| current state of the component in a safe location. |" + echo -e "| All backups are stored in '~/kiauh_backups'. |" + blank_line + echo -e "| Default: ${red}false${white} |" + blank_line back_footer while true; do read -p "${cyan}###### Please select:${white} " choice diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 31ccd99..f952a98 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -13,26 +13,26 @@ set -e function update_ui(){ top_border - echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} | " + echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} |" hr - echo -e "| a) [Update all] | | | " - echo -e "| | Installed: | Latest: | " - echo -e "| Klipper & API: |---------------|--------------| " - echo -e "| 1) [Klipper] |$(compare_klipper_versions)| " - echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)| " - echo -e "| | | | " - echo -e "| Webinterface: |---------------|--------------| " - echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)| " - echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)| " - echo -e "| | | | " - echo -e "| Touchscreen GUI: |---------------|--------------| " - echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)| " - echo -e "| | | | " - echo -e "| Other: |---------------|--------------| " - echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)| " - echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)| " - echo -e "| |------------------------------| " - echo -e "| 8) [System] | $(check_system_updates) | " + echo -e "| a) [Update all] | | |" + echo -e "| | Installed: | Latest: |" + echo -e "| Klipper & API: |---------------|--------------|" + echo -e "| 1) [Klipper] |$(compare_klipper_versions)|" + echo -e "| 2) [Moonraker] |$(compare_moonraker_versions)|" + echo -e "| | | |" + echo -e "| Klipper Webinterface: |---------------|--------------|" + echo -e "| 3) [Mainsail] |$(compare_mainsail_versions)|" + echo -e "| 4) [Fluidd] |$(compare_fluidd_versions)|" + echo -e "| | | |" + echo -e "| Touchscreen GUI: |---------------|--------------|" + echo -e "| 5) [KlipperScreen] |$(compare_klipperscreen_versions)|" + echo -e "| | | |" + echo -e "| Other: |---------------|--------------|" + echo -e "| 6) [PrettyGCode] |$(compare_prettygcode_versions)|" + echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)|" + echo -e "| |------------------------------|" + echo -e "| 8) [System] | $(check_system_updates) |" back_footer } From bf2b24891c3e7f030b22187c45919dde79280fb2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 14:50:00 +0200 Subject: [PATCH 149/183] refactor: add local keyword Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 2 +- scripts/moonraker.sh | 2 +- scripts/nginx.sh | 2 +- scripts/octoprint.sh | 2 +- scripts/pretty_gcode.sh | 4 ++-- scripts/utilities.sh | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index bcb88d7..be92d6a 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -269,7 +269,7 @@ function build_fw(){ else cd "${KLIPPER_DIR}" status_msg "Initializing firmware build ..." - dep=(build-essential dpkg-dev make) + local dep=(build-essential dpkg-dev make) dependency_check "${dep[@]}" make clean && make menuconfig diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 75fb5ea..5272ff3 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -114,7 +114,7 @@ function create_moonraker_virtualenv(){ function moonraker_setup(){ local confirm_msg instances=${1} ### checking dependencies - dep=(git wget curl unzip dfu-util virtualenv) + local dep=(git wget curl unzip dfu-util virtualenv) ### additional required dependencies on armbian dep+=(libjpeg-dev zlib1g-dev) dependency_check "${dep[@]}" diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 5998680..b06f7aa 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -248,7 +248,7 @@ function set_nginx_cfg(){ if [ "${SET_NGINX_CFG}" = "true" ]; then local cfg="${SRCDIR}/kiauh/resources/${1}" #check for dependencies - dep=(nginx) + local dep=(nginx) dependency_check "${dep[@]}" #execute operations status_msg "Creating Nginx configuration for ${1} ..." diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 042b8fd..dd84ed8 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -68,7 +68,7 @@ function octoprint_setup_dialog(){ function octoprint_setup(){ local instances="${1}" ### check and install all dependencies - dep=( + local dep=( git wget python3-pip diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh index 341fb55..a2fffbe 100644 --- a/scripts/pretty_gcode.sh +++ b/scripts/pretty_gcode.sh @@ -26,8 +26,8 @@ function install_pgc_for_klipper(){ echo -e "${cyan}\n###### On which port should PrettyGCode run? (Default: ${pgc_default_port})${white} " read -e -p "${cyan}###### Port:${white} " -i "${pgc_default_port}" pgc_custom_port ### check nginx dependency - dep=(nginx) - dependency_check + local dep=(nginx) + dependency_check "${dep[@]}" ### clone repo [ -d "${PGC_DIR}" ] && rm -rf "${PGC_DIR}" cd "${HOME}" && git clone "${PGC_FOR_KLIPPER_REPO}" diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 0a1bb5b..f0a324f 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -577,7 +577,7 @@ function change_hostname(){ function set_hostname(){ local new_hostname=${1} current_date #check for dependencies - dep=(avahi-daemon) + local dep=(avahi-daemon) dependency_check "${dep[@]}" #create host file if missing or create backup of existing one with current date&time From d87132fc88e9c44267c85be85e064f6e7079566e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 14:57:14 +0200 Subject: [PATCH 150/183] logging: log which function is reading .kiauh.ini Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 2 +- scripts/fluidd.sh | 2 +- scripts/klipper.sh | 4 ++-- scripts/mainsail.sh | 2 +- scripts/nginx.sh | 2 +- scripts/ui/settings_menu.sh | 2 +- scripts/upload_log.sh | 2 +- scripts/utilities.sh | 11 ++++++----- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index bc1ea26..7ab9be2 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -23,7 +23,7 @@ function check_for_backup_dir(){ } function backup_before_update(){ - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" # shellcheck disable=SC2154 local state="${backup_before_update}" [ "${state}" = "false" ] && return diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 00025db..e9395c0 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -312,7 +312,7 @@ function get_fluidd_download_url() { stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1) stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip" - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" if [ "${fluidd_install_unstable}" == "true" ]; then url="${latest_url}" echo "${url}" diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 34bfdb7..6dee58a 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -134,7 +134,7 @@ function create_klipper_virtualenv(){ } function klipper_setup(){ - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local custom_repo="${custom_klipper_repo}" local custom_branch="${custom_klipper_repo_branch}" local instances=${1} python_version=${2} @@ -427,7 +427,7 @@ function compare_klipper_versions(){ function get_klipper_cfg_dir() { local cfg_dir - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" if [ -z "${custom_klipper_cfg_loc}" ]; then cfg_dir="${HOME}/klipper_config" else diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 1b3f60b..dcd3e81 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -428,7 +428,7 @@ function get_mainsail_download_url() { stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1) stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip" - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" if [ "${mainsail_install_unstable}" == "true" ]; then url="${latest_url}" echo "${url}" diff --git a/scripts/nginx.sh b/scripts/nginx.sh index b06f7aa..451087b 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -83,7 +83,7 @@ function symlink_webui_nginx_log(){ function match_nginx_configs(){ local cfg_updated="false" ### reinstall nginx configs if the amount of upstreams don't match anymore - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 1a050a5..3f716c0 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -12,7 +12,7 @@ set -e function settings_ui() { - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local custom_cfg_loc="${custom_klipper_cfg_loc}" local custom_repo="${custom_klipper_repo}" local custom_branch="${custom_klipper_repo_branch}" diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 05185d4..d315988 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -33,7 +33,7 @@ function accept_upload_conditions(){ } function upload_selection(){ - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local upload_agreed="${logupload_accepted}" [ "${upload_agreed}" = "false" ] && accept_upload_conditions diff --git a/scripts/utilities.sh b/scripts/utilities.sh index f0a324f..61fd292 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -99,12 +99,13 @@ function log_error() { #================================================# function read_kiauh_ini(){ + local func=${1} if [ ! -f "${INI_FILE}" ]; then print_error "ERROR: File '~/.kiauh.ini' not found!" log_error "Reading from .kiauh.ini failed! File not found!" return 1 fi - log_info "Reading from .kiauh.ini" + log_info "${func}: reading from .kiauh.ini" source "${INI_FILE}" } @@ -287,7 +288,7 @@ function set_klipper_cfg_path(){ } function switch_mainsail_releasetype() { - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local state="${mainsail_install_unstable}" if [ "${state}" == "false" ]; then sed -i '/mainsail_install_unstable=/s/false/true/' "${INI_FILE}" @@ -299,7 +300,7 @@ function switch_mainsail_releasetype() { } function switch_fluidd_releasetype() { - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local state="${fluidd_install_unstable}" if [ "${state}" == "false" ]; then sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}" @@ -311,7 +312,7 @@ function switch_fluidd_releasetype() { } function toggle_backup_before_update(){ - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local state="${backup_before_update}" if [ "${state}" = "false" ]; then sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}" @@ -321,7 +322,7 @@ function toggle_backup_before_update(){ } function set_custom_klipper_repo() { - read_kiauh_ini + read_kiauh_ini "${FUNCNAME[0]}" local repo_url=${1} branch=${2} sed -i "/^custom_klipper_repo=/d" "${INI_FILE}" sed -i '$a'"custom_klipper_repo=${repo_url}" "${INI_FILE}" From 9bf5a60bfd4c48eb90cbcd0fe07741d094fddd1d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 15:21:48 +0200 Subject: [PATCH 151/183] logging: add log initializer function Signed-off-by: Dominik Willner th33xitus@gmail.com --- kiauh.sh | 1 + scripts/ui/main_menu.sh | 10 ++++++++-- scripts/utilities.sh | 11 +++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 868547b..ecadc64 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -49,6 +49,7 @@ function kiauh_update_avail(){ } check_euid +init_logfile set_globals init_ini kiauh_update_avail diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 3f43eea..3cbfe76 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -25,14 +25,20 @@ function main_ui(){ echo -e "| | KlipperScreen: $(klipperscreen_status)|" echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" echo -e "| | |" - echo -e "| $(get_kiauh_version)| Octoprint: $(octoprint_status)|" + echo -e "| $(print_kiauh_version)| Octoprint: $(octoprint_status)|" quit_footer } function get_kiauh_version(){ local version cd "${SRCDIR}/kiauh" - version="$(printf "%-20s" "$(git describe HEAD --always --tags | cut -d "-" -f 1,2)")" + version="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" + echo "${version}" +} + +function print_kiauh_version(){ + local version + version="$(printf "%-20s" "$(get_kiauh_version)")" echo "${cyan}${version}${white}" } diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 61fd292..4ab6629 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -79,6 +79,17 @@ function timestamp() { date +"[%F %T]" } +function init_logfile() { + local log="/tmp/kiauh.log" + { + echo -e "#================================================================#" + echo -e "# New KIAUH session started on: $(date) #" + echo -e "#================================================================#" + echo -e "KIAUH $(get_kiauh_version)" + echo -e "#================================================================#" + } >> "${log}" +} + function log_info() { local message="${1}" log="${LOGFILE}" echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" From 29f0afb96bd7502ee602b956a5870edd0654539b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 11:53:38 +0200 Subject: [PATCH 152/183] refactor: remove update_log_path function - was introduced due to a change in moonraker in may 2021. as it is now almost 12 month ago, there is likely no need for it anymore. it can probably be assumed that every user now has updated services and configs by now. Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 1 - scripts/moonraker.sh | 53 -------------------------------------------- 2 files changed, 54 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 6dee58a..e2ff050 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -349,7 +349,6 @@ function update_klipper(){ ### install possible new python dependencies /bin/bash "${KLIPPY_ENV}/bin/pip" install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt" fi - update_log_paths "klipper" ok_msg "Update complete!" do_action_service "restart" "klipper" } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 5272ff3..e44d757 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -406,7 +406,6 @@ function update_moonraker(){ ### required due to https://github.com/Arksine/moonraker/issues/349 moonraker_polkit - update_log_paths "moonraker" ok_msg "Update complete!" do_action_service "restart" "moonraker" } @@ -471,56 +470,4 @@ function compare_moonraker_versions(){ MOONRAKER_UPDATE_AVAIL="false" fi echo "${versions}" -} - -#==================================================# -#==================== HELPERS =====================# -#==================================================# - -function update_log_paths(){ - ### update services to make use of moonrakers new log_path option - ### https://github.com/Arksine/moonraker/commit/829b3a4ee80579af35dd64a37ccc092a1f67682a - shopt -s extglob # enable extended globbing - source_kiauh_ini - LPATH="${HOME}/klipper_logs" - [ ! -d "$LPATH" ] && mkdir -p "$LPATH" - FILE="$SYSTEMDDIR/$1?(-*([0-9])).service" - for file in $(ls $FILE); do - [ "$1" == "klipper" ] && LOG="klippy" - [ "$1" == "moonraker" ] && LOG="moonraker" - if [ ! "$(grep "\-l" $file)" ]; then - status_msg "Updating $file ..." - sudo sed -i -r "/ExecStart=/ s|$| -l $LPATH/$LOG.log|" $file - ok_msg "$file updated!" - elif [ "$(grep "\-l \/tmp\/$LOG" $file)" ]; then - status_msg "Updating $file ..." - sudo sed -i -r "/ExecStart=/ s|-l \/tmp\/$LOG|-l $LPATH/$LOG|" $file - ok_msg "$file updated!" - fi - done - sudo systemctl daemon-reload - - # patch log_path entry if not found - dir1="$klipper_cfg_loc" - dir2="$klipper_cfg_loc/printer_*" - for conf in $(find $dir1 $dir2 -name "moonraker.conf" 2> /dev/null); do - if ! grep -q "log_path" $conf; then - status_msg "Patching $conf" - sed -i "/^config_path/a log_path: $LPATH" $conf - ok_msg "OK!" - fi - done - - # create symlink for mainsail and fluidd nginx logs - symlink_webui_nginx_log "mainsail" - symlink_webui_nginx_log "fluidd" - - # create symlink for webcamd log - if [ -f "/var/log/webcamd.log" ] && [ ! -L "$LPATH/webcamd.log" ]; then - status_msg "Creating symlink for '/var/log/webcamd.log' ..." - ln -s "/var/log/webcamd.log" "$LPATH" - ok_msg "OK!" - fi - - shopt -u extglob # disable extended globbing } \ No newline at end of file From 0e2f2a3c938e22aac7f3f7c90c361f2a7e05de32 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 13:17:58 +0200 Subject: [PATCH 153/183] refactor: add kiauh resources to globals.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/globals.sh b/scripts/globals.sh index 964b3e1..daec422 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -27,6 +27,7 @@ function set_globals(){ white=$(echo -en "\e[39m") INI_FILE="${HOME}/.kiauh.ini" LOGFILE="/tmp/kiauh.log" + RESOURCES="${SRCDIR}/kiauh/resources" BACKUP_DIR="${HOME}/kiauh-backups" #================== KLIPPER ===================# From 978a117d6a177fad15a0d0b3001dec65220aacdb Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 13:18:10 +0200 Subject: [PATCH 154/183] refactor: nginx related functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/nginx.sh | 169 +++++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 87 deletions(-) diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 451087b..789372b 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -41,10 +41,16 @@ function remove_nginx(){ function set_upstream_nginx_cfg(){ local current_date current_date=$(get_date) + local upstreams="${NGINX_CONFD}/upstreams.conf" + local common_vars="${NGINX_CONFD}/common_vars.conf" ### backup existing nginx configs [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" - [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" - [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" + if [ -f "${upstreams}" ]; then + sudo mv "${upstreams}" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" + fi + if [ -f "${common_vars}" ]; then + sudo mv "${common_vars}" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" + fi ### transfer ownership of backed up files from root to ${USER} local files files=$(find "${BACKUP_DIR}/nginx_cfg") @@ -55,81 +61,75 @@ function set_upstream_nginx_cfg(){ fi done ### copy nginx configs to target destination - if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "${NGINX_CONFD}" - fi - if [ ! -f "${NGINX_CONFD}/common_vars.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "${NGINX_CONFD}" - fi + [ ! -f "${upstreams}" ] && sudo cp "${RESOURCES}/upstreams.conf" "${upstreams}" + [ ! -f "${common_vars}" ] && sudo cp "${RESOURCES}/common_vars.conf" "${common_vars}" } function symlink_webui_nginx_log(){ - local path="${HOME}/klipper_logs" - local access_log="/var/log/nginx/${1}-access.log" - local error_log="/var/log/nginx/${1}-error.log" + local interface=${1} path="${HOME}/klipper_logs" + local access_log="/var/log/nginx/${interface}-access.log" + local error_log="/var/log/nginx/${interface}-error.log" [ ! -d "${path}" ] && mkdir -p "${path}" - if [ -f "${access_log}" ] && [ ! -L "${path}/${1}-access.log" ]; then + if [ -f "${access_log}" ] && [ ! -L "${path}/${interface}-access.log" ]; then status_msg "Creating symlink for ${access_log} ..." ln -s "${access_log}" "${path}" - ok_msg "OK!" + ok_msg "Done!" fi - if [ -f "${error_log}" ] && [ ! -L "${path}/${1}-error.log" ]; then + if [ -f "${error_log}" ] && [ ! -L "${path}/${interface}-error.log" ]; then status_msg "Creating symlink for ${error_log} ..." ln -s "${error_log}" "${path}" - ok_msg "OK!" + ok_msg "Done!" fi } function match_nginx_configs(){ - local cfg_updated="false" - ### reinstall nginx configs if the amount of upstreams don't match anymore read_kiauh_ini "${FUNCNAME[0]}" - mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" - fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" - upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) + local require_service_restart="false" + local upstreams="${NGINX_CONFD}/upstreams.conf" + local common_vars="${NGINX_CONFD}/common_vars.conf" + local mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" + local fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" + local upstreams_webcams mainsail_webcams fluidd_webcams + + ### reinstall nginx configs if the amount of upstreams don't match anymore + upstreams_webcams=$(grep -Ec "mjpgstreamer" "/etc/nginx/conf.d/upstreams.conf") + mainsail_webcams=$(grep -Ec "mjpgstreamer" "${mainsail_nginx_cfg}" 2>/dev/null || echo "0") + fluidd_webcams=$(grep -Ec "mjpgstreamer" "${fluidd_nginx_cfg}" 2>/dev/null || echo "0") status_msg "Checking validity of NGINX configurations ..." - if [ -e "${mainsail_nginx_cfg}" ]; then - mainsail_webcams=$(grep -E "mjpgstreamer" "${mainsail_nginx_cfg}" | wc -l) - fi - if [ -e "${fluidd_nginx_cfg}" ]; then - fluidd_webcams=$(grep -E "mjpgstreamer" "${fluidd_nginx_cfg}" | wc -l) - fi ### check for outdated upstreams.conf - if [[ "${upstreams_webcams}" -lt "${mainsail_webcams}" ]] || [[ "${upstreams_webcams}" -lt "${fluidd_webcams}" ]]; then + if ((upstreams_webcams < mainsail_webcams || upstreams_webcams < fluidd_webcams)); then status_msg "Outdated upstreams.conf found! Updating ..." - sudo rm -f "${NGINX_CONFD}/upstreams.conf" - sudo rm -f "${NGINX_CONFD}/common_vars.conf" + sudo rm -f "${upstreams}" "${common_vars}" set_upstream_nginx_cfg - cfg_updated="true" + require_service_restart="true" + ok_msg "Done!" fi ### check for outdated mainsail config - if [ -e "${mainsail_nginx_cfg}" ]; then - if [[ "${upstreams_webcams}" -gt "${mainsail_webcams}" ]]; then - status_msg "Outdated Mainsail config found! Updating ..." - sudo rm -f "${mainsail_nginx_cfg}" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}" - sudo sed -i "s/<>/mainsail/g" "${mainsail_nginx_cfg}" - sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}" - sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}" - cfg_updated="true" && ok_msg "Done!" - fi + if [ -e "${mainsail_nginx_cfg}" ] && ((upstreams_webcams > mainsail_webcams)); then + status_msg "Outdated Mainsail config found! Updating ..." + sudo rm -f "${mainsail_nginx_cfg}" + sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}" + sudo sed -i "s/<>/mainsail/g" "${mainsail_nginx_cfg}" + sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}" + sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}" + sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}" + require_service_restart="true" + ok_msg "Done!" fi ### check for outdated fluidd config - if [ -e "${fluidd_nginx_cfg}" ]; then - if [[ "${upstreams_webcams}" -gt "${fluidd_webcams}" ]]; then - status_msg "Outdated Fluidd config found! Updating ..." - sudo rm -f "${fluidd_nginx_cfg}" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}" - sudo sed -i "s/<>/fluidd/g" "${fluidd_nginx_cfg}" - sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}" - sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}" - cfg_updated="true" && ok_msg "Done!" - fi + if [ -e "${fluidd_nginx_cfg}" ] && ((upstreams_webcams > fluidd_webcams)); then + status_msg "Outdated Fluidd config found! Updating ..." + sudo rm -f "${fluidd_nginx_cfg}" + sudo cp "${RESOURCES}/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}" + sudo sed -i "s/<>/fluidd/g" "${fluidd_nginx_cfg}" + sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}" + sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}" + sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}" + require_service_restart="true" + ok_msg "Done!" fi ### only restart nginx if configs were updated - [ "${cfg_updated}" == "true" ] && do_action_service "restart" "nginx" + [ "${require_service_restart}" == "true" ] && sudo systemctl restart nginx.service } function process_disruptive_services(){ @@ -245,74 +245,69 @@ function process_services_dialog(){ } function set_nginx_cfg(){ + local interface=${1} if [ "${SET_NGINX_CFG}" = "true" ]; then - local cfg="${SRCDIR}/kiauh/resources/${1}" + local cfg="${RESOURCES}/${interface}" #check for dependencies local dep=(nginx) dependency_check "${dep[@]}" #execute operations - status_msg "Creating Nginx configuration for ${1} ..." + status_msg "Creating Nginx configuration for ${interface^} ..." #copy content from resources to the respective nginx config file - cat "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" > "${cfg}" + cat "${RESOURCES}/klipper_webui_nginx.cfg" > "${cfg}" ##edit the nginx config file before moving it - sed -i "s/<>/${1}/g" "${cfg}" + sed -i "s/<>/${interface}/g" "${cfg}" if [ "${SET_LISTEN_PORT}" != "${DEFAULT_PORT}" ]; then - status_msg "Configuring port for $1 ..." + status_msg "Configuring port for ${interface^} ..." #set listen port ipv4 sed -i "s/listen\s[0-9]*;/listen ${SET_LISTEN_PORT};/" "${cfg}" #set listen port ipv6 sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${SET_LISTEN_PORT};/" "${cfg}" fi #set correct user - if [ "${1}" = "mainsail" ] || [ "${1}" = "fluidd" ]; then + if [ "${interface}" = "mainsail" ] || [ "${interface}" = "fluidd" ]; then sudo sed -i "/root/s/pi/${USER}/" "${cfg}" fi #moving the config file into correct directory - sudo mv "${cfg}" "/etc/nginx/sites-available/${1}" - ok_msg "Nginx configuration for $1 was set!" + sudo mv "${cfg}" "/etc/nginx/sites-available/${interface}" + ok_msg "Nginx configuration for ${interface^} was set!" if [ -n "${SET_LISTEN_PORT}" ]; then - ok_msg "${1} listening on port ${SET_LISTEN_PORT}!" + ok_msg "${interface^} configured for port ${SET_LISTEN_PORT}!" else - ok_msg "${1} listening on default port ${DEFAULT_PORT}!" + ok_msg "${interface^} configured for default port ${DEFAULT_PORT}!" fi #remove nginx default config - [ -e "/etc/nginx/sites-enabled/default" ] && sudo rm "/etc/nginx/sites-enabled/default" + if [ -e "/etc/nginx/sites-enabled/default" ]; then + sudo rm "/etc/nginx/sites-enabled/default" + fi #create symlink for own sites - [ ! -e "/etc/nginx/sites-enabled/${1}" ] && sudo ln -s "/etc/nginx/sites-available/${1}" "/etc/nginx/sites-enabled/" - - do_action_service "restart" "nginx" + if [ ! -e "/etc/nginx/sites-enabled/${interface}" ]; then + sudo ln -s "/etc/nginx/sites-available/${interface}" "/etc/nginx/sites-enabled/" + fi + sudo systemctl restart nginx.service fi } function read_listen_port(){ - LISTEN_PORT=$(grep listen "/etc/nginx/sites-enabled/${1}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + local port interface=${1} + port=$(grep listen "/etc/nginx/sites-enabled/${interface}" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + echo "${port}" } function detect_enabled_sites(){ - #check if there is another UI config already installed - #and reads the port they are listening on + MAINSAIL_ENABLED="false" FLUIDD_ENABLED="false" OCTOPRINT_ENABLED="false" + #check if there is another UI config already installed and reads the port they are listening on if [ -e "/etc/nginx/sites-enabled/mainsail" ]; then SITE_ENABLED="true" && MAINSAIL_ENABLED="true" - read_listen_port "mainsail" - MAINSAIL_PORT=${LISTEN_PORT} - #echo "debug: Mainsail listens on port: $MAINSAIL_PORT" - else - MAINSAIL_ENABLED="false" + MAINSAIL_PORT=$(read_listen_port "mainsail") fi - if [ -e /etc/nginx/sites-enabled/fluidd ]; then + if [ -e "/etc/nginx/sites-enabled/fluidd" ]; then SITE_ENABLED="true" && FLUIDD_ENABLED="true" - read_listen_port "fluidd" - FLUIDD_PORT=${LISTEN_PORT} - #echo "debug: Fluidd listens on port: $FLUIDD_PORT" - else - FLUIDD_ENABLED="false" + FLUIDD_PORT=$(read_listen_port "fluidd") + fi - if [ -e /etc/nginx/sites-enabled/octoprint ]; then + if [ -e "/etc/nginx/sites-enabled/octoprint" ]; then SITE_ENABLED="true" && OCTOPRINT_ENABLED="true" - read_listen_port "octoprint" - OCTOPRINT_PORT=${LISTEN_PORT} - #echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT" - else - OCTOPRINT_ENABLED="false" + OCTOPRINT_PORT=$(read_listen_port "octoprint") fi } \ No newline at end of file From 94f574d5b04fb3a7e8a4de84f1b2edb50e39b130 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 14:16:27 +0200 Subject: [PATCH 155/183] refactor: some tweaks Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 2 +- scripts/utilities.sh | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index e9395c0..30688db 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -22,7 +22,7 @@ function install_fluidd(){ print_error "${error}" && return fi ### checking dependencies - local dep=(nginx) + local dep=(wget nginx) dependency_check "${dep[@]}" ### check if moonraker is already installed system_check_webui diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 4ab6629..0e4e842 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -116,7 +116,7 @@ function read_kiauh_ini(){ log_error "Reading from .kiauh.ini failed! File not found!" return 1 fi - log_info "${func}: reading from .kiauh.ini" + log_info "Reading from .kiauh.ini ... (${func})" source "${INI_FILE}" } @@ -411,11 +411,6 @@ function dependency_check(){ } function system_check_webui(){ - ### check system for an installed and enabled octoprint service - if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then - OCTOPRINT_ENABLED="true" - fi - ### check system for an installed haproxy service if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then HAPROXY_FOUND="true" @@ -433,13 +428,12 @@ function system_check_webui(){ } function fetch_webui_ports(){ - ### read listen ports from possible installed interfaces - ### and write them to ~/.kiauh.ini - WEBIFS=(mainsail fluidd octoprint) - for interface in "${WEBIFS[@]}"; do + ### read ports from possible installed interfaces and write them to ~/.kiauh.ini + local interfaces=("mainsail" "fluidd" "octoprint") + for interface in "${interfaces[@]}"; do if [ -f "/etc/nginx/sites-available/${interface}" ]; then port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) - if [ ! -n "$(grep -E "${interface}_port" "${INI_FILE}")" ]; then + if ! grep -Eq "${interface}_port" "${INI_FILE}"; then sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" else sed -i "/^${interface}_port/d" "${INI_FILE}" @@ -481,10 +475,10 @@ function update_system(){ function check_usergroups(){ local group_dialout group_tty if grep -q "dialout" Date: Sun, 24 Apr 2022 14:19:09 +0200 Subject: [PATCH 156/183] refactor: some tweaks Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 0e4e842..14041fe 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -92,17 +92,17 @@ function init_logfile() { function log_info() { local message="${1}" log="${LOGFILE}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" + echo -e "$(timestamp) [INFO]: ${message}" | tr -s " " >> "${log}" } function log_warning() { local message="${1}" log="${LOGFILE}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" + echo -e "$(timestamp) [WARN]: ${message}" | tr -s " " >> "${log}" } function log_error() { local message="${1}" log="${LOGFILE}" - echo -e "$(timestamp) ${message}" | tr -s " " >> "${log}" + echo -e "$(timestamp) [ERR]: ${message}" | tr -s " " >> "${log}" } #================================================# From 4a503c494b355f74c223bdfdf40ee7724f6ed324 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 14:24:21 +0200 Subject: [PATCH 157/183] refactor: move nginx globals to globals.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 5 +++++ scripts/nginx.sh | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index daec422..531dfef 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -64,4 +64,9 @@ function set_globals(){ #=============== PRETTY-GCODE =================# PGC_DIR="${HOME}/pgcode" PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" + + #================== NGINX =====================# + NGINX_SA="/etc/nginx/sites-available" + NGINX_SE="/etc/nginx/sites-enabled" + NGINX_CONFD="/etc/nginx/conf.d" } \ No newline at end of file diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 789372b..92ee8a0 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -11,11 +11,6 @@ set -e -### global variables -NGINX_SA="/etc/nginx/sites-available" -NGINX_SE="/etc/nginx/sites-enabled" -NGINX_CONFD="/etc/nginx/conf.d" - #===================================================# #=================== REMOVE NGINX ==================# #===================================================# From 704aef97ff7d9961ce448b2221b673cdeee2a44a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 14:24:45 +0200 Subject: [PATCH 158/183] refactor: add copyright notice and shebang to upload_log.sh Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/upload_log.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index d315988..5f66531 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + function accept_upload_conditions(){ top_border echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |" From 8f2cf3b9a147585bcca5909a523ccd29b65be228 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 24 Apr 2022 15:35:17 +0200 Subject: [PATCH 159/183] refactor: rollback function Signed-off-by: Dominik Willner th33xitus@gmail.com --- docs/changelog.md | 3 + scripts/rollback.sh | 165 ++++++++++++++---------------------- scripts/ui/advanced_menu.sh | 4 +- 3 files changed, 67 insertions(+), 105 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 65d31f1..05f92c6 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,9 @@ KIAUH has now reached major version 4 ! * refactor: Rewriting a lot of functions to pass shellcheck checks * refactor: The update manager sections for Mainsail, Fluidd and KlipperScreen were removed from the moonraker.conf template * They will now be individually added during installation of the corresponding interface +* refactor: The rollback function was reworked and now also allows rollbacks of Moonraker + * It now takes numerical inputs and reverts the corresponding repository by the given amount instead + * KIAUH does not save previous states to its config anymore like it did with the previous approach ### 2022-01-29 diff --git a/scripts/rollback.sh b/scripts/rollback.sh index 93b964b..3827083 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -11,114 +11,73 @@ set -e -function save_klipper_state(){ - source_kiauh_ini - #read current klipper state - cd $KLIPPER_DIR - COMMIT_STATE=$(git rev-parse --short HEAD) - if [ "$GET_BRANCH" = "master" ]; then - ORI_OLD=$previous_origin_state - ORI_NEW=$COMMIT_STATE - sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE - elif [ "$GET_BRANCH" = "scurve-shaping" ]; then - SHA_OLD=$previous_shaping_state - SHA_NEW=$COMMIT_STATE - sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE - elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then - SMO_OLD=$previous_smoothing_state - SMO_NEW=$COMMIT_STATE - sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE - fi -} - -function load_klipper_state(){ - source_kiauh_ini - print_branch - cd $KLIPPER_DIR - CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) - if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then - PREVIOUS_COMMIT=$previous_origin_state - elif [ "$GET_BRANCH" = "scurve-shaping" ]; then - PREVIOUS_COMMIT=$previous_shaping_state - elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then - PREVIOUS_COMMIT=$previous_smoothing_state - fi - CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT) - if [ "$PREVIOUS_COMMIT" != "0" ]; then - PREVIOUS_COMMIT_DATE=$(git show -s --format=%cd --date=short $PREVIOUS_COMMIT) - fi - if [ "$PREVIOUS_COMMIT" = "0" ]; then - CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${white}") - PREV_UI=$(echo -e "${red}None${white} ") - else - if [ "$CURRENT_COMMIT" = "$PREVIOUS_COMMIT" ]; then - CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${white}") - PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${white}") - else - CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${white}") - PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${white}") - fi - fi - rollback_ui - rollback_klipper -} - -function rollback_ui(){ +function rollback_menu(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | " + echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") |" hr - echo -e "| If serious errors occured after updating Klipper, | " - echo -e "| you can use this menu to return to the previously | " - echo -e "| used commit from which you have updated. | " - bottom_border - top_border - echo -e "| Active branch: ${green}$PRINT_BRANCH${white} | " + echo -e "| If serious errors occured after updating Klipper or |" + echo -e "| Moonraker, you can use this menu to try and reset the |" + echo -e "| repository to an earlier state. |" hr - echo -e "| Currently on commit: | " - echo -e "| $CURR_UI | " - hr - echo -e "| Commit last updated from: | " - echo -e "| $PREV_UI | " + echo -e "| 1) Rollback Klipper |" + echo -e "| 2) Rollback Moonraker |" back_footer + + while true; do + read -p "${cyan}###### Perform action:${white} " action + case "${action}" in + 1) + select_msg "Klipper" + rollback_component "klipper" + break;; + 2) + select_msg "Moonraker" + rollback_component "moonraker" + break;; + B|b) + clear; advanced_menu; break;; + *) + error_msg "Invalid command!";; + esac + done } -function rollback_klipper(){ - if [ "$PREVIOUS_COMMIT" != "0" ] && [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then - while true; do - echo -e "${cyan}" - read -p "###### Do you want to rollback to $PREVIOUS_COMMIT? (Y/n): " yn - echo -e "${white}" - case "$yn" in - Y|y|Yes|yes|"") - clear - print_header - status_msg "Rolling back to $PREVIOUS_COMMIT ..." - git reset --hard $PREVIOUS_COMMIT -q - ok_msg "Rollback complete!"; echo - load_klipper_state - break;; - N|n|No|no) clear; advanced_menu; break;; - B|b) clear; advanced_menu; break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - else - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${white}" - case "$action" in - B|b) - clear; advanced_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - rollback_ui;; - esac - done +function rollback_component() { + local component=${1} + + if [ ! -d "${HOME}/${component}" ]; then + print_error "Rollback not possible! Missing installation?" + return fi + + echo + top_border + echo -e "| Please select how many commits you want to revert. |" + echo -e "| Consider using the information provided by the Github |" + echo -e "| commit history to decide how many commits to revert. |" + blank_line + echo -e "| ${red}Warning:${white} |" + echo -e "| ${red}Do not proceed if you are currently in the progress${white} |" + echo -e "| ${red}of printing! Proceeding WILL terminate that print!${white} |" + back_footer + + while true; do + read -p "${cyan}###### Revert this amount of commits:${white} " count + if [ -n "${count}" ] && ((count > 0)); then + status_msg "Revert ${component^} by ${count} commits ..." + cd "${HOME}/${component}" + if git reset --hard HEAD~"${count}"; then + do_action_service "restart" "${component}" + print_confirm "${component^} was successfully reset!" + else + print_error "Reverting ${component^} failed! Please see the console output above." + fi + break + elif [[ "${count}" == "B" || "${count}" == "b" ]]; then + clear && print_header && break + else + error_msg "Invalid command!" + fi + done + rollback_menu } diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index d3e89b9..55985b0 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -15,7 +15,7 @@ function advanced_ui(){ top_border echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${white} |" hr - echo -e "| Klipper: | Mainsail: |" + echo -e "| Klipper & API: | Mainsail: |" echo -e "| 1) [Rollback] | 6) [Theme installer] |" echo -e "| | |" echo -e "| Firmware: | System: |" @@ -32,7 +32,7 @@ function advanced_menu(){ read -p "${cyan}####### Perform action:${white} " action case "${action}" in 1) - do_action "load_klipper_state" "advanced_ui";; + do_action "rollback_menu" "advanced_menu";; 2) do_action "build_fw" "advanced_ui";; 3) From 1e57aa5d24cadb3a80563d5416626dac2fcd0c09 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 26 Apr 2022 20:23:17 +0200 Subject: [PATCH 160/183] feat: display klipper repo in main menu Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 12 +++---- scripts/klipper.sh | 10 +++--- scripts/klipperscreen.sh | 12 +++---- scripts/mainsail.sh | 12 +++---- scripts/moonraker-telegram-bot.sh | 10 +++--- scripts/moonraker.sh | 10 +++--- scripts/octoprint.sh | 8 ++--- scripts/ui/main_menu.sh | 53 ++++++++++++++++++++++++------- 8 files changed, 78 insertions(+), 49 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 30688db..b500822 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -244,7 +244,7 @@ function update_fluidd(){ #================== FLUIDD STATUS ==================# #===================================================# -function fluidd_status(){ +function get_fluidd_status(){ local status local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd") @@ -254,12 +254,12 @@ function fluidd_status(){ [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${filecount}" == "${#data_arr[*]}" ]; then - status="${green}Installed!${white} " - elif [ "${filecount}" == 0 ]; then - status="${red}Not installed!${white} " + if (( filecount == ${#data_arr[*]})); then + status="Installed!" + elif ((filecount == 0)); then + status="Not installed!" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } diff --git a/scripts/klipper.sh b/scripts/klipper.sh index e2ff050..602790f 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -376,12 +376,12 @@ function get_klipper_status(){ [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${filecount}" == "${#data_arr[*]}" ]; then - status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" - elif [ "${filecount}" == 0 ]; then - status="${red}Not installed!${white} " + if (( filecount == ${#data_arr[*]})); then + status="Installed: ${sf_count}" + elif ((filecount == 0)); then + status="Not installed!" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index 451efe9..bd65cc0 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -123,7 +123,7 @@ function update_klipperscreen(){ #=============== KLIPPERSCREEN STATUS ==============# #===================================================# -function klipperscreen_status(){ +function get_klipperscreen_status(){ local sf_count status sf_count="$(klipperscreen_systemd | wc -w)" @@ -137,12 +137,12 @@ function klipperscreen_status(){ [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${filecount}" == "${#data_arr[*]}" ]; then - status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" - elif [ "${filecount}" == 0 ]; then - status="${red}Not installed!${white} " + if (( filecount == ${#data_arr[*]})); then + status="Installed!" + elif ((filecount == 0)); then + status="Not installed!" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index dcd3e81..aacb357 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -249,7 +249,7 @@ function update_mainsail(){ #================= MAINSAIL STATUS =================# #===================================================# -function mainsail_status(){ +function get_mainsail_status(){ local status local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail") @@ -259,12 +259,12 @@ function mainsail_status(){ [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${filecount}" == "${#data_arr[*]}" ]; then - status="${green}Installed!${white} " - elif [ "${filecount}" == 0 ]; then - status="${red}Not installed!${white} " + if (( filecount == ${#data_arr[*]})); then + status="Installed!" + elif ((filecount == 0)); then + status="Not installed!" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 395625c..5d05c53 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -120,12 +120,12 @@ function get_telegram_bot_status(){ [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${filecount}" == "${#data_arr[*]}" ]; then - status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" - elif [ "${filecount}" == 0 ]; then - status="${red}Not installed!${white} " + if (( filecount == ${#data_arr[*]})); then + status="Installed!" + elif ((filecount == 0)); then + status="Not installed!" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index e44d757..8fb64a8 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -428,12 +428,12 @@ function get_moonraker_status(){ [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) done - if [ "${filecount}" == "${#data_arr[*]}" ]; then - status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" - elif [ "${filecount}" == 0 ]; then - status="${red}Not installed!${white} " + if (( filecount == ${#data_arr[*]})); then + status="Installed: ${sf_count}" + elif ((filecount == 0)); then + status="Not installed!" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index dd84ed8..3df9dc9 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -278,18 +278,18 @@ function remove_octoprint(){ #=============== OCTOPRINT STATUS ================# #=================================================# -function octoprint_status(){ +function get_octoprint_status(){ local sf_count env_count dir_count status sf_count="$(octoprint_systemd | wc -w)" env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*" | wc -w) dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*" | wc -w) if (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then - status="${red}Not installed!${white} " + status="Not installed!" elif (( sf_count == env_count)) && (( sf_count == dir_count)); then - status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")" + status="Installed: ${sf_count}" else - status="${yellow}Incomplete!${white} " + status="Incomplete!" fi echo "${status}" } \ No newline at end of file diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 3cbfe76..a316e46 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -15,17 +15,17 @@ function main_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr - echo -e "| 0) [Log-Upload] | Klipper: $(get_klipper_status)|" - echo -e "| | |" - echo -e "| 1) [Install] | |" - echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" - echo -e "| 3) [Remove] | |" - echo -e "| 4) [Advanced] | Mainsail: $(mainsail_status)|" - echo -e "| 5) [Backup] | Fluidd: $(fluidd_status)|" - echo -e "| | KlipperScreen: $(klipperscreen_status)|" - echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" - echo -e "| | |" - echo -e "| $(print_kiauh_version)| Octoprint: $(octoprint_status)|" + echo -e "| 0) [Log-Upload] | Klipper: $(print_status "klipper")|" + echo -e "| | Repo: $(print_klipper_repo)|" + echo -e "| 1) [Install] | |" + echo -e "| 2) [Update] | Moonraker: $(print_status "moonraker")|" + echo -e "| 3) [Remove] | |" + echo -e "| 4) [Advanced] | Mainsail: $(print_status "mainsail")|" + echo -e "| 5) [Backup] | Fluidd: $(print_status "fluidd")|" + echo -e "| | KlipperScreen: $(print_status "klipperscreen")|" + echo -e "| 6) [Settings] | Telegram Bot: $(print_status "telegram_bot")|" + echo -e "| | |" + echo -e "| $(print_kiauh_version)| Octoprint: $(print_status "octoprint")|" quit_footer } @@ -38,10 +38,39 @@ function get_kiauh_version(){ function print_kiauh_version(){ local version - version="$(printf "%-20s" "$(get_kiauh_version)")" + version="$(printf "%-18s" "$(get_kiauh_version)")" echo "${cyan}${version}${white}" } +function print_status(){ + local status component="${1}" + status=$(get_"${component}"_status) + if [ "${status}" == "Not installed!" ]; then + status="${red}${status}${white}" + elif [ "${status}" == "Incomplete!" ]; then + status="${yellow}${status}${white}" + else + status="${green}${status}${white}" + fi + printf "%-28s" "${status}" +} + +function print_klipper_repo(){ + read_kiauh_ini + local repo klipper_status + klipper_status=$(get_klipper_status) + repo=$(echo ${custom_klipper_repo} | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//") + repo="${repo^^}" + if [[ "${klipper_status}" == "Not installed!" ]]; then + repo="${red}-${white}" + elif [[ -n "${repo}" && "${repo}" != "KLIPPER3D/KLIPPER" ]]; then + repo="${cyan}custom${white}" + else + repo="${cyan}Klipper3d/klipper${white}" + fi + printf "%-28s" "${repo}" +} + function kiauh_update_dialog(){ [ ! "$(kiauh_update_avail)" == "true" ] && return top_border From d000ba13737de73aa6bf850c38365004890247ca Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 26 Apr 2022 20:24:53 +0200 Subject: [PATCH 161/183] gitignore: unignore .shellcheckrc * also unignore IDE specific directories, those should be ignored globally by the developer anyways Signed-off-by: Dominik Willner th33xitus@gmail.com --- .gitignore | 2 -- .shellcheckrc | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .shellcheckrc diff --git a/.gitignore b/.gitignore index 42a230f..7084f49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -.idea -.shellcheckrc klipper_repos.txt \ No newline at end of file diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..e5c572b --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,14 @@ +source=scripts + +enable=avoid-nullary-conditions +enable=deprecate-which +enable=quote-safe-variables +enable=require-variable-braces + +# SC2162: `read` without `-r` will mangle backslashes. +# https://github.com/koalaman/shellcheck/wiki/SC2162 +disable=SC2162 + +# SC2164: Use `cd ... || exit` in case `cd` fails +# https://github.com/koalaman/shellcheck/wiki/SC2164 +disable=SC2164 From 82d6ebf459eb1fcf918b5555465b2371a1ef6a8a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Apr 2022 11:01:58 +0200 Subject: [PATCH 162/183] refactor: klipper switch repo mechanics Signed-off-by: Dominik Willner th33xitus@gmail.com --- klipper_repos.txt | 11 ----- klipper_repos.txt.example | 18 +++++++++ scripts/switch_klipper_repo.sh | 74 ++++++++++++++++++---------------- scripts/utilities.sh | 4 +- 4 files changed, 59 insertions(+), 48 deletions(-) delete mode 100644 klipper_repos.txt create mode 100644 klipper_repos.txt.example diff --git a/klipper_repos.txt b/klipper_repos.txt deleted file mode 100644 index 3a6ac38..0000000 --- a/klipper_repos.txt +++ /dev/null @@ -1,11 +0,0 @@ -############################################################## -## DO NOT REMOVE OR EDIT THIS COMMENT BLOCK! ## -## Always add the URL and branch in a pattern like this: ## -## , ## -## E.g.: https://github.com/Klipper3d/klipper,master ## -## ## -## A wrong format will cause problems! ## -## Do NOT insert blank lines. Only add one entry per line! ## -############################################################## -##~~~~~ Add the custom repositories below THIS line ~~~~~~~~## -https://github.com/Klipper3d/klipper,master diff --git a/klipper_repos.txt.example b/klipper_repos.txt.example new file mode 100644 index 0000000..6cc3393 --- /dev/null +++ b/klipper_repos.txt.example @@ -0,0 +1,18 @@ +# This file acts as an example file. +# +# 1) Make a copy of this file and rename it to 'klipper_repos.txt' +# 2) Add your custom Klipper repository to the bottom of that copy +# 3) Save the file +# +# Back in KIAUH you can now go into -> [Settings] and use action '2' to set a different Klipper repository +# +# Make sure to always separate the repository and the branch with a ','. +# , -> https://github.com/Klipper3d/klipper,master +# If you omit a branch, it will always default to 'master' +# +# You are allowed to omit the 'https://github.com/' part of the repository URL +# Down below are now a few examples of what is considered as valid: +https://github.com/Klipper3d/klipper,master +https://github.com/Klipper3d/klipper +Klipper3d/klipper,master +Klipper3d/klipper diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh index 0ecac90..d8cdd08 100644 --- a/scripts/switch_klipper_repo.sh +++ b/scripts/switch_klipper_repo.sh @@ -13,26 +13,40 @@ set -e function change_klipper_repo_menu(){ local repo_file="${SRCDIR}/kiauh/klipper_repos.txt" - local url branch + local repos=() branches=() + + if [ ! -f "${repo_file}" ]; then + print_error "File 'klipper_repos.txt' in ${SRCDIR}/kiauh not found!" + return + fi + + ### generate the repolist from the klipper_repos.txt textfile + while IFS="," read -r repo branch; do + repo=$(echo "${repo}" | sed -r "s/^http(s)?:\/\/github.com\///" | sed "s/\.git$//" ) + repos+=("${repo}") + ### if branch is not given, default to 'master' + [ -z "${branch}" ] && branch="master" + branches+=("${branch}") + done < <(grep -E "^[^#]" "${repo_file}") top_border echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | " hr blank_line - ### dynamically generate the repolist from the klipper_repos.txt textfile - get_klipper_repo_list "${repo_file}" + ### print repolist + local i=0 + for _ in "${repos[@]}"; do + printf "| %s) %-63s|\n" "${i}" "${yellow}${repos[${i}]}${white} → ${branches[${i}]}" + i=$((i+1)) + done blank_line back_help_footer - while IFS="," read -r col1 col2; do - url+=("${col1}") - branch+=("${col2}") - done < <(grep "" "${repo_file}" | tail -n "+11") - while true; do - read -p "${cyan}Perform action:${white} " option + read -p "${cyan}###### Perform action:${white} " option case "${option}" in - 0 | "$((option < ${#url[@]}))") + 0 | "$((option < ${#repos[@]}))") + select_msg "Repo: ${repos[option]} Branch: ${branches[option]}" if [ -d "${KLIPPER_DIR}" ]; then top_border echo -e "| ${red}!!! ATTENTION !!!${white} |" @@ -45,8 +59,8 @@ function change_klipper_repo_menu(){ case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" - switch_klipper_repo "${url[${option}]}" "${branch[${option}]}" - set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" + switch_klipper_repo "${repos[${option}]}" "${branches[${option}]}" + set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" break;; N|n|No|no) select_msg "No" @@ -56,8 +70,8 @@ function change_klipper_repo_menu(){ esac done else - status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}" - set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" + status_msg "Set custom Klipper repository to:\n ● Repository URL: ${repos[${option}]}\n ● Branch: ${branches[${option}]}" + set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" ok_msg "This repo will now be used for new Klipper installations!\n" fi break;; @@ -73,30 +87,21 @@ function change_klipper_repo_menu(){ error_msg "Invalid command!";; esac done + change_klipper_repo_menu } #================================================# #=================== HELPERS ====================# #================================================# -function get_klipper_repo_list(){ - local repo_file=${1} i=0 - while IFS="," read -r col1 col2; do - col1=$(echo "${col1}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" ) - col1=${yellow}${col1}${white} - printf "| ${i}) %s → %-31s|\n" "${col1}" "${col2}" - i=$((i+1)) - done < <(grep "" "${repo_file}" | tail -n "+11") -} - function switch_klipper_repo(){ - local url branch - url=${1} branch=${2} + local repo_url branch + repo_url="https://github.com/${1}" branch=${2} status_msg "Switching Klipper repository..." do_action_service "stop" "klipper" cd "${HOME}" [ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}" - git clone "${url}" "klipper" && cd "${KLIPPER_DIR}" + git clone "${repo_url}" "klipper" && cd "${KLIPPER_DIR}" git checkout "${branch}" && cd "${HOME}" do_action_service "start" "klipper" } @@ -105,14 +110,13 @@ function show_custom_klipper_repo_help(){ top_border echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |" hr - echo -e "| With this setting, it is possible to install Klipper | " - echo -e "| from a custom repository. It will also switch an | " - echo -e "| existing Klipper installation to the newly selected | " - echo -e "| source repository. | " - echo -e "| A list of selectable repositories is automatically | " - echo -e "| generated by a 'klipper_repos.txt' textfile in KIAUHs | " - echo -e "| root folder. You can add as many additional repos as | " - echo -e "| you wish. Make sure to always add URL ${red}and${white} branch! | " + echo -e "| With this setting, it is possible to install Klipper |" + echo -e "| from a custom repository. It will also switch an |" + echo -e "| existing Klipper installation to the newly selected |" + echo -e "| source repository. |" + echo -e "| A list of repositories is automatically generated by |" + echo -e "| a 'klipper_repos.txt' textfile in KIAUHs root folder. |" + echo -e "| An example file is provided at the same location. |" blank_line back_footer while true; do diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 14041fe..2ac7e6d 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -334,9 +334,9 @@ function toggle_backup_before_update(){ function set_custom_klipper_repo() { read_kiauh_ini "${FUNCNAME[0]}" - local repo_url=${1} branch=${2} + local repo=${1} branch=${2} sed -i "/^custom_klipper_repo=/d" "${INI_FILE}" - sed -i '$a'"custom_klipper_repo=${repo_url}" "${INI_FILE}" + sed -i '$a'"custom_klipper_repo=${repo}" "${INI_FILE}" sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}" sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}" } From 47e56bd950f01147489c6f30253f595a9c0e8e74 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Apr 2022 11:23:13 +0200 Subject: [PATCH 163/183] refactor: sort after find Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 4 ++-- scripts/gcode_shell_command.sh | 2 +- scripts/klipper.sh | 10 +++++----- scripts/klipperscreen.sh | 2 +- scripts/mainsail.sh | 4 ++-- scripts/moonraker-telegram-bot.sh | 2 +- scripts/moonraker.sh | 4 ++-- scripts/octoprint.sh | 6 +++--- scripts/utilities.sh | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index b500822..5c27f88 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -125,7 +125,7 @@ function download_fluidd_macros(){ log_info "executing: download_fluidd_macros" local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg" local configs - configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg") + configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort) if [ -n "${configs}" ]; then ### create a backup of the config folder backup_klipper_config_dir @@ -375,7 +375,7 @@ function select_fluidd_port(){ function patch_fluidd_update_manager(){ local moonraker_configs - moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") + moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf" | sort) for conf in ${moonraker_configs}; do if ! grep -Eq "[update_manager fluidd]" "${conf}"; then ### add new line to conf if it doesn't end with one diff --git a/scripts/gcode_shell_command.sh b/scripts/gcode_shell_command.sh index f8d88b2..785cee6 100644 --- a/scripts/gcode_shell_command.sh +++ b/scripts/gcode_shell_command.sh @@ -97,7 +97,7 @@ function create_example_shell_command() { backup_klipper_config_dir local printer_cfgs - printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg") + printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg" | sort) for cfg in ${printer_cfgs}; do path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev) if [ ! -f "${path}/shell_command.cfg" ]; then diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 602790f..5c9d0c1 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -18,13 +18,13 @@ set -e ### check for existing klipper service installations function klipper_initd() { local services - services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*") + services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*" | sort) echo "${services}" } function klipper_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])?[0-9]*.service") + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])?[0-9]*.service" | sort) echo "${services}" } @@ -271,7 +271,7 @@ function remove_klipper_systemd() { function remove_klipper_logs() { local files - files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/klippy(-[^0])?[0-9]*\.log(.*)?") + files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/klippy(-[^0])?[0-9]*\.log(.*)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." @@ -283,7 +283,7 @@ function remove_klipper_logs() { function remove_klipper_uds() { local files - files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[^0])?[0-9]*") + files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[^0])?[0-9]*" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." @@ -295,7 +295,7 @@ function remove_klipper_uds() { function remove_klipper_printer() { local files - files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[^0])?[0-9]*") + files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[^0])?[0-9]*" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index bd65cc0..ff119c2 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -187,7 +187,7 @@ function compare_klipperscreen_versions(){ function patch_klipperscreen_update_manager(){ local moonraker_configs - moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") + moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf" | sort) for conf in ${moonraker_configs}; do if ! grep -Eq "[update_manager KlipperScreen]" "${conf}"; then ### add new line to conf if it doesn't end with one diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index aacb357..0d3bf3e 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -125,7 +125,7 @@ function download_mainsail_macros(){ log_info "executing: download_mainsail_macros" local ms_cfg="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/master/src/modules/mainsail/filesystem/home/pi/klipper_config/mainsail.cfg" local configs - configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg") + configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort) if [ -n "${configs}" ]; then ### create a backup of the config folder backup_klipper_config_dir @@ -497,7 +497,7 @@ function enable_mainsail_remotemode(){ function patch_mainsail_update_manager(){ local moonraker_configs - moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf") + moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf" | sort) for conf in ${moonraker_configs}; do if ! grep -Eq "[update_manager mainsail]" "${conf}"; then ### add new line to conf if it doesn't end with one diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 5d05c53..b13d059 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -17,7 +17,7 @@ set -e function telegram_bot_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[^0])?[0-9]*.service") + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[^0])?[0-9]*.service" | sort) echo "${services}" } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 8fb64a8..f74a0dc 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -17,7 +17,7 @@ set -e function moonraker_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service") + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service" | sort) echo "${services}" } @@ -316,7 +316,7 @@ function remove_moonraker_systemd() { function remove_moonraker_logs() { local files - files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/moonraker(-[^0])?[0-9]*\.log(.*)?") + files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/moonraker(-[^0])?[0-9]*\.log(.*)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 3df9dc9..70ed267 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -17,7 +17,7 @@ set -e function octoprint_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[^0])?[0-9]*.service") + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[^0])?[0-9]*.service" | sort) echo "${services}" } @@ -239,7 +239,7 @@ function remove_octoprint_sudoers(){ function remove_octoprint_env(){ local files - files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*") + files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." @@ -251,7 +251,7 @@ function remove_octoprint_env(){ function remove_octoprint_dir(){ local files - files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*") + files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 2ac7e6d..3f819b7 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -281,7 +281,7 @@ function set_klipper_cfg_path(){ fi fi done - moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf") + moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf" | sort) ### replace old file path with new one in moonraker.conf for conf in ${moonraker_configs}; do loc=$(echo "${conf}" | rev | cut -d"/" -f2- | rev) @@ -347,7 +347,7 @@ function set_custom_klipper_repo() { function do_action_service(){ local action=${1} service=${2} - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[^0])?[0-9]*.service") + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[^0])?[0-9]*.service" | sort) if [ -n "${services}" ]; then for service in ${services}; do service=$(echo "${service}" | rev | cut -d"/" -f1 | rev) From 96e7dd9f231ff7ae232cd73ca00a450b384078e4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Apr 2022 11:33:29 +0200 Subject: [PATCH 164/183] refactor: generate a randomized paste-name Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/upload_log.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 5f66531..73ab117 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -75,7 +75,7 @@ function upload_selection(){ top_border echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |" hr - echo -e "| You can choose the following files for uploading: |" + echo -e "| You can choose the following logfiles for uploading: |" blank_line for log in "${logfiles[@]}"; do log=${log//${HOME}/"~"} @@ -86,7 +86,7 @@ function upload_selection(){ blank_line back_footer while true; do - read -p "${cyan}Please select:${white} " option + read -p "${cyan}###### Please select:${white} " option if [ -n "${option}" ] && ((option < ${#logfiles[@]})); then upload_log "${logfiles[${option}]}" upload_selection @@ -102,7 +102,7 @@ function upload_log(){ local link clear && print_header status_msg "Uploading ${1} ..." - link=$(curl -s --upload-file "${1}" 'http://paste.c-net.org/') + link=$(curl -s -H "x-random;" --upload-file "${1}" 'http://paste.c-net.org/') if [ -n "${link}" ]; then ok_msg "${1} upload successfull!" echo -e "\n${cyan}###### Here is your link:${white}" From 869e4d2b4826783c30c84710114bda4ab1094af3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Apr 2022 12:10:38 +0200 Subject: [PATCH 165/183] fix: arithmetic expression caused issues * replace it with string conditional Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/upload_log.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 73ab117..29c021b 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -87,7 +87,7 @@ function upload_selection(){ back_footer while true; do read -p "${cyan}###### Please select:${white} " option - if [ -n "${option}" ] && ((option < ${#logfiles[@]})); then + if [[ -n "${option}" && "${option}" -ge 0 && "${option}" -lt "${#logfiles[@]}" ]]; then upload_log "${logfiles[${option}]}" upload_selection elif [[ "${option}" == "B" || "${option}" == "b" ]]; then From fbb63af0c1a61dc64907ee48bbdb16ec40af3112 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Apr 2022 12:32:17 +0200 Subject: [PATCH 166/183] fix(switch_klipper_repo.sh): typo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/switch_klipper_repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh index d8cdd08..668e515 100644 --- a/scripts/switch_klipper_repo.sh +++ b/scripts/switch_klipper_repo.sh @@ -70,7 +70,7 @@ function change_klipper_repo_menu(){ esac done else - status_msg "Set custom Klipper repository to:\n ● Repository URL: ${repos[${option}]}\n ● Branch: ${branches[${option}]}" + status_msg "Set custom Klipper repository to:\n ● Repository: ${repos[${option}]}\n ● Branch: ${branches[${option}]}" set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" ok_msg "This repo will now be used for new Klipper installations!\n" fi From 393e6778371d536e2c5400c8bd6d0872c17c7274 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Apr 2022 13:08:19 +0200 Subject: [PATCH 167/183] refactor(settings_menu.sh): print mainsail and fluidd in a single row Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/ui/settings_menu.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 3f716c0..67dc749 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -67,8 +67,7 @@ function settings_ui() { printf "| %-70s|\n" "${custom_repo} (${custom_branch})" hr echo -e "| Install unstable releases: |" - printf "| Mainsail: %-55s|\n" "${ms_pre_rls}" - printf "| Fluidd: %-55s|\n" "${fl_pre_rls}" + printf "| Mainsail: %-29sFluidd: %-27s|\n" "${ms_pre_rls}" "${fl_pre_rls}" hr printf "| Backup before updating: %-42s|\n" "${bbu}" hr From 6690491880a97cfd9c4d7020fbf9b041f43990a5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 4 May 2022 21:02:08 +0200 Subject: [PATCH 168/183] feat(klipper.sh): custom instance names Signed-off-by: Dominik Willner th33xitus@gmail.com --- docs/changelog.md | 1 + scripts/klipper.sh | 173 ++++++++++++++++++++++++++++++------------- scripts/utilities.sh | 2 +- 3 files changed, 125 insertions(+), 51 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 05f92c6..78dfea5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,7 @@ This document covers possible important changes to KIAUH. KIAUH has now reached major version 4 ! * feat: Klipper can be installed under Python3 (consideres experimental) * feat: Klipper can be installed from custom repositories +* feat: Custom instance name for multi instance installations of Klipper * feat: Option to only allow installation of stable builds of Mainsail and Fluidd * feat: Multi-Instance OctoPrint installations now each have their own virtual python environment * allows independent installation of Plugins for each instance diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 5c9d0c1..740adf6 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -24,7 +24,7 @@ function klipper_initd() { function klipper_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[^0])?[0-9]*.service" | sort) + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service" | sort) echo "${services}" } @@ -36,7 +36,9 @@ function klipper_exists() { } function klipper_setup_dialog(){ - local python_version="${1}" + local python_version="${1}" user_input=() + user_input+=("${python_version}") + status_msg "Initializing Klipper installation ..." ### return early if klipper already exists @@ -61,32 +63,86 @@ function klipper_setup_dialog(){ echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |" bottom_border - local count - while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do + ### ask for amount of instances + local count re="^[1-9][0-9]*$" + while ! [[ ${count} =~ ${re} ]]; do read -p "${cyan}###### Number of Klipper instances to set up:${white} " count - if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then - error_msg "Invalid input!\n" + if ! [[ ${count} =~ ${re} ]]; then + error_msg "Invalid input!" else - echo - while true; do - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - ((count == 1)) && status_msg "Installing single Klipper instance ..." - ((count > 1)) && status_msg "Installing ${count} Klipper instances ..." - klipper_setup "${count}" "${python_version}" - break;; - N|n|No|no) - select_msg "No" - abort_msg "Exiting Klipper setup ...\n" - break;; - *) - error_msg "Invalid Input!";; - esac - done + select_msg "${count}" + user_input+=("${count}") + break fi done + + ### confirm instance amount + while true; do + read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + break;; + N|n|No|no) + select_msg "No" + abort_msg "Exiting Klipper setup ...\n" + return;; + *) + error_msg "Invalid Input!";; + esac + done + + ### ask for custom names + if (( count > 1 )); then + local custom_names="false" + top_border + echo -e "| You can now give each instance a custom name or skip. |" + echo -e "| If skipped, KIAUH will automatically assign an index |" + echo -e "| to each instance in ascending order, starting at '1'. |" + blank_line + echo -e "| Info: |" + echo -e "| Only alphanumeric characters will be allowed. |" + bottom_border + while true; do + read -p "${cyan}###### Use custom names? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + custom_names="true" + break;; + N|n|No|no) + select_msg "No" + break;; + *) + error_msg "Invalid Input!";; + esac + done + + ### get user input for custom names + if [[ "${custom_names}" == "true" ]]; then + local i=1 + while [[ "${i}" -le "${count}" ]]; do + local name="" re="^[0-9a-zA-Z]+$" + while ! [[ ${name} =~ ${re} ]]; do + read -p "${cyan}###### Name for instance #${i}:${white} " name + if [[ ${name} =~ ${re} ]]; then + select_msg "Name: ${name}" + user_input+=("${name}") + break + else + error_msg "Invalid Input!" + fi + done + i=$(( i + 1 )) + done + fi + fi + + + ((count > 1)) && status_msg "Installing ${count} Klipper instances ..." + ((count == 1)) && status_msg "Installing single Klipper instance ..." + + klipper_setup "${user_input[@]}" } function install_klipper_packages(){ @@ -135,9 +191,12 @@ function create_klipper_virtualenv(){ function klipper_setup(){ read_kiauh_ini "${FUNCNAME[0]}" + ### index 0: python version, index 1: instance count, index 2-n: instance names (optional) + local user_input=("${@}") + local python_version="${user_input[0]}" && unset "user_input[0]" + local instance_arr=("${user_input[@]}") && unset "user_input[@]" local custom_repo="${custom_klipper_repo}" local custom_branch="${custom_klipper_repo_branch}" - local instances=${1} python_version=${2} ### checking dependencies local dep=(git) dependency_check "${dep[@]}" @@ -152,7 +211,7 @@ function klipper_setup(){ local repo_name repo_name=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" ) status_msg "Downloading Klipper from ${repo_name} ..." - cd "${HOME}" && git clone "${custom_repo}" "klipper" + cd "${HOME}" && git clone "https://github.com/${custom_repo}" "klipper" cd "${KLIPPER_DIR}" && git checkout "${custom_branch}" cd "${HOME}" fi @@ -166,7 +225,7 @@ function klipper_setup(){ [ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs" ### step 4: create klipper instances - create_klipper_service "${instances}" + create_klipper_service "${instance_arr[@]}" ### step 5: enable and start all instances do_action_service "enable" "klipper" @@ -176,11 +235,9 @@ function klipper_setup(){ check_usergroups ### confirm message - if [[ ${instances} -eq 1 ]]; then - local confirm="Klipper has been set up!" - elif [[ ${instances} -gt 1 ]]; then - local confirm="${instances} Klipper instances have been set up!" - fi + local confirm="" + (( instance_arr[0] == 1)) && confirm="Klipper has been set up!" + (( instance_arr[0] > 1)) && confirm="${instance_arr[0]} Klipper instances have been set up!" print_confirm "${confirm}" && return } @@ -208,8 +265,11 @@ function write_klipper_service(){ } function create_klipper_service(){ - local instances=${1} - if [ "${instances}" -eq 1 ]; then + local input=("${@}") + local instances=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local cfg_dir cfg log printer uds service + if (( instances == 1 )); then local i="" local cfg_dir="${KLIPPER_CONFIG}" local cfg="${cfg_dir}/printer.cfg" @@ -220,20 +280,33 @@ function create_klipper_service(){ ### write single instance service write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" ok_msg "Single Klipper instance created!" - elif [ "${instances}" -gt 1 ]; then - local i=1 - while [ "${i}" -le "${instances}" ]; do - local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" - local cfg="${cfg_dir}/printer.cfg" - local log="${HOME}/klipper_logs/klippy-${i}.log" - local printer="/tmp/printer-${i}" - local uds="/tmp/klippy_uds-${i}" - local service="${SYSTEMD}/klipper-${i}.service" - ### write multi instance service - write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" - ok_msg "Klipper instance #${i} created!" + elif (( instances > 1 )); then + local i=1 j=0 cfg_dir cfg log printer uds service + while (( i <= instances )); do + if [[ ${#names[@]} -eq 0 ]]; then + cfg_dir="${KLIPPER_CONFIG}/printer_${i}" + cfg="${cfg_dir}/printer.cfg" + log="${HOME}/klipper_logs/klippy-${i}.log" + printer="/tmp/printer-${i}" + uds="/tmp/klippy_uds-${i}" + service="${SYSTEMD}/klipper-${i}.service" + ### write multi instance service + write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + ok_msg "Klipper instance #${i} created!" + else + cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}" + cfg="${cfg_dir}/printer.cfg" + log="${HOME}/klipper_logs/klippy-${names[${j}]}.log" + printer="/tmp/printer-${names[${j}]}" + uds="/tmp/klippy_uds-${names[${j}]}" + service="${SYSTEMD}/klipper-${names[${j}]}.service" + ### write multi instance service + write_klipper_service "${i}(${names[${j}]})" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + ok_msg "Klipper instance #${i}(${names[${j}]}) created!" + fi i=$((i+1)) - done && unset i + j=$((j+1)) + done && unset i j else return 1 fi @@ -271,7 +344,7 @@ function remove_klipper_systemd() { function remove_klipper_logs() { local files - files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/klippy(-[^0])?[0-9]*\.log(.*)?" | sort) + files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/klippy(-[0-9a-zA-Z]+)?*\.log(.*)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." @@ -283,7 +356,7 @@ function remove_klipper_logs() { function remove_klipper_uds() { local files - files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[^0])?[0-9]*" | sort) + files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." @@ -295,7 +368,7 @@ function remove_klipper_uds() { function remove_klipper_printer() { local files - files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[^0])?[0-9]*" | sort) + files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 3f819b7..d3a2705 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -347,7 +347,7 @@ function set_custom_klipper_repo() { function do_action_service(){ local action=${1} service=${2} - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[^0])?[0-9]*.service" | sort) + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[0-9a-zA-Z]+)?.service" | sort) if [ -n "${services}" ]; then for service in ${services}; do service=$(echo "${service}" | rev | cut -d"/" -f1 | rev) From a8c5efd789f87460438ff3cdfee0d2846e19577d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 5 May 2022 10:13:07 +0200 Subject: [PATCH 169/183] fix(utilities.sh): typo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/utilities.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index d3a2705..603f83a 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -590,7 +590,7 @@ function set_hostname(){ if [ -f /etc/hosts ]; then current_date=$(get_date) status_msg "Creating backup of hosts file ..." - sudo cp "/etc/hosts /etc/hosts.${current_date}.bak" + sudo cp "/etc/hosts" "/etc/hosts.${current_date}.bak" ok_msg "Backup done!" ok_msg "File:'/etc/hosts.${current_date}.bak'" else From 93c1d04912fcc9f075118f2ae029b783734fc826 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 5 May 2022 10:17:08 +0200 Subject: [PATCH 170/183] fix(flash_klipper.sh): fix `menuconfig` call on python3 only systems Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/flash_klipper.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index be92d6a..6d61b0f 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -272,7 +272,9 @@ function build_fw(){ local dep=(build-essential dpkg-dev make) dependency_check "${dep[@]}" - make clean && make menuconfig + make clean + [ "${python_version}" == "3" ] && make PYTHON=python3 menuconfig + [ "${python_version}" == "2" ] && make menuconfig status_msg "Building firmware ..." python_version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1) From bb95c0b7278b2b1f5a66f42a14c06dc84a15126a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 12:58:27 +0200 Subject: [PATCH 171/183] refactor(klipper.sh): several improvements Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/globals.sh | 1 + scripts/klipper.sh | 145 ++++++++++++++++++++++----------------------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/scripts/globals.sh b/scripts/globals.sh index 531dfef..f8135ab 100644 --- a/scripts/globals.sh +++ b/scripts/globals.sh @@ -34,6 +34,7 @@ function set_globals(){ KLIPPY_ENV="${HOME}/klippy-env" KLIPPER_DIR="${HOME}/klipper" KLIPPER_REPO="https://github.com/Klipper3d/klipper.git" + KLIPPER_LOGS="${HOME}/klipper_logs" KLIPPER_CONFIG="$(get_klipper_cfg_dir)" # default: ${HOME}/klipper_config #================= MOONRAKER ==================# diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 740adf6..c83b6e9 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -64,21 +64,21 @@ function klipper_setup_dialog(){ bottom_border ### ask for amount of instances - local count re="^[1-9][0-9]*$" - while ! [[ ${count} =~ ${re} ]]; do - read -p "${cyan}###### Number of Klipper instances to set up:${white} " count - if ! [[ ${count} =~ ${re} ]]; then + local klipper_count re="^[1-9][0-9]*$" + while ! [[ ${klipper_count} =~ ${re} ]]; do + read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e klipper_count + if ! [[ ${klipper_count} =~ ${re} ]]; then error_msg "Invalid input!" else - select_msg "${count}" - user_input+=("${count}") + select_msg "${klipper_count}" + user_input+=("${klipper_count}") break fi done ### confirm instance amount while true; do - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn + read -p "${cyan}###### Install ${klipper_count} instance(s)? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" @@ -93,10 +93,10 @@ function klipper_setup_dialog(){ done ### ask for custom names - if (( count > 1 )); then + if (( klipper_count > 1 )); then local custom_names="false" top_border - echo -e "| You can now give each instance a custom name or skip. |" + echo -e "| You can give each instance a custom name or skip. |" echo -e "| If skipped, KIAUH will automatically assign an index |" echo -e "| to each instance in ascending order, starting at '1'. |" blank_line @@ -104,13 +104,13 @@ function klipper_setup_dialog(){ echo -e "| Only alphanumeric characters will be allowed. |" bottom_border while true; do - read -p "${cyan}###### Use custom names? (Y/n):${white} " yn + read -p "${cyan}###### Use custom names? (y/N):${white} " yn case "${yn}" in - Y|y|Yes|yes|"") + Y|y|Yes|yes) select_msg "Yes" custom_names="true" break;; - N|n|No|no) + N|n|No|no|"") select_msg "No" break;; *) @@ -120,27 +120,28 @@ function klipper_setup_dialog(){ ### get user input for custom names if [[ "${custom_names}" == "true" ]]; then - local i=1 - while [[ "${i}" -le "${count}" ]]; do - local name="" re="^[0-9a-zA-Z]+$" - while ! [[ ${name} =~ ${re} ]]; do - read -p "${cyan}###### Name for instance #${i}:${white} " name - if [[ ${name} =~ ${re} ]]; then - select_msg "Name: ${name}" - user_input+=("${name}") - break - else - error_msg "Invalid Input!" - fi - done - i=$(( i + 1 )) + local i=1 name="" re="^[0-9a-zA-Z]+$" + while ! [[ ${name} =~ ${re} && ${i} -gt ${klipper_count} ]]; do + read -p "${cyan}###### Name for instance #${i}:${white} " name + if [[ ${name} =~ ${re} ]]; then + select_msg "Name: ${name}" + user_input+=("${name}") + i=$(( i + 1 )) + else + error_msg "Invalid Input!" + fi + done + else + ### if no custom names are used, add the respective amount of indices to the user_input array + for ((i=1; i <= klipper_count; i++)); do + user_input+=("${i}") done fi fi - ((count > 1)) && status_msg "Installing ${count} Klipper instances ..." - ((count == 1)) && status_msg "Installing single Klipper instance ..." + ((klipper_count > 1)) && status_msg "Installing ${klipper_count} Klipper instances ..." + ((klipper_count == 1)) && status_msg "Installing single Klipper instance ..." klipper_setup "${user_input[@]}" } @@ -222,7 +223,7 @@ function klipper_setup(){ ### step 3: create gcode_files and logs folder [ ! -d "${HOME}/gcode_files" ] && mkdir -p "${HOME}/gcode_files" - [ ! -d "${HOME}/klipper_logs" ] && mkdir -p "${HOME}/klipper_logs" + [ ! -d "${KLIPPER_LOGS}" ] && mkdir -p "${KLIPPER_LOGS}" ### step 4: create klipper instances create_klipper_service "${instance_arr[@]}" @@ -242,21 +243,12 @@ function klipper_setup(){ } function write_klipper_service(){ - local i=${1} cfg_dir=${2} cfg=${3} log=${4} printer=${5} uds=${6} service=${7} + local i=${1} cfg=${2} log=${3} printer=${4} uds=${5} service=${6} local service_template="${SRCDIR}/kiauh/resources/klipper.service" - local cfg_template="${SRCDIR}/kiauh/resources/printer.cfg" - - ### create a config directory if it doesn't exist - [ ! -d "${cfg_dir}" ] && mkdir -p "${cfg_dir}" - - ### create a minimal config if there is no printer.cfg - [ ! -f "${cfg}" ] && cp "${cfg_template}" "${cfg}" - ### replace all placeholders if [ ! -f "${service}" ]; then status_msg "Creating Klipper Service ${i} ..." sudo cp "${service_template}" "${service}" - [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${KLIPPY_ENV}|; s|%DIR%|${KLIPPER_DIR}|" "${service}" @@ -264,49 +256,56 @@ function write_klipper_service(){ fi } +function write_example_printer_cfg(){ + local cfg_dir=${1} cfg=${2} + local cfg_template="${SRCDIR}/kiauh/resources/printer.cfg" + ### create a config directory if it doesn't exist + [ ! -d "${cfg_dir}" ] && mkdir -p "${cfg_dir}" + ### create a minimal config if there is no printer.cfg + [ ! -f "${cfg}" ] && cp "${cfg_template}" "${cfg}" +} + function create_klipper_service(){ local input=("${@}") - local instances=${input[0]} && unset "input[0]" + local klipper_count=${input[0]} && unset "input[0]" local names=("${input[@]}") && unset "input[@]" local cfg_dir cfg log printer uds service - if (( instances == 1 )); then - local i="" - local cfg_dir="${KLIPPER_CONFIG}" - local cfg="${cfg_dir}/printer.cfg" - local log="${HOME}/klipper_logs/klippy.log" - local printer="/tmp/printer" - local uds="/tmp/klippy_uds" - local service="${SYSTEMD}/klipper.service" + + if (( klipper_count == 1 )); then + cfg_dir="${KLIPPER_CONFIG}" + cfg="${cfg_dir}/printer.cfg" + log="${KLIPPER_LOGS}/klippy.log" + printer="/tmp/printer" + uds="/tmp/klippy_uds" + service="${SYSTEMD}/klipper.service" ### write single instance service - write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + write_klipper_service "" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + write_example_printer_cfg "${cfg_dir}" "${cfg}" ok_msg "Single Klipper instance created!" - elif (( instances > 1 )); then - local i=1 j=0 cfg_dir cfg log printer uds service - while (( i <= instances )); do - if [[ ${#names[@]} -eq 0 ]]; then - cfg_dir="${KLIPPER_CONFIG}/printer_${i}" - cfg="${cfg_dir}/printer.cfg" - log="${HOME}/klipper_logs/klippy-${i}.log" - printer="/tmp/printer-${i}" - uds="/tmp/klippy_uds-${i}" - service="${SYSTEMD}/klipper-${i}.service" - ### write multi instance service - write_klipper_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" - ok_msg "Klipper instance #${i} created!" + + elif (( klipper_count > 1 )); then + local j=0 re="^[1-9][0-9]*$" + + for ((i=1; i <= klipper_count; i++)); do + ### overwrite config folder if name is only a number + if [[ ${names[j]} =~ ${re} ]]; then + cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}" else cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}" - cfg="${cfg_dir}/printer.cfg" - log="${HOME}/klipper_logs/klippy-${names[${j}]}.log" - printer="/tmp/printer-${names[${j}]}" - uds="/tmp/klippy_uds-${names[${j}]}" - service="${SYSTEMD}/klipper-${names[${j}]}.service" - ### write multi instance service - write_klipper_service "${i}(${names[${j}]})" "${cfg_dir}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" - ok_msg "Klipper instance #${i}(${names[${j}]}) created!" fi - i=$((i+1)) + + cfg="${cfg_dir}/printer.cfg" + log="${KLIPPER_LOGS}/klippy-${names[${j}]}.log" + printer="/tmp/printer-${names[${j}]}" + uds="/tmp/klippy_uds-${names[${j}]}" + service="${SYSTEMD}/klipper-${names[${j}]}.service" + ### write multi instance service + write_klipper_service "${i}(${names[${j}]})" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + write_example_printer_cfg "${cfg_dir}" "${cfg}" + ok_msg "Klipper instance #${i}(${names[${j}]}) created!" j=$((j+1)) - done && unset i j + done && unset j + else return 1 fi @@ -344,7 +343,7 @@ function remove_klipper_systemd() { function remove_klipper_logs() { local files - files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/klippy(-[0-9a-zA-Z]+)?*\.log(.*)?" | sort) + files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/klippy(-[0-9a-zA-Z]+)?\.log(.*)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." From e840524fb9c68d1680a62160259451f3630521f7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 13:09:23 +0200 Subject: [PATCH 172/183] feat(moonraker.sh): custom instance names Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 253 +++++++++++++++++++++++++++---------------- scripts/utilities.sh | 10 ++ 2 files changed, 167 insertions(+), 96 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index f74a0dc..a661a7c 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -17,72 +17,104 @@ set -e function moonraker_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[^0])?[0-9]*.service" | sort) + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service" | sort) echo "${services}" } function moonraker_setup_dialog(){ status_msg "Initializing Moonraker installation ..." - ### return early if moonraker already exists - if [ -n "$(moonraker_systemd)" ]; then - local error="At least one Moonraker service is already installed:" - for service in $(moonraker_systemd); do - error="${error}\n ➔ ${service}" - done - print_error "${error}" && return - fi - ### return early if python version check fails - if [ "$(python3_check)" == "false" ]; then + if [[ "$(python3_check)" == "false" ]]; then local error="Versioncheck failed! Python 3.7 or newer required!\n" error="${error} Please upgrade Python." print_error "${error}" && return fi - local klipper_count - klipper_count=$(klipper_systemd | wc -w) - top_border - if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then - printf "|${green}%-55s${white}|\n" " 1 Klipper instance was found!" - elif [ "${klipper_count}" -gt 1 ]; then - printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances were found!" - else - echo -e "| ${yellow}INFO: No existing Klipper installation found!${white} |" + ### return early if moonraker already exists + local moonraker_services + moonraker_services=$(moonraker_systemd) + if [[ -n "${moonraker_services}" ]]; then + local error="At least one Moonraker service is already installed:" + for s in ${moonraker_services}; do + log_info "Found Moonraker service: ${s}" + error="${error}\n ➔ ${s}" + done + print_error "${error}" && return fi - echo -e "| Usually you need one Moonraker instance per Klipper |" - echo -e "| instance. Though you can install as many as you wish. |" + + ### return early if klipper is not installed + local klipper_services + klipper_services=$(klipper_systemd) + if [[ -z "${klipper_services}" ]]; then + local error="Klipper not installed! Please install Klipper first!" + log_error "Moonraker setup started without Klipper being installed. Aborting setup." + print_error "${error}" && return + fi + + local klipper_count user_input=() klipper_names=() + klipper_count=$(echo "${klipper_services}" | wc -w ) + for service in ${klipper_services}; do + klipper_names+=( "$(get_instance_name "${service}")" ) + done + + top_border + echo -e "| Klipper instances with the following names were found:|" + if (( klipper_count > 1 )); then + for name in "${klipper_names[@]}"; do + printf "|${cyan}%-57s${white}|\n" " ● ${name}" + done + blank_line + echo -e "| The setup will apply the same names to Moonraker! |" + fi + blank_line + echo -e "| Please select the number of Moonraker instances to |" + echo -e "| set up. Usually you need one Moonraker instance per |" + echo -e "| Klipper instance. |" bottom_border - local count - while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of Moonraker instances to set up:${white} " count - if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then - error_msg "Invalid Input!\n" - else - echo - while true; do - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - ((count == 1)) && status_msg "Installing single Moonraker instance ..." - ((count > 1)) && status_msg "Installing ${count} Moonraker instances ..." - moonraker_setup "${count}" - break;; - N|n|No|no) - select_msg "No" - error_msg "Exiting Moonraker setup ...\n" - break;; - *) - error_msg "Invalid Input!\n";; - esac - done - fi + ### ask for amount of instances + local moonraker_count re="^[1-9][0-9]*$" + while ! [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]]; do + read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count + ### break if input is valid + [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break + ### conditional error messages + error_msg "Invalid input:" + ! [[ ${moonraker_count} =~ ${re} ]] && error_msg "● Input not a number" + ((moonraker_count > klipper_count)) && error_msg "● Number of Moonraker instances larger than existing Klipper instances" + done && select_msg "${moonraker_count}" + user_input+=("${moonraker_count}") + + ### confirm instance amount + while true; do + read -p "${cyan}###### Install ${moonraker_count} instance(s)? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + break;; + N|n|No|no) + select_msg "No" + abort_msg "Exiting Moonraker setup ...\n" + return;; + *) + error_msg "Invalid Input!";; + esac done + + ### write existing klipper names into user_input array to use them as names for moonraker + if (( klipper_count > 1 )); then + for name in "${klipper_names[@]}"; do + user_input+=("${name}") + done + fi + + ((moonraker_count > 1)) && status_msg "Installing ${moonraker_count} Moonraker instances ..." + ((moonraker_count == 1)) && status_msg "Installing Moonraker ..." + moonraker_setup "${user_input[@]}" } -function install_moonraker_packages(){ +function install_moonraker_dependencies(){ local packages local install_script="${HOME}/moonraker/scripts/install-moonraker.sh" @@ -112,7 +144,7 @@ function create_moonraker_virtualenv(){ } function moonraker_setup(){ - local confirm_msg instances=${1} + local instance_arr=("${@}") ### checking dependencies local dep=(git wget curl unzip dfu-util virtualenv) ### additional required dependencies on armbian @@ -127,14 +159,14 @@ function moonraker_setup(){ ### step 2: install moonraker dependencies and create python virtualenv status_msg "Installing dependencies ..." - install_moonraker_packages + install_moonraker_dependencies create_moonraker_virtualenv ### step 3: create moonraker.conf - create_moonraker_conf "${instances}" + create_moonraker_conf "${instance_arr[@]}" ### step 4: create moonraker instances - create_moonraker_service "${instances}" + create_moonraker_service "${instance_arr[@]}" ### step 5: create polkit rules for moonraker moonraker_polkit || true @@ -144,36 +176,50 @@ function moonraker_setup(){ do_action_service "start" "moonraker" ### confirm message - [ "${instances}" -eq 1 ] && confirm_msg="Moonraker has been set up!" - [ "${instances}" -gt 1 ] && confirm_msg="${instances} Moonraker instances have been set up!" - print_confirm "${confirm_msg}" - print_mr_ip_list "${instances}" + local confirm="" + (( instance_arr[0] == 1)) && confirm="Moonraker has been set up!" + (( instance_arr[0] > 1)) && confirm="${instance_arr[0]} Moonraker instances have been set up!" + print_confirm "${confirm}" && print_mr_ip_list "${instance_arr[0]}" && return } function create_moonraker_conf(){ - local lan instances=${1} log="${HOME}/klipper_logs" + local input=("${@}") + local moonraker_count=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local log="${KLIPPER_LOGS}" + local lan lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" + local port=7125 cfg_dir cfg db uds - if [ "${instances}" -eq 1 ]; then - local cfg_dir="${KLIPPER_CONFIG}" - local cfg="${cfg_dir}/moonraker.conf" - local port=7125 - local db="${HOME}/.moonraker_database" - local uds="/tmp/klippy_uds" + if (( moonraker_count == 1 )); then + cfg_dir="${KLIPPER_CONFIG}" + cfg="${cfg_dir}/moonraker.conf" + db="${HOME}/.moonraker_database" + uds="/tmp/klippy_uds" ### write single instance config write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" - elif [ "${instances}" -gt 1 ]; then - local i=1 port=7125 - while [ "${i}" -le "${instances}" ]; do - local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" - local cfg="${cfg_dir}/moonraker.conf" - local db="${HOME}/.moonraker_database_${i}" - local uds="/tmp/klippy_uds-${i}" + + elif (( moonraker_count > 1 )); then + local j=0 re="^[1-9][0-9]*$" + + for ((i=1; i <= moonraker_count; i++ )); do + ### overwrite config folder if name is only a number + if [[ ${names[j]} =~ ${re} ]]; then + cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}" + else + cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}" + fi + + cfg="${cfg_dir}/moonraker.conf" + uds="/tmp/klippy_uds-${names[${j}]}" + db="${HOME}/.moonraker_database_${names[${j}]}" ### write multi instance config write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" + ok_msg "Moonraker config for instance #${i}(${names[${j}]}) created!" port=$((port+1)) - i=$((i+1)) - done + j=$((j+1)) + done && unset j + else return 1 fi @@ -203,35 +249,50 @@ function write_moonraker_conf(){ } function create_moonraker_service(){ - local instances=${1} - if [ "${instances}" -eq 1 ]; then - local i="" - local cfg_dir="${KLIPPER_CONFIG}" - local cfg="${cfg_dir}/moonraker.conf" - local log="${HOME}/klipper_logs/moonraker.log" - local service="${SYSTEMD}/moonraker.service" + local input=("${@}") + local instances=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local i j cfg_dir cfg log service + if (( instances == 1 )); then + i="" + cfg_dir="${KLIPPER_CONFIG}" + cfg="${cfg_dir}/moonraker.conf" + log="${HOME}/klipper_logs/moonraker.log" + service="${SYSTEMD}/moonraker.service" ### write single instance service write_moonraker_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${service}" ok_msg "Single Moonraker instance created!" - elif [ "${instances}" -gt 1 ]; then - local i=1 - while [ "${i}" -le "${instances}" ]; do - local cfg_dir="${KLIPPER_CONFIG}/printer_${i}" - local cfg="${cfg_dir}/moonraker.conf" - local log="${HOME}/klipper_logs/moonraker-${i}.log" - local service="${SYSTEMD}/moonraker-${i}.service" + + elif (( instances > 1 )); then + local i=1 j=0 re="^[1-9][0-9]*$" + + while (( i <= instances )); do + + ### overwrite config folder if name is only a number + if [[ ${names[j]} =~ ${re} ]]; then + cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}" + else + cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}" + fi + + cfg="${cfg_dir}/moonraker.conf" + log="${HOME}/klipper_logs/moonraker-${names[${j}]}.log" + service="${SYSTEMD}/moonraker-${names[${j}]}.service" ### write multi instance service - write_moonraker_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${service}" - ok_msg "Moonraker instance #${i} created!" + write_moonraker_service "${i}(${names[${j}]})" "${cfg_dir}" "${cfg}" "${log}" "${service}" + ok_msg "Moonraker instance #${i}(${names[${j}]}) created!" i=$((i+1)) + j=$((j+1)) + done && unset i + ### enable mainsails remoteMode if mainsail is found - if [ -d "${MAINSAIL_DIR}" ]; then - status_msg "Mainsail installation found!" - status_msg "Enabling Mainsail remoteMode ..." + if [[ -d "${MAINSAIL_DIR}" ]]; then + status_msg "Mainsail installation found! Enabling Mainsail remote mode ..." enable_mainsail_remotemode - ok_msg "Mainsails remoteMode enabled!" + ok_msg "Mainsails remote mode enabled!" fi + else return 1 fi @@ -254,9 +315,9 @@ function write_moonraker_service(){ } function print_mr_ip_list(){ - local ip instances="${1}" i=1 port=7125 + local ip count=${1} i=1 port=7125 ip=$(hostname -I | cut -d" " -f1) - while [ "${i}" -le "${instances}" ] ; do + while (( i <= count )); do echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}" port=$((port+1)) i=$((i+1)) @@ -316,7 +377,7 @@ function remove_moonraker_systemd() { function remove_moonraker_logs() { local files - files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/moonraker(-[^0])?[0-9]*\.log(.*)?" | sort) + files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/moonraker(-[0-9a-zA-Z]+)?\.log(.*)?" | sort) if [ -n "${files}" ]; then for file in ${files}; do status_msg "Removing ${file} ..." @@ -399,7 +460,7 @@ function update_moonraker(){ status_msg "Updating Moonraker ..." cd "${MOONRAKER_DIR}" && git pull ### read PKGLIST and install possible new dependencies - install_moonraker_packages + install_moonraker_dependencies ### install possible new python dependencies "${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt" fi diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 603f83a..e52d4d4 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -607,4 +607,14 @@ function set_hostname(){ echo "127.0.0.1 ${new_hostname}" | sudo tee -a /etc/hosts &>/dev/null ok_msg "New hostname successfully configured!" ok_msg "Remember to reboot for the changes to take effect!" +} + +function get_instance_name() { + ### this function takes in the full path of a systemd service file and returns + ### either the instance index or the custom name + ### input: /etc/systemd/system/klipper-name.service + ### returns: name + local instance=${1} name + name=$(echo "${instance}" | rev | cut -d"/" -f1 | rev | cut -d"-" -f2 | cut -d"." -f1) + echo "${name}" } \ No newline at end of file From f88ab0689005c3d2b289f905fe29b5fc200acc31 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 13:11:46 +0200 Subject: [PATCH 173/183] refactor(webuis): reword error message Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/fluidd.sh | 2 +- scripts/mainsail.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 5c27f88..bd9f6b6 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -18,7 +18,7 @@ set -e function install_fluidd(){ ### exit early if moonraker not found if [ -z "$(moonraker_systemd)" ]; then - local error="Moonraker service not found!\n Please install Moonraker first!" + local error="Moonraker not installed! Please install Moonraker first!" print_error "${error}" && return fi ### checking dependencies diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 0d3bf3e..750b988 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -18,7 +18,7 @@ set -e function install_mainsail(){ ### exit early if moonraker not found if [ -z "$(moonraker_systemd)" ]; then - local error="Moonraker service not found!\n Please install Moonraker first!" + local error="Moonraker not installed! Please install Moonraker first!" print_error "${error}" && return fi ### checking dependencies From 4fe104c1119a172701872f636716b3703f09176f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 13:25:02 +0200 Subject: [PATCH 174/183] refactor(klipper.sh): simplify condition Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/klipper.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index c83b6e9..db3483f 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -67,14 +67,12 @@ function klipper_setup_dialog(){ local klipper_count re="^[1-9][0-9]*$" while ! [[ ${klipper_count} =~ ${re} ]]; do read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e klipper_count - if ! [[ ${klipper_count} =~ ${re} ]]; then - error_msg "Invalid input!" - else - select_msg "${klipper_count}" - user_input+=("${klipper_count}") - break - fi - done + ### break if input is valid + [[ ${klipper_count} =~ ${re} ]] && break + error_msg "Invalid input:" + error_msg "● Input not a number" + done && select_msg "${klipper_count}" + user_input+=("${klipper_count}") ### confirm instance amount while true; do From 438aa396f4014a22a2f2381a72fb460bdd0e6ff8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 17:56:34 +0200 Subject: [PATCH 175/183] refactor(moonraker.sh): streamline single instance install Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index a661a7c..c698619 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -58,37 +58,48 @@ function moonraker_setup_dialog(){ klipper_names+=( "$(get_instance_name "${service}")" ) done - top_border - echo -e "| Klipper instances with the following names were found:|" - if (( klipper_count > 1 )); then + local moonraker_count + if (( klipper_count == 1 )); then + ok_msg "Klipper installation found!\n" + moonraker_count=1 + elif (( klipper_count > 1 )); then + top_border + printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!" for name in "${klipper_names[@]}"; do printf "|${cyan}%-57s${white}|\n" " ● ${name}" done blank_line echo -e "| The setup will apply the same names to Moonraker! |" - fi - blank_line - echo -e "| Please select the number of Moonraker instances to |" - echo -e "| set up. Usually you need one Moonraker instance per |" - echo -e "| Klipper instance. |" - bottom_border + blank_line + echo -e "| Please select the number of Moonraker instances to |" + echo -e "| install. Usually one Moonraker instance per Klipper |" + echo -e "| instance is required but you may not install more |" + echo -e "| Moonraker instances than available Klipper instances. |" + bottom_border + + ### ask for amount of instances + local re="^[1-9][0-9]*$" + while ! [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]]; do + read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count + ### break if input is valid + [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break + ### conditional error messages + error_msg "Invalid input:" + ! [[ ${moonraker_count} =~ ${re} ]] && error_msg "● Input not a number" + ((moonraker_count > klipper_count)) && error_msg "● Number of Moonraker instances larger than existing Klipper instances" + done && select_msg "${moonraker_count}" + else + log_error "Internal error. klipper_count of '${klipper_count}' not equal or grather than one!" + return 1 + fi - ### ask for amount of instances - local moonraker_count re="^[1-9][0-9]*$" - while ! [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]]; do - read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count - ### break if input is valid - [[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break - ### conditional error messages - error_msg "Invalid input:" - ! [[ ${moonraker_count} =~ ${re} ]] && error_msg "● Input not a number" - ((moonraker_count > klipper_count)) && error_msg "● Number of Moonraker instances larger than existing Klipper instances" - done && select_msg "${moonraker_count}" user_input+=("${moonraker_count}") ### confirm instance amount while true; do - read -p "${cyan}###### Install ${moonraker_count} instance(s)? (Y/n):${white} " yn + ((moonraker_count == 1)) && local ins="instance" + ((moonraker_count > 1)) && local ins="instances" + read -p "${cyan}###### Install ${moonraker_count} Moonraker ${ins}? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" From ebae583dcce2b0037419317563c9df7befa1813b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 18:06:47 +0200 Subject: [PATCH 176/183] refactor(moonraker.sh): improve wording Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index c698619..51f9f01 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -97,9 +97,9 @@ function moonraker_setup_dialog(){ ### confirm instance amount while true; do - ((moonraker_count == 1)) && local ins="instance" - ((moonraker_count > 1)) && local ins="instances" - read -p "${cyan}###### Install ${moonraker_count} Moonraker ${ins}? (Y/n):${white} " yn + ((moonraker_count == 1)) && local question="Install Moonraker?" + ((moonraker_count > 1)) && local question="Install ${moonraker_count} Moonraker instances?" + read -p "${cyan}###### ${question}? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" From 02912db66acc86c6f377bdead3de55abed6e735b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 18:07:24 +0200 Subject: [PATCH 177/183] fix(moonraker.sh): typo Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 51f9f01..995dff5 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -99,7 +99,7 @@ function moonraker_setup_dialog(){ while true; do ((moonraker_count == 1)) && local question="Install Moonraker?" ((moonraker_count > 1)) && local question="Install ${moonraker_count} Moonraker instances?" - read -p "${cyan}###### ${question}? (Y/n):${white} " yn + read -p "${cyan}###### ${question} (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" From 76d98a79f9943f57c8c5ab28b71d317e40d955c7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 20:54:29 +0200 Subject: [PATCH 178/183] fix(moonraker.sh): remove redundant confirm Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/moonraker.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 995dff5..1b5a9a0 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -226,7 +226,6 @@ function create_moonraker_conf(){ db="${HOME}/.moonraker_database_${names[${j}]}" ### write multi instance config write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${log}" "${db}" "${uds}" "${lan}" - ok_msg "Moonraker config for instance #${i}(${names[${j}]}) created!" port=$((port+1)) j=$((j+1)) done && unset j From cacb5d6507da7c4637816face1227b75c2d24e58 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 6 May 2022 20:59:34 +0200 Subject: [PATCH 179/183] feat(moonraker-telegram-bot.sh): multi instance and custom names Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/moonraker-telegram-bot.service | 18 ++ scripts/moonraker-telegram-bot.sh | 360 +++++++++++++++++++---- scripts/ui/install_menu.sh | 2 +- 3 files changed, 322 insertions(+), 58 deletions(-) create mode 100644 resources/moonraker-telegram-bot.service diff --git a/resources/moonraker-telegram-bot.service b/resources/moonraker-telegram-bot.service new file mode 100644 index 0000000..fd0ce2a --- /dev/null +++ b/resources/moonraker-telegram-bot.service @@ -0,0 +1,18 @@ +#Systemd service file for Moonraker Telegram Bot + +[Unit] +Description=Starts Moonraker Telegram Bot instance %INST% on startup +Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki +After=network.target + +[Install] +WantedBy=multi-user.target + +[Service] +Environment=TELEGRAM_CONF=%CFG% +Type=simple +User=%USER% +RemainAfterExit=yes +ExecStart=%ENV%/bin/python %DIR%/bot/main.py -c ${TELEGRAM_CONF} +Restart=always +RestartSec=10 \ No newline at end of file diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index b13d059..b72e151 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -21,26 +21,256 @@ function telegram_bot_systemd() { echo "${services}" } -function install_telegram_bot(){ - telegram_bot_setup - do_action_service "restart" "moonraker-telegram-bot" +function telegram_bot_setup_dialog(){ + status_msg "Initializing Telegram Bot installation ..." + + ### return early if moonraker is not installed + local moonraker_services + moonraker_services=$(moonraker_systemd) + if [[ -z "${moonraker_services}" ]]; then + local error="Moonraker not installed! Please install Moonraker first!" + log_error "Telegram Bot setup started without Moonraker being installed. Aborting setup." + print_error "${error}" && return + fi + + local moonraker_count user_input=() moonraker_names=() + moonraker_count=$(echo "${moonraker_services}" | wc -w ) + for service in ${moonraker_services}; do + moonraker_names+=( "$(get_instance_name "${service}")" ) + done + + local telegram_bot_count + if (( moonraker_count == 1 )); then + ok_msg "Moonraker installation found!\n" + telegram_bot_count=1 + elif (( moonraker_count > 1 )); then + top_border + printf "|${green}%-55s${white}|\n" " ${moonraker_count} Moonraker instances found!" + for name in "${moonraker_names[@]}"; do + printf "|${cyan}%-57s${white}|\n" " ● ${name}" + done + blank_line + echo -e "| The setup will apply the same names to Telegram Bot! |" + blank_line + echo -e "| Please select the number of Telegram Bot instances to |" + echo -e "| install. Usually one Telegram Bot instance per |" + echo -e "| Moonraker instance is required but you may not |" + echo -e "| install more Telegram Bot instances than available |" + echo -e "| Moonraker instances. |" + bottom_border + + ### ask for amount of instances + local re="^[1-9][0-9]*$" + while ! [[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]]; do + read -p "${cyan}###### Number of Telegram Bot instances to set up:${white} " -i "${moonraker_count}" -e telegram_bot_count + ### break if input is valid + [[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]] && break + ### conditional error messages + error_msg "Invalid input:" + ! [[ ${telegram_bot_count} =~ ${re} ]] && error_msg "● Input not a number" + ((telegram_bot_count > moonraker_count)) && error_msg "● Number of Telegram Bot instances larger than existing Moonraker instances" + done && select_msg "${telegram_bot_count}" + else + log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!" + return 1 + fi + + user_input+=("${telegram_bot_count}") + +### confirm instance amount + while true; do + ((telegram_bot_count == 1)) && local question="Install Telegram Bot?" + ((telegram_bot_count > 1)) && local question="Install ${telegram_bot_count} Telegram Bot instances?" + read -p "${cyan}###### ${question} (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + break;; + N|n|No|no) + select_msg "No" + abort_msg "Exiting Telegram Bot setup ...\n" + return;; + *) + error_msg "Invalid Input!";; + esac + done + + ### write existing klipper names into user_input array to use them as names for moonraker + if (( moonraker_count > 1 )); then + for name in "${moonraker_names[@]}"; do + user_input+=("${name}") + done + fi + + ((telegram_bot_count > 1)) && status_msg "Installing ${telegram_bot_count} Telegram Bot instances ..." + ((telegram_bot_count == 1)) && status_msg "Installing Telegram Bot ..." + telegram_bot_setup "${user_input[@]}" +} + +function install_telegram_bot_dependencies(){ + local packages + local install_script="${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/install.sh" + + ### read PKGLIST from official install script + status_msg "Reading dependencies..." + # shellcheck disable=SC2016 + packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')" + + echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' + read -r -a packages <<< "${packages}" + + ### Update system package info + status_msg "Updating lists of packages..." + sudo apt-get update --allow-releaseinfo-change + + ### Install required packages + status_msg "Installing packages..." + sudo apt-get install --yes "${packages[@]}" +} + +function create_telegram_bot_virtualenv(){ + status_msg "Installing python virtual environment..." + ### always create a clean virtualenv + [[ -d ${MOONRAKER_TELEGRAM_BOT_ENV_DIR} ]] && rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" + virtualenv -p /usr/bin/python3 --system-site-packages "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" + "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}"/bin/pip install -r "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/requirements.txt" } function telegram_bot_setup(){ - local klipper_cfg_loc - klipper_cfg_loc="$(get_klipper_cfg_dir)" - export klipper_cfg_loc - local dep=(virtualenv) + local instance_arr=("${@}") + ### checking dependencies + local dep=(git virtualenv) dependency_check "${dep[@]}" + + ### step 1: clone telegram bot status_msg "Downloading Moonraker-Telegram-Bot ..." - #force remove existing Moonraker-Telegram-Bot dir - [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] && rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" - #clone into fresh Moonraker-Telegram-Bot dir + ### force remove existing Moonraker-Telegram-Bot dir + [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] && rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}" - ok_msg "Download complete!" - status_msg "Installing Moonraker-Telegram-Bot ..." - /bin/bash "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/install.sh" - echo; ok_msg "Moonraker-Telegram-Bot successfully installed!" + + ### step 2: install telegram bot dependencies and create python virtualenv + status_msg "Installing dependencies ..." + install_telegram_bot_dependencies + create_telegram_bot_virtualenv + + ### step 3: create telegram.conf + create_telegram_conf "${instance_arr[@]}" + + ### step 4: create telegram bot instances + create_telegram_bot_service "${instance_arr[@]}" + + ### step 5: enable and start all instances + do_action_service "enable" "moonraker-telegram-bot" + do_action_service "start" "moonraker-telegram-bot" + + ### confirm message + local confirm="" + (( instance_arr[0] == 1)) && confirm="Telegram Bot has been set up!" + (( instance_arr[0] > 1)) && confirm="${instance_arr[0]} Telegram Bot instances have been set up!" + print_confirm "${confirm}" && return +} + +function create_telegram_conf(){ + local input=("${@}") + local telegram_bot_count=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local log="${KLIPPER_LOGS}" + + if (( telegram_bot_count == 1 )); then + cfg_dir="${KLIPPER_CONFIG}" + cfg="${cfg_dir}/telegram.conf" + ### write single instance config + write_telegram_conf "${cfg_dir}" "${cfg}" "${log}" + + elif (( telegram_bot_count > 1 )); then + local j=0 re="^[1-9][0-9]*$" + + for ((i=1; i <= telegram_bot_count; i++ )); do + ### overwrite config folder if name is only a number + if [[ ${names[j]} =~ ${re} ]]; then + cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}" + else + cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}" + fi + + ### write multi instance config + write_telegram_conf "${cfg_dir}" "${cfg}" "${log}" + port=$((port+1)) + j=$((j+1)) + done && unset j + + else + return 1 + fi +} + +function write_telegram_conf(){ + local cfg_dir=${1} cfg=${2} log=${3} + local conf_template="${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/base_install_template" + ! [[ -d "${cfg_dir}" ]] && mkdir -p "${cfg_dir}" + + if ! [[ -f "${cfg}" ]]; then + status_msg "Creating telegram.conf in ${cfg_dir} ..." + cp "${conf_template}" "${cfg}" + sed -i "s|some_log_path|${log}|g" "${cfg}" + ok_msg "telegram.conf created!" + else + status_msg "File '${cfg}' already exists!\nSkipping..." + fi +} + +function create_telegram_bot_service(){ + local input=("${@}") + local instances=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local cfg_dir cfg service + if (( instances == 1 )); then + cfg_dir="${KLIPPER_CONFIG}" + cfg="${cfg_dir}/telegram.conf" + service="${SYSTEMD}/moonraker-telegram-bot.service" + ### write single instance service + write_telegram_bot_service "" "${cfg}" "${service}" + ok_msg "Single Telegram Bot instance created!" + + elif (( instances > 1 )); then + local j=0 re="^[1-9][0-9]*$" + + for ((i=1; i <= instances; i++ )); do + + ### overwrite config folder if name is only a number + if [[ ${names[j]} =~ ${re} ]]; then + cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}" + else + cfg_dir="${KLIPPER_CONFIG}/${names[${j}]}" + fi + + cfg="${cfg_dir}/telegram.conf" + service="${SYSTEMD}/moonraker-telegram-bot-${names[${j}]}.service" + ### write multi instance service + write_telegram_bot_service "${i}(${names[${j}]})" "${cfg}" "${service}" + ok_msg "Telegram Bot instance #${i}(${names[${j}]}) created!" + j=$((j+1)) + + done && unset j + + else + return 1 + fi +} + +function write_telegram_bot_service(){ + local i=${1} cfg=${2} service=${3} + local service_template="${SRCDIR}/kiauh/resources/moonraker-telegram-bot.service" + + ### replace all placeholders + if ! [[ -f "${service}" ]]; then + status_msg "Creating Telegram Bot Service ${i} ..." + sudo cp "${service_template}" "${service}" + [[ -z ${i} ]] && sudo sed -i "s|instance %INST% ||" "${service}" + [[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}" + sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_TELEGRAM_BOT_ENV_DIR}|; s|%DIR%|${MOONRAKER_TELEGRAM_BOT_DIR}|" "${service}" + sudo sed -i "s|%CFG%|${cfg}|" "${service}" + fi } @@ -48,44 +278,52 @@ function telegram_bot_setup(){ #=========== REMOVE MOONRAKERTELEGRAMBOT ===========# #===================================================# -function remove_telegram_bot(){ - ### remove Moonraker-Telegram-Bot dir - if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]; then - status_msg "Removing Moonraker-Telegram-Bot directory ..." - rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" && ok_msg "Directory removed!" - fi +function remove_telegram_bot_systemd() { + [[ -z "$(telegram_bot_systemd)" ]] && return + status_msg "Removing Telegram Bot Systemd Services ..." + for service in $(telegram_bot_systemd | cut -d"/" -f5); do + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" + ok_msg "Done!" + done + ### reloading units + sudo systemctl daemon-reload + sudo systemctl reset-failed + ok_msg "Telegram Bot Services removed!" +} - ### remove Moonraker-Telegram-Bot VENV dir - if [ -d "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" ]; then - status_msg "Removing Moonraker-Telegram-Bot VENV directory ..." - rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" && ok_msg "Directory removed!" - fi +function remove_telegram_bot_dir() { + ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] && return + status_msg "Removing Moonraker-Telegram-Bot directory ..." + rm -rf "${MOONRAKER_TELEGRAM_BOT_DIR}" + ok_msg "Directory removed!" +} - ### remove Moonraker-Telegram-Bot service - if [ -e "${SYSTEMD}/moonraker-telegram-bot.service" ]; then - status_msg "Removing Moonraker-Telegram-Bot service ..." - do_action_service "stop" "moonraker-telegram-bot" - do_action_service "disable" "moonraker-telegram-bot" - sudo rm -f "${SYSTEMD}/moonraker-telegram-bot.service" - ###reloading units - sudo systemctl daemon-reload - sudo systemctl reset-failed - ok_msg "Moonraker-Telegram-Bot Service removed!" - fi +function remove_telegram_bot_env() { + ! [[ -d "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" ]] && return + status_msg "Removing moonraker-telegram-bot-env directory ..." + rm -rf "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}" + ok_msg "Directory removed!" +} - ### remove Moonraker-Telegram-Bot log - if [ -e "/tmp/telegram.log" ] || [ -e "${HOME}/klipper_logs/telegram.log" ]; then +function remove_telegram_bot_logs() { + if [[ -f "/tmp/telegram.log"|| -f "${HOME}/klipper_logs/telegram.log" ]]; then status_msg "Removing Moonraker-Telegram-Bot log file ..." - rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" && ok_msg "File removed!" + rm -f "/tmp/telegram.log" "${HOME}/klipper_logs/telegram.log" + ok_msg "File removed!" fi +} - ### remove Moonraker-Telegram-Bot log symlink in config dir - if [ -e "${KLIPPER_CONFIG}/telegram.log" ]; then - status_msg "Removing Moonraker-Telegram-Bot log symlink ..." - rm -f "${KLIPPER_CONFIG}/telegram.log" && ok_msg "File removed!" - fi +function remove_telegram_bot(){ + remove_telegram_bot_systemd + remove_telegram_bot_dir + remove_telegram_bot_env + remove_telegram_bot_logs - print_confirm "Moonraker-Telegram-Bot successfully removed!" + local confirm="Moonraker-Telegram-Bot was successfully removed!" + print_confirm "${confirm}" && return } #===================================================# @@ -93,13 +331,21 @@ function remove_telegram_bot(){ #===================================================# function update_telegram_bot(){ - local klipper_cfg_loc - klipper_cfg_loc="$(get_klipper_cfg_dir)" do_action_service "stop" "moonraker-telegram-bot" - cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git pull - /bin/bash "./scripts/install.sh" - do_action_service "start" "moonraker-telegram-bot" + if ! [[ -d ${MOONRAKER_TELEGRAM_BOT_DIR} ]]; then + cd "${HOME}" && git clone "${MOONRAKER_TELEGRAM_BOT_REPO}" + else + backup_before_update "moonraker-telegram-bot" + status_msg "Updating Moonraker ..." + cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git pull + ### read PKGLIST and install possible new dependencies + install_telegram_bot_dependencies + ### install possible new python dependencies + "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}"/bin/pip install -r "${MOONRAKER_TELEGRAM_BOT_DIR}/scripts/requirements.txt" + fi + ok_msg "Update complete!" + do_action_service "start" "moonraker-telegram-bot" } #===================================================# @@ -112,16 +358,16 @@ function get_telegram_bot_status(){ ### remove the "SERVICE" entry from the data array if a moonraker service is installed local data_arr=(SERVICE "${MOONRAKER_TELEGRAM_BOT_DIR}" "${MOONRAKER_TELEGRAM_BOT_ENV_DIR}") - [ "${sf_count}" -gt 0 ] && unset "data_arr[0]" + ((sf_count > 0)) && unset "data_arr[0]" ### count+1 for each found data-item from array local filecount=0 for data in "${data_arr[@]}"; do - [ -e "${data}" ] && filecount=$(("${filecount}" + 1)) + [[ -e ${data} ]] && filecount=$((filecount + 1)) done - if (( filecount == ${#data_arr[*]})); then - status="Installed!" + if ((filecount == ${#data_arr[*]})); then + status="Installed: ${sf_count}" elif ((filecount == 0)); then status="Not installed!" else @@ -132,7 +378,7 @@ function get_telegram_bot_status(){ function get_local_telegram_bot_commit(){ local commit - [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] || [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ] && return + ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] || ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ]] && return cd "${MOONRAKER_TELEGRAM_BOT_DIR}" commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)" echo "${commit}" @@ -140,7 +386,7 @@ function get_local_telegram_bot_commit(){ function get_remote_telegram_bot_commit(){ local commit - [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] || [ ! -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ] && return + ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ]] || ! [[ -d "${MOONRAKER_TELEGRAM_BOT_DIR}"/.git ]] && return cd "${MOONRAKER_TELEGRAM_BOT_DIR}" && git fetch origin -q commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2) echo "${commit}" @@ -151,7 +397,7 @@ function compare_telegram_bot_versions(){ local versions local_ver remote_ver local_ver="$(get_local_telegram_bot_commit)" remote_ver="$(get_remote_telegram_bot_commit)" - if [ "${local_ver}" != "${remote_ver}" ]; then + if [[ "${local_ver}" != "${remote_ver}" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" # add moonraker-telegram-bot to the update all array for the update all function in the updater diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 0cdb4de..21e5560 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -54,7 +54,7 @@ function install_menu(){ 7) do_action "install_pgc_for_klipper" "install_ui";; 8) - do_action "install_telegram_bot" "install_ui";; + do_action "telegram_bot_setup_dialog" "install_ui";; 9) do_action "install_mjpg-streamer" "install_ui";; B|b) From 261fcd043cba08a51a98f86a575a6c7501660b1b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 7 May 2022 17:46:25 +0200 Subject: [PATCH 180/183] feat(octoprint.sh): multi instance and custom names Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 225 +++++++++++++++++++++++++------------------ 1 file changed, 133 insertions(+), 92 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 70ed267..d52acbd 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -17,56 +17,88 @@ set -e function octoprint_systemd() { local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[^0])?[0-9]*.service" | sort) + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[0-9a-zA-Z]+)?.service" | sort) echo "${services}" } function octoprint_setup_dialog(){ - local klipper_count - klipper_count=$(klipper_systemd | wc -w) - status_msg "Initializing OctoPrint installation ..." - top_border - if [ -f "${INITD}/klipper" ] || [ -f "${SYSTEMD}/klipper.service" ]; then - printf "|${green}%-55s${white}|\n" " 1 Klipper instance was found!" - elif [ "${klipper_count}" -gt 1 ]; then - printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances were found!" - else - echo -e "| ${yellow}INFO: No existing Klipper installation found!${white} |" - fi - echo -e "| Usually you need one OctoPrint instance per Klipper |" - echo -e "| instance. Though you can install as many as you wish. |" - bottom_border - local count - while [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; do - read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " count - if [[ ! (${count} =~ ^[1-9]+((0)+)?$) ]]; then - error_msg "Invalid Input!\n" - else - echo - while true; do - read -p "${cyan}###### Install ${count} instance(s)? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - status_msg "Installing ${count} OctoPrint instance(s) ... \n" - octoprint_setup "${count}" - break;; - N|n|No|no) - select_msg "No" - error_msg "Exiting OctoPrint setup ...\n" - break;; - *) - error_msg "Invalid Input!\n";; - esac - done - fi + local klipper_services klipper_count user_input=() klipper_names=() + klipper_services=$(klipper_systemd) + klipper_count=$(echo "${klipper_services}" | wc -w ) + for service in ${klipper_services}; do + klipper_names+=( "$(get_instance_name "${service}")" ) done + + local octoprint_count + if ((klipper_count == 1)); then + ok_msg "Klipper installation found!\n" + octoprint_count=1 + elif ((klipper_count > 1)); then + top_border + printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!" + for name in "${klipper_names[@]}"; do + printf "|${cyan}%-57s${white}|\n" " ● ${name}" + done + blank_line + echo -e "| The setup will apply the same names to OctoPrint! |" + blank_line + echo -e "| Please select the number of OctoPrint instances to |" + echo -e "| install. Usually one OctoPrint instance per Klipper |" + echo -e "| instance is required but you may not install more |" + echo -e "| OctoPrint instances than available Klipper instances. |" + bottom_border + + local re="^[1-9][0-9]*$" + while ! [[ ${octoprint_count} =~ ${re} && ${octoprint_count} -le ${klipper_count} ]]; do + read -p "${cyan}###### Number of OctoPrint instances to set up:${white} " -i "${klipper_count}" -e octoprint_count + ### break if input is valid + [[ ${octoprint_count} =~ ${re} ]] && break + ### conditional error messages + error_msg "Invalid Input:" + ! [[ ${octoprint_count} =~ ${re} ]] && error_msg "● Input not a number" + ((octoprint_count > klipper_count)) && error_msg "● Number of OctoPrint instances larger than existing Klipper instances" + done && select_msg "${octoprint_count}" + else + log_error "Internal error. octoprint_count of '${octoprint_count}' not equal or grather than one!" + return 1 + fi + + user_input+=("${octoprint_count}") + + ### confirm instance amount + while true; do + ((octoprint_count == 1)) && local question="Install OctoPrint?" + ((octoprint_count > 1)) && local question="Install ${octoprint_count} OctoPrint instances?" + read -p "${cyan}###### ${question} (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + break;; + N|n|No|no) + select_msg "No" + abort_msg "Exiting OctoPrint setup ...\n" + return;; + *) + error_msg "Invalid Input!";; + esac + done + + ### write existing klipper names into user_input array to use them as names for octoprint + if (( klipper_count > 1 )); then + for name in "${klipper_names[@]}"; do + user_input+=("${name}") + done + fi + + ((octoprint_count > 1)) && status_msg "Installing ${octoprint_count} OctoPrint instances ..." + ((octoprint_count == 1)) && status_msg "Installing OctoPrint ..." + octoprint_setup "${user_input[@]}" } function octoprint_setup(){ - local instances="${1}" + local instance_arr=("${@}") ### check and install all dependencies local dep=( git @@ -80,71 +112,81 @@ function octoprint_setup(){ ) dependency_check "${dep[@]}" - ### check for tty and dialout usergroups and add reboot permissions + ### step 1: check for tty and dialout usergroups and add reboot permissions check_usergroups add_reboot_permission - ### install octoprint - install_octoprint "${instances}" + ### step 2: install octoprint + install_octoprint "${instance_arr[@]}" - ### set up service - create_octoprint_service "${instances}" + ### step 3: set up service + create_octoprint_service "${instance_arr[@]}" - ### step 6: enable and start all instances + ### step 4: enable and start all instances do_action_service "enable" "octoprint" do_action_service "start" "octoprint" ### confirm message - [ "${instances}" -eq 1 ] && confirm_msg="OctoPrint has been set up!" - [ "${instances}" -gt 1 ] && confirm_msg="${instances} OctoPrint instances have been set up!" - print_confirm "${confirm_msg}" - print_op_ip_list "${instances}" + local confirm="" + (( instance_arr[0] == 1)) && confirm="OctoPrint has been set up!" + (( instance_arr[0] > 1)) && confirm="${instance_arr[0]} OctoPrint instances have been set up!" + print_confirm "${confirm}" && print_op_ip_list "${instance_arr[0]}" && return } function install_octoprint(){ - local i=1 instances=${1} octo_env - while (( i <= instances )); do - (( instances == 1 )) && octo_env="${HOME}/OctoPrint" - (( instances > 1 )) && octo_env="${HOME}/OctoPrint_${i}" + local input=("${@}") + local octoprint_count=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local j=0 octo_env + + for ((i=1; i <= octoprint_count; i++ )); do + (( octoprint_count == 1 )) && octo_env="${HOME}/OctoPrint" + (( octoprint_count > 1 )) && octo_env="${HOME}/OctoPrint_${names[${j}]}" + ### create and activate the virtualenv status_msg "Installing python virtual environment..." - [ ! -d "${octo_env}" ] && mkdir -p "${octo_env}" + ! [[ -d "${octo_env}" ]] && mkdir -p "${octo_env}" cd "${octo_env}" && virtualenv --python=python3 venv + ### activate virtualenv source venv/bin/activate - (( instances == 1 )) && status_msg "Installing OctoPrint ..." - (( instances > 1 )) && status_msg "Installing OctoPrint instance ${i} ..." + (( octoprint_count == 1 )) && status_msg "Installing OctoPrint ..." + (( octoprint_count > 1 )) && status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..." pip install pip --upgrade pip install --no-cache-dir octoprint ok_msg "Ok!" + ### leave virtualenv deactivate - i=$((i+1)) + j=$((j+1)) done } function create_octoprint_service(){ - local i=1 instances=${1} port=5000 + local input=("${@}") + local octoprint_count=${input[0]} && unset "input[0]" + local names=("${input[@]}") && unset "input[@]" + local j=0 port=5000 local octo_env service basedir tmp_printer config_yaml restart_cmd - while (( i <= instances )); do - if (( instances == 1 )); then + for ((i=1; i <= octoprint_count; i++)); do + if (( octoprint_count == 1 )); then octo_env="${HOME}/OctoPrint" service="${SYSTEMD}/octoprint.service" basedir="${HOME}/.octoprint" tmp_printer="/tmp/printer" config_yaml="${basedir}/config.yaml" restart_cmd="sudo service octoprint restart" - elif (( instances > 1 )); then - octo_env="${HOME}/OctoPrint_${i}" - service="${SYSTEMD}/octoprint-${i}.service" - basedir="${HOME}/.octoprint_${i}" - tmp_printer="/tmp/printer-${i}" + elif (( octoprint_count > 1 )); then + octo_env="${HOME}/OctoPrint_${names[${j}]}" + service="${SYSTEMD}/octoprint-${names[${j}]}.service" + basedir="${HOME}/.octoprint_${names[${j}]}" + tmp_printer="/tmp/printer-${names[${j}]}" config_yaml="${basedir}/config.yaml" - restart_cmd="sudo service octoprint-${i} restart" + restart_cmd="sudo service octoprint-${names[${j}]} restart" fi - (( instances == 1 )) && status_msg "Creating OctoPrint service ..." - (( instances > 1 )) && status_msg "Creating OctoPrint service ${i} ..." + (( octoprint_count == 1 )) && status_msg "Creating OctoPrint service ..." + (( octoprint_count > 1 )) && status_msg "Creating OctoPrint service ${i}(${names[${j}]}) ..." sudo /bin/sh -c "cat > ${service}" << OCTOPRINT [Unit] Description=Starts OctoPrint on startup @@ -161,13 +203,16 @@ ExecStart=${octo_env}/venv/bin/octoprint --basedir ${basedir} --config ${config_ [Install] WantedBy=multi-user.target OCTOPRINT - ok_msg "Ok!" + port=$((port+1)) + j=$((j+1)) + ok_msg "Ok!" - ### create config.yaml - if [ ! -f "${basedir}/config.yaml" ]; then - [ ! -d "${basedir}" ] && mkdir "${basedir}" - status_msg "Creating config.yaml ..." - /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML + ### create config.yaml + if ! [[ -f "${basedir}/config.yaml" ]]; then + ! [[ -d "${basedir}" ]] && mkdir "${basedir}" + (( octoprint_count == 1 )) && status_msg "Creating config.yaml ..." + (( octoprint_count > 1 )) && status_msg "Creating config.yaml for instance ${i}(${names[${j}]}) ..." + /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML serial: additionalPorts: - ${tmp_printer} @@ -179,17 +224,14 @@ server: systemRestartCommand: sudo shutdown -r now systemShutdownCommand: sudo shutdown -h now CONFIGYAML - ok_msg "Ok!" - fi - - port=$((port+1)) - i=$((i+1)) + ok_msg "Ok!" + fi done } function add_reboot_permission(){ #create a backup if file already exists - if [ -f /etc/sudoers.d/octoprint-shutdown ]; then + if [[ -f /etc/sudoers.d/octoprint-shutdown ]]; then sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old fi #create new permission file @@ -201,12 +243,11 @@ function add_reboot_permission(){ } function print_op_ip_list(){ - local ip instances="${1}" i=1 port=5000 + local ip octoprint_count="${1}" port=5000 ip=$(hostname -I | cut -d" " -f1) - while [ "${i}" -le "${instances}" ] ; do + for ((i=1; i <= octoprint_count; i++)); do echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}" port=$((port+1)) - i=$((i+1)) done && echo } @@ -216,7 +257,7 @@ function print_op_ip_list(){ function remove_octoprint_service(){ ###remove all octoprint services - [ -z "$(octoprint_systemd)" ] && return + [[ -z "$(octoprint_systemd)" ]] && return status_msg "Removing OctoPrint Systemd Services ..." for service in $(octoprint_systemd | cut -d"/" -f5) do @@ -232,15 +273,15 @@ function remove_octoprint_service(){ } function remove_octoprint_sudoers(){ - [ ! -f /etc/sudoers.d/octoprint-shutdown ] && return + ! [[ -f /etc/sudoers.d/octoprint-shutdown ]] && return ### remove sudoers file sudo rm -f /etc/sudoers.d/octoprint-shutdown } function remove_octoprint_env(){ local files - files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*" | sort) - if [ -n "${files}" ]; then + files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | sort) + if [[ -n ${files} ]]; then for file in ${files}; do status_msg "Removing ${file} ..." rm -rf "${file}" @@ -251,8 +292,8 @@ function remove_octoprint_env(){ function remove_octoprint_dir(){ local files - files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*" | sort) - if [ -n "${files}" ]; then + files=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | sort) + if [[ -n ${files} ]]; then for file in ${files}; do status_msg "Removing ${file} ..." rm -rf "${file}" @@ -281,8 +322,8 @@ function remove_octoprint(){ function get_octoprint_status(){ local sf_count env_count dir_count status sf_count="$(octoprint_systemd | wc -w)" - env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[^0])?[0-9]*" | wc -w) - dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[^0])?[0-9]*" | wc -w) + env_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/OctoPrint(_[0-9a-zA-Z]+)?" | wc -w) + dir_count=$(find "${HOME}" -maxdepth 1 -regextype posix-extended -regex "${HOME}/.octoprint(_[0-9a-zA-Z]+)?" | wc -w) if (( sf_count == 0 )) && (( env_count == 0 )) && (( dir_count == 0 )); then status="Not installed!" From 755d1b5cd67753668d02d92651d5d318117e8559 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 7 May 2022 18:57:51 +0200 Subject: [PATCH 181/183] refactor(octoprint.sh): drastically improve installation speed of multi instance installations Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 87 ++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index d52acbd..f25fd3b 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -134,32 +134,71 @@ function octoprint_setup(){ } function install_octoprint(){ + + function install_octoprint_python_env() { + local tmp="${1}" + ### create and activate the virtualenv + status_msg "Installing python virtual environment..." + + if ! [[ -d "${tmp}" ]]; then + mkdir -p "${tmp}" + else + error_msg "Cannot create temporary directory in ${HOME}!" + error_msg "Folder 'TMP_OCTO_ENV' exists and may not be empty!" + error_msg "Please remove/rename that folder and start again." + return 1 + fi + + cd "${tmp}" && virtualenv --python=python3 venv + ### activate virtualenv + source venv/bin/activate + pip install pip --upgrade + pip install --no-cache-dir octoprint + ### leave virtualenv + deactivate + cd "${HOME}" + } + local input=("${@}") local octoprint_count=${input[0]} && unset "input[0]" local names=("${input[@]}") && unset "input[@]" local j=0 octo_env + local tmp="${HOME}/TMP_OCTO_ENV" - for ((i=1; i <= octoprint_count; i++ )); do - (( octoprint_count == 1 )) && octo_env="${HOME}/OctoPrint" - (( octoprint_count > 1 )) && octo_env="${HOME}/OctoPrint_${names[${j}]}" + ### handle single instance installs + if ((octoprint_count == 1)); then + if install_octoprint_python_env "${tmp}"; then + status_msg "Installing OctoPrint ..." + octo_env="${HOME}/OctoPrint" + ### rename the temporary directory to the correct name + [[ -d ${octo_env} ]] && rm -rf "${octo_env}" + mv "${tmp}" "${octo_env}" + ### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint + sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint" + else + error_msg "OctoPrint installation failed!" + return 1 + fi + fi - ### create and activate the virtualenv - status_msg "Installing python virtual environment..." - ! [[ -d "${octo_env}" ]] && mkdir -p "${octo_env}" - cd "${octo_env}" && virtualenv --python=python3 venv - - ### activate virtualenv - source venv/bin/activate - (( octoprint_count == 1 )) && status_msg "Installing OctoPrint ..." - (( octoprint_count > 1 )) && status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..." - pip install pip --upgrade - pip install --no-cache-dir octoprint - ok_msg "Ok!" - - ### leave virtualenv - deactivate - j=$((j+1)) - done + ### handle multi instance installs + if (( octoprint_count > 1 )); then + if install_octoprint_python_env "${tmp}"; then + for ((i=1; i <= octoprint_count; i++ )); do + status_msg "Installing OctoPrint instance ${i}(${names[${j}]}) ..." + octo_env="${HOME}/OctoPrint_${names[${j}]}" + ### rename the temporary directory to the correct name + [[ -d ${octo_env} ]] && rm -rf "${octo_env}" + cp -r "${tmp}" "${octo_env}" + ### replace the temporary directory name with the actual one in ${octo_env}/venv/bin/python/octoprint + sed -i "s|${tmp}|${octo_env}|" "${octo_env}/venv/bin/octoprint" + j=$((j+1)) + done && rm -rf "${tmp}" + else + error_msg "OctoPrint installation failed!" + return 1 + fi + fi } function create_octoprint_service(){ @@ -185,8 +224,8 @@ function create_octoprint_service(){ config_yaml="${basedir}/config.yaml" restart_cmd="sudo service octoprint-${names[${j}]} restart" fi - (( octoprint_count == 1 )) && status_msg "Creating OctoPrint service ..." - (( octoprint_count > 1 )) && status_msg "Creating OctoPrint service ${i}(${names[${j}]}) ..." + (( octoprint_count == 1 )) && status_msg "Creating OctoPrint Service ..." + (( octoprint_count > 1 )) && status_msg "Creating OctoPrint Service ${i}(${names[${j}]}) ..." sudo /bin/sh -c "cat > ${service}" << OCTOPRINT [Unit] Description=Starts OctoPrint on startup @@ -208,8 +247,8 @@ OCTOPRINT ok_msg "Ok!" ### create config.yaml - if ! [[ -f "${basedir}/config.yaml" ]]; then - ! [[ -d "${basedir}" ]] && mkdir "${basedir}" + if ! [[ -f ${basedir}/config.yaml ]]; then + ! [[ -d ${basedir} ]] && mkdir "${basedir}" (( octoprint_count == 1 )) && status_msg "Creating config.yaml ..." (( octoprint_count > 1 )) && status_msg "Creating config.yaml for instance ${i}(${names[${j}]}) ..." /bin/sh -c "cat > ${basedir}/config.yaml" << CONFIGYAML From 5a3ab35ba7f65df9f5522f7fb57c82882a4b4ea5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 12 May 2022 20:56:12 +0200 Subject: [PATCH 182/183] refactor(klipper.sh): better conditions - reword service description - reword ok messages Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/klipper.service | 2 +- scripts/klipper.sh | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/klipper.service b/resources/klipper.service index 5b2e996..5bf8f5a 100644 --- a/resources/klipper.service +++ b/resources/klipper.service @@ -1,7 +1,7 @@ #Systemd Klipper Service [Unit] -Description=Starts Klipper instance %INST% on startup +Description=Systemd Klipper Service for instance klipper-%INST% Documentation=https://www.klipper3d.org/ After=network.target Wants=udev.target diff --git a/scripts/klipper.sh b/scripts/klipper.sh index db3483f..8f2e0ed 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -247,7 +247,7 @@ function write_klipper_service(){ if [ ! -f "${service}" ]; then status_msg "Creating Klipper Service ${i} ..." sudo cp "${service_template}" "${service}" - [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" + [ -z "${i}" ] && sudo sed -i "s| for instance klipper-%INST%||" "${service}" [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${KLIPPY_ENV}|; s|%DIR%|${KLIPPER_DIR}|" "${service}" sudo sed -i "s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${printer}|; s|%UDS%|${uds}|" "${service}" @@ -269,7 +269,7 @@ function create_klipper_service(){ local names=("${input[@]}") && unset "input[@]" local cfg_dir cfg log printer uds service - if (( klipper_count == 1 )); then + if (( klipper_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then cfg_dir="${KLIPPER_CONFIG}" cfg="${cfg_dir}/printer.cfg" log="${KLIPPER_LOGS}/klippy.log" @@ -279,9 +279,9 @@ function create_klipper_service(){ ### write single instance service write_klipper_service "" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" write_example_printer_cfg "${cfg_dir}" "${cfg}" - ok_msg "Single Klipper instance created!" + ok_msg "Klipper instance created!" - elif (( klipper_count > 1 )); then + elif (( klipper_count >= 1 )) && [[ ${#names[@]} -gt 0 ]]; then local j=0 re="^[1-9][0-9]*$" for ((i=1; i <= klipper_count; i++)); do @@ -298,9 +298,9 @@ function create_klipper_service(){ uds="/tmp/klippy_uds-${names[${j}]}" service="${SYSTEMD}/klipper-${names[${j}]}.service" ### write multi instance service - write_klipper_service "${i}(${names[${j}]})" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" + write_klipper_service "${names[${j}]}" "${cfg}" "${log}" "${printer}" "${uds}" "${service}" write_example_printer_cfg "${cfg_dir}" "${cfg}" - ok_msg "Klipper instance #${i}(${names[${j}]}) created!" + ok_msg "Klipper instance 'klipper-${names[${j}]} created!" j=$((j+1)) done && unset j From 21710db0c6639efdcfb3313cfef97199dcbad09d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 12 May 2022 20:56:40 +0200 Subject: [PATCH 183/183] refactor(moonraker.sh): better conditions - reword service description - reword ok messages Signed-off-by: Dominik Willner th33xitus@gmail.com --- resources/moonraker.service | 2 +- scripts/moonraker.sh | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/resources/moonraker.service b/resources/moonraker.service index 01d9ab5..0ef771f 100644 --- a/resources/moonraker.service +++ b/resources/moonraker.service @@ -1,7 +1,7 @@ #Systemd Moonraker Service [Unit] -Description=Starts Moonraker %INST% on startup +Description=Systemd Moonraker Service for instance moonraker-%INST% Documentation=https://moonraker.readthedocs.io/ After=network.target diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 1b5a9a0..59c3bfc 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -66,7 +66,7 @@ function moonraker_setup_dialog(){ top_border printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!" for name in "${klipper_names[@]}"; do - printf "|${cyan}%-57s${white}|\n" " ● ${name}" + printf "|${cyan}%-57s${white}|\n" " ● klipper-${name}" done blank_line echo -e "| The setup will apply the same names to Moonraker! |" @@ -260,24 +260,24 @@ function write_moonraker_conf(){ function create_moonraker_service(){ local input=("${@}") - local instances=${input[0]} && unset "input[0]" + local moonraker_count=${input[0]} && unset "input[0]" local names=("${input[@]}") && unset "input[@]" - local i j cfg_dir cfg log service - if (( instances == 1 )); then + local cfg_dir cfg log service + + if (( moonraker_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then i="" cfg_dir="${KLIPPER_CONFIG}" cfg="${cfg_dir}/moonraker.conf" log="${HOME}/klipper_logs/moonraker.log" service="${SYSTEMD}/moonraker.service" ### write single instance service - write_moonraker_service "${i}" "${cfg_dir}" "${cfg}" "${log}" "${service}" - ok_msg "Single Moonraker instance created!" + write_moonraker_service "" "${cfg_dir}" "${cfg}" "${log}" "${service}" + ok_msg "Moonraker instance created!" - elif (( instances > 1 )); then - local i=1 j=0 re="^[1-9][0-9]*$" - - while (( i <= instances )); do + elif (( moonraker_count > 1 )) && [[ ${#names[@]} -gt 0 ]]; then + local j=0 re="^[1-9][0-9]*$" + for ((i=1; i <= moonraker_count; i++)); do ### overwrite config folder if name is only a number if [[ ${names[j]} =~ ${re} ]]; then cfg_dir="${KLIPPER_CONFIG}/printer_${names[${j}]}" @@ -289,11 +289,9 @@ function create_moonraker_service(){ log="${HOME}/klipper_logs/moonraker-${names[${j}]}.log" service="${SYSTEMD}/moonraker-${names[${j}]}.service" ### write multi instance service - write_moonraker_service "${i}(${names[${j}]})" "${cfg_dir}" "${cfg}" "${log}" "${service}" - ok_msg "Moonraker instance #${i}(${names[${j}]}) created!" - i=$((i+1)) + write_moonraker_service "${names[${j}]}" "${cfg_dir}" "${cfg}" "${log}" "${service}" + ok_msg "Moonraker instance 'moonraker-${names[${j}]}' created!" j=$((j+1)) - done && unset i ### enable mainsails remoteMode if mainsail is found @@ -317,7 +315,7 @@ function write_moonraker_service(){ status_msg "Creating Moonraker Service ${i} ..." sudo cp "${service_template}" "${service}" - [ -z "${i}" ] && sudo sed -i "s|instance %INST% ||" "${service}" + [ -z "${i}" ] && sudo sed -i "s| for instance moonraker-%INST%||" "${service}" [ -n "${i}" ] && sudo sed -i "s|%INST%|${i}|" "${service}" sudo sed -i "s|%USER%|${USER}|; s|%ENV%|${MOONRAKER_ENV}|; s|%DIR%|${MOONRAKER_DIR}|" "${service}" sudo sed -i "s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${service}"