libdevuansdk/zlibs/helpers

125 lines
3.9 KiB
Bash

#!/usr/bin/env zsh
# Copyright (c) 2016 Dyne.org Foundation
# libdevuansdk is maintained by Ivan J. <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
build_image_dist() {
fn build_image_dist
req=(arch size parted_boot parted_root parted_type)
req+=(workdir strapdir image_name)
ckreq || return 1
notice "building complete dist image"
act "$image_name"
bootstrap_complete_base || zerr
image_prepare_raw || zerr
image_partition_raw_${parted_type} || zerr
build_kernel_${arch} || zerr
rsync_to_raw_image || zerr
image_pack_dist || zerr
}
devprocsys() {
fn devprocsys "$@"
local watdo="$1"
local werdo="$2"
req=(watdo werdo)
ckreq || return 1
if [[ $watdo = mount ]]; then
sudo mount -o bind /sys $werdo/sys && act "mounted sys" && \
sudo mount -t proc proc $werdo/proc && act "mounted proc" && \
sudo mount -o bind /dev $werdo/dev && act "mounted dev" && \
sudo mount -o bind /dev/pts $werdo/dev/pts && act "mounted devpts" && \
return 0
elif [[ $watdo = umount ]]; then
sudo umount $werdo/dev/pts && act "umounted devpts" && sleep 1 && \
sudo umount $werdo/dev && act "umounted dev" && sleep 1 && \
sudo umount $werdo/proc && act "umounted proc" && sleep 1 && \
sudo umount $werdo/sys && act "umounted sys" && sleep 1 && \
return 0
fi
return 1
}
findloopmapp() {
fn findloopmapp
req=(workdir image_name)
ckreq || return 1
notice "finding a free loopdevice"
loopdevice=$(sudo losetup -f --show $workdir/${image_name}.img)
mappdevice=$(sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | sed 1q)
func "loopdevice: $loopdevice"
func "mappdevice: $mappdevice"
silly sleep 4
}
qemu_install_user() {
fn qemu_install_user
req=(qemu_bin strapdir)
ckreq || return 1
notice "installing qemu-user-static"
sudo cp $qemu_bin $strapdir/usr/bin
}
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 AES256"
"the most common 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"
"god is porco"
"A million hamsters are spinning their wheels right now"
)
local rnd=$(shuf -i1-30 -n 1)
act "${funneh[$rnd]}" ; [[ $arg1 = sleep ]] && sleep $arg2
}