From d14af94e7cb6102f79a1915f150b85dc77ce645b Mon Sep 17 00:00:00 2001 From: Harvie Date: Mon, 24 May 2010 03:52:27 +0200 Subject: [PATCH] initial commit --- PKGBUILD | 44 ++++++++++ README | 1 + aldm | 64 +++++++++++++++ aldm-gui | 136 +++++++++++++++++++++++++++++++ aldm.ui | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 484 insertions(+) create mode 100644 PKGBUILD create mode 100644 README create mode 100755 aldm create mode 100755 aldm-gui create mode 100644 aldm.ui diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..4bf61cd --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,44 @@ +# Contributor: Thomas Mudrunka +# Maintainer: Thomas Mudrunka +# You can also contact me on http://blog.harvie.cz/ + +pkgname=aldm +pkgver=0.4 +pkgrel=1 +pkgdesc="ArchLinux Daemon Manager (Shell + Gnome GTK+ GUI) - Gives you control over services in rc.d and settings in rc.conf" +arch=('any') +license=('GPL') +url="http://aur.archlinux.org/packages.php?ID=29606" +depends=('bash' 'gtk2-perl' 'gksu' 'sed') +source=('aldm' 'aldm-gui' 'aldm.ui') +md5sums=('0c16113ad13f4e79c9b76ec22cf97206' + '6a73ae72411eda426e9f97cfa1942fdd' + 'dd2f8a1d52200756edfb34afa5a574af') + +build() { + mkdir -p ${pkgdir}/usr/bin + mkdir -p ${pkgdir}/usr/sbin + mkdir -p ${pkgdir}/usr/share/aldm-gui + + cp -f ${srcdir}/aldm ${pkgdir}/usr/sbin/ + cp -f ${srcdir}/aldm-gui ${pkgdir}/usr/bin/ + cp -f ${srcdir}/aldm.ui ${pkgdir}/usr/share/aldm-gui + + mkdir -p ${pkgdir}/usr/share/applications + + echo '[Desktop Entry] +Encoding=UTF-8 +Name=ArchLinux Daemon Manager +Comment=GTK frontend to ALDM +Comment[cs]=Grafické rozhraní pro ALDM +GenericName=System Services Manager +Type=Application +Exec=aldm-gui +Icon=server +Terminal=false +StartupNotify=false +Categories=Application;Settings;System; +' > ${pkgdir}/usr/share/applications/aldm-gui.desktop + + chmod -R 755 ${pkgdir}/ +} diff --git a/README b/README new file mode 100644 index 0000000..730a98f --- /dev/null +++ b/README @@ -0,0 +1 @@ +ArchLinux Daemon Manager (Shell + Gnome GTK+ GUI) - Gives you control over services in rc.d and settings in rc.conf diff --git a/aldm b/aldm new file mode 100755 index 0000000..87c3135 --- /dev/null +++ b/aldm @@ -0,0 +1,64 @@ +#!/bin/bash +#ArchLinux Daemon Manager + +if [ $(whoami) != "root" ]; then + echo 'You have to be root ;-P' + exit; +fi; + +rc_conf='/etc/rc.conf'; +rc_d='/etc/rc.d'; + +. "$rc_conf"; + +S=$(echo "$2" | grep -o '[^!#@]*'); #remove flags + +list() { + echo "${DAEMONS[*]}" | tr ' ' "\n"; +} + +update_conf() { + NEW="DAEMONS=(${DAEMONS[*]})"; + echo "$NEW"; + + CONF="$(cat $rc_conf)" + echo "$CONF" | sed -ne '1h;1!H;${;g;s/DAEMONS=([^)]*)/'"$NEW"'/g;p;}' > "$rc_conf"; +} + +case "$1" in + list) + list; + ;; + whatis) + if [ "$S" != '' ]; then + ls -1 /var/run/daemons/ | grep ^"$S"$ >/dev/null 2>&1 + if [ $? == 0 ]; then echo -n 'running'; else echo -n 'stopped'; fi + whatis -l -L C "$S" | grep -o -e ' - \(.*\)$' | cut -d '-' -f 2- + exit; + fi; + + ls -1 "$rc_d" | while read i; do + whatis -l -L C "$i"; + done; + ;; + enable-fg) + DAEMONS=($(list | sed "s/^\(!\|@\)$S$/$S/")); + update_conf; + ;; + enable-bg) + DAEMONS=($(list | sed "s/^!\?$S$/@$S/")); + update_conf; + ;; + disable) + DAEMONS=($(list | sed "s/^@\?$S$/!$S/")); + update_conf; + ;; + start|stop|restart) + "$rc_d/$S" "$1"; + ;; + *) + echo "usage: $0 {list|whatis|enable-fg|enable-bg|disable|start|stop|restart} [service name] + + Note that only daemons specified in $rc_conf can be manipulated - you must add them manually." +esac + diff --git a/aldm-gui b/aldm-gui new file mode 100755 index 0000000..d776119 --- /dev/null +++ b/aldm-gui @@ -0,0 +1,136 @@ +#!/usr/bin/env perl +#ArchLinux Daemon Manager Gui! by Harvie 2oo9 +use strict; +use warnings; +use utf8; +use Gtk2 qw(-init); + +if($< > 0) { + #run as root + print "You are not root! Trying GKSU...\n"; + system("gksu ".$0); + exit; +} + +my $aldm = '/usr/sbin/aldm'; + +my %iterators = {}; + +my $builder = Gtk2::Builder->new(); +$builder->add_from_file('/usr/share/aldm-gui/aldm.ui'); + +my %widgets; +foreach my $widget qw(window1 aboutdialog1 treeview1 liststore1 label2) +{ + $widgets{$widget}=$builder->get_object($widget); +} + +$builder->connect_signals( undef ); +$builder = undef; + +#create columns in treeview + my $column = Gtk2::TreeViewColumn->new_with_attributes('Daemon', Gtk2::CellRendererText->new, text => 0); + $widgets{'treeview1'}->append_column($column); + + $column = Gtk2::TreeViewColumn->new_with_attributes('Running', Gtk2::CellRendererText->new, text => 1); + $widgets{'treeview1'}->append_column($column); + + $column = Gtk2::TreeViewColumn->new_with_attributes('WhatIs', Gtk2::CellRendererText->new, text => 2); + $widgets{'treeview1'}->append_column($column); + +refresh_view(); + +$widgets{'window1'}->show(); + + +Gtk2->main(); +exit; + +sub on_window1_destroy +{ + Gtk2->main_quit(); +} + +sub on_imagemenuitem10_activate +{ + $widgets{'aboutdialog1'}->show(); +} + +sub on_aboutdialog1_close +{ + $widgets{'aboutdialog1'}->hide(); +} + +sub refresh_view +{ + #clear + #$widgets{'liststore1'}->clear(); + + #list daemons + open(my $daemon_list, "$aldm list|"); + while(<$daemon_list>) { + no warnings 'uninitialized'; + $_ =~ s/^\s+|\s+$//g; #trim + open(my $whatis, "'$aldm' whatis '$_'|"); my $w = <$whatis>; close($whatis); $w =~ s/^\s+|\s+$//g; #trim + (my $run, $w) = split(/ /,$w,2); + + #my $iter = $widgets{'liststore1'}->append(); + #$widgets{'liststore1'}->set($iter, 0 => "$_", 1=> "$run", 2 => "$w"); + + my $serv = $_; + $serv =~ s/^(!|@)//g; + + if(!defined($iterators{$serv})) { + $iterators{$serv} = $widgets{'liststore1'}->append(); + } + $widgets{'liststore1'}->set($iterators{$serv}, 0 => "$_", 1=> "$run", 2 => "$w"); + } + close($daemon_list); +} + +sub get_selected_daemon +{ + my $path = $widgets{'treeview1'}->get_selection->get_selected_rows; + my $model = $widgets{'treeview1'}->get_model; + my $iter = $model->get_iter($path); + my $str = $model->get ($iter, 0); + return $str; +} + +sub status +{ + $_[0] =~ s/^\s+|\s+$//g; #trim + $widgets{'label2'}->set_text($_[0]); +} + +sub s_system +{ + open(my $pipe, "$_[0]|"); + while(<$pipe>) { status($_); } + close($pipe); +} + +sub on_button_start_clicked { s_system "$aldm start ".get_selected_daemon(); refresh_view(); } +sub on_button_stop_clicked { s_system "$aldm stop ".get_selected_daemon(); refresh_view(); } +sub on_button_restart_clicked { s_system "$aldm restart ".get_selected_daemon(); refresh_view(); } + +sub on_button_enable_fg_clicked { + my $d = get_selected_daemon(); + system "$aldm enable-fg ".$d; + refresh_view(); + status($d." enabled on init!"); +} + +sub on_button_enable_bg_clicked { + my $d = get_selected_daemon(); + system "$aldm enable-bg ".$d; + refresh_view(); + status($d." enabled on init background!"); +} + +sub on_button_disable_clicked { + my $d = get_selected_daemon(); + system "$aldm disable ".$d; + refresh_view(); + status($d." disabled!"); +} diff --git a/aldm.ui b/aldm.ui new file mode 100644 index 0000000..41f568d --- /dev/null +++ b/aldm.ui @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + ArchLinux Daemon Manager + center + 400 + server + + + + True + vertical + + + True + + + True + 5 + 5 + 32 + server + + + False + 0 + + + + + True + ArchLinux Daemon Manager GUI +CopyLefted by: Harvie 2oo9 ( http://blog.harvie.cz/ ) + center + + + 1 + + + + + False + 0 + + + + + True + True + automatic + automatic + + + True + True + Note that only services specified in rc.conf are listed here. +You can still add more services to rc.conf as disabled with exclamation mark. + +services with ! are disabled. +services with @ will be started on background during init. +services without these signs will be started as blocking during init. + +It is NOT good idea to stop/restart services related to X server or graphical environment using this tool! + liststore1 + both + + + + + 1 + + + + + True + 3 + True + center + + + start + True + True + True + image2 + + + + False + False + 0 + + + + + stop + True + True + True + image3 + + + + False + False + 1 + + + + + restart + True + True + True + image4 + + + + False + False + 2 + + + + + enable-fg + True + True + True + image5 + + + + False + False + 3 + + + + + @enable-bg + True + True + True + image7 + + + + False + False + 4 + + + + + !disable + True + True + True + image6 + + + + False + False + 5 + + + + + False + 2 + + + + + True + + + True + 5 + Welcome to ALDM-GUI! + True + True + + + False + 0 + + + + + + + + False + 3 + + + + + + + True + gtk-media-play + + + True + gtk-media-stop + + + True + gtk-refresh + + + True + gtk-apply + + + True + gtk-cancel + + + True + gtk-apply + + -- 2.30.2