179 lines
4.8 KiB
Bash
Executable File
179 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
#
|
|
# Copyright (c) 2016 Dyne.org Foundation
|
|
# libdevuansdk is written and maintained by
|
|
# Jaromil <jaromil@dyne.org>
|
|
# KatolaZ <katolaz@freaknet.org>
|
|
# parazyd <parazyd@dyne.org>
|
|
#
|
|
# This file is part of libdevuansdk
|
|
#
|
|
# This source code is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This software is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this source code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
## Helper functions that make your life easier
|
|
|
|
escalate() {
|
|
fn escalate $@
|
|
local user="$1"
|
|
local cmnd="$2"
|
|
req=(user cmnd)
|
|
ckreq || return 1
|
|
|
|
if isfound sudo; then
|
|
sudo -E -u ${user} ${=cmnd}
|
|
else
|
|
su -c "${=cmnd}" ${user}
|
|
fi
|
|
}
|
|
|
|
findloopmapp() {
|
|
fn findloopmapp
|
|
req=(imgpath imgname workdir)
|
|
ckreq || return 1
|
|
|
|
pushd ${workdir}
|
|
loopdevice=`sudo losetup -f --show ${imgname}`
|
|
mappdevice=`sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
|
|
func "Loop device: ::1 loopdev::" $loopdevice
|
|
func "Mapper device: ::1 mappdev::" $mappdevice
|
|
|
|
silly sleep
|
|
|
|
mappdevice="/dev/mapper/${mappdevice}"
|
|
bootpart=${mappdevice}p1
|
|
rootpart=${mappdevice}p2
|
|
|
|
popd
|
|
}
|
|
|
|
mountdevprocsys() {
|
|
fn mountdevprocsys $@
|
|
local mntdir="$1"
|
|
req=(mntdir)
|
|
ckreq || return 1
|
|
|
|
sudo mount -o bind /sys ${mntdir}/sys && act "mounted /sys in $mntdir"
|
|
sudo mount -t proc proc ${mntdir}/proc && act "mounted /proc in $mntdir"
|
|
sudo mount -o bind /dev ${mntdir}/dev && act "mounted /dev in $mntdir"
|
|
sudo mount -o bind /dev/pts ${mntdir}/dev/pts && act "mounted /dev/pts $mntdir"
|
|
}
|
|
|
|
umountdevprocsys() {
|
|
fn umountdevprocsys $@
|
|
local mntdir="$1"
|
|
req=(mntdir)
|
|
ckreq || return 1
|
|
|
|
sudo umount ${mntdir}/dev/pts && act "unmounted /dev/pts in $mntdir" && sleep 2
|
|
sudo umount ${mntdir}/dev && act "unmounted /dev in $mntdir" && sleep 2
|
|
sudo umount ${mntdir}/proc && act "unmounted /proc in $mntdir" && sleep 2
|
|
sudo umount ${mntdir}/sys && act "unmounted /sys in $mntdir" && sleep 2
|
|
}
|
|
|
|
aptautostart() {
|
|
fn aptautostart $@
|
|
local watdo="$1"
|
|
local wheredo="$2"
|
|
req=(watdo wheredo)
|
|
|
|
case $watdo in
|
|
on)
|
|
aptautostart printon | sudo tee ${wheredo}/aptautostart.sh
|
|
sudo chmod +x ${wheredo}/aptautostart.sh
|
|
sudo chroot ${wheredo} /aptautostart.sh
|
|
;;
|
|
off)
|
|
aptautostart printoff | sudo tee ${wheredo}/aptautostart.sh
|
|
sudo chmod +x ${wheredo}/aptautostart.sh
|
|
sudo chroot ${wheredo} /aptautostart.sh
|
|
;;
|
|
printon)
|
|
cat << EOF
|
|
#!/bin/sh
|
|
rm -f /usr/sbin/policy-rc.d
|
|
rm -f /usr/sbin/invoke-rc.d
|
|
dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
|
|
rm -f /aptautostart.sh
|
|
EOF
|
|
;;
|
|
printoff)
|
|
cat << EOF
|
|
#!/bin/sh
|
|
dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
|
|
cp /bin/true /usr/sbin/invoke-rc.d
|
|
echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
|
|
chmod +x /usr/sbin/policy-rc.d
|
|
EOF
|
|
;;
|
|
*)
|
|
error "Please pass a correct argument (on/off)"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
silly() {
|
|
fn silly $@
|
|
local arg1="$1"
|
|
local arg2="$2"
|
|
|
|
# cheers mailpile!
|
|
funneh=("do not think of purple hippos"
|
|
"increasing entropy & scrambling bits"
|
|
"indexing kittens..."
|
|
"patching bugs..."
|
|
"spinning violently around the y-axis"
|
|
"warming up particle accelerator"
|
|
"this server is powered by a lemon and two electrodes"
|
|
"becoming self-aware"
|
|
"BCC-ing ALL THE SPIES!"
|
|
"all of your config settings & passwords are encrypted with AES-256"
|
|
"the most common e-mail password is 123456, hopefully yours is different"
|
|
"good things come to those who wait"
|
|
"Make Free Software and be happy"
|
|
"We like volcanos, do you like volcanos?"
|
|
"Crossing out swear words..."
|
|
"Informing David Cameron of suspicious ac^H^H^H ... naaah :)"
|
|
"Abandon all hope, ye who enter here"
|
|
"Compiling bullshit bingo grid..."
|
|
"Estimating chance of asteroid hitting Earth"
|
|
"Applying coupons..."
|
|
"Backing up the entire Internet..."
|
|
"Making you wait for no reason"
|
|
"Doing nothing"
|
|
"Pay no attention to the man behind the curtain"
|
|
"You are great just the way you are"
|
|
"Supplying monkeys with typewriters"
|
|
"Swapping time and space"
|
|
"Self potato"
|
|
"Hey, there is some Nigerian prince here who wants to give you twenty million dollars..."
|
|
"A million hamsters are spinning their wheels right now")
|
|
|
|
local rnd=`shuf -i1-30 -n 1`
|
|
act "${funneh[$rnd]}"
|
|
|
|
[[ arg1 == "sleep" ]] && sleep $arg2
|
|
}
|
|
|
|
check_executable() {
|
|
fn check_executable $@
|
|
progname=$1
|
|
|
|
if [[ `which ${progname} | grep "not found" | wc -l` -ge 1 ]]; then
|
|
return 0;
|
|
else
|
|
return 1;
|
|
fi
|
|
|
|
}
|