<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello, <BR> <BR>I try to port systemd to a live distro.<BR>The biggest problem is that they work with modules. <BR> <BR>So before the start up can be processed all the modules needs to <BR>be packed out and copied to memory.<BR> <BR>The script for that is this :<BR> <BR><div class="code-body highlight"><pre><div class="line" id="LC1"><span class="c">#!/bin/bash</span></div><div class="line" id="LC2"><span class="c"># Activate a module, while running LiveCD.</span></div><div class="line" id="LC3"><span class="c"># Include it into live directory structure on the fly</span></div><div class="line" id="LC4"><span class="c">#</span></div><div class="line" id="LC5"><span class="c"># Author: Tomas M. <http://www.linux-live.org></span></div><div class="line" id="LC6"><span class="c"># Modifications for Porteus by fanthom/brokenman</span></div><div class="line" id="LC7"><br></div><div class="line" id="LC8"><span class="nv">MODULE</span><span class="o">=</span><span class="k">$(</span>readlink -f <span class="s2">"$1"</span><span class="k">)</span></div><div class="line" id="LC9"><br></div><div class="line" id="LC10"><span class="c"># Make sure that only one (two for root) instance of 'activate' script is running</span></div><div class="line" id="LC11"><span class="nv">pid</span><span class="o">=</span><span class="sb">`</span>ps a <span class="p">|</span> egrep -v <span class="s1">'grep|xterm'</span> <span class="p">|</span> grep -c -w /opt/porteus-scripts/activate<span class="sb">`</span></div><div class="line" id="LC12"><span class="k">while</span> <span class="o">[</span> <span class="nv">$pid</span> -gt 3 <span class="o">]</span><span class="p">;</span> <span class="k">do</span></div><div class="line" id="LC13"><span class="k">    </span><span class="nb">echo</span> <span class="s2">"too many activations - sleeping 1 sec..."</span> <span class="o">&&</span> sleep 1</div><div class="line" id="LC14">    <span class="nv">pid</span><span class="o">=</span><span class="sb">`</span>ps a <span class="p">|</span> egrep -v <span class="s1">'grep|xterm'</span> <span class="p">|</span> grep -c -w /opt/porteus-scripts/activate<span class="sb">`</span></div><div class="line" id="LC15"><span class="k">done</span></div><div class="line" id="LC16"><br></div><div class="line" id="LC17"><span class="c"># Switch to root</span></div><div class="line" id="LC18"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$DISPLAY"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC19"><span class="k">    if</span> <span class="o">[</span> <span class="sb">`</span>whoami<span class="sb">`</span> !<span class="o">=</span> <span class="s2">"root"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC20"><span class="k">        </span>xterm -T <span class="s2">"Please enter root's password below"</span> -e su -c <span class="s2">"/opt/porteus-scripts/xactivate $MODULE && sleep 2"</span></div><div class="line" id="LC21">        <span class="nb">exit</span></div><div class="line" id="LC22"><span class="nb">    </span><span class="k">fi</span></div><div class="line" id="LC23"><span class="k">else</span></div><div class="line" id="LC24"><span class="k">    if</span> <span class="o">[</span> <span class="sb">`</span>whoami<span class="sb">`</span> !<span class="o">=</span> <span class="s2">"root"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC25"><span class="k">        </span><span class="nb">echo</span> <span class="s2">"Please enter root's password below"</span></div><div class="line" id="LC26">        su -c <span class="s2">"/opt/porteus-scripts/activate $MODULE"</span></div><div class="line" id="LC27">        <span class="nb">exit</span></div><div class="line" id="LC28"><span class="nb">    </span><span class="k">fi</span></div><div class="line" id="LC29"><span class="k">fi</span></div><div class="line" id="LC30"><br></div><div class="line" id="LC31"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$2"</span> <span class="o">=</span> <span class="s2">"-k"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC32"><span class="k">   </span><span class="nv">CALLED_BY_GUI_HELPER</span><span class="o">=</span>1</div><div class="line" id="LC33"><span class="k">fi</span></div><div class="line" id="LC34"><br></div><div class="line" id="LC35"><span class="k">if</span> <span class="o">[</span> -e /opt/porteus-scripts/xactivate -a <span class="s2">"$DISPLAY"</span> -a ! <span class="s2">"$CALLED_BY_GUI_HELPER"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC36"><span class="k">   </span><span class="nb">exec</span> /opt/porteus-scripts/xactivate <span class="s2">"$MODULE"</span> 2>/dev/null</div><div class="line" id="LC37"><span class="k">fi</span></div><div class="line" id="LC38"><br></div><div class="line" id="LC39"><span class="nv">PATH</span><span class="o">=</span>.:<span class="k">$(</span>dirname <span class="nv">$0</span><span class="k">)</span>:/usr/lib:<span class="nv">$PATH</span></div><div class="line" id="LC40">. liblinuxlive <span class="o">||</span> <span class="nb">exit </span>3</div><div class="line" id="LC41"><br></div><div class="line" id="LC42"><span class="nv">BASE</span><span class="o">=</span><span class="k">$(</span>basename <span class="nv">$1</span> 2>/dev/null<span class="k">)</span></div><div class="line" id="LC43"><span class="k">if </span>ismountpoint <span class="s2">"/mnt/live/memory/images/$BASE"</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC44"><span class="k">    </span><span class="nb">echo</span> <span class="s2">"Module is already activated. Deactivate? Answer y/n"</span></div><div class="line" id="LC45">    <span class="nb">read </span>ans</div><div class="line" id="LC46">    <span class="k">if</span> <span class="o">[</span> <span class="s2">"$ans"</span> <span class="o">=</span> <span class="s2">"y"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC47"><span class="k">        </span>deactivate <span class="nv">$BASE</span></div><div class="line" id="LC48">        <span class="nb">exit</span></div><div class="line" id="LC49"><span class="nb">    </span><span class="k">else</span></div><div class="line" id="LC50"><span class="k">        </span><span class="nb">exit</span></div><div class="line" id="LC51"><span class="nb">    </span><span class="k">fi</span></div><div class="line" id="LC52"><span class="k">fi</span></div><div class="line" id="LC53"><br></div><div class="line" id="LC54"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$MODULE"</span> <span class="o">=</span> <span class="s2">""</span> -o ! -e <span class="s2">"$MODULE"</span> -o -d <span class="s2">"$MODULE"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC55"><span class="k">   </span><span class="nb">echo</span></div><div class="line" id="LC56"><span class="nb">   echo</span> <span class="s2">"Activate a module on the fly while running Linux Live"</span></div><div class="line" id="LC57">   <span class="nb">echo</span> <span class="s2">"Usage: $0 module.xzm"</span></div><div class="line" id="LC58">   <span class="nb">exit </span>1</div><div class="line" id="LC59"><span class="k">fi</span></div><div class="line" id="LC60"><br></div><div class="line" id="LC61"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$(echo $MODULE | fgrep -i .xzm)"</span> <span class="o">=</span> <span class="s2">""</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC62"><span class="k">   </span><span class="nb">echo</span></div><div class="line" id="LC63"><span class="nb">   echo</span> <span class="s2">"$(basename $MODULE): Module must end with .xzm"</span></div><div class="line" id="LC64">   <span class="nb">exit </span>2</div><div class="line" id="LC65"><span class="k">fi</span></div><div class="line" id="LC66"><br></div><div class="line" id="LC67"><span class="nv">IMAGES</span><span class="o">=</span>/mnt/live/memory/images</div><div class="line" id="LC68"><span class="nv">MODULES</span><span class="o">=</span>/mnt/live/memory/modules</div><div class="line" id="LC69"><br></div><div class="line" id="LC70"><span class="c"># are we even using union?</span></div><div class="line" id="LC71"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$(grep '^aufs / ' /proc/mounts)"</span> <span class="o">=</span> <span class="s2">""</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC72"><span class="k">   </span><span class="nb">echo</span> <span class="s2">"not in the live mode, can't continue. Try xzm2dir $MODULE /"</span></div><div class="line" id="LC73">   <span class="nb">exit </span>4</div><div class="line" id="LC74"><span class="k">fi</span></div><div class="line" id="LC75"><br></div><div class="line" id="LC76">mkdir -p <span class="s2">"$MODULES"</span></div><div class="line" id="LC77"><br></div><div class="line" id="LC78"><span class="c"># Test whether the module file is stored in union</span></div><div class="line" id="LC79"><span class="c"># if yes, then we must move it somewhere else (to RAM) else it can't be added</span></div><div class="line" id="LC80"><span class="k">if</span> <span class="o">[</span> -e <span class="s2">"/mnt/live/memory/changes/$(readlink -f "</span><span class="nv">$MODULE</span><span class="s2">")"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC81"><span class="k">   </span><span class="nb">echo</span> <span class="s2">"module file is stored inside the union, moving to $MODULES first..."</span></div><div class="line" id="LC82">   <span class="nv">TARGET</span><span class="o">=</span><span class="s2">"$MODULES/$(basename "</span><span class="nv">$MODULE</span><span class="s2">")"</span></div><div class="line" id="LC83">   mv <span class="s2">"$MODULE"</span> <span class="s2">"$TARGET"</span></div><div class="line" id="LC84">   <span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne 0 <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC85"><span class="k">      </span><span class="nb">echo</span> <span class="s2">"error copying module to memory, not enough free RAM? try df"</span> ><span class="p">&</span>2</div><div class="line" id="LC86">      rm <span class="s2">"$TARGET"</span></div><div class="line" id="LC87">      <span class="nb">exit </span>6</div><div class="line" id="LC88">   <span class="k">fi</span></div><div class="line" id="LC89"><span class="k">   </span><span class="nv">MODULE</span><span class="o">=</span><span class="s2">"$TARGET"</span></div><div class="line" id="LC90"><span class="k">fi</span></div><div class="line" id="LC91"><br></div><div class="line" id="LC92"><span class="c"># 'Stale NFS' workaround</span></div><div class="line" id="LC93"><span class="nb">cd</span> /etc</div><div class="line" id="LC94"><br></div><div class="line" id="LC95"><span class="nv">MOD</span><span class="o">=</span><span class="k">$(</span>union_insert_module / <span class="s2">"$MODULE"</span> <span class="nv">$IMAGES</span><span class="k">)</span></div><div class="line" id="LC96"><span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne 0 <span class="o">]</span><span class="p">;</span> <span class="k">then </span><span class="nb">echo</span> <span class="s2">"error inserting module to live filesystem"</span> ><span class="p">&</span>2<span class="p">;</span> <span class="nb">exit </span>3<span class="p">;</span> <span class="k">fi</span></div><div class="line" id="LC97"><span class="nv">MOD</span><span class="o">=</span><span class="s2">"$IMAGES/$(basename $MOD)"</span></div><div class="line" id="LC98"><br></div><div class="line" id="LC99"><span class="c"># All executables (but symlinks) in /etc/rc.d/init.d/ from this module will be started</span></div><div class="line" id="LC100"><span class="c"># with two arguments: "start" "activate".</span></div><div class="line" id="LC101"><span class="c"># This is done only by the 'activate' script, not in the case when the module is loaded </span></div><div class="line" id="LC102"><span class="c"># during OS startup (in that case, your distro is responsible for execution)</span></div><div class="line" id="LC103"><span class="c">#</span></div><div class="line" id="LC104"><span class="c"># For compatibility, /etc/init.d is also examined, but it's not recommended for you to put your startup scripts</span></div><div class="line" id="LC105"><span class="c"># there in your module</span></div><div class="line" id="LC106">find_n_run_scripts <span class="nv">$MOD</span> start activate</div><div class="line" id="LC107"><br></div><div class="line" id="LC108"><span class="c"># Rebuild the system configuration cache</span></div><div class="line" id="LC109"><span class="nb">echo</span> <span class="s2">"Updating shared library links:  /sbin/ldconfig"</span></div><div class="line" id="LC110">/sbin/ldconfig</div><div class="line" id="LC111"><span class="nb">echo</span> <span class="s2">"Updating MIME database:  /usr/bin/update-mime-database /usr/share/mime"</span></div><div class="line" id="LC112">/usr/bin/update-mime-database /usr/share/mime > /dev/null 2><span class="p">&</span>1</div><div class="line" id="LC113"><br></div><div class="line" id="LC114"><span class="c"># Update KDE menu</span></div><div class="line" id="LC115"><span class="nv">kdeuser</span><span class="o">=</span><span class="sb">`</span>ps aux <span class="p">|</span> grep /usr/bin/startkde <span class="p">|</span> grep -v grep <span class="p">|</span> cut -d <span class="s2">" "</span> -f1<span class="sb">`</span></div><div class="line" id="LC116"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$kdeuser"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC117"><span class="k">    </span><span class="nb">echo</span> <span class="s2">"Updating KDE menu: kbuildsycoca"</span></div><div class="line" id="LC118">    <span class="k">for </span>x in <span class="s2">"$kdeuser"</span><span class="p">;</span> <span class="k">do </span>su --login <span class="nv">$x</span> -c <span class="s2">"kbuildsycoca"</span><span class="p">;</span> <span class="k">done</span></div><div class="line" id="LC119"><span class="k">fi</span></div><div class="line" id="LC120"><br></div><div class="line" id="LC121"><span class="c"># Update LXDE menu</span></div><div class="line" id="LC122"><span class="nv">lxuser</span><span class="o">=</span><span class="sb">`</span>ps aux <span class="p">|</span> grep lxsession <span class="p">|</span> grep -v grep <span class="p">|</span> cut -d <span class="s2">" "</span> -f1<span class="sb">`</span></div><div class="line" id="LC123"><span class="k">if</span> <span class="o">[</span> <span class="s2">"$lxuser"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC124"><span class="k">    </span><span class="nv">desktop</span><span class="o">=</span><span class="sb">`</span>find <span class="nv">$MOD</span>/usr/share/applications -name <span class="s2">"*.desktop"</span> <span class="p">|</span> wc -l<span class="sb">`</span></div><div class="line" id="LC125">    <span class="k">if</span> <span class="o">[</span> <span class="s2">"$desktop"</span> !<span class="o">=</span> <span class="s2">"0"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC126"><span class="k">        </span><span class="nb">echo</span> <span class="s2">"Updating LXDE menu: rm ~/.cache/menus/*; lxpanelctl restart"</span> </div><div class="line" id="LC127">        <span class="k">for </span>x in <span class="s2">"$lxuser"</span><span class="p">;</span> <span class="k">do </span>su --login <span class="nv">$x</span> -c <span class="s2">"rm ~/.cache/menus/*; lxpanelctl restart"</span><span class="p">;</span> <span class="k">done</span></div><div class="line" id="LC128"><span class="k">    fi</span></div><div class="line" id="LC129"><span class="k">fi</span></div><div class="line" id="LC130"><br></div><div class="line" id="LC131"><span class="c"># Make sure that we have at least one free loop device</span></div><div class="line" id="LC132"><span class="nv">x</span><span class="o">=</span><span class="sb">`</span>grep /dev/loop /proc/mounts <span class="p">|</span> tail -n1 <span class="p">|</span> cut -d <span class="s2">" "</span> -f1 <span class="p">|</span> sed <span class="s1">'s@/dev/loop@@'</span><span class="sb">`</span><span class="p">;</span> <span class="nb">let </span><span class="nv">y</span><span class="o">=</span>x+1</div><div class="line" id="LC133"><span class="k">if</span> <span class="o">[</span> ! -e /dev/loop<span class="nv">$y</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span></div><div class="line" id="LC134"><span class="k">    </span><span class="nb">echo</span> <span class="s2">"Adding new loop device: mknod /dev/loop$y b 7 $y"</span></div><div class="line" id="LC135">    mknod /dev/loop<span class="nv">$y</span> b 7 <span class="nv">$y</span></div><div class="line" id="LC136"><span class="k">fi</span></div></pre></div><a class="js-jump-to-line" style="display: none;" href="https://github.com/Byzantium/Byzantium/blob/master/porteus-scripts/activate#jump-to-line" rel="facebox[.linejump]" data-hotkey="l">Jump to Line</a> <BR><div id="jump-to-line" style="display: none;"><form class="js-jump-to-line-form" accept-charset="UTF-8"><input class="linejump-input js-jump-to-line-field" autofocus="" type="text" placeholder="Jump to line.">     <button class="button" type="submit">Go</button>   </form></div><!-- /.repo-container -->       <BR><div class="modal-backdrop">How can I have the same functionallity with systemd.</div><div class="modal-backdrop">Must I make a custom service file which is called at first and how does the service file look like.</div><div class="modal-backdrop">Or is there another better way ?</div><div class="modal-backdrop"> </div><div class="modal-backdrop">Roelof</div><div class="modal-backdrop"> </div><div class="container"><div class="site-footer"><ul class="site-footer-links right">     </ul></div><a href="https://github.com/"><span title="GitHub" class="mega-octicon octicon-mark-github"></span></a></div>                                         </div></body>
</html>