Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
29f5dab4da
10 changed files with 151 additions and 44 deletions
10
scripts/numlock
Executable file
10
scripts/numlock
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/env bash
|
||||||
|
#
|
||||||
|
## Enable numlock if no battery is detected
|
||||||
|
## Credit: https://wiki.archlinux.org/title/Activating_numlock_on_bootup#With_systemd_service
|
||||||
|
|
||||||
|
if ! compgen -G "/sys/class/power_supply/BAT*" >/dev/null; then
|
||||||
|
for tty in /dev/tty{1..6}; do
|
||||||
|
/usr/bin/setleds -D +num < "$tty"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# vim: sts=2 sw=2 ts=2
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ Usage:
|
||||||
[--eset PATH]
|
[--eset PATH]
|
||||||
[--hdclone PATH]
|
[--hdclone PATH]
|
||||||
[--extra-dir PATH]
|
[--extra-dir PATH]
|
||||||
|
[EXTRA_IMAGES...]
|
||||||
build-ufd (-h | --help)
|
build-ufd (-h | --help)
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
@ -46,22 +48,39 @@ Options:
|
||||||
-U --update Don't format device, just update
|
-U --update Don't format device, just update
|
||||||
'''
|
'''
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
MIB = 1024 ** 2
|
||||||
ISO_LABEL = f'{KIT_NAME_SHORT}_LINUX'
|
ISO_LABEL = f'{KIT_NAME_SHORT}_LINUX'
|
||||||
UFD_LABEL = f'{KIT_NAME_SHORT}_UFD'
|
UFD_LABEL = f'{KIT_NAME_SHORT}_UFD'
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
def apply_image(part_path, image_path):
|
||||||
|
"""Apply raw image to dev_path using dd."""
|
||||||
|
cmd = [
|
||||||
|
'sudo',
|
||||||
|
'dd',
|
||||||
|
'bs=4M',
|
||||||
|
f'if={image_path}',
|
||||||
|
f'of={part_path}',
|
||||||
|
]
|
||||||
|
run_program(cmd)
|
||||||
|
|
||||||
|
|
||||||
def build_ufd():
|
def build_ufd():
|
||||||
|
# pylint: disable=too-many-statements
|
||||||
"""Build UFD using selected sources."""
|
"""Build UFD using selected sources."""
|
||||||
args = docopt(DOCSTRING)
|
args = docopt(DOCSTRING)
|
||||||
if args['--debug']:
|
if args['--debug']:
|
||||||
log.enable_debug_mode()
|
log.enable_debug_mode()
|
||||||
|
if args['--update'] and args['EXTRA_IMAGES']:
|
||||||
|
std.print_warning('Extra images are ignored when updating')
|
||||||
log.update_log_path(dest_name='build-ufd', timestamp=True)
|
log.update_log_path(dest_name='build-ufd', timestamp=True)
|
||||||
try_print = std.TryAndPrint()
|
try_print = std.TryAndPrint()
|
||||||
try_print.add_error('FileNotFoundError')
|
try_print.add_error('FileNotFoundError')
|
||||||
try_print.catch_all = False
|
try_print.catch_all = False
|
||||||
try_print.verbose = True
|
|
||||||
try_print.indent = 2
|
try_print.indent = 2
|
||||||
|
try_print.verbose = True
|
||||||
|
try_print.width = 64
|
||||||
|
|
||||||
# Show header
|
# Show header
|
||||||
std.print_success(KIT_NAME_FULL)
|
std.print_success(KIT_NAME_FULL)
|
||||||
|
|
@ -71,7 +90,8 @@ def build_ufd():
|
||||||
# Verify selections
|
# Verify selections
|
||||||
ufd_dev = verify_ufd(args['--ufd-device'])
|
ufd_dev = verify_ufd(args['--ufd-device'])
|
||||||
sources = verify_sources(args, SOURCES)
|
sources = verify_sources(args, SOURCES)
|
||||||
show_selections(args, sources, ufd_dev, SOURCES)
|
extra_images = [io.case_insensitive_path(i) for i in args['EXTRA_IMAGES']]
|
||||||
|
show_selections(args, sources, ufd_dev, SOURCES, extra_images)
|
||||||
if not args['--force']:
|
if not args['--force']:
|
||||||
confirm_selections(update=args['--update'])
|
confirm_selections(update=args['--update'])
|
||||||
|
|
||||||
|
|
@ -88,6 +108,7 @@ def build_ufd():
|
||||||
function=create_table,
|
function=create_table,
|
||||||
dev_path=ufd_dev,
|
dev_path=ufd_dev,
|
||||||
use_mbr=args['--use-mbr'],
|
use_mbr=args['--use-mbr'],
|
||||||
|
images=args['EXTRA_IMAGES'],
|
||||||
)
|
)
|
||||||
try_print.run(
|
try_print.run(
|
||||||
message='Setting boot flag...',
|
message='Setting boot flag...',
|
||||||
|
|
@ -135,6 +156,18 @@ def build_ufd():
|
||||||
overwrite=True,
|
overwrite=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Apply extra images
|
||||||
|
if not args['--update']:
|
||||||
|
std.print_standard(' ')
|
||||||
|
std.print_info('Apply Extra Images')
|
||||||
|
for part_num, image_path in enumerate(extra_images):
|
||||||
|
try_print.run(
|
||||||
|
message=f'Applying {image_path.name}...',
|
||||||
|
function=apply_image,
|
||||||
|
part_path=f'{str(ufd_dev_first_partition)[:-1]}{part_num+2}',
|
||||||
|
image_path=image_path,
|
||||||
|
)
|
||||||
|
|
||||||
# Update boot entries
|
# Update boot entries
|
||||||
std.print_standard(' ')
|
std.print_standard(' ')
|
||||||
std.print_info('Boot Setup')
|
std.print_info('Boot Setup')
|
||||||
|
|
@ -229,17 +262,41 @@ def copy_source(source, items, overwrite=False):
|
||||||
raise FileNotFoundError('One or more items not found')
|
raise FileNotFoundError('One or more items not found')
|
||||||
|
|
||||||
|
|
||||||
def create_table(dev_path, use_mbr=False):
|
def create_table(dev_path, use_mbr=False, images=None):
|
||||||
"""Create GPT or DOS partition table."""
|
"""Create GPT or DOS partition table."""
|
||||||
cmd = [
|
cmd = [
|
||||||
'sudo',
|
'sudo',
|
||||||
'parted', dev_path,
|
'parted', dev_path,
|
||||||
'--script',
|
'--script', '--',
|
||||||
'--',
|
|
||||||
'mklabel', 'msdos' if use_mbr else 'gpt',
|
'mklabel', 'msdos' if use_mbr else 'gpt',
|
||||||
'mkpart', 'primary', 'fat32', '4MiB',
|
|
||||||
'-1s' if use_mbr else '-4MiB',
|
|
||||||
]
|
]
|
||||||
|
if images:
|
||||||
|
images = [os.stat(i_path).st_size for i_path in images]
|
||||||
|
else:
|
||||||
|
images = []
|
||||||
|
start = MIB
|
||||||
|
end = -1
|
||||||
|
|
||||||
|
# Calculate partition sizes
|
||||||
|
## Align all partitions using 1MiB boundaries for 4K alignment
|
||||||
|
## NOTE: Partitions are aligned to 1 MiB boundaries to match parted's usage
|
||||||
|
## NOTE 2: Crashing if dev_size can't be set is fine since it's necessary
|
||||||
|
dev_size = get_block_device_size(dev_path)
|
||||||
|
part_sizes = [math.ceil(i/MIB) * MIB for i in images]
|
||||||
|
main_size = dev_size - start*2 - sum(part_sizes)
|
||||||
|
main_size = math.floor(main_size/MIB) * MIB
|
||||||
|
images.insert(0, main_size)
|
||||||
|
part_sizes.insert(0, main_size)
|
||||||
|
|
||||||
|
# Build cmd
|
||||||
|
for part, real in zip(part_sizes, images):
|
||||||
|
end = start + real
|
||||||
|
cmd.append(
|
||||||
|
f'mkpart primary {"fat32" if start==MIB else "hfs+"} {start}B {end-1}B',
|
||||||
|
)
|
||||||
|
start += part
|
||||||
|
|
||||||
|
# Run cmd
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -274,6 +331,25 @@ def format_partition(dev_path, label):
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def get_block_device_size(dev_path):
|
||||||
|
"""Get block device size via lsblk, returns int."""
|
||||||
|
cmd = [
|
||||||
|
'lsblk',
|
||||||
|
'--bytes',
|
||||||
|
'--nodeps',
|
||||||
|
'--noheadings',
|
||||||
|
'--output',
|
||||||
|
'size',
|
||||||
|
dev_path,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Run cmd
|
||||||
|
proc = run_program(cmd)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return int(proc.stdout.strip())
|
||||||
|
|
||||||
|
|
||||||
def get_uuid(path):
|
def get_uuid(path):
|
||||||
"""Get filesystem UUID via findmnt, returns str."""
|
"""Get filesystem UUID via findmnt, returns str."""
|
||||||
cmd = [
|
cmd = [
|
||||||
|
|
@ -365,7 +441,7 @@ def remove_arch():
|
||||||
shutil.rmtree(io.case_insensitive_path('/mnt/UFD/arch'))
|
shutil.rmtree(io.case_insensitive_path('/mnt/UFD/arch'))
|
||||||
|
|
||||||
|
|
||||||
def show_selections(args, sources, ufd_dev, ufd_sources):
|
def show_selections(args, sources, ufd_dev, ufd_sources, extra_images):
|
||||||
"""Show selections including non-specified options."""
|
"""Show selections including non-specified options."""
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
|
|
@ -378,9 +454,15 @@ def show_selections(args, sources, ufd_dev, ufd_sources):
|
||||||
[f' {label+":":<18}', 'Not Specified'],
|
[f' {label+":":<18}', 'Not Specified'],
|
||||||
[None, 'YELLOW'],
|
[None, 'YELLOW'],
|
||||||
)
|
)
|
||||||
std.print_standard(' ')
|
|
||||||
|
# Extra images
|
||||||
|
if extra_images:
|
||||||
|
print(f' {"Extra Images:":<18} {extra_images[0]}')
|
||||||
|
for image in extra_images[1:]:
|
||||||
|
print(f' {" ":<18} {image}')
|
||||||
|
|
||||||
# Destination
|
# Destination
|
||||||
|
std.print_standard(' ')
|
||||||
std.print_info('Destination')
|
std.print_info('Destination')
|
||||||
cmd = [
|
cmd = [
|
||||||
'lsblk', '--nodeps', '--noheadings', '--paths',
|
'lsblk', '--nodeps', '--noheadings', '--paths',
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,12 @@ from wk.exe import (
|
||||||
popen_program,
|
popen_program,
|
||||||
wait_for_procs,
|
wait_for_procs,
|
||||||
)
|
)
|
||||||
from wk.io import delete_folder, get_path_obj, rename_item
|
from wk.io import (
|
||||||
|
delete_folder,
|
||||||
|
get_path_obj,
|
||||||
|
non_clobber_path,
|
||||||
|
rename_item,
|
||||||
|
)
|
||||||
from wk.kit.tools import (
|
from wk.kit.tools import (
|
||||||
ARCH,
|
ARCH,
|
||||||
download_tool,
|
download_tool,
|
||||||
|
|
@ -1410,12 +1415,11 @@ def reset_windows_policies():
|
||||||
def reset_windows_updates():
|
def reset_windows_updates():
|
||||||
"""Reset Windows Updates."""
|
"""Reset Windows Updates."""
|
||||||
system_root = os.environ.get('SYSTEMROOT', 'C:/Windows')
|
system_root = os.environ.get('SYSTEMROOT', 'C:/Windows')
|
||||||
|
src_path = f'{system_root}/SoftwareDistribution'
|
||||||
|
dest_path = non_clobber_path(f'{src_path}.old')
|
||||||
try:
|
try:
|
||||||
rename_item(
|
rename_item(src_path, dest_path)
|
||||||
f'{system_root}/SoftwareDistribution',
|
delete_folder(dest_path, force=True)
|
||||||
f'{system_root}/SoftwareDistribution.old',
|
|
||||||
)
|
|
||||||
delete_folder(f'{system_root}/SoftwareDistribution.old', force=True)
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# Ignore
|
# Ignore
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -701,40 +701,25 @@ def bytes_to_string(size, decimals=0, use_binary=True):
|
||||||
decimals,
|
decimals,
|
||||||
use_binary,
|
use_binary,
|
||||||
)
|
)
|
||||||
|
scale = 1024 if use_binary else 1000
|
||||||
size = float(size)
|
size = float(size)
|
||||||
abs_size = abs(size)
|
suffix = ' ' if use_binary else ' '
|
||||||
|
units = list('KMGTPEZY')
|
||||||
# Set scale
|
|
||||||
scale = 1000
|
|
||||||
suffix = 'B'
|
|
||||||
if use_binary:
|
|
||||||
scale = 1024
|
|
||||||
suffix = 'iB'
|
|
||||||
|
|
||||||
# Convert to sensible units
|
# Convert to sensible units
|
||||||
if abs_size >= scale ** 5:
|
while units:
|
||||||
size /= scale ** 5
|
if abs(size) < scale:
|
||||||
units = 'P' + suffix
|
break
|
||||||
elif abs_size >= scale ** 4:
|
size /= scale
|
||||||
size /= scale ** 4
|
suffix = units.pop(0)
|
||||||
units = 'T' + suffix
|
size_str = (
|
||||||
elif abs_size >= scale ** 3:
|
f'{size:0.{decimals}f} {suffix}'
|
||||||
size /= scale ** 3
|
f'{"iB" if use_binary and suffix.strip() else "B"}'
|
||||||
units = 'G' + suffix
|
)
|
||||||
elif abs_size >= scale ** 2:
|
|
||||||
size /= scale ** 2
|
|
||||||
units = 'M' + suffix
|
|
||||||
elif abs_size >= scale ** 1:
|
|
||||||
size /= scale ** 1
|
|
||||||
units = 'K' + suffix
|
|
||||||
else:
|
|
||||||
size /= scale ** 0
|
|
||||||
units = f' {" " if use_binary else ""}B'
|
|
||||||
size = f'{size:0.{decimals}f} {units}'
|
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
LOG.debug('string: %s', size)
|
LOG.debug('string: %s', size_str)
|
||||||
return size
|
return size_str
|
||||||
|
|
||||||
|
|
||||||
def choice(choices, prompt='答えろ!'):
|
def choice(choices, prompt='答えろ!'):
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ mkvtoolnix-cli
|
||||||
mpv
|
mpv
|
||||||
noto-fonts
|
noto-fonts
|
||||||
noto-fonts-cjk
|
noto-fonts-cjk
|
||||||
|
numlockx
|
||||||
openbox-patched
|
openbox-patched
|
||||||
otf-font-awesome-4
|
otf-font-awesome-4
|
||||||
papirus-icon-theme
|
papirus-icon-theme
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
/etc/systemd/system/numlock.service
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=numlock
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/local/bin/numlock
|
||||||
|
StandardInput=tty
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
#
|
#
|
||||||
## Start desktop apps based on WM
|
## Start desktop apps based on WM
|
||||||
|
|
||||||
|
# Numlock
|
||||||
|
if ! compgen -G "/sys/class/power_supply/BAT*" >/dev/null; then
|
||||||
|
numlockx &
|
||||||
|
fi
|
||||||
|
|
||||||
# Start common apps
|
# Start common apps
|
||||||
#picom --backend xrender --xrender-sync --xrender-sync-fence &
|
#picom --backend xrender --xrender-sync --xrender-sync-fence &
|
||||||
picom --daemon || picom --daemon --no-vsync
|
picom --daemon || picom --daemon --no-vsync
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ echo "Installing Gnuplot..."
|
||||||
curl -Lo gnuplot.pkg https://ariadne.ms.northwestern.edu/Download/Gnuplot/gnuplot-5.4.1.pkg
|
curl -Lo gnuplot.pkg https://ariadne.ms.northwestern.edu/Download/Gnuplot/gnuplot-5.4.1.pkg
|
||||||
sudo installer -pkg gnuplot.pkg -target /
|
sudo installer -pkg gnuplot.pkg -target /
|
||||||
|
|
||||||
|
# memtest
|
||||||
|
echo "Installing memtest..."
|
||||||
|
curl -Lo /usr/local/bin/memtest https://github.com/Vavius/memtest/raw/8aa02c8c34db8dd00f4470e482dace7eaff265c7/memtest
|
||||||
|
|
||||||
# mprime
|
# mprime
|
||||||
echo "Installing mprime..."
|
echo "Installing mprime..."
|
||||||
if [[ "${OS_VERSION:3:2}" -ge "15" ]]; then
|
if [[ "${OS_VERSION:3:2}" -ge "15" ]]; then
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,11 @@ rsync -aS /usr/share/zsh "${WK_PATH}/usr/share"/
|
||||||
rsync -aS /usr/local/share/zsh "${WK_PATH}/usr/local/share"/
|
rsync -aS /usr/local/share/zsh "${WK_PATH}/usr/local/share"/
|
||||||
sed -Ei '' 's!^(root.*)/bin/sh!\1/bin/zsh!' "${WK_PATH}/etc/passwd"
|
sed -Ei '' 's!^(root.*)/bin/sh!\1/bin/zsh!' "${WK_PATH}/etc/passwd"
|
||||||
|
|
||||||
|
# memtest
|
||||||
|
sudo mv -nv "${WK_PATH}/usr/local/bin/memtest" "${WK_PATH}/usr/sbin"/
|
||||||
|
sudo chown 0:0 "${WK_PATH}/usr/sbin/memtest"
|
||||||
|
sudo chmod 755 "${WK_PATH}/usr/sbin/memtest"
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
cp -a ../linux/known_networks "${WK_PATH}/.known_networks"
|
cp -a ../linux/known_networks "${WK_PATH}/.known_networks"
|
||||||
cp -a /usr/bin/rsync "${WK_PATH}/usr/bin"/
|
cp -a /usr/bin/rsync "${WK_PATH}/usr/bin"/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue